/**
   * @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.");
    }
  }
示例#2
0
  /**
   * Performs the passed OGCWebServiceRequest by accessing service from the pool and passing the
   * request to it
   *
   * @param request the incoming web service request
   * @param httpResponse the outgoing web serivce response
   * @throws ServiceException
   * @throws OGCWebServiceException
   */
  public void perform(OGCWebServiceRequest request, HttpServletResponse httpResponse)
      throws ServiceException, OGCWebServiceException {

    LOG.entering();

    LOG.logDebug(StringTools.concat(200, "Performing request: ", request.toString()));

    OGCWebService service = WPVServiceFactory.createInstance();

    try {
      Object response = service.doService(request);
      if (response instanceof WPVSCapabilities) {
        sendGetCapabilitiesResponse(httpResponse, (WPVSCapabilities) response);
      } else if (response instanceof GetViewResponse) {
        sendGetViewResponse(httpResponse, (GetViewResponse) response);
      } else {
        String s = (response == null ? "null response object" : response.getClass().getName());
        // this is not really nice...because excepts get cought later on below
        throw new OGCWebServiceException(
            getClass().getName(), StringTools.concat(200, "Unknown response class: '", s, "'."));
      }
    } catch (OGCWebServiceException e) {

      LOG.logError("Error performing WPVFS request.", e);
      if (request instanceof GetView
          && ((GetView) request).getExceptionFormat().equals("INIMAGE")) {
        sendExceptionImage(httpResponse, e, (GetView) request);

      } else {
        sendException(httpResponse, e);
      }
    }

    LOG.exiting();
  }