Search in sources :

Example 1 with AccessTimeoutTarget

use of org.codelibs.fess.crawler.client.AccessTimeoutTarget in project fess-crawler by codelibs.

the class FtpClient method processRequest.

protected ResponseData processRequest(final String uri, final boolean includeContent) {
    if (ftpAuthenticationHolder == null) {
        init();
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    try {
        return getResponseData(uri, includeContent);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
}
Also used : AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 2 with AccessTimeoutTarget

use of org.codelibs.fess.crawler.client.AccessTimeoutTarget in project fess-crawler by codelibs.

the class ApiExtractor method getText.

@Override
public ExtractData getText(final InputStream in, final Map<String, String> params) {
    if (logger.isDebugEnabled()) {
        logger.debug("Accessing " + url);
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    final ExtractData data = new ExtractData();
    final HttpPost httpPost = new HttpPost(url);
    final HttpEntity postEntity = MultipartEntityBuilder.create().setMode(HttpMultipartMode.BROWSER_COMPATIBLE).setCharset(Charset.forName("UTF-8")).addBinaryBody("filedata", in).build();
    httpPost.setEntity(postEntity);
    try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
        if (response.getStatusLine().getStatusCode() != Constants.OK_STATUS_CODE) {
            logger.error("Failed to access " + url + ", code: " + response.getStatusLine().getStatusCode() + ".");
            return null;
        }
        data.setContent(EntityUtils.toString(response.getEntity(), Charsets.UTF_8));
        final Header[] headers = response.getAllHeaders();
        for (final Header header : headers) {
            data.putValue(header.getName(), header.getValue());
        }
    } catch (final IOException e) {
        throw new ExtractException(e);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
    return data;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) ExtractException(org.codelibs.fess.crawler.exception.ExtractException) AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) ExtractData(org.codelibs.fess.crawler.entity.ExtractData) HttpEntity(org.apache.http.HttpEntity) RequestHeader(org.codelibs.fess.crawler.client.http.RequestHeader) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 3 with AccessTimeoutTarget

use of org.codelibs.fess.crawler.client.AccessTimeoutTarget in project fess-crawler by codelibs.

the class FileSystemClient method processRequest.

protected ResponseData processRequest(final String uri, final boolean includeContent) {
    if (!isInit.get()) {
        synchronized (isInit) {
            if (!isInit.get()) {
                init();
                isInit.set(true);
            }
        }
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    try {
        return getResponseData(uri, includeContent);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
}
Also used : AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 4 with AccessTimeoutTarget

use of org.codelibs.fess.crawler.client.AccessTimeoutTarget in project fess-crawler by codelibs.

the class HcHttpClient method doHttpMethod.

public ResponseData doHttpMethod(final String url, final HttpUriRequest httpRequest) {
    if (httpClient == null) {
        init();
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Accessing " + url);
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    try {
        return processHttpMethod(url, httpRequest);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
}
Also used : AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Example 5 with AccessTimeoutTarget

use of org.codelibs.fess.crawler.client.AccessTimeoutTarget in project fess-crawler by codelibs.

the class SmbClient method processRequest.

protected ResponseData processRequest(final String uri, final boolean includeContent) {
    if (smbAuthenticationHolder == null) {
        init();
    }
    // start
    AccessTimeoutTarget accessTimeoutTarget = null;
    TimeoutTask accessTimeoutTask = null;
    if (accessTimeout != null) {
        accessTimeoutTarget = new AccessTimeoutTarget(Thread.currentThread());
        accessTimeoutTask = TimeoutManager.getInstance().addTimeoutTarget(accessTimeoutTarget, accessTimeout.intValue(), false);
    }
    try {
        return getResponseData(uri, includeContent);
    } finally {
        if (accessTimeout != null) {
            accessTimeoutTarget.stop();
            if (!accessTimeoutTask.isCanceled()) {
                accessTimeoutTask.cancel();
            }
        }
    }
}
Also used : AccessTimeoutTarget(org.codelibs.fess.crawler.client.AccessTimeoutTarget) TimeoutTask(org.codelibs.core.timer.TimeoutTask)

Aggregations

TimeoutTask (org.codelibs.core.timer.TimeoutTask)5 AccessTimeoutTarget (org.codelibs.fess.crawler.client.AccessTimeoutTarget)5 IOException (java.io.IOException)1 Header (org.apache.http.Header)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 BasicHeader (org.apache.http.message.BasicHeader)1 RequestHeader (org.codelibs.fess.crawler.client.http.RequestHeader)1 ExtractData (org.codelibs.fess.crawler.entity.ExtractData)1 ExtractException (org.codelibs.fess.crawler.exception.ExtractException)1