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:cms.service.app.ServiceController.java

public void init(javax.servlet.ServletConfig conf) throws javax.servlet.ServletException {
    logger.info("\n Initializing Controller Servlet ");
    logger.info("\n  ");
    logger.info("\n  " + conf.getServletContext().getRealPath("WEB-INF"));
    contextPath = conf.getServletContext().getRealPath("WEB-INF");
    super.init(conf);
    m_service = new ServiceManager();
    this.m_autoContext = conf.getServletContext();

}

From source file:org.apache.chemistry.opencmis.server.impl.webservices.CmisWebServicesServlet.java

private String readFile(ServletConfig config, String path) throws ServletException {
    InputStream stream = config.getServletContext().getResourceAsStream(path);
    if (stream == null) {
        throw new ServletException("Cannot find file '" + path + "'!");
    }/*from   w  w w  .j  a  v a2s  .com*/

    try {
        return IOUtils.readAllLines(stream, 100000);
    } catch (IOException e) {
        throw new ServletException("Cannot read file '" + path + "': " + e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(stream);
    }
}

From source file:org.pentaho.test.platform.web.GetResourceIT.java

@Before
public void setUp() throws PlatformInitializationException, ServletException {
    request = mock(HttpServletRequest.class);
    when(request.getMethod()).thenReturn("GET");

    response = mock(HttpServletResponse.class);

    servlet = spy(new GetResource());
    final ServletConfig servletConfig = mock(ServletConfig.class);
    final ServletContext servletContext = mock(ServletContext.class);
    when(servletContext.getMimeType(anyString())).thenReturn(TEST_MIME_TYPE);
    when(servletConfig.getServletContext()).thenReturn(servletContext);
    servlet.init(servletConfig);//from w w  w. ja  va 2s. c  om

    mp.start();
}

From source file:org.atmosphere.spring.bean.AtmosphereSpringServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext())
            .getAutowireCapableBeanFactory().autowireBean(this);

    // set the real servlet context
    atmosphereSpringContext.setServletContext(config.getServletContext());
    framework.init(atmosphereSpringContext, false);

}

From source file:com.ctriposs.rest4j.server.Rest4JServlet.java

private boolean getUseAsync(ServletConfig servletConfig) {
    String useAsync = servletConfig.getInitParameter(USE_ASYNC_PARAM);
    if (useAsync != null) {
        return Boolean.parseBoolean(useAsync);
    } else {//from  w w  w.j  a  v  a 2 s.c o m
        return servletConfig.getServletContext().getMajorVersion() >= 3;
    }
}

From source file:org.apache.jasper.servlet.JspServlet.java

public void init(ServletConfig config) throws ServletException {

    super.init(config);
    this.config = config;
    this.context = config.getServletContext();

    options = new EmbeddedServletOptions(config, context);

    // Initialize the JSP Runtime Context
    rctxt = new JspRuntimeContext(context, options);

    if (log.isDebugEnabled()) {
        log.debug(Localizer.getMessage("jsp.message.scratch.dir.is", options.getScratchDir().toString()));
        log.debug(Localizer.getMessage("jsp.message.dont.modify.servlets"));
    }//www .ja v a  2 s. com
}

From source file:org.alfresco.web.app.servlet.UploadFileServlet.java

/**
 * @see javax.servlet.GenericServlet#init()
 *//*from w w  w. j  a v a  2s .  c  om*/
@Override
public void init(ServletConfig sc) throws ServletException {
    super.init(sc);

    WebApplicationContext ctx = WebApplicationContextUtils
            .getRequiredWebApplicationContext(sc.getServletContext());
    this.configService = (ConfigService) ctx.getBean("webClientConfigService");
}

From source file:org.springframework.http.server.reactive.ServletHttpHandlerAdapter.java

private String getServletPath(ServletConfig config) {
    String name = config.getServletName();
    ServletRegistration registration = config.getServletContext().getServletRegistration(name);
    if (registration == null) {
        throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'");
    }/* w  w  w  . j  a va2 s .co  m*/

    Collection<String> mappings = registration.getMappings();
    if (mappings.size() == 1) {
        String mapping = mappings.iterator().next();
        if (mapping.equals("/")) {
            return "";
        }
        if (mapping.endsWith("/*")) {
            String path = mapping.substring(0, mapping.length() - 2);
            if (!path.isEmpty()) {
                logger.info("Found Servlet mapping '" + path + "' for Servlet '" + name + "'");
            }
            return path;
        }
    }

    throw new IllegalArgumentException(
            "Expected a single Servlet mapping: " + "either the default Servlet mapping (i.e. '/'), "
                    + "or a path based mapping (e.g. '/*', '/foo/*'). " + "Actual mappings: " + mappings
                    + " for Servlet '" + name + "'");
}

From source file:org.apache.maven.archiva.web.ras.RasSearchByKeyword.java

public void init(javax.servlet.ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletConfig.getServletContext());
    userRepositories = (UserRepositories) wac
            .getBean(PlexusToSpringUtils.buildSpringId(UserRepositories.class.getName()));
    servletAuth = (ServletAuthenticator) wac
            .getBean(PlexusToSpringUtils.buildSpringId(ServletAuthenticator.class.getName()));
    httpAuth = (HttpAuthenticator) wac//www  .ja  v a 2s  .c  o  m
            .getBean(PlexusToSpringUtils.buildSpringId(HttpAuthenticator.ROLE, "basic"));
    archivaXworkUser = (ArchivaXworkUser) wac
            .getBean(PlexusToSpringUtils.buildSpringId(ArchivaXworkUser.class));
    //instantiate DAO
    dao = (ArchivaDAO) wac.getBean(PlexusToSpringUtils.buildSpringId(ArchivaDAO.class.getName(), "jdo"));

    crossRepo = (CrossRepositorySearch) wac
            .getBean(PlexusToSpringUtils.buildSpringId(CrossRepositorySearch.class.getName(), "default"));
}

From source file:org.jdesktop.wonderland.artupload.ArtUploadServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    try {/*from  w w w  .j  av a  2s  . co m*/
        File artDir = Util.getArtDir(config.getServletContext());
        if (!artDir.exists()) {
            artDir.mkdirs();
            new File(artDir, "models").mkdir();
            new File(artDir, "textures").mkdir();
        }

        logger.info("Art directory is " + artDir.getCanonicalPath());

        WFSCellDirectory dir = Util.getWFS(config.getServletContext());
        logger.info("WFS directory at " + dir.getPathName());
    } catch (IOException ioe) {
        throw new ServletException(ioe);
    }
}