List of usage examples for javax.servlet UnavailableException UnavailableException
public UnavailableException(String msg)
From source file:com.boylesoftware.web.impl.UserInputControllerMethodArgHandler.java
/** * Create new handler.//w ww . java2s.c om * * @param validatorFactory Validator factory. * @param beanClass User input bean class. * @param validationGroups Validation groups to apply during bean * validation, or empty array to use the default group. * * @throws UnavailableException If an error happens. */ UserInputControllerMethodArgHandler(final ValidatorFactory validatorFactory, final Class<?> beanClass, final Class<?>[] validationGroups) throws UnavailableException { this.validatorFactory = validatorFactory; this.beanClass = beanClass; this.validationGroups = validationGroups; try { final BeanInfo beanInfo = Introspector.getBeanInfo(this.beanClass); final PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors(); final List<FieldDesc> beanFields = new ArrayList<>(); for (final PropertyDescriptor propDesc : propDescs) { final String propName = propDesc.getName(); final Class<?> propType = propDesc.getPropertyType(); final Method propGetter = propDesc.getReadMethod(); final Method propSetter = propDesc.getWriteMethod(); if ((propGetter == null) || (propSetter == null)) continue; Field propField = null; for (Class<?> c = this.beanClass; !c.equals(Object.class); c = c.getSuperclass()) { try { propField = c.getDeclaredField(propName); break; } catch (final NoSuchFieldException e) { // nothing, continue the loop } } final boolean noTrim = (((propField != null) && propField.isAnnotationPresent(NoTrim.class)) || (propGetter.isAnnotationPresent(NoTrim.class))); Class<? extends Binder> binderClass = null; String format = null; String errorMessage = Bind.DEFAULT_MESSAGE; Bind bindAnno = null; if (propField != null) bindAnno = propField.getAnnotation(Bind.class); if (bindAnno == null) bindAnno = propGetter.getAnnotation(Bind.class); if (bindAnno != null) { binderClass = bindAnno.binder(); format = bindAnno.format(); errorMessage = bindAnno.message(); } if (binderClass == null) { if ((String.class).isAssignableFrom(propType)) binderClass = StringBinder.class; else if ((Boolean.class).isAssignableFrom(propType) || propType.equals(Boolean.TYPE)) binderClass = BooleanBinder.class; else if ((Integer.class).isAssignableFrom(propType) || propType.equals(Integer.TYPE)) binderClass = IntegerBinder.class; else if (propType.isEnum()) binderClass = EnumBinder.class; else // TODO: add more standard binders throw new UnavailableException( "Unsupported user input bean field type " + propType.getName() + "."); } beanFields.add(new FieldDesc(propDesc, noTrim, binderClass.newInstance(), format, errorMessage)); } this.beanFields = beanFields.toArray(new FieldDesc[beanFields.size()]); } catch (final IntrospectionException e) { this.log.error("error introspecting user input bean", e); throw new UnavailableException("Specified user input bean" + " class could not be introspected."); } catch (final IllegalAccessException | InstantiationException e) { this.log.error("error instatiating binder", e); throw new UnavailableException("Used user input bean field binder" + " could not be instantiated."); } this.beanPool = new FastPool<>(new PoolableObjectFactory<PoolableUserInput>() { @Override public PoolableUserInput makeNew(final FastPool<PoolableUserInput> pool, final int pooledObjectId) { try { return new PoolableUserInput(pool, pooledObjectId, beanClass.newInstance()); } catch (final InstantiationException | IllegalAccessException e) { throw new RuntimeException("Error instatiating user input bean.", e); } } }, "UserInputBeansPool_" + beanClass.getSimpleName()); }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.XMLConfiguration.java
protected void initialize(XmlParser.Node config) throws ClassNotFoundException, UnavailableException { Iterator iter = config.iterator(); XmlParser.Node node = null;/*from w ww .j av a 2s . c o m*/ while (iter.hasNext()) { try { Object o = iter.next(); if (!(o instanceof XmlParser.Node)) continue; node = (XmlParser.Node) o; String name = node.getTag(); initWebXmlElement(name, node); } catch (ClassNotFoundException e) { throw e; } catch (Exception e) { log.warn("Configuration problem at " + node, e); throw new UnavailableException("Configuration problem"); } } }
From source file:net.lightbody.bmp.proxy.jetty.jetty.servlet.ServletHolder.java
/** Service a request with this servlet. *//*from www.jav a2 s . c o m*/ public void handle(ServletRequest request, ServletResponse response) throws ServletException, UnavailableException, IOException { if (_class == null) throw new UnavailableException("Servlet Not Initialized"); Servlet servlet = (!_initOnStartup || _servlets != null) ? getServlet() : _servlet; if (servlet == null) throw new UnavailableException("Could not instantiate " + _class); // Service the request boolean servlet_error = true; Principal user = null; HttpRequest http_request = null; try { // Handle aliased path if (_forcedPath != null) // TODO complain about poor naming to the Jasper folks request.setAttribute("org.apache.catalina.jsp_file", _forcedPath); // Handle run as if (_runAs != null && _realm != null) { http_request = getHttpContext().getHttpConnection().getRequest(); user = _realm.pushRole(http_request.getUserPrincipal(), _runAs); http_request.setUserPrincipal(user); } servlet.service(request, response); servlet_error = false; } catch (UnavailableException e) { if (_servlets != null && servlet != null) stop(); makeUnavailable(e); } finally { // pop run-as role if (_runAs != null && _realm != null && user != null) { user = _realm.popRole(user); http_request.setUserPrincipal(user); } // Handle error params. if (servlet_error) request.setAttribute("javax.servlet.error.servlet_name", getName()); // Return to singleThreaded pool synchronized (this) { if (_servlets != null && servlet != null) _servlets.push(servlet); } } }
From source file:com.boylesoftware.web.AbstractWebApplication.java
/** * Get web-application object for the specified servlet context. The method * can be used in custom application components that run outside controllers * (controllers can get the application object as a controller method * argument), such as JSP views./*from www . ja v a 2 s . c o m*/ * * @param sc The servlet context. * * @return The web-application object. * * @throws UnavailableException If web-application object is not available * for the specified servlet context. */ public static AbstractWebApplication getApplication(final ServletContext sc) throws UnavailableException { final AbstractWebApplication webapp = (AbstractWebApplication) sc.getAttribute(WEBAPP_ATTNAME); if (webapp == null) throw new UnavailableException("WebApplication listener has not been configured."); return webapp; }
From source file:org.apache.click.extras.spring.SpringClickServlet.java
/** * Initialize the SpringClickServlet and the Spring application context * bean factory. An Spring <tt>ClassPathXmlApplicationContext</tt> bean * factory is used and initialize with the servlet <tt>init-param</tt> * named <tt>"spring-path"</tt>. * * @see ClickServlet#init()//from w ww. jav a2 s .c om * * @throws ServletException if the click app could not be initialized */ @Override public void init() throws ServletException { super.init(); ServletContext servletContext = getServletContext(); applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext); if (applicationContext == null) { String springPath = getInitParameter(SPRING_PATH); if (springPath == null) { String msg = SPRING_PATH + " servlet init parameter not defined"; throw new UnavailableException(msg); } applicationContext = new ClassPathXmlApplicationContext(springPath); } String injectPageBeans = getInitParameter(INJECT_PAGE_BEANS); if ("true".equalsIgnoreCase(injectPageBeans)) { // Process page classes looking for setter methods which match beans // available in the applicationContext List<Class<? extends Page>> pageClassList = getConfigService().getPageClassList(); for (Class<? extends Page> pageClass : pageClassList) { loadSpringBeanSetterMethods(pageClass); } } }
From source file:com.boylesoftware.web.AbstractWebApplication.java
/** * Get user record handler used by the authentication service. This method * is called once during the application initialization. * * <p>Since there is no generic user record handler implementation, this * method, unless overridden, throws an {@link UnavailableException}, so * that if the application uses an authentication service that works with * persistent user account records, it must override this method and provide * an application-specific implementation of the user record handler. * * @param sc Servlet context./*w w w . j a va 2 s. c o m*/ * @param config Application configuration. * * @return User record handler. * * @throws UnavailableException If user record handler is unavailable. * Throwing this exception makes the web-application fail to start. */ @SuppressWarnings("unused") protected UserRecordHandler<?> getUserRecordHandler(final ServletContext sc, final ApplicationConfiguration config) throws UnavailableException { throw new UnavailableException("Application uses user record" + " authentication service implementation, but user record" + " handler is not provided."); }
From source file:com.adito.core.CoreServlet.java
public void init() throws ServletException { pastInitialisation = false;/*from www . ja va2 s .com*/ try { ContextHolder.getContext().addContextListener(this); if (SystemProperties.get("adito.disableNewSSLEngine", "false").equals("true")) SSLTransportFactory.setTransportImpl(SSLTransportImpl.class); // Init bouncy castle Class c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); Security.insertProviderAt((Provider) c.newInstance(), 0); // Start the database // TODO this should be configurable dbServer = new EmbeddedHSQLDBServer( "true".equalsIgnoreCase(SystemProperties.get("adito.hsqldb.tcpipServer", "false"))); // Load the property classes PropertyClassManager.getInstance().registerPropertyClass(new ProfileProperties()); PropertyClassManager.getInstance().registerPropertyClass(new SystemConfiguration()); PropertyClassManager.getInstance().registerPropertyClass(new UserAttributes()); PropertyClassManager.getInstance().registerPropertyClass(new PolicyAttributes()); PropertyClassManager.getInstance().registerPropertyClass(new RealmProperties()); PropertyClassManager.getInstance().registerPropertyClass(new ApplicationParameters()); PropertyClassManager.getInstance().registerPropertyClass(new ResourceAttributes()); // Load the property database and categories // Use the default system database if no other has been registered try { ProfilesFactory.getInstance().open(this); } catch (Exception e) { log.error("Failed to initialise property database.", e); throw new ServletException("Failed to initialise system database.", e); } bootProgressMonitor = ContextHolder.getContext().getBootProgressMonitor(); // Initialise extensions bootProgressMonitor.updateMessage("Initialising extensions"); bootProgressMonitor.updateProgress(10); initExtensionStore(); // Initialise core bootProgressMonitor.updateMessage("Initialising core"); bootProgressMonitor.updateProgress(20); initInternal(); initOther(); initServlet(); getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this); initModuleConfigFactory(); // Initialize modules as needed ModuleConfig moduleConfig = initModuleConfig("", config); initCore(); // Start extensions bootProgressMonitor.updateMessage("Starting extensions"); bootProgressMonitor.updateProgress(30); startExtensions(); // Update module configuration bootProgressMonitor.updateMessage("Updating configuration"); bootProgressMonitor.updateProgress(40); initModuleMessageResources(moduleConfig); initModuleDataSources(moduleConfig); initModulePlugIns(moduleConfig); // Start extensions bootProgressMonitor.updateMessage("Activating core"); bootProgressMonitor.updateProgress(45); activateCore(); // do not freeze, we want to be able to dynamically change struts // configuration // moduleConfig.freeze(); bootProgressMonitor.updateMessage("Finalising configuration"); bootProgressMonitor.updateProgress(85); Enumeration names = getServletConfig().getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (!name.startsWith("moduleConfig/")) { continue; } String prefix = name.substring(6); moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name)); initModuleMessageResources(moduleConfig); initModuleDataSources(moduleConfig); initModulePlugIns(moduleConfig); // do not freeze, we want to be able to dynamically change // struts configuration // moduleConfig.freeze(); } this.initModulePrefixes(this.getServletContext()); this.destroyConfigDigester(); fireCoreEvent(new CoreEvent(this, CoreEventConstants.SERVER_STARTED, null, null)); } catch (UnavailableException ex) { throw ex; } catch (Throwable t) { // The follow error message is not retrieved from internal message // resources as they may not have been able to have been // initialized log.error("Failed to initialise core.", t); throw new UnavailableException(t.getMessage()); } finally { pastInitialisation = true; } }
From source file:com.sslexplorer.core.CoreServlet.java
public void init() throws ServletException { pastInitialisation = false;//from www . j a v a 2 s . c om try { ContextHolder.getContext().addContextListener(this); if (SystemProperties.get("sslexplorer.disableNewSSLEngine", "false").equals("true")) SSLTransportFactory.setTransportImpl(SSLTransportImpl.class); // Init bouncy castle Class c = Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); Security.insertProviderAt((Provider) c.newInstance(), 0); // Start the database // TODO this should be configurable dbServer = new EmbeddedHSQLDBServer( "true".equalsIgnoreCase(SystemProperties.get("sslexplorer.hsqldb.tcpipServer", "false"))); // Load the property classes PropertyClassManager.getInstance().registerPropertyClass(new ProfileProperties()); PropertyClassManager.getInstance().registerPropertyClass(new SystemConfiguration()); PropertyClassManager.getInstance().registerPropertyClass(new UserAttributes()); PropertyClassManager.getInstance().registerPropertyClass(new PolicyAttributes()); PropertyClassManager.getInstance().registerPropertyClass(new RealmProperties()); PropertyClassManager.getInstance().registerPropertyClass(new ApplicationParameters()); PropertyClassManager.getInstance().registerPropertyClass(new ResourceAttributes()); // Load the property database and categories // Use the default system database if no other has been registered try { ProfilesFactory.getInstance().open(this); } catch (Exception e) { log.error("Failed to initialise property database.", e); throw new ServletException("Failed to initialise system database.", e); } bootProgressMonitor = ContextHolder.getContext().getBootProgressMonitor(); // Initialise extensions bootProgressMonitor.updateMessage("Initialising extensions"); bootProgressMonitor.updateProgress(10); initExtensionStore(); // Initialise core bootProgressMonitor.updateMessage("Initialising core"); bootProgressMonitor.updateProgress(20); initInternal(); initOther(); initServlet(); getServletContext().setAttribute(Globals.ACTION_SERVLET_KEY, this); initModuleConfigFactory(); // Initialize modules as needed ModuleConfig moduleConfig = initModuleConfig("", config); initCore(); // Start extensions bootProgressMonitor.updateMessage("Starting extensions"); bootProgressMonitor.updateProgress(30); startExtensions(); // Update module configuration bootProgressMonitor.updateMessage("Updating configuration"); bootProgressMonitor.updateProgress(40); initModuleMessageResources(moduleConfig); initModuleDataSources(moduleConfig); initModulePlugIns(moduleConfig); // Start extensions bootProgressMonitor.updateMessage("Activating core"); bootProgressMonitor.updateProgress(45); activateCore(); // do not freeze, we want to be able to dynamically change struts // configuration // moduleConfig.freeze(); bootProgressMonitor.updateMessage("Finalising configuration"); bootProgressMonitor.updateProgress(85); Enumeration names = getServletConfig().getInitParameterNames(); while (names.hasMoreElements()) { String name = (String) names.nextElement(); if (!name.startsWith("moduleConfig/")) { continue; } String prefix = name.substring(6); moduleConfig = initModuleConfig(prefix, getServletConfig().getInitParameter(name)); initModuleMessageResources(moduleConfig); initModuleDataSources(moduleConfig); initModulePlugIns(moduleConfig); // do not freeze, we want to be able to dynamically change // struts configuration // moduleConfig.freeze(); } this.initModulePrefixes(this.getServletContext()); this.destroyConfigDigester(); fireCoreEvent(new CoreEvent(this, CoreEventConstants.SERVER_STARTED, null, null)); } catch (UnavailableException ex) { throw ex; } catch (Throwable t) { // The follow error message is not retrieved from internal message // resources as they may not have been able to have been // initialized log.error("Failed to initialise core.", t); throw new UnavailableException(t.getMessage()); } finally { pastInitialisation = true; } }
From source file:org.ireland.jnetty.webapp.WebApp.java
/** * /*w w w . ja v a2 s. co m*/ * ContextURI?FilterChainInvocation * * @param contextURI * @param filterMapper DispatcherType?FilterMapper * @return * @throws ServletException */ private FilterChainInvocation createFilterChainInvocation(String contextURI, FilterMapper filterMapper) throws ServletException { if (debug) log.debug("createFilterChainInvocation:" + contextURI); FilterChainInvocation fcInvocation = new FilterChainInvocation(this, contextURI); try { FilterChain chain; if (!isEnabled()) //503 { Exception ex = new UnavailableException("'" + getContextPath() + "' is not currently available."); chain = new ExceptionFilterChain(ex); } else { //?Servlet chain = _servletMapper.buildServletChain(fcInvocation); // JettyTomcat,?Sevlet??,??Filter //?Filter chain = filterMapper.buildFilterChain(fcInvocation, chain); } fcInvocation.setFilterChain(chain); } catch (Exception e) { log.debug(e.toString(), e); FilterChain chain = new ExceptionFilterChain(e); fcInvocation.setFilterChain(chain); } return fcInvocation; }
From source file:net.wastl.webmail.server.WebMailServer.java
protected void initStorage() throws UnavailableException { /* Storage API */ try {/*ww w . j a v a 2 s .c om*/ Class storage_api = Class.forName(config.getProperty("webmail.storage")); Class[] tmp = new Class[1]; tmp[0] = Class.forName("net.wastl.webmail.server.WebMailServer"); Constructor cons = storage_api.getConstructor(tmp); Object[] sargs = new Object[1]; sargs[0] = this; storage = (Storage) cons.newInstance(sargs); } catch (InvocationTargetException e) { log.fatal("Could not initialize. Exiting now! Nested exc:", e.getTargetException()); throw new UnavailableException(e.getMessage()); } catch (Exception e) { log.fatal("Could not initialize. Exiting now!", e); throw new UnavailableException(e.getMessage()); } }