Example usage for javax.servlet ServletConfig getInitParameter

List of usage examples for javax.servlet ServletConfig getInitParameter

Introduction

In this page you can find the example usage for javax.servlet ServletConfig getInitParameter.

Prototype

public String getInitParameter(String name);

Source Link

Document

Gets the value of the initialization parameter with the given name.

Usage

From source file:test.unit.be.fedict.eid.applet.service.SignatureDataMessageHandlerTest.java

public void testHandleMessage() throws Exception {
    // setup/*from www .  j a  va  2 s . com*/
    KeyPair keyPair = MiscTestUtils.generateKeyPair();
    DateTime notBefore = new DateTime();
    DateTime notAfter = notBefore.plusYears(1);
    X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore,
            notAfter, null, keyPair.getPrivate(), true, 0, null, null);

    ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class);
    Map<String, String> httpHeaders = new HashMap<String, String>();
    HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class);
    HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class);

    EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureServiceClass"))
            .andStubReturn(SignatureTestService.class.getName());

    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    byte[] document = "hello world".getBytes();
    byte[] digestValue = messageDigest.digest(document);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_VALUE_SESSION_ATTRIBUTE))
            .andStubReturn(digestValue);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_ALGO_SESSION_ATTRIBUTE))
            .andStubReturn("SHA-1");

    SignatureDataMessage message = new SignatureDataMessage();
    message.certificateChain = new LinkedList<X509Certificate>();
    message.certificateChain.add(certificate);

    Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(keyPair.getPrivate());
    signature.update(document);
    byte[] signatureValue = signature.sign();
    message.signatureValue = signatureValue;

    // prepare
    EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest);

    // operate
    AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance);
    this.testedInstance.init(mockServletConfig);
    this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession);

    // verify
    EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest);
    assertEquals(signatureValue, SignatureTestService.getSignatureValue());
}

From source file:test.unit.be.fedict.eid.applet.service.SignatureDataMessageHandlerTest.java

public void testHandleMessagePSS() throws Exception {
    // setup/*from w  w w  .j ava 2s. c  o  m*/
    KeyPair keyPair = MiscTestUtils.generateKeyPair();
    DateTime notBefore = new DateTime();
    DateTime notAfter = notBefore.plusYears(1);
    X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore,
            notAfter, null, keyPair.getPrivate(), true, 0, null, null);

    ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class);
    Map<String, String> httpHeaders = new HashMap<String, String>();
    HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class);
    HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class);

    EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureServiceClass"))
            .andStubReturn(SignatureTestService.class.getName());

    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    byte[] document = "hello world".getBytes();
    byte[] digestValue = messageDigest.digest(document);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_VALUE_SESSION_ATTRIBUTE))
            .andStubReturn(digestValue);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_ALGO_SESSION_ATTRIBUTE))
            .andStubReturn("SHA-1-PSS");

    SignatureDataMessage message = new SignatureDataMessage();
    message.certificateChain = new LinkedList<X509Certificate>();
    message.certificateChain.add(certificate);

    Signature signature = Signature.getInstance("SHA1withRSA/PSS", "BC");
    signature.initSign(keyPair.getPrivate());
    signature.update(document);
    byte[] signatureValue = signature.sign();
    message.signatureValue = signatureValue;

    // prepare
    EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest);

    // operate
    AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance);
    this.testedInstance.init(mockServletConfig);
    this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession);

    // verify
    EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest);
    assertEquals(signatureValue, SignatureTestService.getSignatureValue());
}

From source file:test.unit.be.fedict.eid.applet.service.SignatureDataMessageHandlerTest.java

