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