Search in sources :

Example 6 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders 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)

Example 7 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.

the class ClientTest method test.

public void test() throws SOAPException, IOException {
    // -- TEST different SOAPACTION properties in RequestContext
    File file = new File("testcases/externalmetadata/fromjava/client/external-wsdl-customization-client.xml");
    WebServiceFeature feature = ExternalMetadataFeature.builder().addFiles(file).build();
    FAKENAME port = new EchoImplService().getFAKENAMEPort(feature);
    Map<String, Object> requestContext = ((BindingProvider) port).getRequestContext();
    // THIS next line is causing the SOAPACTION http header to go blank, if fix JAX_WS-1049 not applied ...
    requestContext.keySet();
    port.doSomething();
    // -- TEST dispatch: http://java.net/jira/browse/JAX_WS-1014 : Bug <12883765>
    String jaxwsMsg = "<?xml version='1.0' encoding='UTF-8'?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<S:Body><doSomething xmlns=\"overriden-target-namespace\"/></S:Body></S:Envelope>";
    EchoImplService service = new EchoImplService();
    Dispatch<SOAPMessage> dispatch = service.createDispatch(new QName("overriden-target-namespace", "FAKE-NAMEPort"), SOAPMessage.class, Service.Mode.MESSAGE);
    Map<String, List> headersMap = new HashMap<String, List>();
    headersMap.put("X-ExampleHeader2", Collections.singletonList("Value"));
    Map<String, Object> context = dispatch.getRequestContext();
    context.put(MessageContext.HTTP_REQUEST_HEADERS, headersMap);
    context.put(SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    MimeHeaders mhs = new MimeHeaders();
    mhs.addHeader("My-Content-Type", "text/xml");
    mhs.addHeader("SOAPAction", "overridenInputAction");
    SOAPMessage msg = MessageFactory.newInstance().createMessage(mhs, new ByteArrayInputStream(jaxwsMsg.getBytes()));
    dispatch.invoke(msg);
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) BindingProvider(jakarta.xml.ws.BindingProvider) SOAPMessage(jakarta.xml.soap.SOAPMessage) MimeHeaders(jakarta.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) WebServiceFeature(jakarta.xml.ws.WebServiceFeature) List(java.util.List) File(java.io.File)

Example 8 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.

the class ClientTest method test.

public void test() throws SOAPException, IOException {
    ServiceName port = new ExternalMetadataServiceImplService().getServiceNamePort();
    port.doSomething();
    // -- TEST dispatch: http://java.net/jira/browse/JAX_WS-1014 : Bug <12883765>
    String jaxwsMsg = "<?xml version='1.0' encoding='UTF-8'?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<S:Body><doSomething xmlns=\"my-target-namespace\"/></S:Body></S:Envelope>";
    // ExternalMetadataService service = new ExternalMetadataService();
    ExternalMetadataServiceImplService service = new ExternalMetadataServiceImplService();
    Dispatch<SOAPMessage> dispatch = service.createDispatch(new QName("my-target-namespace", "ServiceNamePort"), SOAPMessage.class, Service.Mode.MESSAGE);
    Map<String, List> headersMap = new HashMap<String, List>();
    headersMap.put("X-ExampleHeader2", Collections.singletonList("Value"));
    Map<String, Object> context = dispatch.getRequestContext();
    context.put(MessageContext.HTTP_REQUEST_HEADERS, headersMap);
    context.put(SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    MimeHeaders mhs = new MimeHeaders();
    mhs.addHeader("My-Content-Type", "text/xml");
    mhs.addHeader("SOAPAction", "myInputAction");
    SOAPMessage msg = MessageFactory.newInstance().createMessage(mhs, new ByteArrayInputStream(jaxwsMsg.getBytes()));
    dispatch.invoke(msg);
}
Also used : HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) SOAPMessage(jakarta.xml.soap.SOAPMessage) MimeHeaders(jakarta.xml.soap.MimeHeaders) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List)

Example 9 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.

the class ClientServerTestUtil method makeSaajRequest.

public static SOAPMessage makeSaajRequest(Object stub, InputStream is) throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPConnectionFactory connectionFactory = SOAPConnectionFactory.newInstance();
    MimeHeaders headers = new MimeHeaders();
    headers.addHeader("Content-Type", "text/xml");
    SOAPMessage message = messageFactory.createMessage(headers, is);
    BindingProvider bp = (BindingProvider) stub;
    String address = (String) bp.getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
    URL url = new URL(address);
    return connectionFactory.createConnection().call(message, url);
}
Also used : SOAPConnectionFactory(jakarta.xml.soap.SOAPConnectionFactory) MimeHeaders(jakarta.xml.soap.MimeHeaders) MessageFactory(jakarta.xml.soap.MessageFactory) BindingProvider(jakarta.xml.ws.BindingProvider) SOAPMessage(jakarta.xml.soap.SOAPMessage) URL(java.net.URL)

Example 10 with MimeHeaders

use of jakarta.xml.soap.MimeHeaders 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)

Aggregations

MimeHeaders (jakarta.xml.soap.MimeHeaders)30 SOAPMessage (jakarta.xml.soap.SOAPMessage)27 ByteArrayInputStream (java.io.ByteArrayInputStream)24 MessageFactory (jakarta.xml.soap.MessageFactory)19 Packet (com.sun.xml.ws.api.message.Packet)13 SAAJMessage (com.sun.xml.ws.message.saaj.SAAJMessage)12 Element (org.w3c.dom.Element)12 Message (com.sun.xml.ws.api.message.Message)7 QName (javax.xml.namespace.QName)7 WSEndpointReference (com.sun.xml.ws.api.addressing.WSEndpointReference)6 BindingProvider (jakarta.xml.ws.BindingProvider)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 Node (org.w3c.dom.Node)4 MessageContextFactory (com.oracle.webservices.api.message.MessageContextFactory)3 AttachmentPart (jakarta.xml.soap.AttachmentPart)3 SOAPException (jakarta.xml.soap.SOAPException)3 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3