Search in sources :

Example 1 with Codec

use of com.sun.xml.ws.api.pipe.Codec in project metro-jax-ws by eclipse-ee4j.

the class SAAJFactoryTest method getLogicalMessage.

private Message getLogicalMessage(byte[] bytes, String contentType) throws IOException {
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    WSBinding binding = BindingImpl.create(BindingID.SOAP11_HTTP);
    Codec codec = new SOAPBindingCodec(binding.getFeatures());
    Packet packet = new Packet();
    codec.decode(in, contentType, packet);
    return packet.getMessage();
}
Also used : WSBinding(com.sun.xml.ws.api.WSBinding) Packet(com.sun.xml.ws.api.message.Packet) Codec(com.sun.xml.ws.api.pipe.Codec) SOAPBindingCodec(com.sun.xml.ws.encoding.SOAPBindingCodec) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPBindingCodec(com.sun.xml.ws.encoding.SOAPBindingCodec)

Example 2 with Codec

use of com.sun.xml.ws.api.pipe.Codec 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 3 with Codec

use of com.sun.xml.ws.api.pipe.Codec in project metro-jax-ws by eclipse-ee4j.

the class SwACodec method decode.

@Override
protected void decode(MimeMultipartParser mpp, Packet packet) throws IOException {
    // TODO: handle attachments correctly
    Attachment root = mpp.getRootPart();
    Codec rootCodec = getMimeRootCodec(packet);
    if (rootCodec instanceof RootOnlyCodec) {
        ((RootOnlyCodec) rootCodec).decode(root.asInputStream(), root.getContentType(), packet, new MimeAttachmentSet(mpp));
    } else {
        rootCodec.decode(root.asInputStream(), root.getContentType(), packet);
        Map<String, Attachment> atts = mpp.getAttachmentParts();
        for (Map.Entry<String, Attachment> att : atts.entrySet()) {
            packet.getMessage().getAttachments().add(att.getValue());
        }
    }
}
Also used : Codec(com.sun.xml.ws.api.pipe.Codec) Attachment(com.sun.xml.ws.api.message.Attachment) MimeAttachmentSet(com.sun.xml.ws.message.MimeAttachmentSet) Map(java.util.Map)

Example 4 with Codec

use of com.sun.xml.ws.api.pipe.Codec 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 5 with Codec

use of com.sun.xml.ws.api.pipe.Codec in project metro-jax-ws by eclipse-ee4j.

the class XMLMessage method getDataSource.

public static DataSource getDataSource(Message msg, WSFeatureList f) {
    if (msg == null)
        return null;
    if (msg instanceof MessageDataSource) {
        return ((MessageDataSource) msg).getDataSource();
    } else {
        AttachmentSet atts = msg.getAttachments();
        if (atts != null && !atts.isEmpty()) {
            final ByteArrayBuffer bos = new ByteArrayBuffer();
            try {
                Codec codec = new XMLHTTPBindingCodec(f);
                Packet packet = new Packet(msg);
                com.sun.xml.ws.api.pipe.ContentType ct = codec.getStaticContentType(packet);
                codec.encode(packet, bos);
                return createDataSource(ct.getContentType(), bos.newInputStream());
            } catch (IOException ioe) {
                throw new WebServiceException(ioe);
            }
        } else {
            final ByteArrayBuffer bos = new ByteArrayBuffer();
            XMLStreamWriter writer = XMLStreamWriterFactory.create(bos);
            try {
                msg.writePayloadTo(writer);
                writer.flush();
            } catch (XMLStreamException e) {
                throw new WebServiceException(e);
            }
            return XMLMessage.createDataSource("text/xml", bos.newInputStream());
        }
    }
}
Also used : XMLHTTPBindingCodec(com.sun.xml.ws.encoding.XMLHTTPBindingCodec) WebServiceException(jakarta.xml.ws.WebServiceException) IOException(java.io.IOException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer) MimeAttachmentSet(com.sun.xml.ws.message.MimeAttachmentSet) Codec(com.sun.xml.ws.api.pipe.Codec) XMLHTTPBindingCodec(com.sun.xml.ws.encoding.XMLHTTPBindingCodec) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter)

Aggregations

Codec (com.sun.xml.ws.api.pipe.Codec)19 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Packet (com.sun.xml.ws.api.message.Packet)12 ContentType (com.sun.xml.ws.api.pipe.ContentType)3 IOException (java.io.IOException)3 Attachment (com.sun.xml.ws.api.message.Attachment)2 Message (com.sun.xml.ws.api.message.Message)2 MimeAttachmentSet (com.sun.xml.ws.message.MimeAttachmentSet)2 StreamMessage (com.sun.xml.ws.message.stream.StreamMessage)2 ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 BindingID (com.sun.xml.ws.api.BindingID)1 WSBinding (com.sun.xml.ws.api.WSBinding)1 BindingImpl (com.sun.xml.ws.binding.BindingImpl)1 MtomCodec (com.sun.xml.ws.encoding.MtomCodec)1 SOAPBindingCodec (com.sun.xml.ws.encoding.SOAPBindingCodec)1 XMLHTTPBindingCodec (com.sun.xml.ws.encoding.XMLHTTPBindingCodec)1 XMLCodec (com.sun.xml.ws.encoding.xml.XMLCodec)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1