List of usage examples for javax.servlet ServletConfig getInitParameter
public String getInitParameter(String name);
From source file:nl.b3p.kaartenbalie.core.server.persistence.MyEMFDatabase.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); DataMonitoring//from ww w . j a v a 2s. c om .setEnableMonitoring(getConfigValue(config, "reporting", "disabled").equalsIgnoreCase("enabled")); AccountManager .setEnableAccounting(getConfigValue(config, "accounting", "disabled").equalsIgnoreCase("enabled")); Object identity = null; try { openEntityManagerFactory(defaultKaartenbaliePU); identity = createEntityManager(MyEMFDatabase.INIT_EM); log.debug("Getting entity manager ......"); EntityManager em = getEntityManager(MyEMFDatabase.INIT_EM); EntityTransaction tx = em.getTransaction(); tx.begin(); // ReportGenerator.startupClear(em); tx.commit(); } catch (Throwable e) { log.warn("Error creating EntityManager: ", e); throw new ServletException(e); } finally { log.debug("Closing entity manager ....."); closeEntityManager(identity, MyEMFDatabase.INIT_EM); } cachePath = getConfigValue(config, "cache", "/"); if (cachePath != null) { cachePath = getServletContext().getRealPath(cachePath); log.debug("cache pad: " + cachePath); } rg = new Random(); String allowedUpload = config.getInitParameter("allowed_upload_files"); if (allowedUpload != null && allowedUpload.length() > 0) { allowedUploadFiles = allowedUpload.split(","); } // load global context params initGlobalContextParams(config); // configure kb via properties KBConfiguration.configure(); }
From source file:com.portfolio.data.attachment.FileServlet.java
@Override public void init(ServletConfig config) { /// List possible local address try {//from ww w.j a v a 2 s . c om Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface current = interfaces.nextElement(); if (!current.isUp() || current.isLoopback() || current.isVirtual()) continue; Enumeration<InetAddress> addresses = current.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress current_addr = addresses.nextElement(); if (current_addr instanceof Inet4Address) ourIPs.add(current_addr.getHostAddress()); } } } catch (Exception e) { } servContext = config.getServletContext(); backend = config.getServletContext().getInitParameter("backendserver"); server = config.getServletContext().getInitParameter("fileserver"); try { String dataProviderName = config.getInitParameter("dataProviderClass"); dataProvider = (DataProvider) Class.forName(dataProviderName).newInstance(); InitialContext cxt = new InitialContext(); if (cxt == null) { throw new Exception("no context found!"); } /// Init this here, might fail depending on server hosting ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/portfolio-backend"); if (ds == null) { throw new Exception("Data jdbc/portfolio-backend source not found!"); } } catch (Exception e) { e.printStackTrace(); } }
From source file:be.fedict.eid.applet.service.AppletServiceServlet.java
@Override public void init(ServletConfig config) throws ServletException { super.init(config); LOG.debug("init"); this.messageHandlers = new HashMap<Class<?>, MessageHandler<?>>(); for (Class<? extends MessageHandler<?>> messageHandlerClass : MESSAGE_HANDLER_CLASSES) { HandlesMessage handlesMessageAnnotation = messageHandlerClass.getAnnotation(HandlesMessage.class); if (null == handlesMessageAnnotation) { throw new ServletException( "missing meta-data on message handler: " + messageHandlerClass.getName()); }//from w ww . j a v a2 s . c o m Class<? extends AbstractProtocolMessage> protocolMessageClass = handlesMessageAnnotation.value(); MessageHandler<?> messageHandler; try { messageHandler = messageHandlerClass.newInstance(); } catch (Exception e) { throw new ServletException("cannot create message handler instance"); } this.messageHandlers.put(protocolMessageClass, messageHandler); } Collection<MessageHandler<?>> messageHandlers = this.messageHandlers.values(); for (MessageHandler<?> messageHandler : messageHandlers) { try { injectInitParams(config, messageHandler); } catch (Exception e) { throw new ServletException( "error injecting init-param into message handler field: " + e.getMessage(), e); } messageHandler.init(config); } this.unmarshaller = new Unmarshaller(new AppletProtocolMessageCatalog()); String skipSecureConnectionCheck = config.getInitParameter(SKIP_SECURE_CONNECTION_CHECK_INIT_PARAM); if (null != skipSecureConnectionCheck) { this.skipSecureConnectionCheck = Boolean.parseBoolean(skipSecureConnectionCheck); LOG.debug("skipping secure connection check: " + this.skipSecureConnectionCheck); } }
From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java
/** * Initialize the servlet.// w ww . j a v a 2 s . c o m * * @param config * The servlet config. * @throws ServletException */ public void init(ServletConfig config) throws ServletException { super.init(config); portalContext = config.getInitParameter("portal.context"); if (portalContext == null || portalContext.length() == 0) { portalContext = DEFAULT_PORTAL_CONTEXT; } boolean findPageAliases = ServerConfigurationService.getBoolean("portal.use.page.aliases", false); siteHelper = new PortalSiteHelperImpl(this, findPageAliases); portalService = org.sakaiproject.portal.api.cover.PortalService.getInstance(); securityService = (SecurityService) ComponentManager.get("org.sakaiproject.authz.api.SecurityService"); chatHelper = org.sakaiproject.portal.api.cover.PortalChatPermittedHelper.getInstance(); M_log.info("init()"); forceContainer = ServerConfigurationService.getBoolean("login.use.xlogin.to.relogin", true); handlerPrefix = ServerConfigurationService.getString("portal.handler.default", "site"); gatewaySiteUrl = ServerConfigurationService.getString("gatewaySiteUrl", null); sakaiTutorialEnabled = ServerConfigurationService.getBoolean("portal.use.tutorial", true); basicAuth = new BasicAuth(); basicAuth.init(); enableDirect = portalService.isEnableDirect(); // do this before adding handlers to prevent handlers registering 2 // times. // if the handlers were already there they will be re-registered, // but when they are added again, they will be replaced. // warning messages will appear, but the end state will be the same. portalService.addPortal(this); worksiteHandler = new WorksiteHandler(); siteHandler = new SiteHandler(); addHandler(siteHandler); addHandler(new SiteResetHandler()); addHandler(new ToolHandler()); addHandler(new ToolResetHandler()); addHandler(new PageResetHandler()); addHandler(new PageHandler()); addHandler(worksiteHandler); addHandler(new WorksiteResetHandler()); addHandler(new RssHandler()); addHandler(new AtomHandler()); addHandler(new OpmlHandler()); addHandler(new NavLoginHandler()); addHandler(new PresenceHandler()); addHandler(new HelpHandler()); addHandler(new ReLoginHandler()); addHandler(new LoginHandler()); addHandler(new XLoginHandler()); addHandler(new LogoutHandler()); addHandler(new ErrorDoneHandler()); addHandler(new ErrorReportHandler()); addHandler(new StaticStylesHandler()); addHandler(new StaticScriptsHandler()); addHandler(new DirectToolHandler()); addHandler(new RoleSwitchHandler()); addHandler(new RoleSwitchOutHandler()); addHandler(new TimeoutDialogHandler()); addHandler(new JoinHandler()); }
From source file:net.sf.qooxdoo.rpc.RpcServlet.java
/** * Looks up an instance of a service and creates one if necessary. * * @param session the current session (for storing * instances). * @param serviceClassName the fully qualified name of the class * to instantiate. * @param name the name to use for the instance. * @param requiredType The type the service must have. May be * null. /*from www . jav a 2s . c o m*/ */ public synchronized Service getServiceInstance(HttpSession session, String serviceClassName, Object name, Class requiredType) throws ClassNotFoundException, IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException { if (requiredType == null) { requiredType = Service.class; } String lookFor = serviceClassName; if (name != null) { lookFor += "/" + name; } Service inst = (Service) session.getAttribute(lookFor); if (inst == null) { Class clazz = Class.forName(serviceClassName); if (!requiredType.isAssignableFrom(clazz)) { throw new ClassCastException("The requested service class " + clazz.getName() + " is not from the required type " + requiredType.getName() + ""); } inst = (Service) clazz.newInstance(); Class[] paramTypes = new Class[1]; Object[] params = new Object[1]; paramTypes[0] = Environment.class; Method method = MethodUtils.getMatchingAccessibleMethod(clazz, "setWebcomponentEnvironment", paramTypes); if (method == null) { method = MethodUtils.getMatchingAccessibleMethod(clazz, "setQooxdooEnvironment", paramTypes); } if (method != null) { params[0] = new Environment(); method.invoke(inst, params); } if (name != null) { paramTypes[0] = String.class; method = MethodUtils.getMatchingAccessibleMethod(clazz, "setWebcomponentName", paramTypes); if (method != null) { params[0] = name; method.invoke(inst, params); } } session.setAttribute(lookFor, inst); // initialize the service properties ServletConfig servletConfig = getServletConfig(); Enumeration initParamNames = servletConfig.getInitParameterNames(); String initParamName; String initParamValue; int pos; String packageName; String propertyName; HashMap candidates = new HashMap(); while (initParamNames.hasMoreElements()) { initParamName = (String) initParamNames.nextElement(); pos = initParamName.lastIndexOf('.'); if (pos == -1) { packageName = ""; propertyName = initParamName; } else { packageName = initParamName.substring(0, pos); propertyName = initParamName.substring(pos + 1); } String candidateName; if (serviceClassName.startsWith(packageName)) { candidateName = (String) candidates.get(propertyName); if (candidateName == null) { candidates.put(propertyName, initParamName); } else if (candidateName.length() < initParamName.length()) { candidates.put(propertyName, initParamName); } } } Iterator candidatesIterator = candidates.keySet().iterator(); Class propertyType; while (candidatesIterator.hasNext()) { propertyName = (String) candidatesIterator.next(); initParamName = (String) candidates.get(propertyName); initParamValue = servletConfig.getInitParameter(initParamName); propertyType = PropertyUtils.getPropertyType(inst, propertyName); if (propertyType != null) { if (propertyType.getComponentType() == String.class) { PropertyUtils.setSimpleProperty(inst, propertyName, StringUtils.tokenize(initParamValue, ';')); } else { try { PropertyUtils.setSimpleProperty(inst, propertyName, ConvertUtils.convert(initParamValue, propertyType)); } catch (Exception e) { // try to instatiate a class of the supplied parameter //System.out.println("***** setting '" + propertyName + "' to an instance of '" + initParamValue + "'"); PropertyUtils.setSimpleProperty(inst, propertyName, getServiceInstance(session, initParamValue, null, null)); } } } else { //System.out.println("***** property '" + propertyName + "' not matched"); } } // tell the instance that we're done paramTypes = new Class[0]; method = MethodUtils.getMatchingAccessibleMethod(clazz, "webcomponentInit", paramTypes); if (method != null) { params = new Object[0]; method.invoke(inst, params); } } return inst; }
From source file:org.sakaiproject.james.JamesServlet.java
protected void startJames(ServletConfig config) { // get config info String logDir = JamesServlet.getLogDirectory(); String host = ServerConfigurationService.getServerName(); String dns1 = StringUtils.trimToNull(ServerConfigurationService.getString("smtp.dns.1")); String dns2 = StringUtils.trimToNull(ServerConfigurationService.getString("smtp.dns.2")); String smtpPort = StringUtils.trimToNull(ServerConfigurationService.getString("smtp.port")); boolean enabled = ServerConfigurationService.getBoolean("smtp.enabled", false); String postmasterAddress = null; String postmasterLocalPart = StringUtils .trimToNull(ServerConfigurationService.getString("smtp.postmaster.address.local-part")); String postmasterDomain = StringUtils .trimToNull(ServerConfigurationService.getString("smtp.postmaster.address.domain")); if (postmasterDomain != null) { if (postmasterLocalPart == null) { postmasterLocalPart = "postmaster"; }/*from w w w . ja v a2s. c o m*/ postmasterAddress = postmasterLocalPart + "@" + postmasterDomain; try { InternetAddress email = new InternetAddress(postmasterAddress); email.validate(); } catch (Exception ex) { M_log.warn("init(): '" + postmasterAddress + "' is not valid"); postmasterAddress = null; } } // check for missing values if (host == null) host = "127.0.0.1"; if (smtpPort == null) smtpPort = "25"; M_log.debug("init(): host: " + host + " enabled: " + enabled + " dns1: " + dns1 + " dns2: " + dns2 + " smtp.port: " + smtpPort + " logdir: " + logDir); // if not enabled, don't start james if (!enabled) { M_log.debug("init(): James not enabled, aborting"); return; } // set the home for james / phoenix, as configured String homeRelative = config.getInitParameter(PHOENIX_HOME); if (homeRelative == null) { // or pointing to the webapps root if not configured homeRelative = ""; } // expand to real path m_phoenixHome = getServletContext().getRealPath(homeRelative); try { customizeConfig(host, dns1, dns2, smtpPort, logDir, postmasterAddress); } catch (JamesConfigurationException e) { M_log.error("init(): James could not be configured, aborting"); return; } // start the James thread m_runner = new JamesRunner(); }
From source file:de.zib.scalaris.examples.wikipedia.bliki.WikiServlet.java
/** * Extracts servlet parameters from its config into the {@link Options} * class./*from w w w . jav a 2s . c o m*/ * * @param config * servlet config */ protected void readOptionsFromConfig(ServletConfig config) { final Options options = Options.getInstance(); Options.parseOptions(options, config.getInitParameter("SERVERNAME"), config.getInitParameter("SERVERPATH"), config.getInitParameter("WIKI_USE_BACKLINKS"), config.getInitParameter("WIKI_SAVEPAGE_RETRIES"), config.getInitParameter("WIKI_SAVEPAGE_RETRY_DELAY"), config.getInitParameter("WIKI_PAGES_CACHE_IMPL"), config.getInitParameter("WIKI_REBUILD_PAGES_CACHE"), config.getInitParameter("WIKI_STORE_CONTRIBUTIONS"), config.getInitParameter("WIKI_OPTIMISATIONS"), config.getInitParameter("LOG_USER_REQS"), config.getInitParameter("SCALARIS_NODE_DISCOVERY")); System.out.println("Effective optimisations: " + options.OPTIMISATIONS.toString()); }
From source file:org.sakaiproject.portal.charon.SkinnableCharonPortal.java
private void showSnoop(PortalRenderContext rcontext, boolean b, ServletConfig servletConfig, HttpServletRequest req) {/*from w ww . java2s.c om*/ Enumeration e = null; rcontext.put("snoopRequest", req.toString()); if (servletConfig != null) { Map<String, Object> m = new HashMap<String, Object>(); e = servletConfig.getInitParameterNames(); if (e != null) { while (e.hasMoreElements()) { String param = (String) e.nextElement(); m.put(param, servletConfig.getInitParameter(param)); } } rcontext.put("snoopServletConfigParams", m); } rcontext.put("snoopRequest", req); e = req.getHeaderNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); m.put(name, req.getHeader(name)); } rcontext.put("snoopRequestHeaders", m); } e = req.getParameterNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); m.put(name, req.getParameter(name)); } rcontext.put("snoopRequestParamsSingle", m); } e = req.getParameterNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); String[] vals = (String[]) req.getParameterValues(name); StringBuilder sb = new StringBuilder(); if (vals != null) { sb.append(vals[0]); for (int i = 1; i < vals.length; i++) sb.append(" ").append(vals[i]); } m.put(name, sb.toString()); } rcontext.put("snoopRequestParamsMulti", m); } e = req.getAttributeNames(); if (e.hasMoreElements()) { Map<String, Object> m = new HashMap<String, Object>(); while (e.hasMoreElements()) { String name = (String) e.nextElement(); m.put(name, req.getAttribute(name)); } rcontext.put("snoopRequestAttr", m); } }
From source file:org.amplafi.jawr.maven.JawrMojo.java
private void setupJawrConfig(ServletConfig config, ServletContext context, final Map<String, Object> attributes, final Response respData) { expect(config.getServletContext()).andReturn(context).anyTimes(); expect(config.getServletName()).andReturn("maven-jawr-plugin").anyTimes(); context.log(isA(String.class)); expectLastCall().anyTimes();/*w w w.j a va 2s . co m*/ expect(context.getResourcePaths(isA(String.class))).andAnswer(new IAnswer<Set>() { public Set<String> answer() throws Throwable { final Set<String> set = new HashSet<String>(); // hack to disallow orphan bundles Exception e = new Exception(); for (StackTraceElement trace : e.getStackTrace()) { if (trace.getClassName().endsWith("OrphanResourceBundlesMapper")) { return set; } } String path = (String) EasyMock.getCurrentArguments()[0]; File file = new File(getRootPath() + path); if (file.exists() && file.isDirectory()) { for (String one : file.list()) { set.add(path + one); } } return set; } }).anyTimes(); expect(context.getResourceAsStream(isA(String.class))).andAnswer(new IAnswer<InputStream>() { public InputStream answer() throws Throwable { String path = (String) EasyMock.getCurrentArguments()[0]; File file = new File(getRootPath(), path); return new FileInputStream(file); } }).anyTimes(); expect(context.getAttribute(isA(String.class))).andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { return attributes.get(EasyMock.getCurrentArguments()[0]); } }).anyTimes(); context.setAttribute(isA(String.class), isA(Object.class)); expectLastCall().andAnswer(new IAnswer<Object>() { public Object answer() throws Throwable { String key = (String) EasyMock.getCurrentArguments()[0]; Object value = EasyMock.getCurrentArguments()[1]; attributes.put(key, value); return null; } }).anyTimes(); expect(config.getInitParameterNames()).andReturn(new Enumeration<String>() { public boolean hasMoreElements() { return false; } public String nextElement() { return null; } }).anyTimes(); expect(config.getInitParameter(JawrConstant.TYPE_INIT_PARAMETER)).andAnswer(new IAnswer<String>() { public String answer() throws Throwable { return respData == null ? null : respData.getType(); } }).anyTimes(); expect(config.getInitParameter("configLocation")).andReturn(getConfigLocation()).anyTimes(); expect(config.getInitParameter("configPropertiesSourceClass")).andReturn(null).anyTimes(); }
From source file:com.concursive.connect.web.webdav.servlets.WebdavServlet.java
/** * Initialize this servlet./* ww w . jav a2s. c o m*/ * * @throws javax.servlet.ServletException Description of the Exception */ public void init() throws ServletException { super.init(); ServletConfig config = getServletConfig(); String value = null; try { value = config.getInitParameter("secret"); if (value != null) { secret = value; } } catch (Throwable t) { ; } }