Search in sources :

Example 31 with WSEndpointReference

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

the class ReferenceParametersTest method testReferenceParametersConversion2.

public void testReferenceParametersConversion2() 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");
    Element el2 = doc.createElementNS("http:foo.bar", "Element1");
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    EndpointReference epr = builder.address("http://foo.bar").referenceParameter(el1).referenceParameter(el2).build();
    System.out.println("EPR " + epr);
    WSEndpointReference wsepr = new WSEndpointReference(epr);
    MemberSubmissionEndpointReference translated = wsepr.toSpec(MemberSubmissionEndpointReference.class);
    assert (translated.referenceParameters.elements.size() == 2);
}
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 32 with WSEndpointReference

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

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

the class ReferenceParametersTest method testReplyToReferenceParameters.

/**
 * See if the ReferenceParamaters get added properly from ReplyTo EPR to response
 * @throws Exception
 */
public void testReplyToReferenceParameters() 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:ReplyTo>" + "<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:ReplyTo>" + "</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().getReplyTo(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><DataTypeResponse xmlns=\"http://cptestservice.org/xsd\"><param>foo bar</param></DataTypeResponse></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 34 with WSEndpointReference

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

the class ReferenceParametersTest method testReferenceParametersConversion3.

public void testReferenceParametersConversion3() 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");
    Element el2 = doc.createElementNS("http:foo.bar", "Element1");
    Element el3 = doc.createElementNS("http:foo.bar", "Element1");
    W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
    EndpointReference epr = builder.address("http://foo.bar").referenceParameter(el1).referenceParameter(el2).referenceParameter(el3).build();
    System.out.println("EPR " + epr);
    WSEndpointReference wsepr = new WSEndpointReference(epr);
    MemberSubmissionEndpointReference translated = wsepr.toSpec(MemberSubmissionEndpointReference.class);
    assert (translated.referenceParameters.elements.size() == 3);
}
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 35 with WSEndpointReference

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

the class ReferenceParametersTest method testReferenceParameters2.

public void testReferenceParameters2() throws Exception {
    String xmlParam1 = "<myns:MyParam1 xmlns:myns=\"http://cptestservice.org/wsdl\">Hello</myns:MyParam1>";
    String xmlParam2 = "<myns:MyParam2 xmlns:myns=\"http://cptestservice.org/wsdl\"><myns:InnerEl> Hello Hello </myns:InnerEl></myns:MyParam2>";
    String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Body><DataType xmlns=\"http://cptestservice.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(request.getBytes()));
    Packet p = new Packet(new SAAJMessage(soapMsg));
    List<Element> refparams = new ArrayList<Element>();
    Node n1 = DOMUtil.createDOMNode(new ByteArrayInputStream(xmlParam1.getBytes()));
    Node n2 = DOMUtil.createDOMNode(new ByteArrayInputStream(xmlParam2.getBytes()));
    refparams.add((Element) n1.getFirstChild());
    refparams.add((Element) n2.getFirstChild());
    WSEndpointReference wsepr = new WSEndpointReference(AddressingVersion.W3C, "http://foo.bar", null, null, null, null, null, refparams);
    wsepr.addReferenceParametersToList(p.getMessage().getHeaders());
    // p.getMessage().writeTo(XMLOutputFactory.newInstance().createXMLStreamWriter(System.out));
    List<Element> refParams = p.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);
    }
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) Packet(com.sun.xml.ws.api.message.Packet) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SAAJMessage(com.sun.xml.ws.message.saaj.SAAJMessage) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) WSEndpointReference(com.sun.xml.ws.api.addressing.WSEndpointReference) ArrayList(java.util.ArrayList) SOAPMessage(jakarta.xml.soap.SOAPMessage)

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