private void setupTraceLog(HttpContext httpContext, String queue, AccessLog accessLog) throws IOException { String clientIp = httpContext.getClientIp(); // DBへのアクセスログ採取有無 if (!isLogging(clientIp, "accessDb." + queue)) { return; } // DBに記録する accessLog.insert(); // リクエストStreamのpeek処理 if (isLogging(clientIp, "accessTrace.request." + queue)) { PeekStream requestPeeker = accessLog.setupPeekRequest(); httpContext.peekRequest(requestPeeker); context.enque(requestPeeker, Config.QUEUE_PEEK); // 既に受け取っているヘッダ部分をPeekStreamに流し込む HttpParser requestParser = httpContext.getRequestParser(); OutputStream os = requestPeeker.getPeekOutputStream(); requestParser.writeSeriarizeHeader(os); } // レスポンスStreamのpeek処理 if (isLogging(clientIp, "accessTrace.response." + queue)) { PeekStream responsePeeker = accessLog.setupPeekResponse(); httpContext.peekResponse(responsePeeker); context.enque(responsePeeker, Config.QUEUE_PEEK); } }
// WWW-Authenticate: Basic realm="FIND2",Basicはreverseの事を考えると使えない // Authorization: Basic XXXbase64XXX // "Proxy-Authenticate", "Basic Realm=\"myProxy\"",proxyの場合こちらを使う // Proxy-Authorization: Basic XXXbase64XXX // Response Queueに依頼する前にレスポンスを返却したい場合 private void responseDirect(HttpContext httpContext, String statusCode, String text) { httpContext.registerResponse(statusCode, text); httpContext.startResponse(); try { httpContext.responseDirect(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } context.enque(httpContext, Config.QUEUE_CLOSE); }
/* (non-Javadoc) * @see naru.queuelet.Queuelet#service(java.lang.Object) */ public boolean service(Object req) { HttpContext httpContext = null; if (req instanceof Socket) { Socket socket = (Socket) req; // 指定IPからのリクエストかどうかをチェック if (checkIp(socket) == false) { return false; } httpContext = (HttpContext) context.deque(Config.QUEUE_HTTPCONTEXT_POOL); httpContext.setSocket(socket); } else { // KeepAliveを実装する時はこちら httpContext = (HttpContext) req; } // 処理の起点がaccessLogの中に採られる AccessLog accessLog = (AccessLog) context.deque(Config.QUEUE_ACCESSLOG_POOL); httpContext.setupAccessLog(accessLog); boolean parseHeader = false; try { parseHeader = httpContext.parseRequestHeader(); } catch (IOException e) { // 不当リクエスト logger.error("fail to parse Request.", e); } catch (Throwable t) { // java.nio.channels.ClosedSelectorExceptionが発生したりする logger.error("fail to parse Request.!!", t); } if (!parseHeader) { context.enque(httpContext, Config.QUEUE_CLOSE); return false; } MappingEntry entry = mappingQueue(httpContext); if (entry == null) { logger.warn("fail to mapping.URL:" + httpContext.getRequestUri()); responseDirect(httpContext, "404", "failt to mapping." + httpContext.getRequestUri()); return false; } String queue = entry.getQueue(); // 一連streamの初期化 try { setupTraceLog(httpContext, queue, accessLog); } catch (IOException e) { // streamの初期化に失敗、レスポンスもできない logger.error("fail to setupAccessTrace", e); responseDirect(httpContext, "404", "failt to accesslog." + httpContext.getRequestUri()); return false; } // 以降普通にレスポンスできる // response予約 context.enque(httpContext, Config.QUEUE_RESPONSE); entry = authentication(httpContext, entry); if (entry == null) { return false; } accessLog.setMappingSource(entry.getSourcePath()); accessLog.setMappingDestination(entry.getDestination()); // response作成依頼(認証時にqueueが変更されている可能性がある) context.enque(httpContext, entry.getQueue()); return true; }
public void writable(SocketChannel channel) { ASyncIOIf ioif = popChannel(channel); context.enque(ioif, writeQueue); }
public void readable(SocketChannel channel) { ASyncIOIf ioif = popChannel(channel); context.enque(ioif, readQueue); }