Search in sources :

Example 11 with Codec

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

the class StreamMessageTest method useStreamCodec.

private StreamMessage useStreamCodec(String msg) throws IOException {
    Codec codec = Codecs.createSOAPEnvelopeXmlCodec(SOAPVersion.SOAP_11);
    Packet packet = new Packet();
    ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes());
    codec.decode(in, "text/xml", packet);
    return (StreamMessage) packet.getInternalMessage();
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Codec(com.sun.xml.ws.api.pipe.Codec) MtomCodec(com.sun.xml.ws.encoding.MtomCodec) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 12 with Codec

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

the class AbstractServerAsyncTransport method handle.

/**
 * Reads and decodes infoset from the connection and invokes the endpoints. The
 * response is encoded and written to the connection. The response could be
 * written using a different thread.
 *
 * @param connection that carries the web service request
 * @throws IOException if an i/o error happens while encoding/decoding
 */
protected void handle(final T connection) throws IOException {
    final Codec codec = codecPool.take();
    Packet request = decodePacket(connection, codec);
    if (!request.getMessage().isFault()) {
        endpoint.schedule(request, new WSEndpoint.CompletionCallback() {

            public void onCompletion(@NotNull Packet response) {
                try {
                    encodePacket(connection, response, codec);
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
                codecPool.recycle(codec);
            }
        });
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Codec(com.sun.xml.ws.api.pipe.Codec) IOException(java.io.IOException)

Example 13 with Codec

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

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

the class StreamMessageTester method useStreamCodec.

/**
 * Test to see if ns declarations on soap envelope are captured on to the headers after parsing.
 *
 * @throws Exception
 */
/* This test has been moved to jaxws-unit harness to use tag 2.1.5

    public void testHeadersInStreamMessage() throws Exception {
    	String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
                "xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\" xmlns:user=\"http://foo.bar\">" +
                "<S:Header>" +
                "<user:foo>bar</user:foo>" +
                "</S:Header>" +
                "<S:Body>" +
                "<addNumbers xmlns=\"http://example.com/\">" +
                "<number1>10</number1>" +
                "<number2>10</number2>" +
                "</addNumbers>" +
                "</S:Body></S:Envelope>";
        Message message = useStreamCodec(requestStr);
        HeaderList hl = message.getHeaders();
        ByteArrayBuffer baos = new ByteArrayBuffer();
        XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
        writer.writeStartDocument();
        for(Header h: hl) {
            h.writeTo(writer);
        }
        writer.writeEndDocument();
        writer.flush();
        //baos.writeTo(System.out);

        XMLInputFactory readerFactory = XMLInputFactory.newInstance();
        XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
        reader.next();// go to start element
        Header h = Headers.create(SOAPVersion.SOAP_11,reader);
        assertEquals(h.getNamespaceURI(),"http://foo.bar");
    }
    
    */
Message useStreamCodec(String msg) throws IOException {
    Codec codec = Codecs.createSOAPEnvelopeXmlCodec(SOAPVersion.SOAP_11);
    Packet packet = new Packet();
    ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes());
    codec.decode(in, "text/xml", packet);
    return packet.getMessage();
}
Also used : Codec(com.sun.xml.ws.api.pipe.Codec) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 15 with Codec

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

the class ReferenceParametersTest method useStream12Codec.

Message useStream12Codec(String msg) throws IOException {
    Codec codec = Codecs.createSOAPEnvelopeXmlCodec(SOAPVersion.SOAP_12);
    Packet packet = new Packet();
    ByteArrayInputStream in = new ByteArrayInputStream(msg.getBytes());
    codec.decode(in, "application/soap+xml", packet);
    return packet.getMessage();
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) Codec(com.sun.xml.ws.api.pipe.Codec) ByteArrayInputStream(java.io.ByteArrayInputStream)

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