Search in sources :

Example 6 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer 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)

Example 7 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class ReferenceParametersTest method testFaultToReferenceParametersStreamMessage1.

/**
 * See if the ReferenceParamaters get added proeprly from FaultToEPR to fault response
 * @throws Exception
 */
public void testFaultToReferenceParametersStreamMessage1() throws Exception {
    String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" " + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar xmlns:user=\"http://foo.bar\">" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
    Message message = useStreamCodec(requestStr);
    WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
    String responseStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><S:Fault>" + "<faultcode>echo:EmptyEchoString</faultcode>" + "<faultstring>The echo string was empty.</faultstring>" + "</S:Fault></S:Body></S:Envelope>";
    Message m2 = useStreamCodec(responseStr);
    wsepr.addReferenceParametersToList(m2.getHeaders());
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    m2.writeTo(writer);
    writer.flush();
    XMLInputFactory readerFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
    Message sm = Messages.create(reader);
    Packet sm_packet = new Packet(sm);
    List<Element> refParams = sm_packet.getReferenceParameters();
    assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
    for (Element e : refParams) {
        assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
        assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) Element(org.w3c.dom.Element) XMLInputFactory(javax.xml.stream.XMLInputFactory) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 8 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class GlobalNsDeclTest method testNsDecl.

public void testNsDecl() 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);
    MessageHeaders hl = message.getHeaders();
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    writer.writeStartDocument();
    for (Header h : hl.asList()) {
        h.writeTo(writer);
    }
    writer.writeEndDocument();
    writer.flush();
    // baos.writeTo(System.out);
    XMLInputFactory readerFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
    // go to start element
    reader.next();
    Header h = Headers.create(SOAPVersion.SOAP_11, reader);
    assertEquals(h.getNamespaceURI(), "http://foo.bar");
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XMLInputFactory(javax.xml.stream.XMLInputFactory) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 9 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class ReferenceParametersTest method testFaultToReferenceParametersStreamMessage1.

/**
 * See if the ReferenceParamaters get added proeprly from FaultToEPR to fault response
 * @throws Exception
 */
public void testFaultToReferenceParametersStreamMessage1() throws Exception {
    String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" " + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar xmlns:user=\"http://foo.bar\">" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
    Message message = useStreamCodec(requestStr);
    WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
    String responseStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><S:Fault>" + "<faultcode>echo:EmptyEchoString</faultcode>" + "<faultstring>The echo string was empty.</faultstring>" + "</S:Fault></S:Body></S:Envelope>";
    Message m2 = useStreamCodec(responseStr);
    wsepr.addReferenceParametersToList(m2.getHeaders());
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    m2.writeTo(writer);
    writer.flush();
    XMLInputFactory readerFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
    Message sm = Messages.create(reader);
    Packet sm_packet = new Packet(sm);
    List<Element> refParams = sm_packet.getReferenceParameters();
    assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
    for (Element e : refParams) {
        assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
        assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) Element(org.w3c.dom.Element) XMLInputFactory(javax.xml.stream.XMLInputFactory) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 10 with ByteArrayBuffer

use of com.sun.xml.ws.util.ByteArrayBuffer in project metro-jax-ws by eclipse-ee4j.

the class ReferenceParametersTest method testFaultToReferenceParametersJAXBMessage1.

public void testFaultToReferenceParametersJAXBMessage1() throws Exception {
    String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:user=\"http://foo.bar\" " + "xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">" + "<S:Header>" + "<wsa:Action>http://example.org/action/echoIn</wsa:Action>" + "<wsa:To>http://www.w3.org/2005/08/addressing/anonymous</wsa:To>" + "<wsa:MessageID>urn:uuid:1234567890</wsa:MessageID>" + "<wsa:FaultTo>" + "<wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address>" + "<wsa:ReferenceParameters>" + "<user:foo xmlns:wsa=\"http://www.w3.org/2005/08/addressing\" wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user:bar xmlns:user=\"http://foo.bar\">" + "<user:foobar>barfoo</user:foobar>" + "</user:bar>" + "</wsa:ReferenceParameters>" + "</wsa:FaultTo>" + "</S:Header>" + "<S:Body><DataType xmlns=\"http://foo.org/xsd\"><param>foo bar</param></DataType></S:Body></S:Envelope>";
    Message message = useStreamCodec(requestStr);
    WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.W3C, SOAPVersion.SOAP_11);
    Message m2 = Messages.create("Test Unsupported", AddressingVersion.W3C, SOAPVersion.SOAP_11);
    wsepr.addReferenceParametersToList(m2.getHeaders());
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    m2.writeTo(writer);
    writer.flush();
    XMLInputFactory readerFactory = XMLInputFactory.newInstance();
    XMLStreamReader reader = readerFactory.createXMLStreamReader(baos.newInputStream());
    Message sm = Messages.create(reader);
    Packet sm_packet = new Packet(sm);
    List<Element> refParams = sm_packet.getReferenceParameters();
    assertEquals("Did n't get expected ReferenceParameters", 2, refParams.size());
    for (Element e : refParams) {
        assertTrue("isReferenceParameter attribute not present on header", e.getAttributeNodeNS(W3CAddressingConstants.WSA_NAMESPACE_NAME, "IsReferenceParameter") != null);
        assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
    }
}
Also used : Packet(com.sun.xml.ws.api.message.Packet) XMLStreamReader(javax.xml.stream.XMLStreamReader) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) Element(org.w3c.dom.Element) XMLInputFactory(javax.xml.stream.XMLInputFactory) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Aggregations

ByteArrayBuffer (com.sun.xml.ws.util.ByteArrayBuffer)29 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)13 Message (com.sun.xml.ws.api.message.Message)9 WebServiceException (jakarta.xml.ws.WebServiceException)9 Packet (com.sun.xml.ws.api.message.Packet)7 ClientTransportException (com.sun.xml.ws.client.ClientTransportException)7 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)6 SOAPMessage (jakarta.xml.soap.SOAPMessage)6 IOException (java.io.IOException)6 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)5 ObjectInputStream (java.io.ObjectInputStream)5 ObjectOutputStream (java.io.ObjectOutputStream)5 Transformer (javax.xml.transform.Transformer)5 StreamSource (javax.xml.transform.stream.StreamSource)5 XMLInputFactory (javax.xml.stream.XMLInputFactory)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 URL (java.net.URL)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 TransformerException (javax.xml.transform.TransformerException)3 DOMResult (javax.xml.transform.dom.DOMResult)3