Пример #1
0
  /** Initializes the servlet. */
  @Override
  public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // It seems that if the servlet fails to initialize the first time,
    // init can be called again (it has been observed in Tomcat log files
    // but not explained).

    if (initAttempted) {
      // This happens - the query and update servlets share this class
      // log.info("Re-initialization of servlet attempted") ;
      return;
    }

    initAttempted = true;

    servletConfig = config;

    // Modify the (Jena) global filemanager to include loading by servlet context
    FileManager fileManager = FileManager.get();

    if (config != null) {
      servletContext = config.getServletContext();
      fileManager.addLocator(new LocatorServletContext(servletContext));
    }

    printName = config.getServletName();
    String configURI = config.getInitParameter(Joseki.configurationFileProperty);
    servletEnv();
    try {
      Dispatcher.initServiceRegistry(fileManager, configURI);
    } catch (ConfigurationErrorException confEx) {
      throw new ServletException("Joseki configuration error", confEx);
    }
  }
Пример #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) {
      }
    }
  }