use of org.codelibs.fess.exception.ThumbnailGenerationException in project fess by codelibs.
the class BaseThumbnailGenerator method process.
protected boolean process(final String id, final Predicate<ResponseData> consumer) {
return process(id, (configId, url) -> {
final CrawlingConfigHelper crawlingConfigHelper = ComponentUtil.getCrawlingConfigHelper();
final CrawlingConfig config = crawlingConfigHelper.getCrawlingConfig(configId);
if (config == null) {
throw new ThumbnailGenerationException("No CrawlingConfig: " + configId);
}
if (logger.isInfoEnabled()) {
logger.info("Generating Thumbnail: {}", url);
}
final CrawlerClientFactory crawlerClientFactory = config.initializeClientFactory(() -> ComponentUtil.getComponent(CrawlerClientFactory.class));
final CrawlerClient client = crawlerClientFactory.getClient(url);
if (client == null) {
throw new ThumbnailGenerationException("No CrawlerClient: " + configId + ", url: " + url);
}
String u = url;
for (int i = 0; i < maxRedirectCount; i++) {
try (final ResponseData responseData = client.execute(RequestDataBuilder.newRequestData().get().url(u).build())) {
if (StringUtil.isNotBlank(responseData.getRedirectLocation())) {
u = responseData.getRedirectLocation();
continue;
}
if (StringUtil.isBlank(responseData.getUrl())) {
throw new ThumbnailGenerationException("Failed to process a thumbnail content: " + url + " (Response URL is empty)");
}
return consumer.test(responseData);
} catch (final CrawlingAccessException e) {
if (logger.isDebugEnabled()) {
throw new ThumbnailGenerationException("Failed to process a thumbnail content: " + url, e);
}
throw new ThumbnailGenerationException(e.getMessage());
} catch (final Exception e) {
throw new ThumbnailGenerationException("Failed to process a thumbnail content: " + url, e);
}
}
throw new ThumbnailGenerationException("Failed to process a thumbnail content: " + url + " (Redirect Loop)");
});
}
use of org.codelibs.fess.exception.ThumbnailGenerationException in project fess by codelibs.
the class BaseThumbnailGenerator method process.
protected boolean process(final String id, final BiPredicate<String, String> consumer) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
try {
final Map<String, Object> doc = indexingHelper.getDocument(searchEngineClient, id, new String[] { fessConfig.getIndexFieldThumbnail(), fessConfig.getIndexFieldConfigId() });
if (doc == null) {
throw new ThumbnailGenerationException("Document is not found: " + id);
}
final String url = DocumentUtil.getValue(doc, fessConfig.getIndexFieldThumbnail(), String.class);
if (StringUtil.isBlank(url)) {
throw new ThumbnailGenerationException("Invalid thumbnail: " + url);
}
final String configId = DocumentUtil.getValue(doc, fessConfig.getIndexFieldConfigId(), String.class);
if (configId == null || configId.length() < 2) {
throw new ThumbnailGenerationException("Invalid configId: " + configId);
}
return consumer.test(configId, url);
} catch (final ThumbnailGenerationException e) {
if (e.getCause() == null) {
logger.debug(e.getMessage());
} else {
logger.warn("Failed to process {}", id, e);
}
} catch (final Exception e) {
logger.warn("Failed to process {}", id, e);
}
return false;
}
Aggregations