List of usage examples for javax.servlet ServletContext getInitParameter
public String getInitParameter(String name);
String
containing the value of the named context-wide initialization parameter, or null
if the parameter does not exist. From source file:com.github.persapiens.jsfboot.ServletContextConfigurerIT.java
public void testKey() { ServletContext servletContext = new MockServletContext(); ServletContextConfigurer servletContextConfigurer = new JsfServletContextConfigurer(servletContext); servletContextConfigurer.configure(); assertThat(servletContext.getInitParameter("jsf.key")).isEqualTo("value"); }
From source file:org.joinfaces.ServletContextConfigurerIT.java
@Test public void testEmpty() { ServletContext servletContext = new MockServletContext(); ServletContextConfigurer servletContextConfigurer = new JsfServletContextConfigurer(servletContext); servletContextConfigurer.configure(); assertThat(servletContext.getInitParameter("jsf.empty")).isNull(); }
From source file:org.joinfaces.ServletContextConfigurerIT.java
@Test public void testKey() { ServletContext servletContext = new MockServletContext(); ServletContextConfigurer servletContextConfigurer = new JsfServletContextConfigurer(servletContext); servletContextConfigurer.configure(); assertThat(servletContext.getInitParameter("jsf.key")).isEqualTo("value"); }
From source file:br.bireme.web.AuthenticationServlet.java
@Override public void init() { try {// w w w . jav a 2 s .co m final ServletContext context = getServletContext(); final String host = context.getInitParameter("host"); final int port = Integer.parseInt(context.getInitParameter("port")); final String user = context.getInitParameter("username"); final String password = context.getInitParameter("password"); final MongoClient mongoClient = new MongoClient(host, port); final DB db = mongoClient.getDB(SOCIAL_CHECK_DB); if (!user.trim().isEmpty()) { final boolean auth = db.authenticate(user, password.toCharArray()); if (!auth) { throw new IllegalArgumentException("invalid user/password"); } } final DBCollection coll = db.getCollection(BROKEN_LINKS_COL); final DBCollection hcoll = db.getCollection(HISTORY_COL); context.setAttribute("collection", coll); context.setAttribute("historycoll", hcoll); context.setAttribute("readOnlyMode", false); } catch (UnknownHostException ex) { Logger.getLogger(AuthenticationServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.github.persapiens.jsfboot.ServletContextConfigurerIT.java
@Test(expectedExceptions = IllegalArgumentException.class) public void testNull() { ServletContext servletContext = new MockServletContext(); ServletContextConfigurer servletContextConfigurer = new NullServletContextConfigurer(servletContext); servletContextConfigurer.configure(); assertThat(servletContext.getInitParameter(null)).isNull(); assertThat(servletContext.getInitParameter("string")).isNull(); assertThat(servletContext.getInitParameter("boolean")).isNull(); assertThat(servletContext.getInitParameter("integer")).isNull(); }
From source file:org.joinfaces.ServletContextConfigurerIT.java
@Test(expected = IllegalArgumentException.class) public void testNull() { ServletContext servletContext = new MockServletContext(); ServletContextConfigurer servletContextConfigurer = new NullServletContextConfigurer(servletContext); servletContextConfigurer.configure(); assertThat(servletContext.getInitParameter(null)).isNull(); assertThat(servletContext.getInitParameter("string")).isNull(); assertThat(servletContext.getInitParameter("boolean")).isNull(); assertThat(servletContext.getInitParameter("integer")).isNull(); assertThat(servletContext.getInitParameter("long")).isNull(); }
From source file:com.nabla.dc.server.MyReadWriteDatabase.java
@Inject public MyReadWriteDatabase(final ServletContext serverContext, final ReportManager reportManager) throws SQLException, DispatchException { super("dcrw", serverContext, IRoles.class, serverContext.getInitParameter("root_password")); if ("1".equals(serverContext.getInitParameter(PRODUCTION_MODE))) { if (log.isDebugEnabled()) log.debug("loading internal report table"); final Connection conn = getConnection(); try {/* w ww .j ava 2 s .com*/ final ConnectionTransactionGuard guard = new ConnectionTransactionGuard(conn); try { Database.executeUpdate(conn, "DELETE FROM report WHERE internal_name IS NOT NULL;"); final File reportFolder = new File( serverContext.getRealPath(ReportManager.INTERNAL_REPORT_FOLDER)); for (File folder : reportFolder.listFiles((FileFilter) DirectoryFileFilter.INSTANCE)) loadInternalReport(conn, folder, reportManager); guard.setSuccess(); } finally { guard.close(); } } finally { conn.close(); } } }
From source file:info.magnolia.init.DefaultMagnoliaInitPaths.java
/** * Figures out the local host name, makes sure it's lowercase, and use its unqualified name if the {@value #MAGNOLIA_UNQUALIFIED_SERVER_NAME} init parameter is set to true. */// w w w . ja v a 2 s. c om protected String determineServerName(ServletContext context) { final boolean unqualifiedServerName = BooleanUtils .toBoolean(context.getInitParameter(MAGNOLIA_UNQUALIFIED_SERVER_NAME)); final String retroCompatMethodCall = magnoliaServletContextListener.initServername(unqualifiedServerName); if (retroCompatMethodCall != null) { DeprecationUtil.isDeprecated( "You should update your code and override determineServerName(ServletContext) instead of initServername(String)"); return retroCompatMethodCall; } try { String serverName = StringUtils.lowerCase(InetAddress.getLocalHost().getHostName()); if (unqualifiedServerName && StringUtils.contains(serverName, ".")) { serverName = StringUtils.substringBefore(serverName, "."); } return serverName; } catch (UnknownHostException e) { log.error(e.getMessage()); return null; } }
From source file:org.accada.epcis.repository.query.QueryInitServlet.java
/** * Loads the application property file and populates a java.util.Properties * instance.//from w w w. java 2s .co m * * @param servletConfig * The ServletConfig used to locate the application property * file. */ private void loadApplicationProperties(ServletConfig servletConfig) { properties = new Properties(); // read application.properties from classpath String path = "/"; String appConfigFile = "application.properties"; InputStream is = QueryInitServlet.class.getResourceAsStream(path + appConfigFile); try { if (is == null) { // read properties from file specified in servlet context ServletContext ctx = servletConfig.getServletContext(); path = ctx.getRealPath("/"); appConfigFile = ctx.getInitParameter(APP_CONFIG_LOCATION); is = new FileInputStream(path + appConfigFile); } properties.load(is); is.close(); LOG.info("Loaded application properties from " + path + appConfigFile); } catch (IOException e) { LOG.error("Unable to load application properties from " + path + appConfigFile, e); } }
From source file:dinistiq.web.DinistiqContextLoaderListener.java
/** * Web related dinistiq initialization with parameters taken from the web.xml. * * Looks up relevant packages for scanning and a custom class resolver's implementation class name. Exposes any * bean from the dinistiq scope to the application scope (servlet context) of the web layer including an instance * of dinistiq itself./*from w w w .j a v a2 s. c om*/ * * @param contextEvent */ @Override public void contextInitialized(ServletContextEvent contextEvent) { // just to check what our log instance looks like LOG.warn("contextInitialized() log: {}", LOG.getClass().getName()); ServletContext context = contextEvent.getServletContext(); Set<String> packages = new HashSet<>(); String packagNameString = context.getInitParameter(DINISTIQ_PACKAGES); if (StringUtils.isNotBlank(packagNameString)) { for (String packageName : packagNameString.split(",")) { packageName = packageName.trim(); packages.add(packageName); } // for } // if String classResolverName = context.getInitParameter(DINISTIQ_CLASSRESOLVER); ClassResolver classResolver = null; if (StringUtils.isNotBlank(classResolverName)) { try { Class<?> forName = Class.forName(classResolverName); Object[] args = new Object[1]; args[0] = packages; classResolver = (ClassResolver) forName.getConstructors()[0].newInstance(args); } catch (Exception e) { LOG.error("contextInitialized() cannot obtain custom class resolver", e); } // try/catch } // if LOG.info("contextInitialized() classResolver: {} :{}", classResolver, classResolverName); classResolver = (classResolver == null) ? new SimpleClassResolver(packages) : classResolver; try { Map<String, Object> externalBeans = new HashMap<>(); externalBeans.put("servletContext", context); Dinistiq dinistiq = new Dinistiq(classResolver, externalBeans); context.setAttribute(DINISTIQ_INSTANCE, dinistiq); for (String name : dinistiq.getAllBeanNames()) { context.setAttribute(name, dinistiq.findBean(Object.class, name)); } // for Collection<RegisterableServlet> servlets = dinistiq.findBeans(RegisterableServlet.class); List<RegisterableServlet> orderedServlets = new ArrayList<>(servlets.size()); orderedServlets.addAll(servlets); Collections.sort(orderedServlets); LOG.debug("contextInitialized() servlets {}", orderedServlets); for (RegisterableServlet servlet : orderedServlets) { ServletRegistration registration = context.addServlet(servlet.getClass().getSimpleName(), servlet); for (String urlPattern : servlet.getUrlPatterns()) { LOG.debug("contextInitialized() * {}", urlPattern); registration.addMapping(urlPattern); } // for } // for } catch (Exception ex) { LOG.error("init()", ex); } // try/catch }