Search in sources :

Example 21 with ByteArrayBuffer

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

the class SourceMessageTester method testWriteSOAP11MessagePayloadToXMLStreamWriter.

public void testWriteSOAP11MessagePayloadToXMLStreamWriter() {
    Message msg = createPayloadSourceMessage();
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    try {
        msg.writePayloadTo(writer);
        writer.flush();
        Transformer transformer = XmlUtil.newTransformer();
        StreamSource source = new StreamSource(baos.newInputStream());
        DOMResult domResult = new DOMResult();
        transformer.transform(source, domResult);
        Node n = domResult.getNode().getFirstChild();
        assertTrue(n.getLocalName().equals("Body") && n.getNamespaceURI().equals("urn:test:types"));
        Node c = n.getFirstChild();
        assertTrue(c.getLocalName().equals("value") && c.getNamespaceURI().equals("urn:test:types"));
        assertTrue(c.getFirstChild().getNodeValue().equals("Its Body"));
    } catch (XMLStreamException e) {
        e.printStackTrace();
        assertTrue(false);
    } catch (TransformerException e) {
        e.printStackTrace();
        assertTrue(false);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) DOMResult(javax.xml.transform.dom.DOMResult) Message(com.sun.xml.ws.api.message.Message) PayloadSourceMessage(com.sun.xml.ws.message.source.PayloadSourceMessage) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StreamSource(javax.xml.transform.stream.StreamSource) Node(org.w3c.dom.Node) TransformerException(javax.xml.transform.TransformerException) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 22 with ByteArrayBuffer

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

the class WSDLGen method run.

public static int run() throws Exception {
    if (!useLocal()) {
        return 0;
    }
    String outputDir = System.getProperty("tempdir");
    if (outputDir == null) {
        System.err.println("**** Set tempdir system property ****");
        return -1;
    }
    String riFile = outputDir + "/WEB-INF/sun-jaxws.xml";
    DeploymentDescriptorParser<WSEndpoint> parser = new DeploymentDescriptorParser<WSEndpoint>(Thread.currentThread().getContextClassLoader(), new FileSystemResourceLoader(new File(outputDir)), null, new AdapterFactory<WSEndpoint>() {

        public WSEndpoint createAdapter(String name, String urlPattern, WSEndpoint<?> endpoint) {
            return endpoint;
        }
    });
    List<WSEndpoint> endpoints = parser.parse(new File(riFile));
    final String addr = new File(outputDir).toURL().toExternalForm();
    // file:// -> local://
    final String address = "local" + addr.substring(4);
    for (WSEndpoint endpoint : endpoints) {
        ServiceDefinition def = endpoint.getServiceDefinition();
        if (def == null) {
            continue;
        }
        SDDocument primary = def.getPrimary();
        File file = new File(primary.getURL().toURI());
        if (file.exists()) {
            System.out.println("**** Primary WSDL " + file + " already exists - not generating any WSDL artifacts ****");
            // Primary WSDL already exists
            continue;
        }
        for (SDDocument doc : def) {
            int index = doc.getURL().getFile().indexOf("/WEB-INF/wsdl");
            String name = "";
            if (index == -1)
                name = outputDir + "/WEB-INF/wsdl" + doc.getURL().getFile();
            else
                name = doc.getURL().getFile();
            System.out.println("Creating WSDL artifact=" + name);
            ByteArrayBuffer buffer = new ByteArrayBuffer();
            doc.writeTo(new PortAddressResolver() {

                public String getAddressFor(QName serviceName, String portName) {
                    return address;
                }
            }, new DocumentAddressResolver() {

                public String getRelativeAddressFor(SDDocument current, SDDocument referenced) {
                    String rel = referenced.getURL().toExternalForm();
                    // remove file:/
                    return rel.substring(6);
                }
            }, buffer);
            FileOutputStream fos = new FileOutputStream(name);
            buffer.writeTo(fos);
            fos.close();
        }
    }
    return 0;
}
Also used : PortAddressResolver(com.sun.xml.ws.api.server.PortAddressResolver) DeploymentDescriptorParser(com.sun.xml.ws.transport.http.DeploymentDescriptorParser) QName(javax.xml.namespace.QName) FileSystemResourceLoader(com.sun.xml.ws.transport.local.FileSystemResourceLoader) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) DocumentAddressResolver(com.sun.xml.ws.api.server.DocumentAddressResolver) ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer) WSEndpoint(com.sun.xml.ws.api.server.WSEndpoint) FileOutputStream(java.io.FileOutputStream) SDDocument(com.sun.xml.ws.api.server.SDDocument) File(java.io.File) ServiceDefinition(com.sun.xml.ws.api.server.ServiceDefinition)

Example 23 with ByteArrayBuffer

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

the class AttachmentHelper method getBytes.

private static byte[] getBytes(InputStream is) throws IOException {
    ByteArrayBuffer bab = new ByteArrayBuffer();
    bab.write(is);
    return bab.toByteArray();
}
Also used : ByteArrayBuffer(com.sun.xml.ws.util.ByteArrayBuffer)

Example 24 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)

Example 25 with ByteArrayBuffer

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

the class StreamMessageTest method testMessageWriteTo.

/**
 * jax-ws issue 610
 * @throws Exception
 */
public void testMessageWriteTo() throws Exception {
    String soapMsg = "<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<Header>" + "</Header>" + "<Body>" + "<GetCountryCodesResponse xmlns='http://www.strikeiron.com'> <GetCountryCodesResult/></GetCountryCodesResponse>" + "</Body>" + "</Envelope>";
    Message message = createSOAP11StreamMessage(soapMsg);
    ByteArrayBuffer baos = new ByteArrayBuffer();
    XMLStreamWriter writer = XMLStreamWriterFactory.create(baos);
    message.writeTo(writer);
    writer.flush();
    baos.writeTo(System.out);
}
Also used : Message(com.sun.xml.ws.api.message.Message) StreamMessage(com.sun.xml.ws.message.stream.StreamMessage) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) 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