public void testHandleMessagePSS_SHA256() throws Exception {
    // setup/* w ww .  j  av  a2 s  .com*/
    KeyPair keyPair = MiscTestUtils.generateKeyPair();
    DateTime notBefore = new DateTime();
    DateTime notAfter = notBefore.plusYears(1);
    X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore,
            notAfter, null, keyPair.getPrivate(), true, 0, null, null);

    ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class);
    Map<String, String> httpHeaders = new HashMap<String, String>();
    HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class);
    HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class);

    EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureServiceClass"))
            .andStubReturn(SignatureTestService.class.getName());

    MessageDigest messageDigest = MessageDigest.getInstance("SHA256");
    byte[] document = "hello world".getBytes();
    byte[] digestValue = messageDigest.digest(document);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_VALUE_SESSION_ATTRIBUTE))
            .andStubReturn(digestValue);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_ALGO_SESSION_ATTRIBUTE))
            .andStubReturn("SHA-256-PSS");

    SignatureDataMessage message = new SignatureDataMessage();
    message.certificateChain = new LinkedList<X509Certificate>();
    message.certificateChain.add(certificate);

    Signature signature = Signature.getInstance("SHA256withRSA/PSS", "BC");
    signature.initSign(keyPair.getPrivate());
    signature.update(document);
    byte[] signatureValue = signature.sign();
    message.signatureValue = signatureValue;

    // prepare
    EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest);

    // operate
    AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance);
    this.testedInstance.init(mockServletConfig);
    this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession);

    // verify
    EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest);
    assertEquals(signatureValue, SignatureTestService.getSignatureValue());
}

From source file:test.unit.be.fedict.eid.applet.service.SignatureDataMessageHandlerTest.java

public void testHandleMessageWithAudit() throws Exception {
    // setup/* ww  w.  j  av a 2 s .  c  o  m*/
    KeyPair keyPair = MiscTestUtils.generateKeyPair();
    DateTime notBefore = new DateTime();
    DateTime notAfter = notBefore.plusYears(1);
    X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(),
            "CN=Test,SERIALNUMBER=1234", notBefore, notAfter, null, keyPair.getPrivate(), true, 0, null, null);

    ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class);
    Map<String, String> httpHeaders = new HashMap<String, String>();
    HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class);
    HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class);

    EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass"))
            .andStubReturn(AuditTestService.class.getName());
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureServiceClass"))
            .andStubReturn(SignatureTestService.class.getName());

    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    byte[] document = "hello world".getBytes();
    byte[] digestValue = messageDigest.digest(document);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_VALUE_SESSION_ATTRIBUTE))
            .andStubReturn(digestValue);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_ALGO_SESSION_ATTRIBUTE))
            .andStubReturn("SHA-1");

    SignatureDataMessage message = new SignatureDataMessage();
    message.certificateChain = new LinkedList<X509Certificate>();
    message.certificateChain.add(certificate);

    Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(keyPair.getPrivate());
    signature.update(document);
    byte[] signatureValue = signature.sign();
    message.signatureValue = signatureValue;

    // prepare
    EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest);

    // operate
    AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance);
    this.testedInstance.init(mockServletConfig);
    this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession);

    // verify
    EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest);
    assertEquals(signatureValue, SignatureTestService.getSignatureValue());
    assertEquals("1234", AuditTestService.getAuditSigningUserId());
}

From source file:org.wandora.modules.servlet.ModulesServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    moduleManager = new ModuleManager();

    servletHome = config.getServletContext().getRealPath("/") + "WEB-INF";
    moduleManager.setVariable("servletHome", servletHome);

    //        SimpleLog log=new SimpleLog("ModulesServlet");
    //        log.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
    Log log = new Jdk14Logger("ModulesServlet");
    moduleManager.setLogging(log);//w  ww  . j a  va 2s  .  com
    String configFile = config.getInitParameter("modulesconfig");
    if (configFile == null) {
        configFile = config.getInitParameter("modulesConfig");
        if (configFile == null)
            configFile = "modulesconfig.xml";
    }

    bindAddress = config.getInitParameter("bindaddress");
    if (bindAddress == null) {
        bindAddress = config.getInitParameter("bindAddress");
    }

    moduleManager.addModule(servletModule, new ModuleSettings("rootServlet"));
    moduleManager.readXMLOptionsFile(configFile);

    if (bindAddress == null) {
        bindAddress = moduleManager.getVariable("bindAddress");
        if (bindAddress == null)
            bindAddress = DEFAULT_BIND_ADDRESS;
    }

    try {
        moduleManager.autostartModules();
    } catch (ModuleException me) {
        throw new ServletException("Unable to start modules.", me);
    }
}

