/* -------------------- AsyncRequestHandler Interface --------------------- */
  public void handle(Message request, Response response) throws Exception {
    if (req_handler != null) {
      if (req_handler instanceof AsyncRequestHandler)
        ((AsyncRequestHandler) req_handler).handle(request, response);
      else {
        Object retval = req_handler.handle(request);
        if (response != null) response.send(retval, false);
      }
      return;
    }

    Object retval = handle(request);
    if (response != null) response.send(retval, false);
  }
Beispiel #2
0
  /** getting the request from the web and handling it. */
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/xml");
    // to be sure it isn't cached
    response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
    response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
    response.addHeader("Cache-Control", "post-check=0, pre-check=0");
    response.setHeader("Pragma", "no-cache");

    String rawRequest = request.getParameter(WebConstants.REQUEST);
    int requestType = -1;
    if (rawRequest == null || rawRequest.trim().length() == 0) {
      requestType = 0;
    } else
      try {
        requestType = Integer.parseInt((String) rawRequest);
      } catch (Exception e) {
        logger.debug(e.getMessage(), e);
        requestType = -1;
      }
    StringBuilder sb = new StringBuilder("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n");
    response.getWriter().write(sb.toString());
    RequestHandler handler;
    if (logger.isDebugEnabled()) logger.debug("Received a request with code : " + requestType);

    switch (requestType) {
      case 0: // default case pointing to the /org.openiot.gsn
        handler = new ContainerInfoHandler();
        if (handler.isValid(request, response)) handler.handle(request, response);
        break;
      case REQUEST_GML: // case pointing to gml (v2) output
        handler = new GMLHandler();
        if (handler.isValid(request, response)) handler.handle(request, response);
        break;
      case REQUEST_ONE_SHOT_QUERY:
        handler = new OneShotQueryHandler();
        if (handler.isValid(request, response)) handler.handle(request, response);
        break;
      case REQUEST_ONE_SHOT_QUERY_WITH_ADDRESSING:
        handler = new OneShotQueryWithAddressingHandler();
        if (handler.isValid(request, response)) handler.handle(request, response);
        break;
      case REQUEST_OUTPUT_FORMAT:
        handler = new OutputStructureHandler();
        if (handler.isValid(request, response)) handler.handle(request, response);
        break;
      case REQUEST_ADDRESSING:
        handler = new AddressingReqHandler();
        if (handler.isValid(request, response)) handler.handle(request, response);
        break;
      default:
        response.sendError(UNSUPPORTED_REQUEST_ERROR, "The requested operation is not supported.");
        break;
    }
  }
 /* ------------------------ RequestHandler Interface ---------------------- */
 public Object handle(Message msg) throws Exception {
   if (req_handler != null) return req_handler.handle(msg);
   return null;
 }