下面列出了org.apache.http.impl.auth.DigestScheme#org.lastaflute.di.core.factory.SingletonLaContainerFactory 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
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;
}
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"));
}
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"));
}
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());
}
/**
* @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;
}
private static void destroyContainer() {
if (running.getAndSet(false)) {
TimeoutManager.getInstance().stop();
if (logger.isDebugEnabled()) {
logger.debug("Destroying LaContainer...");
}
SingletonLaContainerFactory.destroy();
logger.info("Destroyed LaContainer.");
}
}
protected void prepareActionComponent(String actionName) {
SingletonLaContainerFactory.getContainer().getComponent(actionName); // initialize
}
protected boolean isAlreadyInitialized() {
return SingletonLaContainerFactory.hasContainer();
}
protected void setupOriginalConfigPath() {
if (!LdiStringUtil.isEmpty(configPath)) {
SingletonLaContainerFactory.setConfigPath(configPath);
}
}
protected void doInitContainer() {
SingletonLaContainerFactory.init();
}
public static boolean canDispatch(Class<?> componentClass) { // check before without instance
return SingletonLaContainerFactory.hasContainer() && findEnvDispatch(componentClass) != null;
}
private static void destroyContainer() {
TimeoutManager.getInstance().stop();
synchronized (SingletonLaContainerFactory.class) {
SingletonLaContainerFactory.destroy();
}
}
private static void destroyContainer() {
TimeoutManager.getInstance().stop();
synchronized (SingletonLaContainerFactory.class) {
SingletonLaContainerFactory.destroy();
}
}
public static boolean hasViewHelper() {
return SingletonLaContainerFactory.getContainer().hasComponentDef(VIEW_HELPER);
}
public static boolean hasQueryHelper() {
return SingletonLaContainerFactory.getContainer().hasComponentDef(QUERY_HELPER);
}
public static boolean hasPopularWordHelper() {
return SingletonLaContainerFactory.getContainer().hasComponentDef(POPULAR_WORD_HELPER);
}
public static boolean hasRelatedQueryHelper() {
return SingletonLaContainerFactory.getContainer().hasComponentDef(RELATED_QUERY_HELPER);
}
public static boolean hasIngestFactory() {
return SingletonLaContainerFactory.getContainer().hasComponentDef(INGEST_FACTORY);
}
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);
}
/**
* @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);
}
/**
* @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);
}
/**
* @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);
}
/**
* @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);
}
/**
* Does the Lasta Di have external context instance?
* @return The determination, true or false.
*/
public static boolean hasExternalContext() {
return SingletonLaContainerFactory.getExternalContext() != null;
}