Search in sources :

Example 1 with RequestHeaderService

use of org.codelibs.fess.app.service.RequestHeaderService in project fess by codelibs.

the class WebConfig method initializeClientFactory.

@Override
public Map<String, Object> initializeClientFactory(final CrawlerClientFactory clientFactory) {
    final WebAuthenticationService webAuthenticationService = ComponentUtil.getComponent(WebAuthenticationService.class);
    final RequestHeaderService requestHeaderService = ComponentUtil.getComponent(RequestHeaderService.class);
    final FessConfig fessConfig = ComponentUtil.getFessConfig();
    // HttpClient Parameters
    final Map<String, Object> paramMap = new HashMap<>();
    clientFactory.setInitParameterMap(paramMap);
    final Map<String, String> clientConfigMap = getConfigParameterMap(ConfigName.CLIENT);
    if (clientConfigMap != null) {
        paramMap.putAll(clientConfigMap);
    }
    // robots txt enabled
    if (paramMap.get(HcHttpClient.ROBOTS_TXT_ENABLED_PROPERTY) == null) {
        paramMap.put(HcHttpClient.ROBOTS_TXT_ENABLED_PROPERTY, !fessConfig.isCrawlerIgnoreRobotsTxt());
    }
    final String userAgent = getUserAgent();
    if (StringUtil.isNotBlank(userAgent)) {
        paramMap.put(HcHttpClient.USER_AGENT_PROPERTY, userAgent);
    }
    final List<WebAuthentication> webAuthList = webAuthenticationService.getWebAuthenticationList(getId());
    final List<Authentication> basicAuthList = new ArrayList<>();
    for (final WebAuthentication webAuth : webAuthList) {
        basicAuthList.add(webAuth.getAuthentication());
    }
    paramMap.put(HcHttpClient.BASIC_AUTHENTICATIONS_PROPERTY, basicAuthList.toArray(new Authentication[basicAuthList.size()]));
    // request header
    final List<RequestHeader> requestHeaderList = requestHeaderService.getRequestHeaderList(getId());
    final List<org.codelibs.fess.crawler.client.http.RequestHeader> rhList = new ArrayList<>();
    for (final RequestHeader requestHeader : requestHeaderList) {
        rhList.add(requestHeader.getCrawlerRequestHeader());
    }
    paramMap.put(HcHttpClient.REQUERT_HEADERS_PROPERTY, rhList.toArray(new org.codelibs.fess.crawler.client.http.RequestHeader[rhList.size()]));
    // proxy credentials
    if (paramMap.get("proxyUsername") != null && paramMap.get("proxyPassword") != null) {
        paramMap.put(HcHttpClient.PROXY_CREDENTIALS_PROPERTY, new UsernamePasswordCredentials(paramMap.remove("proxyUsername").toString(), paramMap.remove("proxyPassword").toString()));
    }
    return paramMap;
}
Also used : WebAuthenticationService(org.codelibs.fess.app.service.WebAuthenticationService) RequestHeaderService(org.codelibs.fess.app.service.RequestHeaderService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) Authentication(org.codelibs.fess.crawler.client.http.Authentication)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 RequestHeaderService (org.codelibs.fess.app.service.RequestHeaderService)1 WebAuthenticationService (org.codelibs.fess.app.service.WebAuthenticationService)1 Authentication (org.codelibs.fess.crawler.client.http.Authentication)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1