use of org.apache.chemistry.opencmis.client.bindings.spi.http.Output in project iaf by ibissource.
the class CmisHttpSender method getMethod.
@Override
public HttpRequestBase getMethod(URIBuilder uri, String message, ParameterValueList pvl, Map<String, String> headersParamsMap, IPipeLineSession session) throws SenderException {
HttpRequestBase method = null;
try {
if (getMethodType().equals("GET")) {
method = new HttpGet(uri.build());
} else if (getMethodType().equals("POST")) {
HttpPost httpPost = new HttpPost(uri.build());
// send data
if (pvl.getParameterValue("writer") != null) {
Output writer = (Output) pvl.getParameterValue("writer").getValue();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Object clientCompression = pvl.getParameterValue(SessionParameter.CLIENT_COMPRESSION);
if ((clientCompression != null) && Boolean.parseBoolean(clientCompression.toString())) {
httpPost.setHeader("Content-Encoding", "gzip");
writer.write(new GZIPOutputStream(out, 4096));
} else {
writer.write(out);
}
HttpEntity entity = new BufferedHttpEntity(new ByteArrayEntity(out.toByteArray()));
httpPost.setEntity(entity);
out.close();
method = httpPost;
}
} else if (getMethodType().equals("PUT")) {
HttpPut httpPut = new HttpPut(uri.build());
// send data
if (pvl.getParameterValue("writer") != null) {
Output writer = (Output) pvl.getParameterValue("writer").getValue();
ByteArrayOutputStream out = new ByteArrayOutputStream();
Object clientCompression = pvl.getParameterValue(SessionParameter.CLIENT_COMPRESSION);
if ((clientCompression != null) && Boolean.parseBoolean(clientCompression.toString())) {
httpPut.setHeader("Content-Encoding", "gzip");
writer.write(new GZIPOutputStream(out, 4096));
} else {
writer.write(out);
}
HttpEntity entity = new BufferedHttpEntity(new ByteArrayEntity(out.toByteArray()));
httpPut.setEntity(entity);
out.close();
method = httpPut;
}
} else if (getMethodType().equals("DELETE")) {
method = new HttpDelete(uri.build());
} else {
throw new MethodNotSupportedException("method [" + getMethodType() + "] not implemented");
}
} catch (Exception e) {
throw new SenderException(e);
}
for (Map.Entry<String, String> entry : headers.entrySet()) {
log.debug("append header [" + entry.getKey() + "] with value [" + entry.getValue() + "]");
method.addHeader(entry.getKey(), entry.getValue());
}
// Cmis creates it's own contentType depending on the method and bindingType
method.setHeader("Content-Type", getContentType());
log.debug(getLogPrefix() + "HttpSender constructed " + getMethodType() + "-method [" + method.getURI() + "] query [" + method.getURI().getQuery() + "] ");
return method;
}
Aggregations