Search in sources :

Example 11 with W3CEndpointReferenceBuilder

use of jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder in project metro-jax-ws by eclipse-ee4j.

the class ReferenceParametersTest method testReferenceParametersConversion1.

/*
     * Whitebox test for issue564   
     */
/*
    This test has been moved to jaxws-unit test harness so that 2.1.5 tag can be used.
    
    public void testFaultToReferenceParametersJAXBMessage2() throws Exception {
        String requestStr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                "<S:Envelope xmlns:S=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:user=\"http://foo.bar\" " +
                "xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/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:ReplyTo>" +
                "<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" +
                "<wsa:ReferenceParameters>" +
                "<user:foo>bar</user:foo>" +
                "<user:bar xmlns:user=\"http://foo.bar\">" +
                "<user:foobar>barfoo</user:foobar>" +
                "</user:bar>" +
                "</wsa:ReferenceParameters>" +
                "</wsa:ReplyTo>" +
                "<wsa:FaultTo>" +
                "<wsa:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:Address>" +
                "<wsa:ReferenceParameters>" +
                "<user:foo>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>" +
                "<addNumbers xmlns=\"http://example.com/\">" +
                "<number1>10</number1>" +
                "<number2>10</number2>" +
                "</addNumbers>" +
                "</S:Body></S:Envelope>";
        Message message = useStream12Codec(requestStr);
        WSEndpointReference wsepr = message.getHeaders().getFaultTo(AddressingVersion.MEMBER, SOAPVersion.SOAP_12);
        Message m2 = Messages.create("Test Unsupported",AddressingVersion.MEMBER,SOAPVersion.SOAP_12);
        wsepr.addReferenceParameters(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) {
            assertEquals("NS Decl did not match", "http://foo.bar", e.getNamespaceURI());
        }
    }
    */
public void testReferenceParametersConversion1() throws Exception {
    DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
    docFactory.setNamespaceAware(true);
    DocumentBuilder db = docFactory.newDocumentBuilder();
    Document doc = db.newDocument();
    Element el1 = doc.createElementNS("http:foo.bar", "Element1");
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    EndpointReference epr = builder.address("http://foo.bar").referenceParameter(el1).build();
    System.out.println("EPR " + epr);
    WSEndpointReference wsepr = new WSEndpointReference(epr);
    MemberSubmissionEndpointReference translated = wsepr.toSpec(MemberSubmissionEndpointReference.class);
    // System.out.println(translated);
    assert (translated.referenceParameters.elements.size() == 1);
}
Also used : W3CEndpointReferenceBuilder(jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder) Element(org.w3c.dom.Element) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) Document(org.w3c.dom.Document) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) MemberSubmissionEndpointReference(com.sun.xml.ws.developer.MemberSubmissionEndpointReference) EndpointReference(jakarta.xml.ws.EndpointReference)

Example 12 with W3CEndpointReferenceBuilder

use of jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder in project metro-jax-ws by eclipse-ee4j.

the class EprMarshalUnmarshalTest method testW3CEprMarshalling.

public void testW3CEprMarshalling() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(W3CEndpointReference.class);
    JAXBResult res = new JAXBResult(ctx);
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder.address("http://example.com");
    W3CEndpointReference epr = builder.build();
    // You will get the NPE
    epr.writeTo(res);
}
Also used : W3CEndpointReferenceBuilder(jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) JAXBContext(jakarta.xml.bind.JAXBContext) JAXBResult(jakarta.xml.bind.util.JAXBResult)

Example 13 with W3CEndpointReferenceBuilder

use of jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder in project metro-jax-ws by eclipse-ee4j.

the class W3CEPRTest method testW3CEprBuilder_withWSDL_InterfaceName.

public void testW3CEprBuilder_withWSDL_InterfaceName() throws Exception {
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder = builder.address(getEndpointAddress());
    builder = builder.wsdlDocumentLocation(getEndpointAddress() + "?wsdl");
    builder = builder.interfaceName(INTERFACE_NAME);
    W3CEndpointReference epr = builder.build();
    DOMResult result = new DOMResult();
    epr.writeTo(result);
    assertTrue(EprUtil.validateEPR(result.getNode(), W3CEndpointReference.class, getEndpointAddress(), null, null, INTERFACE_NAME, getEndpointAddress() + "?wsdl"));
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// epr.writeTo(new StreamResult(baos));
// baos.writeTo(System.out);
}
Also used : W3CEndpointReferenceBuilder(jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) DOMResult(javax.xml.transform.dom.DOMResult) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference)

Example 14 with W3CEndpointReferenceBuilder

use of jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder in project metro-jax-ws by eclipse-ee4j.

the class EPRTest method test.

public void test() {
    Test proxy = new TestService().getTestPort();
    W3CEndpointReferenceBuilder eprbuilder = new W3CEndpointReferenceBuilder();
    String address = "http://example.com";
    eprbuilder.address(address);
    W3CEndpointReference epr = eprbuilder.build();
    W3CEndpointReference ret = proxy.test(epr);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ret.writeTo(new StreamResult(baos));
    String retEprStr = new String(baos.toByteArray());
    assertTrue(retEprStr.contains(address));
}
Also used : W3CEndpointReferenceBuilder(jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) StreamResult(javax.xml.transform.stream.StreamResult) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 15 with W3CEndpointReferenceBuilder

use of jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder in project metro-jax-ws by eclipse-ee4j.

the class W3CEPRTest method testEPRWithReferenceParameters.

public void testEPRWithReferenceParameters() throws Exception {
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    builder = builder.address(getEndpointAddress());
    DOMSource domsrc = makeDOMSource(xmlInterfaceName);
    Document document = (Document) domsrc.getNode();
    builder = builder.metadata(document.getDocumentElement());
    builder = builder.serviceName(SERVICE_QNAME);
    builder = builder.endpointName(PORT_QNAME);
    // builder = builder.wsdlDocumentLocation(wsdlurl.toString());
    domsrc = makeDOMSource(xmlRefParam1);
    document = (Document) domsrc.getNode();
    builder = builder.referenceParameter(document.getDocumentElement());
    domsrc = makeDOMSource(xmlRefParam2);
    document = (Document) domsrc.getNode();
    builder = builder.referenceParameter(document.getDocumentElement());
    W3CEndpointReference epr = builder.build();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    epr.writeTo(new StreamResult(baos));
    AddNumbersService service = new AddNumbersService();
    AddNumbersPortType myport = (AddNumbersPortType) service.getPort(epr, AddNumbersPortType.class, new AddressingFeature(true, true));
    myport.addNumbers(10, 10);
}
Also used : W3CEndpointReferenceBuilder(jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) DOMSource(javax.xml.transform.dom.DOMSource) AddressingFeature(jakarta.xml.ws.soap.AddressingFeature) StreamResult(javax.xml.transform.stream.StreamResult) W3CEndpointReference(jakarta.xml.ws.wsaddressing.W3CEndpointReference) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document)

Aggregations

W3CEndpointReferenceBuilder (jakarta.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)16 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)10 Document (org.w3c.dom.Document)8 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)6 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)6 EndpointReference (jakarta.xml.ws.EndpointReference)6 DocumentBuilder (javax.xml.parsers.DocumentBuilder)6 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)6 Element (org.w3c.dom.Element)6 StreamResult (javax.xml.transform.stream.StreamResult)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DOMResult (javax.xml.transform.dom.DOMResult)3 Node (org.w3c.dom.Node)3 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBException (jakarta.xml.bind.JAXBException)2 JAXBResult (jakarta.xml.bind.util.JAXBResult)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 DOMSource (javax.xml.transform.dom.DOMSource)2