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;
}
Aggregations