Пример #1
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"));
  }
Пример #2
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);
  }
Пример #3
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) {
      }
    }
  }