/** * @param request * @param response @TODO refactor and optimize code for initializing handler */ public void doService(HttpServletRequest request, HttpServletResponse response) { if (response.isCommitted()) { LOG.logWarning("The response object is already committed!"); } long startTime = System.currentTimeMillis(); address = request.getRequestURL().toString(); String service = null; try { OGCWebServiceRequest ogcRequest = OGCRequestFactory.create(request); LOG.logInfo( StringTools.concat( 500, "Handling request '", ogcRequest.getId(), "' from '", request.getRemoteAddr(), "' to service: '", ogcRequest.getServiceName(), "'")); // get service from request service = ogcRequest.getServiceName().toUpperCase(); // get handler instance ServiceDispatcher handler = ServiceLookup.getInstance().getHandler(service, request.getRemoteAddr()); // dispatch request to specific handler handler.perform(ogcRequest, response); } catch (OGCWebServiceException e) { LOG.logError(e.getMessage(), e); sendException(response, e, request, service); } catch (ServiceException e) { if (e.getNestedException() instanceof OGCWebServiceException) { sendException(response, (OGCWebServiceException) e.getNestedException(), request, service); } else { sendException( response, new OGCWebServiceException(this.getClass().getName(), e.getMessage()), request, service); } LOG.logError(e.getMessage(), e); } catch (Exception e) { sendException( response, new OGCWebServiceException(this.getClass().getName(), e.getMessage()), request, service); LOG.logError(e.getMessage(), e); } if (LOG.isDebug()) { LOG.logDebug( "OGCServletController: request performed in " + Long.toString(System.currentTimeMillis() - startTime) + " milliseconds."); } }
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpMessage msg) throws Exception { // 1 // Request header 처리 if (msg instanceof HttpRequest) { // 2 this.request = (HttpRequest) msg; // 3 if (HttpHeaders.is100ContinueExpected(request)) { send100Continue(ctx); } HttpHeaders headers = request.headers(); // 4 if (!headers.isEmpty()) { for (Map.Entry<String, String> h : headers) { String key = h.getKey(); if (usingHeader.contains(key)) { // 5 reqData.put(key, h.getValue()); // 6 } } } reqData.put("REQUEST_URI", request.getUri()); // 7 reqData.put("REQUEST_METHOD", request.getMethod().name()); // 8 } if (msg instanceof HttpContent) { // 9 HttpContent httpContent = (HttpContent) msg; // 10 ByteBuf content = httpContent.content(); // 11 if (msg instanceof LastHttpContent) { // 12 System.out.println("LastHttpContent message received!!" + request.getUri()); LastHttpContent trailer = (LastHttpContent) msg; readPostData(); // 13 ApiRequest service = ServiceDispatcher.dispatch(reqData); // 14 try { service.executeService(); // 15 apiResult = service.getApiResult(); // 16 } finally { reqData.clear(); } if (!writeResponse(trailer, ctx)) { // 17 ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } reset(); } } }
private GenericDispatcher(String name, Delegator delegator) { ClassLoader loader; try { loader = Thread.currentThread().getContextClassLoader(); } catch (SecurityException e) { loader = this.getClass().getClassLoader(); } this.name = name; this.dispatcher = ServiceDispatcher.getInstance(delegator); DispatchContext ctx = new DispatchContext(name, loader, this); this.dispatcher.register(ctx); this.ctx = ctx; if (Debug.verboseOn()) Debug.logVerbose("[GenericDispatcher] : Created Dispatcher for: " + name, module); }
@Override public LocalDispatcher createLocalDispatcher(String name, Delegator delegator) { if (UtilValidate.isEmpty(name)) { throw new IllegalArgumentException( "The name of a LocalDispatcher cannot be a null or empty String"); } // attempts to retrieve an already registered DispatchContext with the name "name" LocalDispatcher dispatcher = ServiceDispatcher.getLocalDispatcher(name, delegator); // if not found then create a new GenericDispatcher object; the constructor will also register a // new DispatchContext in the ServiceDispatcher with name "dispatcherName" if (dispatcher == null) { dispatcher = new GenericDispatcher(name, delegator); } return dispatcher; }