private void initServices(ServletContext context) throws ServletException {

    // get list of OGC services
    String serviceList = this.getRequiredInitParameter(SERVICE);

    String[] serviceNames = StringTools.toArray(serviceList, ",", false);

    ServiceLookup lookup = ServiceLookup.getInstance();
    for (int i = 0; i < serviceNames.length; i++) {
      LOG.logInfo(
          StringTools.concat(100, "---- Initializing ", serviceNames[i].toUpperCase(), " ----"));
      try {
        String className = this.getRequiredInitParameter(serviceNames[i] + HANDLER_CLASS);
        Class<?> handlerClzz = Class.forName(className);

        // initialize each service factory
        String s = this.getRequiredInitParameter(serviceNames[i] + HANDLER_CONF);
        URL serviceConfigurationURL = WebappResourceResolver.resolveFileLocation(s, context, LOG);

        // set configuration
        LOG.logInfo(
            StringTools.concat(
                300,
                "Reading configuration for ",
                serviceNames[i].toUpperCase(),
                " from URL: '",
                serviceConfigurationURL,
                "'."));

        String factoryClassName = SERVICE_FACTORIES_MAPPINGS.get(handlerClzz);

        Class<?> factory = Class.forName(factoryClassName);
        Method method = factory.getMethod("setConfiguration", new Class[] {URL.class});
        method.invoke(factory, new Object[] {serviceConfigurationURL});

        // The csw-ebrim profile adds an alternative service name, it too is registred with the CSW
        // handler.
        if ("CSW".equals(serviceNames[i].toUpperCase())) {
          lookup.addService(OGCRequestFactory.CSW_SERVICE_NAME_EBRIM.toUpperCase(), handlerClzz);
        }
        // put handler to available service list
        lookup.addService(serviceNames[i].toUpperCase(), handlerClzz);

        LOG.logInfo(
            StringTools.concat(300, serviceNames[i].toUpperCase(), " successfully initialized."));
      } catch (ServletException e) {
        LOG.logError(e.getMessage(), e);
      } catch (InvocationTargetException e) {
        e.getTargetException().printStackTrace();
        LOG.logError(this.produceMessage(ERR_MSG, new Object[] {serviceNames[i]}), e);
      } catch (Exception e) {
        LOG.logError("Can't initialize OGC service:" + serviceNames[i], e);
      }
    }
  }
  /** @see javax.servlet.GenericServlet#init() */
  @Override
  public void init() throws ServletException {

    synchronized (OGCServletController.class) {
      if (LOG == null) {
        // hack to figure out and set the context path name
        // for a laugh, see http://marc.info/?l=tomcat-user&m=109215904113904&w=2 and the related
        // thread
        // http://marc.info/?t=109215871400004&r=1&w=2
        String path = getServletContext().getRealPath("");
        String[] ps = path.split("[/\\\\]");
        path = ps[ps.length - 1];
        // heuristics are always a charm (and work best for tomcat in this case)
        if (isDigit(path.charAt(0)) && path.indexOf("-") != -1) {
          path = path.split("-", 2)[1];
        }
        // note that setting this changes it on a JVM GLOBAL BASIS, so it WILL GET OVERWRITTEN in
        // subsequent
        // deegree startups! (However, since the log4j.properties will only be read on startup, this
        // hack is
        // useful anyway)
        setProperty("context.name", path);

        LOG = getLogger(OGCServletController.class);
      }
    }

    super.init();
    LOG.logDebug("Logger for " + this.getClass().getName() + " initialized.");

    SERVICE_FACTORIES_MAPPINGS.put(CSWHandler.class, "org.deegree.ogcwebservices.csw.CSWFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WFSHandler.class, "org.deegree.ogcwebservices.wfs.WFServiceFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WCSHandler.class, "org.deegree.ogcwebservices.wcs.WCServiceFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WMSHandler.class, "org.deegree.ogcwebservices.wms.WMServiceFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WPVSHandler.class, "org.deegree.ogcwebservices.wpvs.WPVServiceFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WMPSHandler.class, "org.deegree.ogcwebservices.wmps.WMPServiceFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WPSHandler.class, "org.deegree.ogcwebservices.wps.WPServiceFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WASSHandler.class, "org.deegree.ogcwebservices.wass.common.WASServiceFactory");
    SERVICE_FACTORIES_MAPPINGS.put(
        WCTSHandler.class, "org.deegree.ogcwebservices.wcts.WCTServiceFactory");

    LOG.logInfo("-------------------------------------------------------------------------------");
    LOG.logInfo("Starting deegree version " + Version.getVersion());
    LOG.logInfo("- context        : " + this.getServletContext().getServletContextName());
    LOG.logInfo("- real path      : " + this.getServletContext().getRealPath("/"));
    LOG.logInfo("- java version   : " + System.getProperty("java.version") + "");
    LOG.logInfo(
        "- dom builder    : " + DocumentBuilderFactory.newInstance().getClass().getName() + "");
    LOG.logInfo("- xslt builder   : " + TransformerFactory.newInstance().getClass().getName() + "");
    LOG.logInfo("- system charset : " + CharsetUtils.getSystemCharset());
    LOG.logInfo("- default charset: " + Charset.defaultCharset());
    LOG.logInfo("- server info    : " + this.getServletContext().getServerInfo());
    logIfThere("proxyHost");
    logIfThere("proxyPort");
    logIfThere("noProxyHosts");
    logIfThere("nonProxyHosts");
    logIfThere("http.proxyHost");
    logIfThere("http.proxyPort");
    logIfThere("http.noProxyHosts");
    logIfThere("http.nonProxyHosts");
    logIfThere("ftp.proxyHost");
    logIfThere("ftp.proxyPort");
    logIfThere("ftp.noProxyHosts");
    logIfThere("ftp.nonProxyHosts");
    logIfThere("https.proxyHost");
    logIfThere("https.proxyPort");
    logIfThere("https.noProxyHosts");
    logIfThere("https.nonProxyHosts");
    try {
      LOG.logInfo("- ip             : " + InetAddress.getLocalHost().getHostAddress());
      LOG.logInfo("- host name      : " + InetAddress.getLocalHost().getHostName());
      LOG.logInfo("- domain name    : " + InetAddress.getLocalHost().getCanonicalHostName());
    } catch (Exception e) {
      LOG.logError(e.getMessage(), e);
    }
    LOG.logInfo("-------------------------------------------------------------------------------");
    this.initServices(getServletContext());
    checkServerCompatibility();
    LOG.logInfo("-------------------------------------------------------------------------------");
    String tmpServiceList = this.getServiceList();
    if (tmpServiceList != null && !("".equals(tmpServiceList.trim()))) {
      LOG.logInfo(
          "Initialized successfully (context '"
              + this.getServletContext().getServletContextName()
              + "'):");
      String[] tmpServices = tmpServiceList.split(",");
      for (String service : tmpServices) {
        // Added a check for the alternative service name, because it should not be outputed twice
        // for the csw.
        if (!OGCRequestFactory.CSW_SERVICE_NAME_EBRIM.toUpperCase().equals(service)) {
          LOG.logInfo("- " + service);
        }
      }
    } else {
      LOG.logError(
          "An Error occured while initializing context '"
              + this.getServletContext().getServletContextName()
              + "', no services are available.");
    }

    LOG.logInfo("-------------------------------------------------------------------------------");
    // Sets the attributes for tomcat -> application.getAttribute(); in jsp sites
    this.getServletContext().setAttribute("deegree_ogc_services", this.getServiceList());
  }