Search in sources :

Example 6 with ContentType

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();
        }
    }
}
Also used : Message(com.sun.xml.ws.api.message.Message) ExceptionHasMessage(com.sun.xml.ws.api.message.ExceptionHasMessage) WebServiceException(jakarta.xml.ws.WebServiceException) ContentType(com.sun.xml.ws.api.pipe.ContentType) SOAPVersion(com.sun.xml.ws.api.SOAPVersion) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 7 with ContentType

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;
    }
}
Also used : Codec(com.sun.xml.ws.api.pipe.Codec) ContentType(com.sun.xml.ws.api.pipe.ContentType) Message(com.sun.xml.ws.api.message.Message)

Example 8 with ContentType

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;
}
Also used : ContentType(com.sun.xml.ws.api.pipe.ContentType)

Example 9 with ContentType

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;
}
Also used : ContentType(com.sun.xml.ws.api.pipe.ContentType)

Aggregations

ContentType (com.sun.xml.ws.api.pipe.ContentType)9 WebServiceException (jakarta.xml.ws.WebServiceException)4 IOException (java.io.IOException)4 Message (com.sun.xml.ws.api.message.Message)3 Codec (com.sun.xml.ws.api.pipe.Codec)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 Packet (com.sun.xml.ws.api.message.Packet)2 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 NotNull (com.sun.istack.NotNull)1 SOAPVersion (com.sun.xml.ws.api.SOAPVersion)1 Attachment (com.sun.xml.ws.api.message.Attachment)1 ExceptionHasMessage (com.sun.xml.ws.api.message.ExceptionHasMessage)1 XMLCodec (com.sun.xml.ws.encoding.xml.XMLCodec)1 MessageDataSource (com.sun.xml.ws.encoding.xml.XMLMessage.MessageDataSource)1 OutputStream (java.io.OutputStream)1