Example usage for javax.servlet ServletConfig getServletContext

List of usage examples for javax.servlet ServletConfig getServletContext

Introduction

In this page you can find the example usage for javax.servlet ServletConfig getServletContext.

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns a reference to the ServletContext in which the caller is executing.

Usage

From source file:org.wso2.carbon.inbound.ui.internal.InboundManagementClient.java

public static InboundManagementClient getInstance(ServletConfig config, HttpSession session) throws AxisFault {

    String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    return new InboundManagementClient(cookie, backendServerURL, configContext);
}

From source file:org.apache.synapse.ServerConfigurationInformationFactory.java

/**
 * Factory method for create a ServerConfigurationInformation based on information
 * from ServletConfig//  w w w  .  j a v  a2s  .c om
 *
 * @param servletConfig ServletConfig instance
 * @return ServerConfigurationInformation instance
 */
public static ServerConfigurationInformation createServerConfigurationInformation(ServletConfig servletConfig) {

    ServerConfigurationInformation information = new ServerConfigurationInformation();

    String synapseHome = loadParameter(servletConfig, SynapseConstants.SYNAPSE_HOME, false);

    if (synapseHome == null) {
        log.info("synapse.home not set; using web application root as default value");
        String webInfPath = servletConfig.getServletContext().getRealPath("WEB-INF");
        if (webInfPath == null || !webInfPath.endsWith("WEB-INF")) {
            handleFatal("Unable to currentState web application root directory");
        } else {
            synapseHome = webInfPath.substring(0, webInfPath.length() - 7);
            log.info("Setting synapse.home to : " + synapseHome);
        }
    }

    information.setSynapseHome(synapseHome);
    information.setSynapseXMLLocation(loadParameter(servletConfig, SynapseConstants.SYNAPSE_XML, true));
    information.setResolveRoot(loadParameter(servletConfig, SynapseConstants.RESOLVE_ROOT, false));
    information.setAxis2RepoLocation(loadParameter(servletConfig, org.apache.axis2.Constants.AXIS2_REPO, true));
    information.setAxis2Xml(loadParameter(servletConfig, org.apache.axis2.Constants.AXIS2_CONF, true));
    information.setServerName(loadParameter(servletConfig, SynapseConstants.SERVER_NAME, false));
    information.setDeploymentMode(loadParameter(servletConfig, SynapseConstants.DEPLOYMENT_MODE, false));

    return information;
}

From source file:org.wso2.carbon.andes.extensions.device.mgt.jaxrs.service.impl.MQTTManagementAdminServiceImpl.java

/**
 * Gets the AndesAdminServices stub.//from   w w  w.j a  v a 2  s  . c o  m
 *
 * @param config  the servlet configuration
 * @return an AndesAdminServiceStub
 * @throws AxisFault, UserStoreException
 */
private static AndesMQTTAdminServiceStub getAndesMQTTAdminServiceStub(ServletConfig config)
        throws AxisFault, UserStoreException, MQTTConfigurationException {

    String hostName = System.getProperty("mqtt.broker.host");
    String mqttPort = System.getProperty("mqtt.broker.https.port");

    if (hostName == null || mqttPort == null) {
        throw new MQTTConfigurationException(
                "MQTT hostname/port configuration is not available in system " + "properties");
    }

    String backendServerURL = "https://" + hostName + ":" + mqttPort
            + "/services/AndesMQTTAdminService.AndesMQTTAdminServiceHttpsSoap11Endpoint/";
    ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
    AndesMQTTAdminServiceStub stub = new AndesMQTTAdminServiceStub(configContext, backendServerURL);

    HttpTransportProperties.Authenticator basicAuthentication = new HttpTransportProperties.Authenticator();
    basicAuthentication.setUsername(MQTTMgtAPIUtils.getUserRealm().getRealmConfiguration().getAdminUserName());
    basicAuthentication.setPassword(MQTTMgtAPIUtils.getUserRealm().getRealmConfiguration().getAdminPassword());
    stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, basicAuthentication);

    return stub;
}

From source file:org.wso2.carbon.registry.resource.ui.processors.ImportResourceProcessor.java

/**
 * Process the form data and send it to ResourceServiceClient
 *
 * @param request HTML request// w  w  w. ja  v  a  2s. c  o m
 * @param config  server configuration
 * @param response  in case if we needed to sendRedirect
 * @throws RegistryException
 */
