Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 package org.apache.marmotta.platform.core.servlet;
This filter is evaluated when the Apache Marmotta system is accessed for the very first time using an HTTP client (e.g. a browser). Its purpose is to set configuration variables that cannot be determined when the server is starting up because they need information how the server is accessed. In particular, it will set the following configuration variables in case the system has not yet been configured:
  • kiwi.context - will be set to the base URI of this KiWi installation; used for constructing resource URIs
  • - will be set to the base URL of the KiWi installation; used for accessing additional web services like SOLR and H2

User: Sebastian Schaffert

 public class MarmottaPreStartupFilter implements Filter {
     private Logger log;
     private boolean started = false;

If the hostname (config properties and kiwi.context) of the system has not been configured yet, we try to automatically determine the correct values from the first request. The config variable indicates whether setup has already been carried out.

     private String getBaseUrl(ServletRequest request) {
         // check whether we need to perform setup
         if (request instanceof HttpServletRequest) {
             HttpServletRequest hreq = (HttpServletRequestrequest;
             String contextName = hreq.getContextPath();
             String hostName    = hreq.getServerName();
             int hostPort       = hreq.getServerPort();
             String hostScheme  = hreq.getScheme();
             String baseUrl = hostScheme + "://" + hostName;
             ifhostPort == 80 && "http".equals(hostScheme) ||
                     hostPort == 443 && "https".equals(hostScheme)  ) {
                 baseUrl = baseUrl + contextName + "/";
             } else {
                 baseUrl = baseUrl + ":" + hostPort + contextName + "/";
             return baseUrl;
         } else {
             return null;
     public void init(FilterConfig filterConfigthrows ServletException {
     public void doFilter(ServletRequest requestServletResponse servletResponseFilterChain filterChainthrows IOExceptionServletException {
         if(!) {
             synchronized (this) {
                  = true;
                 String baseUrl = getBaseUrl(request);
                 if(baseUrl != null) {
                } else {
                    .error("could not determine host name; cannot startup Apache Marmotta");
    public void destroy() {
New to GrepCode? Check out our FAQ X