use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class MimeCodec method encode.
// TODO: preencode String literals to byte[] so that they don't have to
// go through char[]->byte[] conversion at runtime.
public ContentType encode(Packet packet, OutputStream out) throws IOException {
Message msg = packet.getMessage();
if (msg == null) {
return null;
}
ContentTypeImpl ctImpl = (ContentTypeImpl) getStaticContentType(packet);
String boundary = ctImpl.getBoundary();
String rootId = ctImpl.getRootId();
boolean hasAttachments = (boundary != null);
Codec rootCodec = getMimeRootCodec(packet);
if (hasAttachments) {
writeln("--" + boundary, out);
ContentType ct = rootCodec.getStaticContentType(packet);
String ctStr = (ct != null) ? ct.getContentType() : rootCodec.getMimeType();
if (rootId != null)
writeln("Content-ID: " + rootId, out);
writeln("Content-Type: " + ctStr, out);
writeln(out);
}
ContentType primaryCt = rootCodec.encode(packet, out);
if (hasAttachments) {
writeln(out);
// Encode all the attchments
for (Attachment att : msg.getAttachments()) {
writeln("--" + boundary, out);
// SAAJ's AttachmentPart.getContentId() returns content id already enclosed with
// angle brackets. For now put angle bracket only if its not there
String cid = att.getContentId();
if (cid != null && cid.length() > 0 && cid.charAt(0) != '<')
cid = '<' + cid + '>';
writeln("Content-Id:" + cid, out);
writeln("Content-Type: " + att.getContentType(), out);
writeCustomMimeHeaders(att, out);
writeln("Content-Transfer-Encoding: binary", out);
// write \r\n
writeln(out);
att.writeTo(out);
// write \r\n
writeln(out);
}
writeAsAscii("--" + boundary, out);
writeAsAscii("--", out);
}
// TODO not returing correct multipart/related type(no boundary)
return hasAttachments ? ctImpl : primaryCt;
}
use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class XMLHTTPBindingCodec method getStaticContentType.
@Override
public ContentType getStaticContentType(Packet packet) {
ContentType ct;
if (packet.getInternalMessage() instanceof MessageDataSource) {
final MessageDataSource mds = (MessageDataSource) packet.getInternalMessage();
if (mds.hasUnconsumedDataSource()) {
ct = getStaticContentType(mds);
return (ct != null) ? // _adaptingContentType.set(packet, ct)
setAcceptHeader(packet, ct) : null;
}
}
ct = super.getStaticContentType(packet);
return (ct != null) ? // _adaptingContentType.set(packet, ct)
setAcceptHeader(packet, ct) : null;
}
use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class XMLHTTPBindingCodec method transformDataSource.
public static DataSource transformDataSource(DataSource in, boolean isFastInfoset, boolean useFastInfoset, WSFeatureList f) {
try {
if (isFastInfoset && !useFastInfoset) {
// Convert from Fast Infoset to XML
Codec codec = new XMLHTTPBindingCodec(f);
Packet p = new Packet();
codec.decode(in.getInputStream(), in.getContentType(), p);
p.getMessage().getAttachments();
codec.getStaticContentType(p);
ByteArrayBuffer bos = new ByteArrayBuffer();
ContentType ct = codec.encode(p, bos);
return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
} else if (!isFastInfoset && useFastInfoset) {
// Convert from XML to Fast Infoset
Codec codec = new XMLHTTPBindingCodec(f);
Packet p = new Packet();
codec.decode(in.getInputStream(), in.getContentType(), p);
p.contentNegotiation = ContentNegotiation.optimistic;
p.getMessage().getAttachments();
codec.getStaticContentType(p);
ByteArrayBuffer bos = new ByteArrayBuffer();
com.sun.xml.ws.api.pipe.ContentType ct = codec.encode(p, bos);
return XMLMessage.createDataSource(ct.getContentType(), bos.newInputStream());
}
} catch (Exception ex) {
throw new WebServiceException(ex);
}
return in;
}
use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class LocalAsyncTransportTube method processRequest.
@NotNull
@Override
public NextAction processRequest(@NotNull Packet request) {
try {
// Set up WSConnection with tranport headers, request content
// get transport headers from message
reqHeaders.clear();
Map<String, List<String>> rh = (Map<String, List<String>>) request.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
// assign empty map if its null
if (rh != null) {
reqHeaders.putAll(rh);
}
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);
}
// Packet serverReq = adapter.decodePacket(con, codec);
adapter.invokeAsync(con);
return doSuspend();
} catch (IOException ioe) {
throw new WebServiceException(ioe);
}
}
use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class LocalTransportTube method process.
public Packet process(Packet request) {
try {
// Set up WSConnection with tranport headers, request content
// get transport headers from message
reqHeaders.clear();
Map<String, List<String>> rh = (Map<String, List<String>>) request.invocationProperties.get(MessageContext.HTTP_REQUEST_HEADERS);
// assign empty map if its null
if (rh != null) {
reqHeaders.putAll(rh);
}
LocalConnectionImpl con = new LocalConnectionImpl(baseURI, reqHeaders);
// 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());
}
reqHeaders.put("Content-Type", Collections.singletonList(requestContentType));
String requestAccept = contentType.getAcceptHeader();
if (contentType.getAcceptHeader() != null) {
reqHeaders.put("Accept", Collections.singletonList(requestAccept));
}
writeSOAPAction(reqHeaders, contentType.getSOAPActionHeader(), request);
if (dump)
dump(con, "request", reqHeaders);
adapter.handle(con);
if (dump)
dump(con, "response", con.getResponseHeaders());
String responseContentType = getResponseContentType(con);
if (con.getStatus() == WSHTTPConnection.ONEWAY) {
// one way. no response given.
return request.createClientResponse(null);
}
// TODO: check if returned MIME type is the same as that which was sent
// or is acceptable if an Accept header was used
checkFIConnegIntegrity(request.contentNegotiation, requestContentType, requestAccept, responseContentType);
Packet reply = request.createClientResponse(null);
codec.decode(con.getInput(), responseContentType, reply);
return reply;
} catch (IOException ex) {
throw new WebServiceException(ex);
}
}
Aggregations