List of usage examples for javax.servlet ServletConfig getInitParameter
public String getInitParameter(String name);
From source file:org.wrml.server.WrmlServlet.java
@Override public void init(final ServletConfig servletConfig) throws ServletException { LOGGER.debug("Servlet Name {}", servletConfig.getServletName()); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Parameters names passed ["); List<String> paramList = new ArrayList<>(); Enumeration<String> params = servletConfig.getInitParameterNames(); while (params.hasMoreElements()) { String paramName = params.nextElement(); paramList.add(String.format("%s=%s", paramName, servletConfig.getInitParameter(paramName))); }//from ww w . j ava 2s . c o m LOGGER.debug("Parameters names passed={}", Arrays.toString(paramList.toArray())); } super.init(servletConfig); final String configFileLocation = PropertyUtil.getSystemProperty( EngineConfiguration.WRML_CONFIGURATION_FILE_PATH_PROPERTY_NAME, servletConfig.getInitParameter(WRML_CONFIGURATION_FILE_PATH_INIT_PARAM_NAME)); String configResourceLocation = null; if (configFileLocation == null) { configResourceLocation = servletConfig .getInitParameter(WRML_CONFIGURATION_RESOURCE_PATH_INIT_PARAM_NAME); } try { final EngineConfiguration engineConfig; if (configFileLocation != null) { LOGGER.info("Extracted configuration file location: {}", configFileLocation); engineConfig = EngineConfiguration.load(configFileLocation); } else if (configResourceLocation != null) { LOGGER.info("Extracted configuration resource location: {}", configResourceLocation); engineConfig = EngineConfiguration.load(getClass(), configResourceLocation); } else { throw new ServletException("The WRML engine configuration is null. Unable to initialize servlet."); } final Engine engine = new DefaultEngine(); engine.init(engineConfig); setEngine(engine); LOGGER.debug("Initialized WRML with: {}", engineConfig); } catch (IOException ex) { throw new ServletException("Unable to initialize servlet.", ex); } LOGGER.info("WRML SERVLET INITIALIZED --------------------------------------------------"); }
From source file:test.unit.be.fedict.eid.applet.service.AuthenticationDataMessageHandlerTest.java
public void testHandleMessageNRCID() throws Exception { // setup//www. ja v a 2 s. c om KeyPair keyPair = MiscTestUtils.generateKeyPair(); DateTime notBefore = new DateTime(); DateTime notAfter = notBefore.plusYears(1); String userId = "1234"; X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test, SERIALNUMBER=" + userId, notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null); byte[] salt = "salt".getBytes(); byte[] sessionId = "session-id".getBytes(); AuthenticationDataMessage message = new AuthenticationDataMessage(); message.authnCert = certificate; message.saltValue = salt; message.sessionId = sessionId; Map<String, String> httpHeaders = new HashMap<String, String>(); HttpSession testHttpSession = new HttpTestSession(); HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class); ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class); byte[] challenge = AuthenticationChallenge.generateChallenge(testHttpSession); AuthenticationContract authenticationContract = new AuthenticationContract(salt, null, null, sessionId, null, challenge); byte[] toBeSigned = authenticationContract.calculateToBeSigned(); Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(keyPair.getPrivate()); signature.update(toBeSigned); byte[] signatureValue = signature.sign(); message.signatureValue = signatureValue; EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.CHALLENGE_MAX_MATURITY_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.AUTHN_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUTHN_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(AuthenticationTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.HOSTNAME_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INET_ADDRESS_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.AUDIT_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUDIT_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(AuditTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVER_CERTIFICATE)) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(HelloMessageHandler.SESSION_ID_CHANNEL_BINDING_INIT_PARAM_NAME)) .andStubReturn(null); String nrcidSecret = "112233445566778899AABBCCDDEEFF00112233445566778899"; EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_SECRET_INIT_PARAM_NAME)) .andStubReturn(nrcidSecret); String nrcidAppId = "my-app-id"; EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_APP_ID_INIT_PARAM_NAME)) .andStubReturn(nrcidAppId); String nrcidOrgId = "my-org-id"; EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_ORG_ID_INIT_PARAM_NAME)) .andStubReturn(nrcidOrgId); EasyMock.expect(mockServletRequest.getAttribute("javax.servlet.request.ssl_session")) .andStubReturn(new String(Hex.encodeHex(sessionId))); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_IDENTITY_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_CERTS_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_ADDRESS_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_PHOTO_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(HelloMessageHandler.IDENTITY_INTEGRITY_SERVICE_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(HelloMessageHandler.IDENTITY_INTEGRITY_SERVICE_INIT_PARAM_NAME + "Class")) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVICE)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVICE + "Class")) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(IdentityDataMessageHandler.INCLUDE_DATA_FILES)) .andReturn(null); EasyMock.expect(mockServletRequest.getRemoteAddr()).andStubReturn("1.2.3.4"); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUTHN_SIGNATURE_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter( AuthenticationDataMessageHandler.AUTHN_SIGNATURE_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(null); // prepare EasyMock.replay(mockServletRequest, mockServletConfig); // operate AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance); this.testedInstance.init(mockServletConfig); this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, testHttpSession); // verify EasyMock.verify(mockServletRequest, mockServletConfig); assertTrue(AuthenticationTestService.isCalled()); String nrcid = UserIdentifierUtil.getNonReversibleCitizenIdentifier(userId, nrcidOrgId, nrcidAppId, nrcidSecret); assertTrue(nrcid.equals(AuditTestService.getAuditUserId())); assertTrue(nrcid.equals(testHttpSession.getAttribute("eid.identifier"))); }
From source file:test.unit.be.fedict.eid.applet.service.AuthenticationDataMessageHandlerTest.java
@Test public void testInvalidAuthenticationSignature() throws Exception { // setup/*from w w w . jav a2 s . c o m*/ KeyPair keyPair = MiscTestUtils.generateKeyPair(); DateTime notBefore = new DateTime(); DateTime notAfter = notBefore.plusYears(1); String userId = "1234"; X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test, SERIALNUMBER=" + userId, notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null); byte[] salt = "salt".getBytes(); byte[] sessionId = "session-id".getBytes(); AuthenticationDataMessage message = new AuthenticationDataMessage(); message.authnCert = certificate; message.saltValue = salt; message.sessionId = sessionId; Map<String, String> httpHeaders = new HashMap<String, String>(); HttpSession testHttpSession = new HttpTestSession(); HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class); ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class); AuthenticationChallenge.generateChallenge(testHttpSession); AuthenticationContract authenticationContract = new AuthenticationContract(salt, null, null, sessionId, null, "foobar-challenge".getBytes()); byte[] toBeSigned = authenticationContract.calculateToBeSigned(); Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(keyPair.getPrivate()); signature.update(toBeSigned); byte[] signatureValue = signature.sign(); message.signatureValue = signatureValue; EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.CHALLENGE_MAX_MATURITY_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.AUTHN_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUTHN_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(AuthenticationTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.HOSTNAME_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INET_ADDRESS_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVER_CERTIFICATE)) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(HelloMessageHandler.SESSION_ID_CHANNEL_BINDING_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.AUDIT_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUDIT_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(AuditTestService.class.getName()); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_SECRET_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_IDENTITY_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_CERTS_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_ADDRESS_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_PHOTO_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(HelloMessageHandler.IDENTITY_INTEGRITY_SERVICE_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(HelloMessageHandler.IDENTITY_INTEGRITY_SERVICE_INIT_PARAM_NAME + "Class")) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVICE)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVICE + "Class")) .andReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_ORG_ID_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_APP_ID_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(IdentityDataMessageHandler.INCLUDE_DATA_FILES)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUTHN_SIGNATURE_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter( AuthenticationDataMessageHandler.AUTHN_SIGNATURE_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(null); EasyMock.expect(mockServletRequest.getAttribute("javax.servlet.request.ssl_session")) .andStubReturn(new String(Hex.encodeHex(sessionId))); String remoteAddress = "1.2.3.4"; EasyMock.expect(mockServletRequest.getRemoteAddr()).andReturn(remoteAddress); // prepare EasyMock.replay(mockServletRequest, mockServletConfig); // operate AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance); this.testedInstance.init(mockServletConfig); try { this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, testHttpSession); fail(); } catch (SecurityException e) { // expected } // verify EasyMock.verify(mockServletRequest, mockServletConfig); assertFalse(AuthenticationTestService.isCalled()); assertNull(AuditTestService.getAuditUserId()); assertEquals(remoteAddress, AuditTestService.getAuditRemoteAddress()); assertEquals(certificate, AuditTestService.getAuditClientCertificate()); assertNull(testHttpSession.getAttribute("eid.identifier")); }
From source file:org.wings.session.SessionServlet.java
/** * init/*w ww . ja v a 2 s.c o m*/ */ public final void init(ServletConfig config, HttpServletRequest request, HttpServletResponse response) throws ServletException { try { session = new Session(parent); SessionManager.setSession(session); // set request.url in session, if used in constructor of wings main classs //if (request.isRequestedSessionIdValid()) { // this will fire an event, if the encoding has changed .. session.setProperty("request.url", new RequestURL("", getSessionEncoding(response))); //} session.init(config, request, response); try { String mainClassName = config.getInitParameter("wings.mainclass"); Class mainClass = null; try { mainClass = Class.forName(mainClassName, true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { // fallback, in case the servlet container fails to set the // context class loader. mainClass = Class.forName(mainClassName); } mainClass.newInstance(); } catch (Exception ex) { log.fatal("could not load wings.mainclass: " + config.getInitParameter("wings.mainclass"), ex); throw new ServletException(ex); } } finally { // The session was set by the constructor. After init we // expect that only doPost/doGet is called, which set the // session also. So remove it here. SessionManager.removeSession(); } }
From source file:org.tinygroup.jspengine.servlet.JspServlet.java
public void init(ServletConfig config) throws ServletException { if (!(config instanceof TinyServletConfig)) { JspServlet servlet = BeanContainerFactory.getBeanContainer(this.getClass().getClassLoader()) .getBean("jspServlet"); TinyServletConfig tinyServletConfig = (TinyServletConfig) servlet.getServletConfig(); if (tinyServletConfig == null) { tinyServletConfig = new TinyServletConfig(); }/*from www . j a v a2s . c o m*/ tinyServletConfig.setServletConfig(config); servlet.setServletConfig(tinyServletConfig); config = tinyServletConfig; } this.config = config; this.context = config.getServletContext(); // Initialize the JSP Runtime Context options = new EmbeddedServletOptions(config, context); rctxt = new JspRuntimeContext(context, options); // Instantiate and init our resource injector String resourceInjectorClassName = config .getInitParameter(Constants.JSP_RESOURCE_INJECTOR_CONTEXT_ATTRIBUTE); if (resourceInjectorClassName != null) { try { ResourceInjector ri = (ResourceInjector) Class.forName(resourceInjectorClassName).newInstance(); ri.setContext(this.context); this.context.setAttribute(Constants.JSP_RESOURCE_INJECTOR_CONTEXT_ATTRIBUTE, ri); } catch (Exception e) { throw new ServletException(e); } } // START SJSWS 6232180 // Determine which HTTP methods to service ("*" means all) httpMethodsString = config.getInitParameter("httpMethods"); if (httpMethodsString != null && !httpMethodsString.equals("*")) { httpMethodsSet = new HashSet(); StringTokenizer tokenizer = new StringTokenizer(httpMethodsString, ", \t\n\r\f"); while (tokenizer.hasMoreTokens()) { httpMethodsSet.add(tokenizer.nextToken()); } } // END SJSWS 6232180 // START GlassFish 750 taglibs = new ConcurrentHashMap<String, TagLibraryInfo>(); context.setAttribute(Constants.JSP_TAGLIBRARY_CACHE, taglibs); tagFileJarUrls = new ConcurrentHashMap<String, URL>(); context.setAttribute(Constants.JSP_TAGFILE_JAR_URLS_CACHE, tagFileJarUrls); // END GlassFish 750 if (log.isTraceEnabled()) { log.trace(Localizer.getMessage("jsp.message.scratch.dir.is", options.getScratchDir().toString())); log.trace(Localizer.getMessage("jsp.message.dont.modify.servlets")); } }
From source file:test.unit.be.fedict.eid.applet.service.AuthenticationDataMessageHandlerTest.java
@Test public void testHandleMessageExpiredChallenge() throws Exception { // setup// w w w . j a v a 2 s .c om KeyPair keyPair = MiscTestUtils.generateKeyPair(); DateTime notBefore = new DateTime(); DateTime notAfter = notBefore.plusYears(1); String userId = "1234"; X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test, SERIALNUMBER=" + userId, notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null); byte[] salt = "salt".getBytes(); byte[] sessionId = "session-id".getBytes(); AuthenticationDataMessage message = new AuthenticationDataMessage(); message.authnCert = certificate; message.saltValue = salt; message.sessionId = sessionId; Map<String, String> httpHeaders = new HashMap<String, String>(); HttpSession testHttpSession = new HttpTestSession(); HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class); ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class); byte[] challenge = AuthenticationChallenge.generateChallenge(testHttpSession); Thread.sleep(1000); // > 1 ms AuthenticationContract authenticationContract = new AuthenticationContract(salt, null, null, sessionId, null, challenge); byte[] toBeSigned = authenticationContract.calculateToBeSigned(); Signature signature = Signature.getInstance("SHA1withRSA"); signature.initSign(keyPair.getPrivate()); signature.update(toBeSigned); byte[] signatureValue = signature.sign(); message.signatureValue = signatureValue; EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.CHALLENGE_MAX_MATURITY_INIT_PARAM_NAME)) .andReturn("1"); // 1 ms EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.AUTHN_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUTHN_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(AuthenticationTestService.class.getName()); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.HOSTNAME_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INET_ADDRESS_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVER_CERTIFICATE)) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(HelloMessageHandler.SESSION_ID_CHANNEL_BINDING_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_IDENTITY_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_CERTS_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_ADDRESS_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.INCLUDE_PHOTO_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(HelloMessageHandler.IDENTITY_INTEGRITY_SERVICE_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(HelloMessageHandler.IDENTITY_INTEGRITY_SERVICE_INIT_PARAM_NAME + "Class")) .andStubReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.AUDIT_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUDIT_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(AuditTestService.class.getName()); EasyMock.expect(mockServletRequest.getRemoteAddr()).andStubReturn("remote-address"); EasyMock.expect(mockServletRequest.getAttribute("javax.servlet.request.ssl_session")) .andStubReturn(new String(Hex.encodeHex(sessionId))); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_SECRET_INIT_PARAM_NAME)) .andStubReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVICE)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(HelloMessageHandler.CHANNEL_BINDING_SERVICE + "Class")) .andReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_ORG_ID_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect( mockServletConfig.getInitParameter(AuthenticationDataMessageHandler.NRCID_APP_ID_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter(IdentityDataMessageHandler.INCLUDE_DATA_FILES)) .andReturn(null); EasyMock.expect(mockServletConfig .getInitParameter(AuthenticationDataMessageHandler.AUTHN_SIGNATURE_SERVICE_INIT_PARAM_NAME)) .andReturn(null); EasyMock.expect(mockServletConfig.getInitParameter( AuthenticationDataMessageHandler.AUTHN_SIGNATURE_SERVICE_INIT_PARAM_NAME + "Class")) .andReturn(null); // prepare EasyMock.replay(mockServletRequest, mockServletConfig); // operate AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance); this.testedInstance.init(mockServletConfig); try { this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, testHttpSession); fail(); } catch (ServletException e) { // verify EasyMock.verify(mockServletRequest, mockServletConfig); assertNull(AuditTestService.getAuditUserId()); assertNull(testHttpSession.getAttribute("eid.identifier")); assertEquals(certificate, AuditTestService.getAuditClientCertificate()); assertEquals("remote-address", AuditTestService.getAuditRemoteAddress()); } }
From source file:net.jawr.web.bundle.processor.BundleProcessor.java
/** * Process the Jawr Servlets/*from w w w . j a va 2 s. c o m*/ * * @param destDirPath * the destination directory path * @param jawrServletDefinitions * the destination directory * @throws Exception * if an exception occurs. */ protected void processJawrServlets(String destDirPath, List<ServletDefinition> jawrServletDefinitions, boolean keepUrlMapping) throws Exception { String appRootDir = ""; String jsServletMapping = ""; String cssServletMapping = ""; String binaryServletMapping = ""; for (Iterator<ServletDefinition> iterator = jawrServletDefinitions.iterator(); iterator.hasNext();) { ServletDefinition servletDef = (ServletDefinition) iterator.next(); ServletConfig servletConfig = servletDef.getServletConfig(); // Force the production mode, and remove config listener parameters Map<?, ?> initParameters = ((MockServletConfig) servletConfig).getInitParameters(); initParameters.remove("jawr.config.reload.interval"); String jawrServletMapping = servletConfig.getInitParameter(JawrConstant.SERVLET_MAPPING_PROPERTY_NAME); String servletMapping = servletConfig .getInitParameter(JawrConstant.SPRING_SERVLET_MAPPING_PROPERTY_NAME); if (servletMapping == null) { servletMapping = jawrServletMapping; } ResourceBundlesHandler bundleHandler = null; BinaryResourcesHandler binaryRsHandler = null; // Retrieve the bundle Handler ServletContext servletContext = servletConfig.getServletContext(); String type = servletConfig.getInitParameter(TYPE_INIT_PARAMETER); if (type == null || type.equals(JawrConstant.JS_TYPE)) { bundleHandler = (ResourceBundlesHandler) servletContext .getAttribute(JawrConstant.JS_CONTEXT_ATTRIBUTE); String contextPathOverride = bundleHandler.getConfig().getContextPathOverride(); if (StringUtils.isNotEmpty(contextPathOverride)) { int idx = contextPathOverride.indexOf("//"); if (idx != -1) { idx = contextPathOverride.indexOf("/", idx + 2); if (idx != -1) { appRootDir = PathNormalizer.asPath(contextPathOverride.substring(idx)); } } } if (jawrServletMapping != null) { jsServletMapping = PathNormalizer.asPath(jawrServletMapping); } } else if (type.equals(JawrConstant.CSS_TYPE)) { bundleHandler = (ResourceBundlesHandler) servletContext .getAttribute(JawrConstant.CSS_CONTEXT_ATTRIBUTE); if (jawrServletMapping != null) { cssServletMapping = PathNormalizer.asPath(jawrServletMapping); } } else if (type.equals(JawrConstant.BINARY_TYPE)) { binaryRsHandler = (BinaryResourcesHandler) servletContext .getAttribute(JawrConstant.BINARY_CONTEXT_ATTRIBUTE); if (jawrServletMapping != null) { binaryServletMapping = PathNormalizer.asPath(jawrServletMapping); } } if (bundleHandler != null) { createBundles(servletDef.getServlet(), bundleHandler, destDirPath, servletMapping, keepUrlMapping); } else if (binaryRsHandler != null) { createBinaryBundle(servletDef.getServlet(), binaryRsHandler, destDirPath, servletConfig, keepUrlMapping); } } // Create the apache rewrite config file. createApacheRewriteConfigFile(destDirPath, appRootDir, jsServletMapping, cssServletMapping, binaryServletMapping); }
From source file:org.kurento.repository.internal.http.RepositoryHttpServlet.java
/** * Initialize this servlet./* w w w . ja va 2 s. c o m*/ */ @Override public void init(ServletConfig servletConfig) throws ServletException { super.init(servletConfig); configureServletMapping(servletConfig); configureWebappPublicUrl(servletConfig); if (servletConfig.getInitParameter("debug") != null) { debug = Integer.parseInt(getServletConfig().getInitParameter("debug")); } }
From source file:org.tinygroup.jspengine.EmbeddedServletOptions.java
/** * Create an EmbeddedServletOptions object using data available from * ServletConfig and ServletContext. //from ww w. j ava 2 s.c om */ public EmbeddedServletOptions(ServletConfig config, ServletContext context) throws JasperException { // JVM version numbers try { if (Float.parseFloat(System.getProperty("java.specification.version")) > 1.4) { compilerSourceVM = compilerTargetVM = "1.5"; } else { compilerSourceVM = compilerTargetVM = "1.4"; } } catch (NumberFormatException e) { // Ignore } Enumeration enumeration = config.getInitParameterNames(); while (enumeration.hasMoreElements()) { String k = (String) enumeration.nextElement(); String v = config.getInitParameter(k); setProperty(k, v); } /* SJSAS 6384538 // quick hack String validating=config.getInitParameter( "validating"); if( "false".equals( validating )) ParserUtils.validating=false; */ // START SJSAS 6384538 String validating = config.getInitParameter("validating"); if ("true".equals(validating)) { isValidationEnabled = true; } validating = config.getInitParameter("enableTldValidation"); if ("true".equals(validating)) { isValidationEnabled = true; } // END SJSAS 6384538 // keepgenerated default is false for JDK6 for later, true otherwise keepGenerated = getBoolean(config, !isJDK6(), "keepgenerated"); saveBytecode = getBoolean(config, saveBytecode, "saveBytecode"); trimSpaces = getBoolean(config, trimSpaces, "trimSpaces"); isPoolingEnabled = getBoolean(config, isPoolingEnabled, "enablePooling"); mappedFile = getBoolean(config, mappedFile, "mappedfile"); sendErrorToClient = getBoolean(config, sendErrorToClient, "sendErrToClient"); classDebugInfo = getBoolean(config, classDebugInfo, "classdebuginfo"); development = getBoolean(config, development, "development"); isSmapSuppressed = getBoolean(config, isSmapSuppressed, "suppressSmap"); isSmapDumped = getBoolean(config, isSmapDumped, "dumpSmap"); genStringAsCharArray = getBoolean(config, genStringAsCharArray, "genStrAsCharArray"); genStringAsByteArray = getBoolean(config, genStringAsByteArray, "genStrAsByteArray"); defaultBufferNone = getBoolean(config, defaultBufferNone, "defaultBufferNone"); errorOnUseBeanInvalidClassAttribute = getBoolean(config, errorOnUseBeanInvalidClassAttribute, "errorOnUseBeanInvalidClassAttribute"); fork = getBoolean(config, fork, "fork"); xpoweredBy = getBoolean(config, xpoweredBy, "xpoweredBy"); String checkIntervalStr = config.getInitParameter("checkInterval"); if (checkIntervalStr != null) { parseCheckInterval(checkIntervalStr); } String modificationTestIntervalStr = config.getInitParameter("modificationTestInterval"); if (modificationTestIntervalStr != null) { parseModificationTestInterval(modificationTestIntervalStr); } String ieClassId = config.getInitParameter("ieClassId"); if (ieClassId != null) this.ieClassId = ieClassId; String classpath = config.getInitParameter("classpath"); if (classpath != null) this.classpath = classpath; // START PWC 1.2 6311155 String sysClassPath = config.getInitParameter("com.sun.appserv.jsp.classpath"); this.sysClassPath = sysClassPath != null ? sysClassPath : System.getProperty("java.class.path"); // END PWC 1.2 6311155 if ("false".equals(config.getInitParameter("delegate"))) { delegate = false; } /* * scratchdir */ String dir = config.getInitParameter("scratchdir"); if (dir != null) { scratchDir = new File(dir); } else { // First try the Servlet 2.2 javax.servlet.context.tempdir property scratchDir = (File) context.getAttribute(Constants.TMP_DIR); if (scratchDir == null) { // Not running in a Servlet 2.2 container. // Try to get the JDK 1.2 java.io.tmpdir property dir = System.getProperty("java.io.tmpdir"); if (dir != null) scratchDir = new File(dir); } } if (this.scratchDir == null) { log.fatal(Localizer.getMessage("jsp.error.no.scratch.dir")); return; } if (!(scratchDir.exists() && scratchDir.canRead() && scratchDir.canWrite() && scratchDir.isDirectory())) log.fatal(Localizer.getMessage("jsp.error.bad.scratch.dir", scratchDir.getAbsolutePath())); this.compiler = config.getInitParameter("compiler"); String compilerTargetVM = config.getInitParameter("compilerTargetVM"); if (compilerTargetVM != null) { this.compilerTargetVM = compilerTargetVM; } String compilerSourceVM = config.getInitParameter("compilerSourceVM"); if (compilerSourceVM != null) { this.compilerSourceVM = compilerSourceVM; } String javaEncoding = config.getInitParameter("javaEncoding"); if (javaEncoding != null) { this.javaEncoding = javaEncoding; } String reloadIntervalString = config.getInitParameter("reload-interval"); if (reloadIntervalString != null) { int reloadInterval = 0; try { reloadInterval = Integer.parseInt(reloadIntervalString); } catch (NumberFormatException e) { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.reloadInterval")); } } if (reloadInterval == -1) { // Never check JSPs for modifications, and disable // recompilation this.development = false; this.checkInterval = 0; } else { // Check JSPs for modifications at specified interval in // both (development and non-development) modes parseCheckInterval(reloadIntervalString); parseModificationTestInterval(reloadIntervalString); } } // BEGIN S1AS 6181923 String usePrecompiled = config.getInitParameter("usePrecompiled"); if (usePrecompiled == null) { usePrecompiled = config.getInitParameter("use-precompiled"); } if (usePrecompiled != null) { if (usePrecompiled.equalsIgnoreCase("true")) { this.usePrecompiled = true; } else if (usePrecompiled.equalsIgnoreCase("false")) { this.usePrecompiled = false; } else { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.usePrecompiled")); } } } // END S1AS 6181923 // START SJSWS String capacity = config.getInitParameter("initialCapacity"); if (capacity == null) { capacity = config.getInitParameter("initial-capacity"); } if (capacity != null) { try { initialCapacity = Integer.parseInt(capacity); // Find a value that is power of 2 and >= the specified // initial capacity, in order to make Hashtable indexing // more efficient. int value = Constants.DEFAULT_INITIAL_CAPACITY; while (value < initialCapacity) { value *= 2; } initialCapacity = value; } catch (NumberFormatException nfe) { if (log.isWarnEnabled()) { String msg = Localizer.getMessage("jsp.warning.initialcapacity"); msg = MessageFormat.format(msg, capacity, Integer.valueOf(Constants.DEFAULT_INITIAL_CAPACITY)); log.warn(msg); } } } String jspCompilerPlugin = config.getInitParameter("javaCompilerPlugin"); if (jspCompilerPlugin != null) { if ("org.apache.jasper.compiler.JikesJavaCompiler".equals(jspCompilerPlugin)) { this.compiler = "jikes"; } else if ("org.apache.jasper.compiler.SunJava14Compiler".equals(jspCompilerPlugin)) { // use default, do nothing } else { // use default, issue warning if (log.isWarnEnabled()) { String msg = Localizer.getMessage("jsp.warning.unsupportedJavaCompiler"); msg = MessageFormat.format(msg, jspCompilerPlugin); log.warn(msg); } } } // END SJSWS // Setup the global Tag Libraries location cache for this // web-application. /* SJSAS 6384538 tldLocationsCache = new TldLocationsCache(context); */ // START SJSAS 6384538 tldLocationsCache = new TldLocationsCache(context, this); // END SJSAS 6384538 // Setup the jsp config info for this web app. /* SJSAS 6384538 jspConfig = new JspConfig(context); */ // START SJSAS 6384538 jspConfig = new JspConfig(context, this); // END SJSAS 6384538 // Create a Tag plugin instance tagPluginManager = new TagPluginManager(context); }