示例#1
0
  protected void doCommon(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
    try {
      if (log.isDebugEnabled()) log.debug(HttpUtils.fmtRequest(httpRequest));

      // getRequestURL is the exact string used by the caller in the request.
      // Internally, it's the "request URI" that names the service

      // String requestURL = httpRequest.getRequestURL().toString() ;
      String uri = httpRequest.getRequestURI();

      if (uri.length() > urlLimit) {
        httpResponse.setStatus(HttpServletResponse.SC_REQUEST_URI_TOO_LONG);
        return;
      }

      String serviceURI = chooseServiceURI(uri, httpRequest);
      serviceURI = Service.canonical(serviceURI);

      String sender = httpRequest.getRemoteAddr();
      log.info("[" + sender + "] Service URI = <" + serviceURI + ">");

      // MIME-Type
      String contentType = httpRequest.getContentType();

      //            if ( Joseki.contentSPARQLUpdate.equals(contentType) ||
      //                Joseki.contentSPARQLUpdate_X.equals(contentType) )
      //            {}

      Request request = setupRequest(serviceURI, httpRequest);
      request.setParam(Joseki.VERB, httpRequest.getMethod());

      Response response = new ResponseHttp(request, httpRequest, httpResponse);
      Dispatcher.dispatch(serviceURI, request, response);
    } catch (Exception ex) {
      try {
        log.warn("Internal server error", ex);
        //                httpResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR) ;
        //                httpResponse.flushBuffer() ;
        //                httpResponse.getWriter().close() ;
        httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      } catch (Exception e) {
      }
    }
  }
示例#2
0
  public static boolean isHTMLForm(HttpServletRequest httpRequest) {
    String s = httpRequest.getContentType();
    if (s == null) return false;

    AcceptItem aItem = new AcceptItem(s);
    String t1 = aItem.getType();
    String t2 = aItem.getSubType();

    return (t1.equalsIgnoreCase("application") && t2.equalsIgnoreCase("x-www-form-urlencoded"));
  }
示例#3
0
  // ------------------------------------------
  public static String chooseServiceURI(String uri, HttpServletRequest httpRequest) {
    String serviceURI = uri;
    String contextPath = httpRequest.getContextPath();

    if (contextPath != null && contextPath.length() > 0)
      serviceURI = serviceURI.substring(contextPath.length());

    String servletPath = httpRequest.getServletPath();

    // Suggested by Frank Hartman: helps make conf files more portable
    // between /joseki/myModel and /myModel but if the servlet is
    // explicitly named in web.xml, it strips that off
    //        if ( servletPath != null && servletPath.length() > 0 )
    //            dispatchURI = dispatchURI.substring(servletPath.length()) ;

    // Suggested by damien_coraboeuf
    // TODO Test and verify
    //        if ( servletPath != null && servletPath.length() > 0 )
    //            serviceURI = serviceURI.substring(servletPath.length()) ;

    // Example:
    //    <servlet-mapping>
    //        <servlet-name>JosekiServlet</servlet-name>
    //        <url-pattern>/ws/joseki/*</url-pattern>
    //    </servlet-mapping>

    if (log.isDebugEnabled()) {
      if (servletPath == null) servletPath = "";
      if (contextPath == null) contextPath = "";
      log.debug(
          "DispatchURI: "
              + uri
              + " => "
              + serviceURI
              + " (ContextPath = "
              + contextPath
              + ", ServletPath = "
              + servletPath
              + ")");
    }
    return serviceURI;
  }
示例#4
0
  protected Request setupRequest(String serviceURI, HttpServletRequest httpRequest, String opType)
      throws IOException {
    // No reader.  Done by standard servlet form processing.
    Request request = new Request(serviceURI, null);
    // params => request items
    @SuppressWarnings("unchecked")
    Enumeration<String> en = httpRequest.getParameterNames();

    for (; en.hasMoreElements(); ) {
      String k = en.nextElement();
      String[] x = httpRequest.getParameterValues(k);

      for (int i = 0; i < x.length; i++) {
        String s = x[i];
        request.setParam(k, s);
      }
    }
    request.setParam(Joseki.OPERATION, opType);
    return request;
  }
示例#5
0
  @Override
  public void doPost(HttpServletRequest httpRequest, HttpServletResponse httpResponse) {
    String s = httpRequest.getContentType();
    if (s != null && !isHTMLForm(httpRequest)) {
      try {
        httpResponse.sendError(
            HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,
            "Must be application/x-www-form-urlencoded");
      } catch (Exception ex) {
      }
      return;
    }

    doCommon(httpRequest, httpResponse);
  }