From source file:test.unit.be.fedict.eid.applet.service.SignatureDataMessageHandlerTest.java

@Test
public void testHandleMessageInvalidSignature() throws Exception {
    // setup//w ww  . j a va  2s .  co m
    KeyPair keyPair = MiscTestUtils.generateKeyPair();
    DateTime notBefore = new DateTime();
    DateTime notAfter = notBefore.plusYears(1);
    X509Certificate certificate = MiscTestUtils.generateCertificate(keyPair.getPublic(), "CN=Test", notBefore,
            notAfter, null, keyPair.getPrivate(), true, 0, null, null);

    ServletConfig mockServletConfig = EasyMock.createMock(ServletConfig.class);
    Map<String, String> httpHeaders = new HashMap<String, String>();
    HttpSession mockHttpSession = EasyMock.createMock(HttpSession.class);
    HttpServletRequest mockServletRequest = EasyMock.createMock(HttpServletRequest.class);

    EasyMock.expect(mockServletConfig.getInitParameter("AuditService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("AuditServiceClass"))
            .andStubReturn(AuditTestService.class.getName());
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureService")).andStubReturn(null);
    EasyMock.expect(mockServletConfig.getInitParameter("SignatureServiceClass"))
            .andStubReturn(SignatureTestService.class.getName());

    EasyMock.expect(mockServletRequest.getRemoteAddr()).andStubReturn("remote-address");

    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");
    byte[] document = "hello world".getBytes();
    byte[] digestValue = messageDigest.digest(document);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_VALUE_SESSION_ATTRIBUTE))
            .andStubReturn(digestValue);
    EasyMock.expect(mockHttpSession.getAttribute(SignatureDataMessageHandler.DIGEST_ALGO_SESSION_ATTRIBUTE))
            .andStubReturn("SHA-1");

    SignatureDataMessage message = new SignatureDataMessage();
    message.certificateChain = new LinkedList<X509Certificate>();
    message.certificateChain.add(certificate);

    Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(keyPair.getPrivate());
    signature.update("foobar-document".getBytes());
    byte[] signatureValue = signature.sign();
    message.signatureValue = signatureValue;

    // prepare
    EasyMock.replay(mockServletConfig, mockHttpSession, mockServletRequest);

    // operate
    AppletServiceServlet.injectInitParams(mockServletConfig, this.testedInstance);
    this.testedInstance.init(mockServletConfig);
    try {
        this.testedInstance.handleMessage(message, httpHeaders, mockServletRequest, mockHttpSession);
        fail();
    } catch (ServletException e) {
        LOG.debug("expected exception: " + e.getMessage());
        // verify
        EasyMock.verify(mockServletConfig, mockHttpSession, mockServletRequest);
        assertNull(SignatureTestService.getSignatureValue());
        assertEquals("remote-address", AuditTestService.getAuditSignatureRemoteAddress());
        assertEquals(certificate, AuditTestService.getAuditSignatureClientCertificate());
    }
}

From source file:com.meltmedia.cadmium.servlets.BasicFileServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);
    if (this.contentDir == null) {
        setBasePath(config.getInitParameter("basePath"));
    }/*from www .ja v  a  2  s .c  om*/
}

