@Override
public Packet process(Packet request) {
HttpClientTransport con;
try {
// get transport headers from message
Map<String, List<String>> reqHeaders = new Headers();
@SuppressWarnings("unchecked")
Map<String, List<String>> userHeaders = (Map<String, List<String>>) request.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
boolean addUserAgent = true;
if (userHeaders != null) {
// userHeaders may not be modifiable like SingletonMap, just copy them
reqHeaders.putAll(userHeaders);
// application wants to use its own User-Agent header
if (userHeaders.get("User-Agent") != null) {
addUserAgent = false;
}
}
if (addUserAgent) {
reqHeaders.put("User-Agent", USER_AGENT);
}
addBasicAuth(request, reqHeaders);
addCookies(request, reqHeaders);
con = new HttpClientTransport(request,reqHeaders);
request.addSatellite(new HttpResponseProperties(con));
ContentType ct = codec.getStaticContentType(request);
if (ct == null) {
ByteArrayBuffer buf = new ByteArrayBuffer();
ct = codec.encode(request, buf);
// data size is available, set it as Content-Length
reqHeaders.put("Content-Length", Collections.singletonList(Integer.toString(buf.size())));
reqHeaders.put("Content-Type", Collections.singletonList(ct.getContentType()));
if (ct.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(ct.getAcceptHeader()));
}
if (binding instanceof SOAPBinding) {
writeSOAPAction(reqHeaders, ct.getSOAPActionHeader());
}
if(dump)
dump(buf, "HTTP request", reqHeaders);
buf.writeTo(con.getOutput());
} else {
// Set static Content-Type
reqHeaders.put("Content-Type", Collections.singletonList(ct.getContentType()));
if (ct.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(ct.getAcceptHeader()));
}
if (binding instanceof SOAPBinding) {
writeSOAPAction(reqHeaders, ct.getSOAPActionHeader());
}