List of usage examples for javax.servlet ServletConfig getServletContext
public ServletContext getServletContext();
From source file:pl.exsio.frameset.vaadin.bootstrap.servlet.FramesetServlet.java
@Override public void init(ServletConfig config) throws ServletException { this.applicationContext = WebApplicationContextUtils.getWebApplicationContext(config.getServletContext()); if (config.getInitParameter(CONTEXT_CONFIG_LOCATION_PARAMETER) != null) { XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setParent(this.applicationContext); context.setConfigLocation(config.getInitParameter(CONTEXT_CONFIG_LOCATION_PARAMETER)); context.setServletConfig(config); context.setServletContext(config.getServletContext()); context.refresh();/*from w w w . j av a 2 s .c om*/ this.applicationContext = context; } if (config.getInitParameter(SYSTEM_MESSAGES_BEAN_NAME_PARAMETER) != null) { this.systemMessagesBeanName = config.getInitParameter(SYSTEM_MESSAGES_BEAN_NAME_PARAMETER); } if (FramesetApplicationContext.getApplicationContext() == null) { FramesetApplicationContext.setApplicationContext(applicationContext); } super.init(config); }
From source file:org.wso2.carbon.registry.indexing.ui.ContentSearchServiceClient.java
public ContentSearchServiceClient(String cookie, ServletConfig config, HttpSession session) throws RegistryException { String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session); ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); epr = backendServerURL + "ContentSearchAdminService"; try {/*w ww.j av a 2 s. co m*/ stub = new ContentSearchAdminServiceStub(configContext, epr); ServiceClient client = stub._getServiceClient(); Options option = client.getOptions(); option.setManageSession(true); option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie); } catch (AxisFault axisFault) { String msg = "Failed to initiate search service client. " + axisFault.getMessage(); log.error(msg, axisFault); throw new RegistryException(msg, axisFault); } }
From source file:com.jaspersoft.jasperserver.war.xmla.XmlaServletImpl.java
public void init(ServletConfig config) throws ServletException { ServletContext servletContext = config.getServletContext(); // TODO it is meaningless to generate URLs here, but the XMLServlet requires it // Looks like XML/A clients ignore the URL try {/*from www. j a v a 2s. c o m*/ InetAddress local = InetAddress.getLocalHost(); // We can override the default protocol and port with servlet init parameters String defaultProtocol = servletContext.getInitParameter("defaultProtocol"); if (defaultProtocol == null || defaultProtocol.trim().length() == 0) { defaultProtocol = "http"; } String defaultPort = servletContext.getInitParameter("defaultPort"); if (defaultPort == null || defaultPort.trim().length() == 0) { defaultPort = "-1"; } int port = Integer.parseInt(defaultPort); URL root = servletContext.getResource("/"); // Looks like the path will be /localhost/webapp int pastHost = root.getPath().indexOf("/", 1); String path = root.getPath().substring(pastHost, root.getPath().length()); SERVER_URL = (new URL(defaultProtocol, local.getCanonicalHostName(), port, path)).toString() + "xmla"; } catch (Exception e) { throw new RuntimeException(e); } super.init(config); }
From source file:com.deltastar.task7.web.servlet.customer.BaseCustomerServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(servletConfig.getServletContext()); customerService = applicationContext.getBean(CustomerService.class); }
From source file:edu.mayo.cts2.framework.webapp.rest.osgi.ProxyServlet.java
private void doInit(ServletConfig config) throws Exception { this.tracker = new DispatcherTracker(getBundleContext(), null, getServletConfig()); this.tracker.open(); config.getServletContext().setAttribute("osgi-servlet-tracker", this.tracker); }
From source file:org.electrologic.convergence.server.NotaryBundleServlet.java
@Override public void init(ServletConfig config) throws ServletException { try {// www. j ava 2 s . 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:org.restcomm.sbc.Bootstrapper.java
@Override public void init(final ServletConfig config) throws ServletException { final ServletContext context = config.getServletContext(); final String path = context.getRealPath("WEB-INF/conf/sbc.xml"); // Initialize the configuration interpolator. final ConfigurationStringLookup strings = new ConfigurationStringLookup(); strings.addProperty("home", home(config)); strings.addProperty("uri", uri(config)); ConfigurationInterpolator.registerGlobalLookup("sbc", strings); // Load the RestComm configuration file. Configuration xml = null;//from www.j a v a 2 s .c o m try { xml = new XMLConfiguration(path); } catch (final ConfigurationException exception) { logger.error(exception); } xml.setProperty("runtime-settings.home-directory", home(config)); xml.setProperty("runtime-settings.root-uri", uri(config)); context.setAttribute(Configuration.class.getName(), xml); // Initialize global dependencies. final ClassLoader loader = getClass().getClassLoader(); // Create the actor system. //final Config settings = ConfigFactory.load(); ConfigFactory.load(); // Create the storage system. DaoManager storage = null; try { storage = storage(xml, loader); } catch (final ObjectInstantiationException exception) { throw new ServletException(exception); } context.setAttribute(DaoManager.class.getName(), storage); ShiroResources.getInstance().set(DaoManager.class, storage); ShiroResources.getInstance().set(Configuration.class, xml.subset("runtime-settings")); // Create high-level restcomm configuration RestcommConfiguration.createOnce(xml); // Initialize identityContext IdentityContext identityContext = new IdentityContext(xml); context.setAttribute(IdentityContext.class.getName(), identityContext); logger.info("Extern IP:" + xml.getString("runtime-settings.external-ip")); Version.printVersion(); }
From source file:com.controlj.green.modstat.servlets.LongRunning.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); sc = config.getServletContext(); if (test) {/* ww w. ja v a2 s . c o m*/ test = getFileInWebApp(TEST_SOURCE).exists(); } }
From source file:io.github.benas.todolist.web.servlet.todo.CreateTodoServlet.java
@Override public void init(ServletConfig servletConfig) throws ServletException { ApplicationContext applicationContext = WebApplicationContextUtils .getWebApplicationContext(servletConfig.getServletContext()); todoService = applicationContext.getBean(TodoService.class); }
From source file:com.google.android.gcm.demo.server.SendMessageServlet.java
/** * Creates the {@link Sender} based on the servlet settings. *///from w w w. ja v a 2 s . c om protected Sender newSender(ServletConfig config) { String key = (String) config.getServletContext().getAttribute(ApiKeyInitializer.ATTRIBUTE_ACCESS_KEY); return new Sender(key); }