From source file:org.apache.chemistry.opencmis.server.impl.browser.CmisBrowserBindingServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    super.init(config);

    // initialize the call context handler
    callContextHandler = null;//from w w w  .  j a  va 2  s . c o m

    String callContextHandlerClass = config.getInitParameter(PARAM_CALL_CONTEXT_HANDLER);

    if (callContextHandlerClass != null) {
        try {
            callContextHandler = (CallContextHandler) Class.forName(callContextHandlerClass).newInstance();
        } catch (Exception e) {
            throw new ServletException("Could not load call context handler: " + e, e);
        }
    }

    // get memory threshold and temp directory
    CmisServiceFactory factory = (CmisServiceFactory) config.getServletContext()
            .getAttribute(CmisRepositoryContextListener.SERVICES_FACTORY);

    tempDir = factory.getTempDirectory();
    memoryThreshold = factory.getMemoryThreshold();

    // initialize the dispatchers
    repositoryDispatcher = new Dispatcher(false);
    rootDispatcher = new Dispatcher(false);

    try {
        repositoryDispatcher.addResource(SELECTOR_REPOSITORY_INFO, METHOD_GET, RepositoryService.class,
                "getRepositoryInfo");
        repositoryDispatcher.addResource(SELECTOR_LAST_RESULT, METHOD_GET, RepositoryService.class,
                "getLastResult");
        repositoryDispatcher.addResource(SELECTOR_TYPE_CHILDREN, METHOD_GET, RepositoryService.class,
                "getTypeChildren");
        repositoryDispatcher.addResource(SELECTOR_TYPE_DESCENDANTS, METHOD_GET, RepositoryService.class,
                "getTypeDescendants");
        repositoryDispatcher.addResource(SELECTOR_TYPE_DEFINITION, METHOD_GET, RepositoryService.class,
                "getTypeDefinition");
        repositoryDispatcher.addResource(SELECTOR_QUERY, METHOD_GET, DiscoveryService.class, "query");
        repositoryDispatcher.addResource(SELECTOR_CHECKEDOUT, METHOD_GET, NavigationService.class,
                "getCheckedOutDocs");
        repositoryDispatcher.addResource(SELECTOR_CONTENT_CHANGES, METHOD_GET, DiscoveryService.class,
                "getContentChanges");

        repositoryDispatcher.addResource(CMISACTION_QUERY, METHOD_POST, DiscoveryService.class, "query");
        repositoryDispatcher.addResource(CMISACTION_CREATE_DOCUMENT, METHOD_POST, ObjectService.class,
                "createDocument");
        repositoryDispatcher.addResource(CMISACTION_CREATE_DOCUMENT_FROM_SOURCE, METHOD_POST,
                ObjectService.class, "createDocumentFromSource");
        repositoryDispatcher.addResource(CMISACTION_CREATE_POLICY, METHOD_POST, ObjectService.class,
                "createPolicy");
        repositoryDispatcher.addResource(CMISACTION_CREATE_RELATIONSHIP, METHOD_POST, ObjectService.class,
                "createRelationship");

        rootDispatcher.addResource(SELECTOR_OBJECT, METHOD_GET, ObjectService.class, "getObject");
        rootDispatcher.addResource(SELECTOR_PROPERTIES, METHOD_GET, ObjectService.class, "getProperties");
        rootDispatcher.addResource(SELECTOR_ALLOWABLEACTIONS, METHOD_GET, ObjectService.class,
                "getAllowableActions");
        rootDispatcher.addResource(SELECTOR_RENDITIONS, METHOD_GET, ObjectService.class, "getRenditions");
        rootDispatcher.addResource(SELECTOR_CONTENT, METHOD_GET, ObjectService.class, "getContentStream");
        rootDispatcher.addResource(SELECTOR_CHILDREN, METHOD_GET, NavigationService.class, "getChildren");
        rootDispatcher.addResource(SELECTOR_DESCENDANTS, METHOD_GET, NavigationService.class, "getDescendants");
        rootDispatcher.addResource(SELECTOR_FOLDER_TREE, METHOD_GET, NavigationService.class, "getFolderTree");
        rootDispatcher.addResource(SELECTOR_PARENT, METHOD_GET, NavigationService.class, "getFolderParent");
        rootDispatcher.addResource(SELECTOR_PARENTS, METHOD_GET, NavigationService.class, "getObjectParents");
        rootDispatcher.addResource(SELECTOR_VERSIONS, METHOD_GET, VersioningService.class, "getAllVersions");
        rootDispatcher.addResource(SELECTOR_RELATIONSHIPS, METHOD_GET, RelationshipService.class,
                "getObjectRelationships");
        rootDispatcher.addResource(SELECTOR_CHECKEDOUT, METHOD_GET, NavigationService.class,
                "getCheckedOutDocs");
        rootDispatcher.addResource(SELECTOR_POLICIES, METHOD_GET, PolicyService.class, "getAppliedPolicies");
        rootDispatcher.addResource(SELECTOR_ACL, METHOD_GET, AclService.class, "getACL");

        rootDispatcher.addResource(CMISACTION_CREATE_DOCUMENT, METHOD_POST, ObjectService.class,
                "createDocument");
        rootDispatcher.addResource(CMISACTION_CREATE_DOCUMENT_FROM_SOURCE, METHOD_POST, ObjectService.class,
                "createDocumentFromSource");
        rootDispatcher.addResource(CMISACTION_CREATE_FOLDER, METHOD_POST, ObjectService.class, "createFolder");
        rootDispatcher.addResource(CMISACTION_CREATE_POLICY, METHOD_POST, ObjectService.class, "createPolicy");
        rootDispatcher.addResource(CMISACTION_UPDATE_PROPERTIES, METHOD_POST, ObjectService.class,
                "updateProperties");
        rootDispatcher.addResource(CMISACTION_SET_CONTENT, METHOD_POST, ObjectService.class,
                "setContentStream");
        rootDispatcher.addResource(CMISACTION_DELETE_CONTENT, METHOD_POST, ObjectService.class,
                "deleteContentStream");
        rootDispatcher.addResource(CMISACTION_DELETE, METHOD_POST, ObjectService.class, "deleteObject");
        rootDispatcher.addResource(CMISACTION_DELETE_TREE, METHOD_POST, ObjectService.class, "deleteTree");
        rootDispatcher.addResource(CMISACTION_MOVE, METHOD_POST, ObjectService.class, "moveObject");
        rootDispatcher.addResource(CMISACTION_ADD_OBJECT_TO_FOLDER, METHOD_POST, MultiFilingService.class,
                "addObjectToFolder");
        rootDispatcher.addResource(CMISACTION_REMOVE_OBJECT_FROM_FOLDER, METHOD_POST, MultiFilingService.class,
                "removeObjectFromFolder");
        rootDispatcher.addResource(CMISACTION_CHECK_OUT, METHOD_POST, VersioningService.class, "checkOut");
        rootDispatcher.addResource(CMISACTION_CANCEL_CHECK_OUT, METHOD_POST, VersioningService.class,
                "cancelCheckOut");
        rootDispatcher.addResource(CMISACTION_CHECK_IN, METHOD_POST, VersioningService.class, "checkIn");
        rootDispatcher.addResource(CMISACTION_APPLY_POLICY, METHOD_POST, PolicyService.class, "applyPolicy");
        rootDispatcher.addResource(CMISACTION_REMOVE_POLICY, METHOD_POST, PolicyService.class, "removePolicy");
        rootDispatcher.addResource(CMISACTION_APPLY_ACL, METHOD_POST, AclService.class, "applyACL");
    } catch (NoSuchMethodException e) {
        LOG.error("Cannot initialize dispatcher!", e);
    }
}

