Search in sources :

Example 1 with ContentType

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

Example 2 with ContentType

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

Example 3 with ContentType

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;
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Codec(com.sun.xml.ws.api.pipe.Codec) XMLCodec(com.sun.xml.ws.encoding.xml.XMLCodec) ContentType(com.sun.xml.ws.api.pipe.ContentType) WebServiceException(jakarta.xml.ws.WebServiceException) IOException(java.io.IOException) WebServiceException(jakarta.xml.ws.WebServiceException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 4 with ContentType

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);
    }
}
Also used : ContentType(com.sun.xml.ws.api.pipe.ContentType) WebServiceException(jakarta.xml.ws.WebServiceException) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) NotNull(com.sun.istack.NotNull)

Example 5 with ContentType

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);
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) ContentType(com.sun.xml.ws.api.pipe.ContentType) WebServiceException(jakarta.xml.ws.WebServiceException) List(java.util.List) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map)

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