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.sakaiproject.tool.assessment.ui.servlet.InitMimeTypes.java

public void init(ServletConfig config) throws ServletException {
    super.init(config);
    String path = config.getServletContext().getRealPath("/WEB-INF/mime.types");
    log.debug("**** mimetypes path=" + path);
    MimetypesFileTypeMap mimeTypeMap = null;
    FileInputStream input = null;
    try {//from   www  . ja  v a 2s. c  o  m
        input = new FileInputStream(path);
        log.debug("**** input=" + input);
        mimeTypeMap = new MimetypesFileTypeMap(input);
        log.debug("**** mimeTypeMap=" + mimeTypeMap);
        MimeTypesLocator.setMimetypesFileTypeMap(mimeTypeMap);
    } catch (Exception ex) {
        log.warn(ex.getMessage());
    } finally {
        try {
            if (input != null)
                input.close();
        } catch (IOException ex1) {
            log.warn(ex1.getMessage());
        }
    }
}

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

public void init() throws ServletException {
    ServletConfig servletConfig = getServletConfig();
    ServletContext servletContext = servletConfig.getServletContext();
    if (Boolean.TRUE.equals(servletContext.getAttribute(ALREADY_INITED))) {
        return;//from w w w  . ja  v a  2 s .  c om
    }
    ServerManager serverManager = new ServerManager();
    ServerConfigurationInformation information = ServerConfigurationInformationFactory
            .createServerConfigurationInformation(servletConfig);
    serverManager.init(information, null);
    serverManager.start();
    servletContext.setAttribute(ALREADY_INITED, Boolean.TRUE);

    servletContext.setAttribute(SYNAPSE_SERVER_MANAGER, serverManager);
}

From source file:org.paxle.gui.impl.servlets.RootView.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    this.smanager = (IServletManager) config.getServletContext().getAttribute("servletManager");
}

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

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    context = config.getServletContext();
    Injector injector = (Injector) context.getAttribute(ServletListener.INJECTOR);
    fileRoot = injector.getInstance(MsjsConfiguration.class).getScriptRoot();
}

From source file:com.conwet.silbops.connectors.comet.CometServlet.java

@Override
protected void loadConfiguration(ServletConfig sc) throws ServletException {
    WebApplicationContext wac = WebApplicationContextUtils.getWebApplicationContext(sc.getServletContext());

    // Adding the handler to avoid auto-detection in super.init()
    this.addAtmosphereHandler(this.getInitParameter("mapping"),
            wac.getBean("cometHandler", AtmosphereHandler.class));

    super.loadConfiguration(sc);
}

From source file:org.atomserver.server.servlet.AtomServerServlet.java

protected void loadSpringContext() {
    if (appContext == null) {
        ServletConfig config = getServletConfig();

        ServletContext context = config.getServletContext();
        if (context != null) {
            logger.debug("LOADING: WebApplicationContextUtils.getRequiredWebApplicationContext(context))");
            appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
        } else {/*  ww  w  .  j  a va2s. co m*/
            logger.debug("LOADING: new ClassPathXmlApplicationContext( .... )");
            appContext = new ClassPathXmlApplicationContext(
                    config.getInitParameter(SPRING_APPLICATION_CONTEXT_FILE));
        }

        if (logger.isDebugEnabled()) {
            logger.debug("Application context set:: appContext= " + appContext);
        }
    }
}

From source file:user.controller.ProcessFileUpload.java

@SuppressWarnings("null")
private void processData(HttpServletRequest request, HttpServletResponse response) throws IOException {
    OutputStream os = null;// ww  w.  jav  a2  s  .  c om
    try {
        DiskFileItemFactory factory = new DiskFileItemFactory();
        File filedir = (File) getServletContext().getAttribute("FILES_DIR_FILE");
        factory.setRepository(filedir);
        List items = new ServletFileUpload(factory).parseRequest(request);
        for (FileItem item : (List<FileItem>) items) {
            if (!item.isFormField()) {
                ServletConfig config = getServletConfig();
                ServletContext context = config.getServletContext();
                String webInfPath = context.getRealPath("static");
                InputStream inputStream = item.getInputStream();
                File file = new File(webInfPath + "/images/" + item.getName());
                //                    file.createNewFile();
                os = new FileOutputStream(file);
                byte[] buffer = new byte[10 * 1024];
                for (int length; (length = inputStream.read(buffer)) != -1;) {
                    os.write(buffer, 0, length);
                }
                response.getWriter().write(item.getName());
            }
        }
    } catch (FileNotFoundException | FileUploadException ex) {
        Logger.getLogger(ProcessFileUpload.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        os.close();
    }
}

From source file:org.talend.esb.job.console.DeployServlet.java

public void init(ServletConfig servletConfig) throws ServletException {
    ServletContext context = servletConfig.getServletContext();
    bundleContext = (BundleContext) context.getAttribute("osgi-bundlecontext");
    tmpDir = new File(System.getProperty("java.io.tmpdir"));
    deployDir = new File(System.getProperty("karaf.base") + "/deploy");
    if (!deployDir.exists()) {
        deployDir.mkdirs();/*from www . java 2s .  c  o m*/
    }
}

From source file:de.dennishoersch.web.chat.spring.DelegatingWebSocketServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, config.getServletContext());
    webSocketServlet.init(config);//  w ww  .j  a  v  a 2 s.c om
}

From source file:net.arnx.jsonic.web.SpringContainer.java

@Override
public void init(ServletConfig config) {
    super.init(config);
    appContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext());
}