public static void process(HttpServletRequest request, HttpServletResponse response, ServletConfig config)
        throws RegistryException {

    String parentPath = request.getParameter("parentPath");
    String resourceName = request.getParameter("resourceName");
    String mediaType = MediaTypesUtils.getMimeTypeFromHumanReadableMediaType(request.getParameter("mediaType"));
    String description = request.getParameter("description");
    String fetchURL = request.getParameter("fetchURL");
    String async = request.getParameter("isAsync");
    String symlinkLocation = request.getParameter("symlinkLocation");

    String cookie = (String) request.getSession().getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);
    HttpSession session = request.getSession();
    String serverURL = CarbonUIUtil.getServerURL(config.getServletContext(), session);

    try {
        ConfigurationContext configContext = (ConfigurationContext) config.getServletContext()
                .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);
        IServerAdmin adminClient = new ServerAdminClient(configContext, serverURL, cookie, session);
        ServerData data;
        try {
            data = adminClient.getServerData();
        } catch (RegistryException e) {
            // If we can't get server data the chroot cannot be determined.
            throw new RegistryException("No server data", e);
        }
        // TODO: refactor the code to remove chroot = ""
        String chroot = "";
        if (validateServerData(data)) {
            chroot = data.getRemoteRegistryChroot();
            if (!chroot.startsWith(RegistryConstants.PATH_SEPARATOR)) {
                chroot = RegistryConstants.PATH_SEPARATOR + chroot;
            }
            if (chroot.endsWith(RegistryConstants.PATH_SEPARATOR)) {
                chroot = chroot.substring(0, chroot.length() - RegistryConstants.PATH_SEPARATOR.length());
            }
        }
        if (chroot == null) {
            symlinkLocation = null;
            log.debug("Unable to determine chroot. Symbolic Link cannot be created");
        }
        if (symlinkLocation != null) {
            symlinkLocation = chroot + symlinkLocation;
        }
        // fetching custom properties from the request. eg: version
        String[][] properties = Utils.getProperties(request);

        ResourceServiceClient client = new ResourceServiceClient(cookie, config, request.getSession());
        boolean isAsync = JavaUtils.isTrueExplicitly(async);

        client.importResource(parentPath, resourceName, mediaType, description, fetchURL, symlinkLocation,
                properties, isAsync);
    } catch (AxisFault axisFault) {
        String msg = "Failed to initiate Server Admin Client.";
        log.error(msg, axisFault);
        throw new RegistryException(msg, axisFault);
    } catch (Exception e) {
        // Since ResourceServiceClient.importResource has thrown a Exception need to handle that as well,
        // Therefore adding the original exception below.
        // having additional details will make the error message long
        String msg = "Unable to process (ResourceServiceClient.importResource) function."
                + " Please check the network connection.";
        log.error(msg, e);
        // if we skip msg and put just e, error message contain the axis2 fault story
        throw new RegistryException(msg, e);
    }
}

From source file:org.sakaiproject.imagegallery.web.ReasonableRsacServlet.java

@Override
public void init(ServletConfig config) {
    ServletContext sc = config.getServletContext();
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc);
    rsacbeanlocator = (RSACBeanLocator) wac.getBean(RSACBeanLocator.RSAC_BEAN_LOCATOR_NAME);
}

From source file:org.alfresco.repo.lotus.server.QuickrServlet.java

private void updateContext(ApplicationContext ctx) {
    // This constructor works whether there is a context or not
    // If the ctx is null, we just start up the default bus
    if (ctx == null) {
        bus = new SpringBusFactory().createBus();
        ctx = bus.getExtension(BusApplicationContext.class);
    } else {/*from ww  w . j a v a2s.c  o  m*/
        bus = new SpringBusFactory(ctx).createBus();
    }

    replaceDestinationFactory();
    ServletConfig conf = new QuickrServletConfig();
    sc = conf.getServletContext();
    // Set up the ServletController
    controller = createServletController(conf);
}

From source file:io.swagger.generator.Bootstrap.java

@Override
public void init(ServletConfig config) throws ServletException {
    ServletContext context = config.getServletContext();

    DynamicSwaggerConfig bc = new DynamicSwaggerConfig();
    bc.setBasePath("/api");
    bc.setTitle("Swagger Generator");
    bc.setDescription("This is an online swagger codegen server.  You can find out more "
            + "at https://github.com/swagger-api/swagger-codegen or on [irc.freenode.net, #swagger](http://swagger.io/irc/).");
    bc.setTermsOfServiceUrl("http://swagger.io/terms/");
    bc.setContact("apiteam@swagger.io");
    bc.setLicense("Apache 2.0");
    InputStream stream = getClass().getResourceAsStream("/version.prop");
    if (stream == null) {
        bc.setVersion("0.0.0");
    } else {//w w w .jav a 2  s.c om
        try {
            bc.setVersion(IOUtils.toString(stream, "UTF-8"));
            stream.close();
        } catch (IOException e) {
            bc.setVersion("0.0.0");
        }
    }

    bc.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
    bc.setResourcePackage("io.swagger.generator.resource");
    bc.setScan(true);
}

From source file:org.restcomm.sbc.Bootstrapper.java

private String uri(final ServletConfig config) {
    return config.getServletContext().getContextPath();
}

From source file:org.apache.synapse.core.axis2.SynapseAxisServlet.java

/**
 * Overrides init method so that avoid  starting listeners again
 *
 * @param config//from w w  w  . jav a 2 s.  co  m
 * @throws ServletException
 */
public void init(ServletConfig config) throws ServletException {
    ServletContext servletContext = config.getServletContext();
    this.configContext = ServerManager.getInstance().getConfigurationContext();
    this.axisConfiguration = this.configContext.getAxisConfiguration();
    servletContext.setAttribute(this.getClass().getName(), this);
    this.servletConfig = config;

    // Initialize the agent field. Since it is declared private, we need to do
    // it using reflection.
    try {
        Field agentField = AxisServlet.class.getDeclaredField("agent");
        agentField.setAccessible(true);
        agentField.set(this, new ListingAgent(configContext));
    } catch (Throwable ex) {
        log.warn("Unable to initialize AxisServlet#agent. Published WSDL documents may be inaccessible.");
    }

    initParams();
}

From source file:org.msjs.servlet.ScriptServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ServletContext servletContext = config.getServletContext();
    Injector injector = (Injector) servletContext.getAttribute(ServletListener.INJECTOR);
    locator = injector.getInstance(ScriptLocator.class);
}