org.lastaflute.di.core.factory.SingletonLaContainerFactory Java Examples
The following examples show how to use
org.lastaflute.di.core.factory.SingletonLaContainerFactory.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LastaPrepareFilter.java From lastaflute with Apache License 2.0 | 6 votes |
protected void viaLastaDiContext(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { final LaContainer container = SingletonLaContainerFactory.getContainer(); final ExternalContext externalContext = container.getExternalContext(); if (externalContext == null) { throw new IllegalStateException("The externalContext should not be null from the container: " + container); } final Object prevoiusRequest = externalContext.getRequest(); final Object previousResponse = externalContext.getResponse(); try { externalContext.setRequest(request); externalContext.setResponse(response); viaHotdeploy(request, response, chain); // #to_action } finally { externalContext.setRequest(prevoiusRequest); externalContext.setResponse(previousResponse); } }
Example #2
Source File: FessPropTest.java From fess with Apache License 2.0 | 6 votes |
public void test_maxUsernameLength10() throws IOException { FessProp.propMap.clear(); FessConfig fessConfig = new FessConfig.SimpleImpl() { @Override public Integer getLdapMaxUsernameLengthAsInteger() { return Integer.valueOf(10); } }; File file = File.createTempFile("test", ".properties"); file.deleteOnExit(); FileUtil.writeBytes(file.getAbsolutePath(), "ldap.security.principal=%[email protected]".getBytes("UTF-8")); DynamicProperties systemProps = new DynamicProperties(file); SingletonLaContainerFactory.getContainer().register(systemProps, "systemProperties"); assertEquals("@fess.codelibs.local", fessConfig.getLdapSecurityPrincipal(null)); assertEquals("@fess.codelibs.local", fessConfig.getLdapSecurityPrincipal("")); assertEquals("[email protected]", fessConfig.getLdapSecurityPrincipal("123456789")); assertEquals("[email protected]", fessConfig.getLdapSecurityPrincipal("1234567890")); assertEquals("[email protected]", fessConfig.getLdapSecurityPrincipal("12345678901")); }
Example #3
Source File: FessPropTest.java From fess with Apache License 2.0 | 6 votes |
public void test_maxUsernameLength() throws IOException { FessProp.propMap.clear(); FessConfig fessConfig = new FessConfig.SimpleImpl() { @Override public Integer getLdapMaxUsernameLengthAsInteger() { return Integer.valueOf(-1); } }; File file = File.createTempFile("test", ".properties"); file.deleteOnExit(); FileUtil.writeBytes(file.getAbsolutePath(), "ldap.security.principal=%[email protected]".getBytes("UTF-8")); DynamicProperties systemProps = new DynamicProperties(file); SingletonLaContainerFactory.getContainer().register(systemProps, "systemProperties"); assertEquals("@fess.codelibs.local", fessConfig.getLdapSecurityPrincipal(null)); assertEquals("@fess.codelibs.local", fessConfig.getLdapSecurityPrincipal("")); assertEquals("[email protected]", fessConfig.getLdapSecurityPrincipal("123456789")); assertEquals("[email protected]", fessConfig.getLdapSecurityPrincipal("1234567890")); assertEquals("[email protected]", fessConfig.getLdapSecurityPrincipal("12345678901")); }
Example #4
Source File: PathMappingHelper.java From fess with Apache License 2.0 | 6 votes |
private boolean matchUserAgent(final PathMapping pathMapping) { if (!pathMapping.hasUAMathcer()) { return true; } if (SingletonLaContainerFactory.getExternalContext().getRequest() != null) { return LaRequestUtil.getOptionalRequest().map(request -> { final String userAgent = request.getHeader("user-agent"); if (StringUtil.isBlank(userAgent)) { return false; } return pathMapping.getUAMatcher(userAgent).find(); }).orElse(false); } return false; }
Example #5
Source File: WebLastaContainerInitializer.java From lastaflute with Apache License 2.0 | 5 votes |
protected void setupExternalContext() { if (ComponentDeployerFactory.getProvider() instanceof ComponentDeployerFactory.DefaultProvider) { ComponentDeployerFactory.setProvider(newExternalComponentDeployerProvider()); } final HttpServletExternalContext externalContext = newHttpServletExternalContext(); externalContext.setApplication(application); SingletonLaContainerFactory.setExternalContext(externalContext); SingletonLaContainerFactory.setExternalContextComponentDefRegister(newHttpServletExternalContextComponentDefRegister()); }
Example #6
Source File: Crawler.java From fess with Apache License 2.0 | 5 votes |
private static void destroyContainer() { if (running.getAndSet(false)) { TimeoutManager.getInstance().stop(); if (logger.isDebugEnabled()) { logger.debug("Destroying LaContainer..."); } SingletonLaContainerFactory.destroy(); logger.info("Destroyed LaContainer."); } }
Example #7
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 5 votes |
/** * @return The external context of Lasta Di. (NotNull) * @throws IllegalStateException When the external context is not found. */ public static ExternalContext retrieveExternalContext() { final ExternalContext context = SingletonLaContainerFactory.getExternalContext(); if (context == null) { throw new IllegalStateException("Not found external context in Lasta Di container."); } return context; }
Example #8
Source File: FessXpathTransformerTest.java From fess with Apache License 2.0 | 4 votes |
public void test_transform() throws Exception { String data = "<html><head><title>Test</title></head><body><h1>Header1</h1><p>This is a pen.</p></body></html>"; final FessXpathTransformer fessXpathTransformer = new FessXpathTransformer(); fessXpathTransformer.init(); SingletonLaContainerFactory.getContainer().register(CrawlingInfoHelper.class, "crawlingInfoHelper"); SingletonLaContainerFactory.getContainer().register(PathMappingHelper.class, "pathMappingHelper"); SingletonLaContainerFactory.getContainer().register(CrawlingConfigHelper.class, "crawlingConfigHelper"); SingletonLaContainerFactory.getContainer().register(SystemHelper.class, "systemHelper"); SingletonLaContainerFactory.getContainer().register(FileTypeHelper.class, "fileTypeHelper"); SingletonLaContainerFactory.getContainer().register(DocumentHelper.class, "documentHelper"); SingletonLaContainerFactory.getContainer().register(LabelTypeHelper.class, "labelTypeHelper"); WebConfig webConfig = new WebConfig(); ComponentUtil.getCrawlingConfigHelper().store("test", webConfig); setValueToObject(ComponentUtil.getLabelTypeHelper(), "labelTypePatternList", new ArrayList<LabelTypePattern>()); long max = 0; for (int i = 0; i < 10000; i++) { if (i % 1000 == 0) { logger.info(MemoryUtil.getMemoryUsageLog() + ":" + i); long mem = MemoryUtil.getUsedMemory(); if (max < mem) { max = mem; } } ResponseData responseData = new ResponseData(); responseData.setCharSet("UTF-8"); responseData.setContentLength(data.length()); responseData.setExecutionTime(1000L); responseData.setHttpStatusCode(200); responseData.setLastModified(new Date()); responseData.setMethod("GET"); responseData.setMimeType("text/html"); responseData.setParentUrl("http://fess.codelibs.org/"); responseData.setResponseBody(data.getBytes()); responseData.setSessionId("test-1"); responseData.setStatus(0); responseData.setUrl("http://fess.codelibs.org/test.html"); /*ResultData resultData =*/fessXpathTransformer.transform(responseData); // System.out.println(resultData.toString()); } System.gc(); Thread.sleep(1000L); logger.info(MemoryUtil.getMemoryUsageLog()); assertTrue(MemoryUtil.getUsedMemory() < max - 100000000L); }
Example #9
Source File: ComponentUtil.java From fess with Apache License 2.0 | 4 votes |
public static boolean hasIngestFactory() { return SingletonLaContainerFactory.getContainer().hasComponentDef(INGEST_FACTORY); }
Example #10
Source File: ComponentUtil.java From fess with Apache License 2.0 | 4 votes |
public static boolean hasRelatedQueryHelper() { return SingletonLaContainerFactory.getContainer().hasComponentDef(RELATED_QUERY_HELPER); }
Example #11
Source File: ComponentUtil.java From fess with Apache License 2.0 | 4 votes |
public static boolean hasPopularWordHelper() { return SingletonLaContainerFactory.getContainer().hasComponentDef(POPULAR_WORD_HELPER); }
Example #12
Source File: ComponentUtil.java From fess with Apache License 2.0 | 4 votes |
public static boolean hasQueryHelper() { return SingletonLaContainerFactory.getContainer().hasComponentDef(QUERY_HELPER); }
Example #13
Source File: ComponentUtil.java From fess with Apache License 2.0 | 4 votes |
public static boolean hasViewHelper() { return SingletonLaContainerFactory.getContainer().hasComponentDef(VIEW_HELPER); }
Example #14
Source File: SuggestCreator.java From fess with Apache License 2.0 | 4 votes |
private static void destroyContainer() { TimeoutManager.getInstance().stop(); synchronized (SingletonLaContainerFactory.class) { SingletonLaContainerFactory.destroy(); } }
Example #15
Source File: ThumbnailGenerator.java From fess with Apache License 2.0 | 4 votes |
private static void destroyContainer() { TimeoutManager.getInstance().stop(); synchronized (SingletonLaContainerFactory.class) { SingletonLaContainerFactory.destroy(); } }
Example #16
Source File: ComponentEnvDispatcher.java From lastaflute with Apache License 2.0 | 4 votes |
public static boolean canDispatch(Class<?> componentClass) { // check before without instance return SingletonLaContainerFactory.hasContainer() && findEnvDispatch(componentClass) != null; }
Example #17
Source File: WebLastaContainerInitializer.java From lastaflute with Apache License 2.0 | 4 votes |
protected void doInitContainer() { SingletonLaContainerFactory.init(); }
Example #18
Source File: WebLastaContainerInitializer.java From lastaflute with Apache License 2.0 | 4 votes |
protected void setupOriginalConfigPath() { if (!LdiStringUtil.isEmpty(configPath)) { SingletonLaContainerFactory.setConfigPath(configPath); } }
Example #19
Source File: WebLastaContainerInitializer.java From lastaflute with Apache License 2.0 | 4 votes |
protected boolean isAlreadyInitialized() { return SingletonLaContainerFactory.hasContainer(); }
Example #20
Source File: ModuleConfig.java From lastaflute with Apache License 2.0 | 4 votes |
protected void prepareActionComponent(String actionName) { SingletonLaContainerFactory.getContainer().getComponent(actionName); // initialize }
Example #21
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 2 votes |
/** * Does the Lasta Di have external context instance? * @return The determination, true or false. */ public static boolean hasExternalContext() { return SingletonLaContainerFactory.getExternalContext() != null; }
Example #22
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 2 votes |
/** * @param componentName The component name to find. (NotNull) * @return The determination, true or false. */ public static boolean proveComponentByName(String componentName) { return SingletonLaContainerFactory.getContainer().hasComponentDef(componentName); }
Example #23
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 2 votes |
/** * @param componentType The component type to find. (NotNull) * @return The determination, true or false. */ public static boolean hasComponent(Class<?> componentType) { return SingletonLaContainerFactory.getContainer().hasComponentDef(componentType); }
Example #24
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 2 votes |
/** * @param componentType The component type to find. (NotNull) * @return The array of found components. (NotNull) * @throws CyclicReferenceComponentException When the components refers each other. */ @SuppressWarnings("unchecked") public static <COMPONENT> COMPONENT[] searchComponentsAll(Class<COMPONENT> componentType) { return (COMPONENT[]) SingletonLaContainerFactory.getContainer().findAllComponents(componentType); }
Example #25
Source File: ContainerUtil.java From lastaflute with Apache License 2.0 | 2 votes |
/** * @param componentType The component type to find. (NotNull) * @return The array of found components. (NotNull) * @throws CyclicReferenceComponentException When the components refers each other. */ @SuppressWarnings("unchecked") public static <COMPONENT> COMPONENT[] searchComponents(Class<COMPONENT> componentType) { return (COMPONENT[]) SingletonLaContainerFactory.getContainer().findComponents(componentType); }