use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class HttpAdapter method encodePacket.
private void encodePacket(@NotNull Packet packet, @NotNull WSHTTPConnection con, @NotNull Codec codec) throws IOException {
if (isNonAnonymousUri(packet.endpointAddress) && packet.getMessage() != null) {
try {
// Message is targeted to non-anonymous response endpoint.
// After call to non-anonymous processor, typically, packet.getMessage() will be null
// however, processors could use this pattern to modify the response sent on the back-channel,
// e.g. send custom HTTP headers with the HTTP 202
packet = getNonAnonymousResponseProcessor().process(packet);
} catch (RuntimeException re) {
// if processing by NonAnonymousResponseProcessor fails, new SOAPFaultMessage is created to be sent
// to back-channel client
SOAPVersion soapVersion = packet.getBinding().getSOAPVersion();
Message faultMsg = SOAPFaultBuilder.createSOAPFaultMessage(soapVersion, null, re);
packet = packet.createServerResponse(faultMsg, packet.endpoint.getPort(), null, packet.endpoint.getBinding());
}
}
if (con.isClosed()) {
// Connection is already closed
return;
}
Message responseMessage = packet.getMessage();
addStickyCookie(con);
addReplicaCookie(con, packet);
if (responseMessage == null) {
if (!con.isClosed()) {
// for example, 415 may have been set earlier for Unsupported Content-Type
if (con.getStatus() == 0) {
con.setStatus(WSHTTPConnection.ONEWAY);
}
OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(packet, buf);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
codec.encode(packet, os);
}
// close the response channel now
try {
// no payload
os.close();
} catch (IOException e) {
throw new WebServiceException(e);
}
}
} else {
if (con.getStatus() == 0) {
// if the appliation didn't set the status code,
// set the default one.
con.setStatus(responseMessage.isFault() ? HttpURLConnection.HTTP_INTERNAL_ERROR : HttpURLConnection.HTTP_OK);
}
if (isClientErrorStatus(con.getStatus())) {
OutputStream os = con.getOutput();
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
writeClientError(con.getStatus(), buf, packet);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
writeClientError(con.getStatus(), os, packet);
}
os.close();
return;
}
ContentType contentType = codec.getStaticContentType(packet);
if (contentType != null) {
con.setContentTypeResponseHeader(contentType.getContentType());
OutputStream os = con.getProtocol().contains("1.1") ? con.getOutput() : new Http10OutputStream(con);
if (dump || LOGGER.isLoggable(Level.FINER)) {
ByteArrayBuffer buf = new ByteArrayBuffer();
codec.encode(packet, buf);
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
buf.writeTo(os);
} else {
codec.encode(packet, os);
}
os.close();
} else {
ByteArrayBuffer buf = new ByteArrayBuffer();
contentType = codec.encode(packet, buf);
con.setContentTypeResponseHeader(contentType.getContentType());
if (dump || LOGGER.isLoggable(Level.FINER)) {
dump(buf, "HTTP response " + con.getStatus(), con.getResponseHeaders());
}
OutputStream os = con.getOutput();
buf.writeTo(os);
os.close();
}
}
}
use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class MimeCodec method getStaticContentType.
public ContentType getStaticContentType(Packet packet) {
ContentType ct = (ContentType) packet.getInternalContentType();
if (ct != null)
return ct;
Message msg = packet.getMessage();
boolean hasAttachments = !msg.getAttachments().isEmpty();
Codec rootCodec = getMimeRootCodec(packet);
if (hasAttachments) {
String boundary = "uuid:" + UUID.randomUUID();
String boundaryParameter = "boundary=\"" + boundary + "\"";
// TODO use primaryEncoder to get type
String messageContentType = MULTIPART_RELATED_MIME_TYPE + "; type=\"" + rootCodec.getMimeType() + "\"; " + boundaryParameter;
ContentTypeImpl impl = new ContentTypeImpl(messageContentType, packet.soapAction, null);
impl.setBoundary(boundary);
impl.setBoundaryParameter(boundaryParameter);
packet.setContentType(impl);
return impl;
} else {
ct = rootCodec.getStaticContentType(packet);
packet.setContentType(ct);
return ct;
}
}
use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class SOAPBindingCodec method encode.
@Override
public ContentType encode(Packet packet, WritableByteChannel buffer) {
preEncode(packet);
ContentType ct = getEncoder(packet).encode(packet, buffer);
ct = setAcceptHeader(packet, (ContentTypeImpl) ct);
postEncode();
return ct;
}
use of com.sun.xml.ws.api.pipe.ContentType in project metro-jax-ws by eclipse-ee4j.
the class SOAPBindingCodec method encode.
@Override
public ContentType encode(Packet packet, OutputStream out) throws IOException {
preEncode(packet);
ContentType ct = getEncoder(packet).encode(packet, out);
ct = setAcceptHeader(packet, (ContentTypeImpl) ct);
postEncode();
return ct;
}
Aggregations