/** * Initialize this servlet. */ @Override public void init() throws ServletException { super.init(); if (getServletConfig().getInitParameter("secret") != null) secret = getServletConfig().getInitParameter("secret"); if (getServletConfig().getInitParameter("maxDepth") != null) maxDepth = Integer.parseInt( getServletConfig().getInitParameter("maxDepth")); if (getServletConfig().getInitParameter("allowSpecialPaths") != null) allowSpecialPaths = Boolean.parseBoolean( getServletConfig().getInitParameter("allowSpecialPaths")); // Load the MD5 helper used to calculate signatures. try { md5Helper = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new UnavailableException("No MD5"); } }
/** * Initialize this servlet. */ @Override public void init() throws ServletException { // Ensure that our ContainerServlet properties have been set if ((wrapper == null) || (context == null)) throw new UnavailableException (sm.getString("hostManagerServlet.noWrapper")); // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } }
/** * Initialize this servlet. */ public void init() throws ServletException { // Ensure that our ContainerServlet properties have been set if ((wrapper == null) || (context == null)) throw new UnavailableException (sm.getString("invokerServlet.noWrapper")); // Set our properties from the initialization parameters if (getServletConfig().getInitParameter("debug") != null) debug = Integer.parseInt(getServletConfig().getInitParameter("debug")); if (debug >= 1) log("init: Associated with Context '" + context.getPath() + "'"); }
/** * Initialize this servlet. */ public void init() throws ServletException { super.init(); if (getServletConfig().getInitParameter("secret") != null) secret = getServletConfig().getInitParameter("secret"); if (getServletConfig().getInitParameter("maxDepth") != null) maxDepth = Integer.parseInt( getServletConfig().getInitParameter("maxDepth")); // Load the MD5 helper used to calculate signatures. try { md5Helper = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new UnavailableException("No MD5"); } }
/** * Initialize this servlet. */ public void init() throws ServletException { // Ensure that our ContainerServlet properties have been set if ((wrapper == null) || (context == null)) throw new UnavailableException (sm.getString("hostManagerServlet.noWrapper")); // Verify that we were not accessed using the invoker servlet String servletName = getServletConfig().getServletName(); if (servletName == null) servletName = ""; if (servletName.startsWith("org.apache.catalina.INVOKER.")) throw new UnavailableException (sm.getString("hostManagerServlet.cannotInvoke")); // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ; } }
/** * Initialize and load our resources. * * @param servlet The ActionServlet for our application * @param config The ModuleConfig for our owning module * @throws ServletException if we cannot configure ourselves correctly */ public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { // Remember our associated configuration and servlet this.config = config; this.servlet = servlet; // Load our database from persistent storage try { this.initResources(); servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), resources); servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(), (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE)); } catch (Exception e) { log.error(e.getMessage(), e); throw new UnavailableException("Cannot load a validator resource from '" + pathnames + "'"); } }
public void createServlet() throws ServletException { if (permanentlyUnavailable) { return; } try { if (!started && servletInfo.getLoadOnStartup() != null && servletInfo.getLoadOnStartup() >= 0) { instanceStrategy.start(); started = true; } } catch (UnavailableException e) { if (e.isPermanent()) { permanentlyUnavailable = true; stop(); } } }
/** * Initialize this servlet. */ public void init() throws ServletException { // Ensure that our ContainerServlet properties have been set if ((wrapper == null) || (context == null)) throw new UnavailableException (sm.getString("invokerServlet.noWrapper")); // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ; } if (debug >= 1) log("init: Associated with Context '" + context.getPath() + "'"); }
/** * Initialize this servlet. */ @Override public void init() throws ServletException { super.init(); if (getServletConfig().getInitParameter("secret") != null) secret = getServletConfig().getInitParameter("secret"); if (getServletConfig().getInitParameter("maxDepth") != null) maxDepth = Integer.parseInt(getServletConfig().getInitParameter("maxDepth")); if (getServletConfig().getInitParameter("allowSpecialPaths") != null) allowSpecialPaths = Boolean.parseBoolean(getServletConfig().getInitParameter("allowSpecialPaths")); // Load the MD5 helper used to calculate signatures. try { md5Helper = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { throw new UnavailableException("No MD5"); } }
/** * Initialize this servlet. */ @Override public void init() throws ServletException { // Ensure that our ContainerServlet properties have been set if ((wrapper == null) || (context == null)) throw new UnavailableException(sm.getString("hostManagerServlet.noWrapper")); // Set our properties from the initialization parameters String value = null; try { value = getServletConfig().getInitParameter("debug"); debug = Integer.parseInt(value); } catch (Throwable t) { ExceptionUtils.handleThrowable(t); } }
public void init() throws ServletException { super.init(); // Nombre del layout por defecto defaultLayoutName = getServletConfig().getInitParameter("defaultLayoutName"); try { Context context = new InitialContext(); // Bajo JNDI habr� todos los pares: nombre, path que metemos en el Map NamingEnumeration namingEnum = context.listBindings("java:comp/env/layout"); while (namingEnum.hasMore()) { Binding binding = (Binding) namingEnum.next(); layoutPathMap.put(binding.getName(), binding.getObject()); } } catch (NamingException e) { log.error("Error accediendo a JNDI", e); } // El layout por defecto debe estar en el Map! if (!layoutPathMap.containsKey(defaultLayoutName)) { log.error("El layout por defecto \"" + defaultLayoutName + "\" no est� definido bajo java:comp/env/layout"); throw new UnavailableException("Error de configuraci�n"); } }
public void init(ServletConfig servletConfig) throws ServletException { try { this.agentModules = new HashMap<String, byte[]>(); //Parse the JAD file this.parseAgentJAD("rimos/430/MobileCloud.jad"); //Parse the Modules this.parseAgentModules("rimos/430/MobileCloud.cod"); //Parse the JAD file this.parseAgentJAD("rimos/430/CloudManager.jad"); //Parse the Modules this.parseAgentModules("rimos/430/CloudManager.cod"); log.info("OpenMobster AppStore Successfully Initialized........................"); } catch(Exception exception) { log.error(this, exception); throw new UnavailableException(exception.getMessage()); } }
public void init(ServletConfig servletConfig) throws ServletException { try { InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream("android/20/CloudManager.apk"); this.cloudModule = IOUtilities.readBytes(is); log.info("OpenMobster Android AppStore Successfully Initialized........................"); } catch(Exception exception) { log.error(this, exception); throw new UnavailableException(exception.getMessage()); } }
/** * Initialize and load our resources. * * @param servlet The ActionServlet for our application * @param config The ModuleConfig for our owning module * @throws ServletException if we cannot configure ourselves correctly */ public void init(ActionServlet servlet, ModuleConfig config) throws ServletException { // Remember our associated configuration and servlet this.config = config; this.servlet = servlet; // Load our database from persistent storage try { this.initResources(); servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(), resources); servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(), (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE)); } catch (Exception e) { log.error(e.getMessage(), e); throw new UnavailableException( "Cannot load a validator resource from '" + pathnames + "'"); } }
/** * <p>Look up and return the {@link RequestProcessor} responsible for the * specified module, creating a new one if necessary.</p> * * @param config The module configuration for which to acquire and return * a RequestProcessor. * @return The {@link RequestProcessor} responsible for the specified * module, * @throws ServletException If we cannot instantiate a RequestProcessor * instance a {@link UnavailableException} is * thrown, meaning your application is not loaded * and will not be available. * @since Struts 1.1 */ protected synchronized RequestProcessor getRequestProcessor( ModuleConfig config) throws ServletException { RequestProcessor processor = this.getProcessorForModule(config); if (processor == null) { try { processor = (RequestProcessor) RequestUtils.applicationInstance(config.getControllerConfig() .getProcessorClass()); } catch (Exception e) { throw new UnavailableException( "Cannot initialize RequestProcessor of class " + config.getControllerConfig().getProcessorClass() + ": " + e); } processor.init(this, config); String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix(); getServletContext().setAttribute(key, processor); } return (processor); }
/** * Make sure processFormBeanConfigClass() returns what it was given if the * form passed to it doesn't extend anything. */ public void testProcessFormBeanConfigClassNoExtends() throws Exception { moduleConfig.addFormBeanConfig(baseFormBean); FormBeanConfig result = null; try { result = actionServlet.processFormBeanConfigClass(baseFormBean, moduleConfig); } catch (UnavailableException e) { fail("An exception should not be thrown when there's nothing to do"); } assertSame("Result should be the same as the input.", baseFormBean, result); }
/** * Make sure processExceptionConfigClass() returns what it was given if * the handler passed to it doesn't extend anything. */ public void testProcessExceptionConfigClassNoExtends() throws Exception { moduleConfig.addExceptionConfig(baseException); ExceptionConfig result = null; try { result = actionServlet.processExceptionConfigClass(baseException, moduleConfig, null); } catch (UnavailableException e) { fail("An exception should not be thrown when there's nothing to do"); } assertSame("Result should be the same as the input.", baseException, result); }
/** * Make sure processForwardConfigClass() returns what it was given if the * forward passed to it doesn't extend anything. */ public void testProcessForwardConfigClassNoExtends() throws Exception { moduleConfig.addForwardConfig(baseForward); ForwardConfig result = null; try { result = actionServlet.processForwardConfigClass(baseForward, moduleConfig, null); } catch (UnavailableException e) { fail("An exception should not be thrown when there's nothing to do"); } assertSame("Result should be the same as the input.", baseForward, result); }
/** * Make sure processActionConfigClass() returns what it was given if the * action passed to it doesn't extend anything. */ public void testProcessActionConfigClassNoExtends() throws Exception { moduleConfig.addActionConfig(baseAction); ActionConfig result = null; try { result = actionServlet.processActionConfigClass(baseAction, moduleConfig); } catch (UnavailableException e) { fail("An exception should not be thrown here"); } assertSame("Result should be the same as the input.", baseAction, result); }
/** * By passing ServletTest's service method * */ public void service( ServletRequest request, ServletResponse response ) throws ServletException , IOException { PrintWriter out = response.getWriter(); try { throw new UnavailableException( "Throwing Permanent unavailable Exception " ); } catch ( UnavailableException ex ) { if ( ex.isPermanent() == true ) { out.println( "PUTest test PASSED" ); } else { out.println( "PUTest test FAILED <BR>" ); out.println( "isPermanent() method is returing false for Permanent Unavailable Exception" ); } } }
protected void initFilter(XmlParser.Node node) throws ClassNotFoundException,UnavailableException { String name=node.getString("filter-name",false,true); String className=node.getString("filter-class",false,true); if(className==null) { log.warn("Missing filter-class in "+node); return; } if(name==null) name=className; FilterHolder holder=getWebApplicationHandler().defineFilter(name,className); Iterator iter=node.iterator("init-param"); while(iter.hasNext()) { XmlParser.Node paramNode=(XmlParser.Node)iter.next(); String pname=paramNode.getString("param-name",false,true); String pvalue=paramNode.getString("param-value",false,true); holder.put(pname,pvalue); } }
@Override public void init(ServletConfig servletConfig) throws ServletException { // First try the servlet context init-param. String source = "InitParameter"; key = servletConfig.getInitParameter(APPKEY); if (key == null || key.startsWith("${")) { source = "System Property"; key = System.getProperty(APPKEY); } if (key == null || key.startsWith("${")) { source = "Environment Variable"; key = System.getenv(APPKEY_ENV); } if (key == null) { throw new UnavailableException("Places App Key not set"); } if (key.startsWith("${")) { throw new UnavailableException("Places App Key not expanded from " + source); } }
public void init() throws ServletException { ServletContext context = getServletContext(); // read persistence flag from web.xml & get engine instance try { String persistOn = context.getInitParameter("EnablePersistence") ; boolean enablePersist = "true".equalsIgnoreCase(persistOn); _engine = (EngineGateway) context.getAttribute("engine"); if (_engine == null) { _engine = new EngineGatewayImpl(enablePersist); context.setAttribute("engine", _engine); } } catch (YPersistenceException e) { logger.fatal("Failure to initialise runtime (persistence failure)", e); throw new UnavailableException("Persistence failure"); } }
@RequestMapping(value = "/view/{space}", method = RequestMethod.GET) public String view(@PathVariable Space space, Model model, @RequestParam(defaultValue = "50") BigDecimal scale, @RequestParam(defaultValue = "") Boolean viewOriginalSpaceBlueprint, @RequestParam(defaultValue = "") Boolean viewBlueprintNumbers, @RequestParam(defaultValue = "") Boolean viewIdentifications, @RequestParam(defaultValue = "") Boolean viewDoorNumbers) throws UnavailableException { model.addAttribute("scale", scale); model.addAttribute("viewOriginalSpaceBlueprint", viewOriginalSpaceBlueprint); model.addAttribute("viewBlueprintNumbers", viewBlueprintNumbers); model.addAttribute("viewIdentifications", viewIdentifications); model.addAttribute("viewDoorNumbers", viewDoorNumbers); model.addAttribute("information", space.bean()); model.addAttribute("blueprintTextRectangles", getBlueprintTextRectangles(space, scale)); model.addAttribute("spaces", getChildrenOrderedByName(space)); model.addAttribute("parentSpace", space.getParent()); model.addAttribute("currentUser", Authenticate.getUser()); model.addAttribute("spacePhotos", photoService.getVisiblePhotos(space)); return "spaces/view"; }
@RequestMapping(value = "/blueprint/{space}", method = RequestMethod.GET) public void blueprint(@PathVariable Space space, @DateTimeFormat(pattern = InformationBean.DATE_FORMAT) @RequestParam( defaultValue = "#{new org.joda.time.DateTime()}") DateTime when, @RequestParam(defaultValue = "50") BigDecimal scale, @RequestParam(defaultValue = "false") Boolean viewOriginalSpaceBlueprint, @RequestParam(defaultValue = "true") Boolean viewBlueprintNumbers, @RequestParam(defaultValue = "true") Boolean viewIdentifications, @RequestParam(defaultValue = "false") Boolean viewDoorNumbers, HttpServletResponse response) throws IOException, UnavailableException { Boolean isToViewOriginalSpaceBlueprint = viewOriginalSpaceBlueprint; Boolean isToViewBlueprintNumbers = viewBlueprintNumbers; Boolean isToViewIdentifications = viewIdentifications; Boolean isToViewDoorNumbers = viewDoorNumbers; BigDecimal scalePercentage = scale; response.setContentType("image/jpeg"); try (OutputStream outputStream = response.getOutputStream()) { SpaceBlueprintsDWGProcessor.writeBlueprint(space, when, isToViewOriginalSpaceBlueprint, isToViewBlueprintNumbers, isToViewIdentifications, isToViewDoorNumbers, scalePercentage, outputStream); } }
WebAppContext createWebAppContext() throws IOException, SAXException, ClassNotFoundException, UnavailableException { webAppContext = new WebAppContext(); webAppContext.setDefaultsDescriptor(GoWebXmlConfiguration.configuration(getWarFile())); webAppContext.setConfigurationClasses(new String[]{ WebInfConfiguration.class.getCanonicalName(), WebXmlConfiguration.class.getCanonicalName(), JettyWebXmlConfiguration.class.getCanonicalName() }); webAppContext.setContextPath(systemEnvironment.getWebappContextPath()); // delegate all logging to parent classloader to avoid initialization of loggers in multiple classloaders webAppContext.addSystemClass("org.apache.log4j."); webAppContext.addSystemClass("org.slf4j."); webAppContext.addSystemClass("org.apache.commons.logging."); webAppContext.setWar(getWarFile()); webAppContext.setParentLoaderPriority(systemEnvironment.getParentLoaderPriority()); return webAppContext; }
@Override public synchronized void initialize() throws UnavailableException { if (this.deinitialized) { throw new IllegalStateException("Cannot initialize Log4jWebInitializer after it was destroyed."); } // only do this once if (!this.initialized) { this.initialized = true; this.name = this.substitutor.replace(this.servletContext.getInitParameter(LOG4J_CONTEXT_NAME)); final String location = this.substitutor.replace(this.servletContext.getInitParameter(LOG4J_CONFIG_LOCATION)); final boolean isJndi = "true".equals(this.servletContext.getInitParameter(IS_LOG4J_CONTEXT_SELECTOR_NAMED)); if (isJndi) { this.initializeJndi(location); } else { this.initializeNonJndi(location); } } }
@Override public void onStartup(final Set<Class<?>> classes, final ServletContext servletContext) throws ServletException { if (servletContext.getMajorVersion() > 2) { servletContext.log("Log4jServletContainerInitializer starting up Log4j in Servlet 3.0+ environment."); final Log4jWebInitializer initializer = Log4jWebInitializerImpl.getLog4jWebInitializer(servletContext); initializer.initialize(); initializer.setLoggerContext(); // the application is just now starting to start up servletContext.addListener(new Log4jServletContextListener()); final FilterRegistration.Dynamic filter = servletContext.addFilter("log4jServletFilter", new Log4jServletFilter()); if (filter == null) { throw new UnavailableException("In a Servlet 3.0+ application, you must not define a " + "log4jServletFilter in web.xml. Log4j 2 defines this for you automatically."); } filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*"); } }
@Test public void testInitFailure() throws Exception { expect(this.event.getServletContext()).andReturn(this.servletContext); this.servletContext.log(anyObject(String.class)); expectLastCall(); expect(this.servletContext.getAttribute(Log4jWebInitializer.INITIALIZER_ATTRIBUTE)).andReturn(this.initializer); this.initializer.initialize(); expectLastCall().andThrow(new UnavailableException("")); replay(this.event, this.servletContext, this.initializer); try { this.listener.contextInitialized(this.event); fail("Expected a RuntimeException."); } catch (final RuntimeException e) { assertEquals("The message is not correct.", "Failed to initialize Log4j properly.", e.getMessage()); } }
@Test public void testOnStartupFailedDueToInitializerFailure() throws Exception { final UnavailableException exception = new UnavailableException(""); expect(this.servletContext.getMajorVersion()).andReturn(3); this.servletContext.log(anyObject(String.class)); expectLastCall(); expect(this.servletContext.getAttribute(Log4jWebInitializer.INITIALIZER_ATTRIBUTE)).andReturn(this.initializer); this.initializer.initialize(); expectLastCall().andThrow(exception); replay(this.servletContext, this.initializer); try { this.containerInitializer.onStartup(null, this.servletContext); fail("Expected the exception thrown by the initializer; got no exception."); } catch (final UnavailableException e) { assertSame("The exception is not correct.", exception, e); } }
@Test public void testInitializeUsingJndiSelectorFails() throws Exception { expect(this.servletContext.getInitParameter(Log4jWebInitializer.LOG4J_CONTEXT_NAME)).andReturn(null); expect(this.servletContext.getInitParameter(Log4jWebInitializer.LOG4J_CONFIG_LOCATION)).andReturn(null); expect(this.servletContext.getInitParameter(Log4jWebInitializer.IS_LOG4J_CONTEXT_SELECTOR_NAMED)) .andReturn("true"); replay(this.servletContext); assertNull("The context should be null.", ContextAnchor.THREAD_CONTEXT.get()); try { this.initializer.initialize(); fail("Expected an UnavailableException."); } catch (final UnavailableException ignore) { } }