MyClosedCallback callback = new MyClosedCallback(request);
LocalConnectionImpl con = new LocalConnectionImpl(baseURI,reqHeaders,callback);
callback.setConnection(con);
// Calling getStaticContentType sets some internal state in the codec
// TODO : need to fix this properly in Codec
ContentType contentType = codec.getStaticContentType(request);
String requestContentType;
if (contentType != null) {
requestContentType = contentType.getContentType();
codec.encode(request, con.getOutput());
} else {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
contentType = codec.encode(request, baos);
requestContentType = contentType.getContentType();
baos.writeTo(con.getOutput());
}
callback.setContentType(contentType);
reqHeaders.put("Content-Type", Collections.singletonList(requestContentType));
String requestAccept = contentType.getAcceptHeader();
if (contentType.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(requestAccept));
}
if (dump) {
dump(con, "request", reqHeaders);