Example usage for javax.servlet ServletContext getAttribute

List of usage examples for javax.servlet ServletContext getAttribute

Introduction

In this page you can find the example usage for javax.servlet ServletContext getAttribute.

Prototype

public Object getAttribute(String name);

Source Link

Document

Returns the servlet container attribute with the given name, or null if there is no attribute by that name.

Usage

From source file:com.ws.WS_TCS.java

/**
 * Creates a new instance of WS_TCSResource
 */// www  .  j  a  v  a2  s. c  om
public WS_TCS(@Context ServletContext sc) {
    db = (DatabaseAccess) sc.getAttribute("db");
    this.connection = db.getConnection();
}

From source file:org.brutusin.rpc.RpcWebInitializer.java

private RpcSpringContext createRpcSpringContext(ServletContext ctx) {
    ServerContainer sc = (ServerContainer) ctx.getAttribute("javax.websocket.server.ServerContainer");
    if (sc == null) {
        throw new Error("ServerContainer not found");
    }// w ww  .j a  v a  2 s.c  o m
    RpcSpringContext rpcCtx = new RpcSpringContext(sc, !RpcConfig.getInstance().isTestMode());
    return rpcCtx;
}

From source file:org.apache.ambari.view.tez.ProxyServlet.java

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

    ServletContext context = config.getServletContext();
    ViewContext viewContext = (ViewContext) context.getAttribute(ViewContext.CONTEXT_ATTRIBUTE);
    this.urlConnectionProvider = viewContext.getURLConnectionProvider();
}

From source file:org.electrologic.convergence.server.TargetServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    ServletContext ctx = config.getServletContext();
    cache = (Cache) ctx.getAttribute(TargetConfigurator.CACHEPATH);
    signer = (Sha1RSASignature) ctx.getAttribute(TargetConfigurator.SIGNERPATH);
}

From source file:org.apache.pluto.driver.TCKDriverServlet.java

public void init() {
    super.init();
    ServletContext servletContext = getServletContext();
    container = (PortletContainer) servletContext.getAttribute(AttributeKeys.PORTLET_CONTAINER);
}

From source file:org.electrologic.convergence.server.NotaryBundleServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    try {/*from  www.j  av a 2s  .  co m*/
        super.init(config);
        ServletContext ctx = config.getServletContext();
        Sha1RSASignature signer = (Sha1RSASignature) ctx.getAttribute(TargetConfigurator.SIGNERPATH);
        Certificate cert = signer.getCertificate();
        // convert certificate to PEM format
        byte[] derCert = cert.getEncoded();
        String base64Cert = Base64.encodeToString(derCert, true);
        base64Cert = base64Cert.replace("\r", "");
        StringBuilder buf = new StringBuilder(10000);
        buf.append("-----BEGIN CERTIFICATE-----\n");
        buf.append(base64Cert);
        buf.append("\n-----END CERTIFICATE-----\n");

        pemCert = buf.toString();
    } catch (CertificateEncodingException ex) {
        String msg = "Failed to convert certificate to PEM format.";
        logger.error(msg, ex);
        throw new ServletException(msg, ex);
    }
}

From source file:controller.uploadPaymentServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from w  w  w. jav a 2s.c  om
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        /* TODO output your page here. You may use following sample code. */
        HttpSession session = request.getSession();
        boolean isMultipart;
        String filePath;

        // Get the file location where it would be stored.
        filePath = getServletContext().getInitParameter("file-upload");

        isMultipart = ServletFileUpload.isMultipartContent(request);

        List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
        String uploadFolder = ("D:\\Dropbox\\CharityWeb_Kloy_Ice\\Implemented_Sytem\\Code\\punpun_final\\punpun_\\punpun_demo_final\\web\\assets\\img\\payment");
        out.print(uploadFolder);
        ServletContext context = getServletContext();
        DataSource ds = (DataSource) context.getAttribute("dataSource");
        DonationUtil donationUtil = new DonationUtil(ds);
        donationUtil.connect();
        String id = request.getParameter("id");
        out.print("ID : " + id);
        Donations donation = donationUtil.findDonationtById(Integer.parseInt(id));
        out.print(donation);
        for (FileItem item : multiparts) {
            if (!item.isFormField()) {
                String name = new File(item.getName()).getName();
                System.out.println(uploadFolder + File.separator + donation.getDonationId() + ".jpg");
                item.write(new File(uploadFolder + File.separator + donation.getDonationId() + ".jpg"));
            }
        }
        response.sendRedirect("success-payment.jsp");
    } catch (Exception ex) {
        Logger.getLogger(uploadPaymentServlet.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:net.mojodna.sprout.support.SpringHttpServlet.java

/**
 * Fetch ContextLoaderPlugIn's WebApplicationContext from the ServletContext,
 * falling back to the root WebApplicationContext (the usual case).
 * @return the WebApplicationContext/* w  w w .  jav a  2 s .com*/
 * @throws IllegalStateException if no WebApplicationContext could be found
 * @see ContextLoaderPlugIn#SERVLET_CONTEXT_PREFIX
 * @see WebApplicationContextUtils#getWebApplicationContext
 */
protected WebApplicationContext initWebApplicationContext(final ServletContext sc)
        throws IllegalStateException {
    WebApplicationContext wac = (WebApplicationContext) sc
            .getAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX);
    if (null == wac) {
        wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
    }
    return wac;
}

From source file:com.sun.socialsite.web.filters.ThreadContextFilter.java

/**
 * Initializes this filter./*from  w  w w.  j  a va  2 s .co m*/
 */
public void init(FilterConfig filterConfig) throws ServletException {
    ServletContext context = filterConfig.getServletContext();
    Injector injector = (Injector) (context.getAttribute(GuiceServletContextListener.INJECTOR_ATTRIBUTE));
    SecurityTokenDecoder securityTokenDecoder = injector.getInstance(SecurityTokenDecoder.class);
    if (securityTokenDecoder instanceof SocialSiteTokenDecoder) {
        this.decoder = (SocialSiteTokenDecoder) securityTokenDecoder;
    }
}

From source file:org.infoglue.deliver.portal.information.InformationProviderServiceFactoryIG.java

public StaticInformationProvider getStaticProvider() {
    // TODO stolen from portalImpl
    log.debug("getStaticProvider(): using default from portalImpl, fix this!");
    javax.servlet.ServletContext context = config.getServletContext();

    StaticInformationProvider provider = (StaticInformationProvider) context.getAttribute(STATIC);

    if (provider == null) {
        provider = new StaticInformationProviderImpl(config);
        context.setAttribute(STATIC, provider);
    }/*from  w ww .ja va  2s  .  c om*/

    return provider;
}