Example usage for javax.servlet ServletRegistration getInitParameter

List of usage examples for javax.servlet ServletRegistration getInitParameter

Introduction

In this page you can find the example usage for javax.servlet ServletRegistration getInitParameter.

Prototype

public String getInitParameter(String name);

Source Link

Document

Gets the value of the initialization parameter with the given name that will be used to initialize the Servlet or Filter represented by this Registration object.

Usage

From source file:org.wso2.carbon.webapp.mgt.WebApplication.java

public WebApplication(TomcatGenericWebappsDeployer tomcatGenericWebappsDeployer, Context context,
        File webappFile) {/*from  w  w  w  .ja  va2 s  .  c  o  m*/
    this.tomcatGenericWebappsDeployer = tomcatGenericWebappsDeployer;
    this.context = context;
    this.hostName = WebAppUtils.getMatchingHostName(WebAppUtils.getWebappDirPath(webappFile.getAbsolutePath()));
    setWebappFile(webappFile);
    setLastModifiedTime(webappFile.lastModified());

    String versionString = context.getName();
    if (context.getName().startsWith("/t/")) {
        //remove tenant context
        versionString = versionString.substring(context.getName().lastIndexOf("/webapps/") + 9);
    } else if (context.getName().startsWith("/")) {
        versionString = versionString.substring(1);
    }
    if (versionString.contains("/")) {
        versionString = versionString.substring(versionString.indexOf("/"));
        setVersion(versionString);
    } else {
        setVersion(WebappsConstants.DEFAULT_VERSION);
    }

    //Some of the information in context will not be available if the webapp is not started.. ex. init-params.
    boolean isFaulty = checkFaultyWebappParam(context);
    if (isFaulty || !"STARTED".equalsIgnoreCase(context.getStateName())) {
        return;
    }

    String serviceListPathParamName = "service-list-path";
    String serviceListPathParam = context.getServletContext().getInitParameter(serviceListPathParamName);
    if ("".equals(serviceListPathParam) || serviceListPathParam == null) {
        Map<String, ? extends ServletRegistration> servletRegs = context.getServletContext()
                .getServletRegistrations();
        for (ServletRegistration servletReg : servletRegs.values()) {
            serviceListPathParam = servletReg.getInitParameter(serviceListPathParamName);
            if (!"".equals(serviceListPathParam) || serviceListPathParam != null) {
                break;
            }
        }
    }
    if ("".equals(serviceListPathParam) || serviceListPathParam == null) {
        serviceListPathParam = "/services";
    } else {
        serviceListPathParam = "";
    }
    setServiceListPath(serviceListPathParam);
}