Exemplo n.º 1
0
  private void servletEnv() {
    if (!log.isDebugEnabled()) return;

    try {
      java.net.URL url = servletContext.getResource("/");
      log.trace("Joseki base directory: " + url);
    } catch (Exception ex) {
    }

    if (servletConfig != null) {
      String tmp = servletConfig.getServletName();
      log.trace("Servlet = " + (tmp != null ? tmp : "<null>"));
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletConfig.getInitParameterNames();

      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.trace("Servlet parameter: " + s + " = " + servletConfig.getInitParameter(s));
      }
    }
    if (servletContext != null) {
      // Name of webapp
      String tmp = servletContext.getServletContextName();
      // msg(Level.FINE, "Webapp = " + (tmp != null ? tmp : "<null>"));
      log.debug("Webapp = " + (tmp != null ? tmp : "<null>"));

      // NB This servlet may not have been loaded as part of a web app
      @SuppressWarnings("unchecked")
      Enumeration<String> en = servletContext.getInitParameterNames();
      for (; en.hasMoreElements(); ) {
        String s = en.nextElement();
        log.debug("Webapp parameter: " + s + " = " + servletContext.getInitParameter(s));
      }
    }
    /*
    for ( Enumeration enum = servletContext.getAttributeNames() ;  enum.hasMoreElements() ; )
    {
        String s = (String)enum.nextElement() ;
        logger.log(LEVEL, "Webapp attribute: "+s+" = "+context.getAttribute(s)) ;
    }
     */
  }
Exemplo n.º 2
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) {
      }
    }
  }
Exemplo n.º 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;
  }
Exemplo n.º 4
0
 /** Destroys the servlet. */
 @Override
 public void destroy() {
   log.debug("destroy");
 }