Beispiel #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);
    }
  }
Beispiel #2
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)) ;
    }
     */
  }