List of usage examples for javax.servlet ServletConfig getServletContext
public ServletContext getServletContext();
From source file:csiro.pidsvc.core.Settings.java
private Settings(HttpServlet servlet) throws NullPointerException, IOException { // Retrieve manifest. if ((_servlet = servlet) != null) { ServletConfig config = _servlet.getServletConfig(); if (config != null) { ServletContext application = config.getServletContext(); _manifest = new Manifest(application.getResourceAsStream("/META-INF/MANIFEST.MF")); }//from ww w .j a v a 2 s . c o m } // Retrieve settings. FileInputStream fis = null; try { InitialContext context = new InitialContext(); String settingsFile = (String) context.lookup("java:comp/env/" + SETTINGS_OPT); fis = new FileInputStream(settingsFile); _properties = new PropertyResourceBundle(fis); } catch (NamingException ex) { _logger.debug("Using default pidsvc.properties file."); _properties = ResourceBundle.getBundle("pidsvc"); } finally { if (fis != null) fis.close(); } // Get additional system properties. _serverProperties.put("serverJavaVersion", System.getProperty("java.version")); _serverProperties.put("serverJavaVendor", System.getProperty("java.vendor")); _serverProperties.put("javaHome", System.getProperty("java.home")); _serverProperties.put("serverOsArch", System.getProperty("os.arch")); _serverProperties.put("serverOsName", System.getProperty("os.name")); _serverProperties.put("serverOsVersion", System.getProperty("os.version")); }
From source file:MainServer.ImageUploadServlet.java
@Override public void init(ServletConfig config) throws ServletException { FileItemFactory factory = new DiskFileItemFactory(); this.upload = new ServletFileUpload(factory); this.upload.setSizeMax(this.MAXsize); fileDir = config.getServletContext().getRealPath("image"); System.out.println("fileDir = " + fileDir); }
From source file:org.openmrs.web.dwr.OpenmrsDWRServlet.java
/** * Overriding the init(ServletConfig) method to save the dwr servlet to the ModuleWebUtil class */// ww w . j a v a 2 s . com public void init(ServletConfig config) throws ServletException { Thread.currentThread().setContextClassLoader(OpenmrsClassLoader.getInstance()); DwrServletConfig conf = new DwrServletConfig(config.getServletName(), config.getServletContext()); conf.setInitParameter("debug", "false"); conf.setInitParameter("config-modules", "/WEB-INF/dwr-modules.xml"); super.init(conf); }
From source file:org.wso2.carbon.bpel.ui.bpel2svg.SVGGenerateServlet.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * Handles the HTTP process request which creates the SVG graph for a bpel process * * @param request servlet request//from w ww . j av a 2s. com * @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 { Log log = LogFactory.getLog(SVGGenerateServlet.class); HttpSession session = request.getSession(true); //Get the bpel process id String pid = CharacterEncoder.getSafeText(request.getParameter("pid")); ServletConfig config = getServletConfig(); 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); String processDef = null; ProcessManagementServiceClient client = null; SVGInterface svg = null; String svgStr = null; ServletOutputStream sos = null; sos = response.getOutputStream(); try { client = new ProcessManagementServiceClient(cookie, backendServerURL, configContext, request.getLocale()); //Gets the bpel process definition needed to create the SVG from the processId processDef = client.getProcessInfo(QName.valueOf(pid)).getDefinitionInfo().getDefinition() .getExtraElement().toString(); BPELInterface bpel = new BPELImpl(); //Converts the bpel process definition to an omElement which is how the AXIS2 Object Model (AXIOM) // represents an XML document OMElement bpelStr = bpel.load(processDef); /** * Process the OmElement containing the bpel process definition * Process the subactivites of the bpel process by iterating through the omElement * */ bpel.processBpelString(bpelStr); //Create a new instance of the LayoutManager for the bpel process LayoutManager layoutManager = BPEL2SVGFactory.getInstance().getLayoutManager(); //Set the layout of the SVG to vertical layoutManager.setVerticalLayout(true); //Get the root activity i.e. the Process Activity layoutManager.layoutSVG(bpel.getRootActivity()); svg = new SVGImpl(); //Set the root activity of the SVG i.e. the Process Activity svg.setRootActivity(bpel.getRootActivity()); //Set the content type of the HTTP response as "image/svg+xml" response.setContentType("image/svg+xml"); //Get the SVG graph created for the process as a SVG string svgStr = svg.generateSVGString(); //Checks whether the SVG string generated contains a value if (svgStr != null) { // stream to write binary data into the response sos.write(svgStr.getBytes(Charset.defaultCharset())); sos.flush(); sos.close(); } } catch (ProcessManagementException e) { log.error("SVG Generation Error", e); String errorSVG = "<svg version=\"1.1\"\n" + " xmlns=\"http://www.w3.org/2000/svg\"><text y=\"50\">Could not display SVG</text></svg>"; sos.write(errorSVG.getBytes(Charset.defaultCharset())); sos.flush(); sos.close(); } }
From source file:org.apache.stratos.account.mgt.ui.clients.EmailValidationClient.java
public EmailValidationClient(ServletConfig config, HttpSession session) throws RegistryException { String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session); ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); epr = backendServerURL + "EmailValidationService"; try {//from w ww. j a v a 2 s.com stub = new EmailValidationServiceStub(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 EmailValidationService service client."; log.error(msg, axisFault); throw new RegistryException(msg, axisFault); } }
From source file:org.wso2.carbon.registry.handler.ui.clients.HandlerManagementServiceClient.java
public HandlerManagementServiceClient(String cookie, ServletConfig config, HttpSession session) throws RegistryException { String backendServerURL = CarbonUIUtil.getServerURL(config.getServletContext(), session); ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String epr = backendServerURL + "HandlerManagementService"; try {//from w w w .ja va 2s .c o m stub = new HandlerManagementServiceStub(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 handler management service client. " + axisFault.getMessage(); log.error(msg, axisFault); throw new RegistryException(msg, axisFault); } }
From source file:com.liferay.arquillian.DeployerServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext servletContext = config.getServletContext(); if (servletContext instanceof BundleReference) { _bundle = ((BundleReference) servletContext).getBundle(); }//from ww w. j a v a 2s .c o m _contextPathHeader = GetterUtil.getString(config.getInitParameter("contextPathHeader"), BUNDLE_CONTEXT_PATH); _deployerServletInstallLocation = GetterUtil .getString(config.getInitParameter("deployerServletInstallLocation"), DEPLOYER_SERVLET_LOCATION); _installTimeout = GetterUtil.getLong(config.getInitParameter("installTimeout"), TIMEOUT); }
From source file:org.wso2.carbon.governance.notifications.ui.worklist.HumanTaskClient.java
public HumanTaskClient(ServletConfig config, HttpSession session) throws AxisFault { ConfigurationContext configContext = (ConfigurationContext) config.getServletContext() .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String backendServerURL = workListConfig.getServerURL() != null ? workListConfig.getServerURL() : CarbonUIUtil.getServerURL(config.getServletContext(), session); htStub = new HumanTaskClientAPIAdminStub(configContext, backendServerURL + "HumanTaskClientAPIAdmin"); configureServiceClient(htStub, session); umStub = new UserAdminStub(configContext, backendServerURL + "UserAdmin"); configureServiceClient(umStub, session); wlStub = new WorkListServiceStub(configContext, backendServerURL + "WorkListService"); configureServiceClient(wlStub, session); }
From source file:gwtupload.server.UploadAction.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext ctx = config.getServletContext(); removeSessionFiles = Boolean.valueOf(ctx.getInitParameter("removeSessionFiles")); removeData = Boolean.valueOf(ctx.getInitParameter("removeData")); logger.info("UPLOAD-ACTION init: removeSessionFiles=" + removeSessionFiles + ", removeData=" + removeData); }
From source file:org.apache.roller.weblogger.ui.rendering.servlets.PreviewResourceServlet.java
public void init(ServletConfig config) throws ServletException { super.init(config); log.info("Initializing PreviewResourceServlet"); this.context = config.getServletContext(); }