Search in sources :

Example 1 with Response

use of org.apache.chemistry.opencmis.client.bindings.spi.http.Response in project iaf by ibissource.

the class CmisHttpInvoker method invoke.

private Response invoke(UrlBuilder url, String method, String contentType, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) {
    log.debug("Session " + session.getSessionId() + ": " + method + " " + url);
    Response response = null;
    try {
        sender = getInstance(session);
        if (sender == null)
            throw new CmisConnectionException("Failed to create IbisHttpSender");
        sender.setMethodType(method);
        if (contentType != null)
            sender.setContentType(contentType);
        // init headers if not exist
        if (headers == null)
            headers = new HashMap<String, String>();
        headers.put("User-Agent", (String) session.get(SessionParameter.USER_AGENT, ClientVersion.OPENCMIS_USER_AGENT));
        // offset
        if (offset != null || length != null) {
            StringBuilder sb = new StringBuilder("bytes=");
            if ((offset == null) || (offset.signum() == -1)) {
                offset = BigInteger.ZERO;
            }
            sb.append(offset.toString());
            sb.append('-');
            if (length != null && length.signum() == 1) {
                sb.append(offset.add(length.subtract(BigInteger.ONE)).toString());
            }
            headers.put("Range", sb.toString());
        }
        // compression
        Object compression = session.get(SessionParameter.COMPRESSION);
        if (compression != null && Boolean.parseBoolean(compression.toString())) {
            headers.put("Accept-Encoding", "gzip,deflate");
        }
        // locale
        if (session.get(CmisBindingsHelper.ACCEPT_LANGUAGE) instanceof String) {
            headers.put("Accept-Language", session.get(CmisBindingsHelper.ACCEPT_LANGUAGE).toString());
        }
        log.trace("invoking CmisHttpSender: content-type[" + contentType + "] headers[" + headers.toString() + "]");
        response = sender.invoke(url.toString(), headers, writer, session, offset, length);
    } catch (Exception e) {
        e.printStackTrace();
        throw new CmisConnectionException(url.toString(), -1, e);
    }
    log.trace("received result code[" + response.getResponseCode() + "] headers[" + response.getHeaders().toString() + "]");
    return response;
}
Also used : Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) HashMap(java.util.HashMap) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 2 with Response

use of org.apache.chemistry.opencmis.client.bindings.spi.http.Response in project iaf by ibissource.

the class CmisHttpSender method invoke.

public Response invoke(String url, Map<String, String> headers, Output writer, BindingSession session, BigInteger offset, BigInteger length) throws SenderException, TimeOutException {
    // Prepare the message. We will overwrite things later...
    this.headers = headers;
    int responseCode = -1;
    IPipeLineSession pls = new PipeLineSessionBase();
    pls.put("writer", writer);
    pls.put("url", url);
    ParameterResolutionContext prc = new ParameterResolutionContext("", pls);
    try {
        sendMessageWithTimeoutGuarded(null, null, prc);
        return (Response) pls.get("response");
    } catch (Exception e) {
        throw new CmisConnectionException(getUrl(), responseCode, e);
    }
}
Also used : Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 3 with Response

use of org.apache.chemistry.opencmis.client.bindings.spi.http.Response in project iaf by ibissource.

the class CmisHttpSender method extractResult.

@Override
public String extractResult(HttpResponseHandler responseHandler, ParameterResolutionContext prc) throws SenderException, IOException {
    int responseCode = -1;
    try {
        StatusLine statusline = responseHandler.getStatusLine();
        responseCode = statusline.getStatusCode();
        InputStream responseStream = null;
        InputStream errorStream = null;
        Map<String, List<String>> headerFields = responseHandler.getHeaderFields();
        if (responseCode == 200 || responseCode == 201 || responseCode == 203 || responseCode == 206) {
            responseStream = responseHandler.getResponse();
        } else {
            errorStream = new ByteArrayInputStream("ERROR".getBytes());
            responseHandler.close();
        }
        Response response = new Response(responseCode, statusline.toString(), headerFields, responseStream, errorStream);
        prc.getSession().put("response", response);
    } catch (Exception e) {
        throw new CmisConnectionException(getUrl(), responseCode, e);
    }
    return "response";
}
Also used : StatusLine(org.apache.http.StatusLine) Response(org.apache.chemistry.opencmis.client.bindings.spi.http.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) List(java.util.List) CmisConnectionException(org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException) MethodNotSupportedException(org.apache.http.MethodNotSupportedException) IOException(java.io.IOException) TimeOutException(nl.nn.adapterframework.core.TimeOutException) SenderException(nl.nn.adapterframework.core.SenderException)

Aggregations

SenderException (nl.nn.adapterframework.core.SenderException)3 Response (org.apache.chemistry.opencmis.client.bindings.spi.http.Response)3 CmisConnectionException (org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException)3 IOException (java.io.IOException)2 TimeOutException (nl.nn.adapterframework.core.TimeOutException)2 MethodNotSupportedException (org.apache.http.MethodNotSupportedException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)1 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)1 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)1 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)1 StatusLine (org.apache.http.StatusLine)1