Search in sources :

Example 61 with WSEndpointReference

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

the class WSEPRTester method testEPRs.

public void testEPRs() throws Exception {
    URL res = getClass().getResource("../epr/ms_epr_metadata.xml");
    // assuming that this is a file:// URL.
    File folder = new File(res.getFile()).getParentFile();
    for (File f : folder.listFiles()) {
        System.out.println("***********" + f.getName() + "***********");
        if (!f.getName().endsWith(".xml"))
            continue;
        InputStream is = new FileInputStream(f);
        StreamSource s = new StreamSource(is);
        EndpointReference epr = EndpointReference.readFrom(s);
        WSEndpointReference wsepr = new WSEndpointReference(epr);
        WSEndpointReference.Metadata metadata = wsepr.getMetaData();
        if (f.getName().equals("w3c_epr_identity.xml")) {
            QName q = new QName("http://schemas.xmlsoap.org/ws/2006/02/addressingidentity", "Identity");
            WSEndpointReference.EPRExtension eprExtn = wsepr.getEPRExtension(q);
            XMLStreamReader xsr = eprExtn.readAsXMLStreamReader();
            if (xsr.getEventType() == XMLStreamConstants.START_DOCUMENT)
                xsr.next();
            assertEquals(q.getNamespaceURI(), xsr.getNamespaceURI());
            assertEquals(q.getLocalPart(), xsr.getLocalName());
        }
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) QName(javax.xml.namespace.QName) StreamSource(javax.xml.transform.stream.StreamSource) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) EndpointReference(jakarta.xml.ws.EndpointReference)

Example 62 with WSEndpointReference

use of com.sun.xml.ws.api.addressing.WSEndpointReference 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 63 with WSEndpointReference

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

the class ReferenceParametersTest method testFaultToReferenceParameters.

/**
 * See if the ReferenceParamaters get added proeprly from FaultToEPR to fault response
 * @throws Exception
 */
public void testFaultToReferenceParameters() 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 wsa:IsReferenceParameter='true'>bar</user:foo>" + "<user: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>";
    MessageFactory messageFactory = MessageFactory.newInstance();
    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("Content-Type", "text/xml");
    SOAPMessage soapMsg = messageFactory.createMessage(headers, new ByteArrayInputStream(requestStr.getBytes()));
    Message message = new SAAJMessage(soapMsg);
    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>";
    MimeHeaders headers1 = new MimeHeaders();
    headers1.addHeader("Content-Type", "text/xml");
    SOAPMessage soapMsg1 = messageFactory.createMessage(headers1, new ByteArrayInputStream(responseStr.getBytes()));
    Message m2 = new SAAJMessage(soapMsg1);
    wsepr.addReferenceParametersToList(m2.getHeaders());
    Packet response = new Packet(m2);
    List<Element> refParams = response.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 : MimeHeaders(jakarta.xml.soap.MimeHeaders) Packet(com.sun.xml.ws.api.message.Packet) MessageFactory(jakarta.xml.soap.MessageFactory) Message(com.sun.xml.ws.api.message.Message) SOAPMessage(jakarta.xml.soap.SOAPMessage) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) Element(org.w3c.dom.Element) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 64 with WSEndpointReference

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

the class AddNumbersClient method testOnewayWithReplyTo.

public void testOnewayWithReplyTo() throws Exception {
    AddNumbersPortType stub = createStub(new OneWayFeature(true, new WSEndpointReference(getAddress(), AddressingVersion.W3C)));
    stub.addNumbers5(10, 10);
}
Also used : OneWayFeature(com.sun.xml.ws.api.addressing.OneWayFeature) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference)

Example 65 with WSEndpointReference

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

the class AddNumbersClient method testCustomFault1.

/**
 * This test tests the functionality of OnewayFeature and AddressingFeature the way it being used in WS-AT implementation
 * In WS-AT impl, Server-side has to send fault messages to predefined coordinator and this test replicates that usage.
 *
 * @throws Exception
 */
public void testCustomFault1() throws Exception {
    SOAPFault fault = SOAPFactory.newInstance().createFault("custom fault from client", SOAPConstants.SOAP_SENDER_FAULT);
    WSEndpointReference to = new WSEndpointReference(getAddress(), AddressingVersion.MEMBER);
    OneWayFeature owf = new OneWayFeature();
    owf.setRelatesToID("uuid:foobar");
    WSService service = WSService.create();
    service.addPort(PORT_QNAME, SOAPBinding.SOAP11HTTP_BINDING, getAddress());
    Dispatch<Source> dispatch = service.createDispatch(PORT_QNAME, to, Source.class, Service.Mode.PAYLOAD, new MemberSubmissionAddressingFeature(true), owf);
    // Since this fault is not a wsdl operation, we need to set SOAPAction for correct wsa:Action
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true);
    dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "http://example.com/myfault");
    try {
        dispatch.invokeOneWay(new DOMSource(fault));
    } catch (WebServiceException e) {
    // since the server-side is not provider based for this test.
    // it does n't know from the fault message request that it is oneway and throws 500 code.
    // so, expect a WebServcieException here.
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) OneWayFeature(com.sun.xml.ws.api.addressing.OneWayFeature) WSService(com.sun.xml.ws.api.WSService) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) SOAPFault(jakarta.xml.soap.SOAPFault) MemberSubmissionAddressingFeature(com.sun.xml.ws.developer.MemberSubmissionAddressingFeature) DOMSource(javax.xml.transform.dom.DOMSource) Source(javax.xml.transform.Source)

Aggregations

WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)80 QName (javax.xml.namespace.QName)32 Element (org.w3c.dom.Element)17 URL (java.net.URL)16 StreamSource (javax.xml.transform.stream.StreamSource)16 EndpointReference (jakarta.xml.ws.EndpointReference)13 WSBindingProvider (com.sun.xml.ws.developer.WSBindingProvider)11 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)11 SOAPMessage (jakarta.xml.soap.SOAPMessage)11 Packet (com.sun.xml.ws.api.message.Packet)10 XMLStreamReader (javax.xml.stream.XMLStreamReader)10 Message (com.sun.xml.ws.api.message.Message)9 WebServiceException (jakarta.xml.ws.WebServiceException)9 MemberSubmissionEndpointReference (com.sun.xml.ws.developer.MemberSubmissionEndpointReference)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 WSDLPort (com.sun.xml.ws.api.model.wsdl.WSDLPort)6 MessageFactory (jakarta.xml.soap.MessageFactory)6 MimeHeaders (jakarta.xml.soap.MimeHeaders)6 Service (jakarta.xml.ws.Service)6 W3CEndpointReference (jakarta.xml.ws.wsaddressing.W3CEndpointReference)6