From source file:com.log4ic.compressor.servlet.CompressionServlet.java

@Override
public void init(ServletConfig config) throws ServletException {
    if (!initialized) {
        String cacheDir;// ww  w  .j a va2 s .c o m
        CacheType cacheType = null;
        Integer cacheCount = null;
        boolean autoClean = true;
        int cleanHourAgo = 4;
        int lowHit = 3;
        if (config != null) {
            //?
            cacheDir = config.getInitParameter("cacheDir");
            if (StringUtils.isNotBlank(cacheDir)) {
                if (cacheDir.startsWith("{contextPath}")) {
                    cacheDir = getRootAbsolutePath(config.getServletContext())
                            + cacheDir.replace("{contextPath}", "");
                }
                cacheDir = FileUtils.appendSeparator(cacheDir);
            } else {
                cacheDir = getRootAbsolutePath(config.getServletContext()) + "static/compressed/";
            }
            //
            String cacheTypeStr = config.getInitParameter("cacheType");
            if (StringUtils.isNotBlank(cacheTypeStr)) {
                try {
                    cacheType = CacheType.valueOf(cacheTypeStr.toUpperCase());
                } catch (IllegalArgumentException e) {
                }
            }
            if ("none".equals(cacheTypeStr)) {
                cacheType = null;
            }
            //
            String cacheCountStr = config.getInitParameter("cacheCount");
            if (StringUtils.isNotBlank(cacheCountStr)) {
                try {
                    cacheCount = Integer.parseInt(cacheCountStr);
                } catch (Exception e) {
                }
            }
            if (cacheCount == null) {
                cacheCount = 5000;
            }

            String autoCleanStr = config.getInitParameter("autoClean");

            if (StringUtils.isNotBlank(autoCleanStr)) {
                try {
                    autoClean = Boolean.parseBoolean(autoCleanStr);
                } catch (Exception e) {
                }
            }

            String fileDomain = config.getInitParameter("fileDomain");

            if (StringUtils.isNotBlank(fileDomain)) {
                CompressionServlet.fileDomain = fileDomain;
            }

            Class cacheManagerClass = null;
            String cacheManagerClassStr = config.getInitParameter("cacheManager");
            if (StringUtils.isNotBlank(cacheManagerClassStr)) {
                try {
                    cacheManagerClass = CompressionServlet.class.getClassLoader()
                            .loadClass(cacheManagerClassStr);
                } catch (ClassNotFoundException e) {
                    logger.error("??!", e);
                }
            } else {
                cacheManagerClass = SimpleCacheManager.class;
            }

            if (autoClean) {
                String cleanIntervalStr = config.getInitParameter("cleanInterval");
                long cleanInterval = 1000 * 60 * 60 * 5L;
                if (StringUtils.isNotBlank(cleanIntervalStr)) {
                    try {
                        cleanInterval = Long.parseLong(cleanIntervalStr);
                    } catch (Exception e) {
                    }
                }
                String lowHitStr = config.getInitParameter("cleanLowHit");

                if (StringUtils.isNotBlank(lowHitStr)) {
                    try {
                        lowHit = Integer.parseInt(autoCleanStr);
                    } catch (Exception e) {
                    }
                }
                String cleanHourAgoStr = config.getInitParameter("cleanHourAgo");

                if (StringUtils.isNotBlank(cleanHourAgoStr)) {
                    try {
                        cleanHourAgo = Integer.parseInt(cleanHourAgoStr);
                    } catch (Exception e) {
                    }
                }
                if (cacheType != null) {
                    try {
                        Constructor constructor = cacheManagerClass.getConstructor(CacheType.class, int.class,
                                int.class, int.class, long.class, String.class);
                        cacheManager = (CacheManager) constructor.newInstance(cacheType, cacheCount, lowHit,
                                cleanHourAgo, cleanInterval, cacheDir);
                    } catch (NoSuchMethodException e) {
                        logger.error("??", e);
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    } catch (InstantiationException e) {
                        logger.error("??", e);
                    } catch (IllegalAccessException e) {
                        logger.error("??", e);
                    } catch (Exception e) {
                        logger.error("??", e);
                    }
                }
            } else {
                if (cacheType != null) {
                    try {
                        Constructor constructor = cacheManagerClass.getConstructor(CacheType.class, int.class,
                                String.class);
                        cacheManager = (CacheManager) constructor.newInstance(cacheType, cacheCount, cacheDir);
                    } catch (NoSuchMethodException e) {
                        logger.error("??", e);
                    } catch (InvocationTargetException e) {
                        logger.error("??", e);
                    } catch (InstantiationException e) {
                        logger.error("??", e);
                    } catch (IllegalAccessException e) {
                        logger.error("??", e);
                    } catch (Exception e) {
                        logger.error("??", e);
                    }
                }
            }
        }
        initialized = true;
    }
}