Search in sources :

Example 1 with ThumbnailGenerationException

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)");
    });
}
Also used : CrawlingConfigHelper(org.codelibs.fess.helper.CrawlingConfigHelper) CrawlingConfig(org.codelibs.fess.es.config.exentity.CrawlingConfig) ThumbnailGenerationException(org.codelibs.fess.exception.ThumbnailGenerationException) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) CrawlerClientFactory(org.codelibs.fess.crawler.client.CrawlerClientFactory) ResponseData(org.codelibs.fess.crawler.entity.ResponseData) CrawlerClient(org.codelibs.fess.crawler.client.CrawlerClient) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) ThumbnailGenerationException(org.codelibs.fess.exception.ThumbnailGenerationException)

Example 2 with ThumbnailGenerationException

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;
}
Also used : IndexingHelper(org.codelibs.fess.helper.IndexingHelper) ThumbnailGenerationException(org.codelibs.fess.exception.ThumbnailGenerationException) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrawlingAccessException(org.codelibs.fess.crawler.exception.CrawlingAccessException) ThumbnailGenerationException(org.codelibs.fess.exception.ThumbnailGenerationException)

Aggregations

CrawlingAccessException (org.codelibs.fess.crawler.exception.CrawlingAccessException)2 ThumbnailGenerationException (org.codelibs.fess.exception.ThumbnailGenerationException)2 CrawlerClient (org.codelibs.fess.crawler.client.CrawlerClient)1 CrawlerClientFactory (org.codelibs.fess.crawler.client.CrawlerClientFactory)1 ResponseData (org.codelibs.fess.crawler.entity.ResponseData)1 SearchEngineClient (org.codelibs.fess.es.client.SearchEngineClient)1 CrawlingConfig (org.codelibs.fess.es.config.exentity.CrawlingConfig)1 CrawlingConfigHelper (org.codelibs.fess.helper.CrawlingConfigHelper)1 IndexingHelper (org.codelibs.fess.helper.IndexingHelper)1 FessConfig (org.codelibs.fess.mylasta.direction.FessConfig)1