Search in sources :

Example 26 with MimeHeaders

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

Example 28 with MimeHeaders

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

the class StringHeaderTest method test2.

public void test2() throws SOAPException, IOException {
    Header h = new StringHeader(AddressingVersion.W3C.actionTag, "http://example.com/action");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage message = factory.createMessage(new MimeHeaders(), new ByteArrayInputStream(TEST_MESSAGE.getBytes()));
    h.writeTo(message);
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) StringHeader(com.sun.xml.ws.message.StringHeader) Header(com.sun.xml.ws.api.message.Header) StringHeader(com.sun.xml.ws.message.StringHeader) MessageFactory(jakarta.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPMessage(jakarta.xml.soap.SOAPMessage)

Example 29 with MimeHeaders

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

the class HelloImpl method invoke.

public SOAPMessage invoke(SOAPMessage msg) {
    SOAPBody body;
    try {
        body = msg.getSOAPBody();
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    Node node = body.getFirstChild();
    if (!node.getLocalName().equals("Hello")) {
        throw new WebServiceException("Expecting localName=Hello but got=" + node.getLocalName());
    }
    if (!node.getNamespaceURI().equals("urn:test:types")) {
        throw new WebServiceException("Expecting NS=urn:test:types but got=" + node.getNamespaceURI());
    }
    MimeHeaders headers = msg.getMimeHeaders();
    /*
		Iterator i = headers.getAllHeaders();
		while(i.hasNext()) {
			MimeHeader header = (MimeHeader)i.next();
			System.out.println("name="+header.getName()+" value="+header.getValue());
		}
*/
    String[] action = headers.getHeader("SOAPAction");
    if (action == null || action.length > 1 || !action[0].equals("\"urn:test:hello\"")) {
        throw new WebServiceException("SOAPMessage doesn't contain transport header: SOAPAction");
    }
    String[] ct = headers.getHeader("Content-Type");
    if (ct == null || ct.length > 1 || !ct[0].startsWith("text/xml")) {
        throw new WebServiceException("SOAPMessage doesn't contain transport header: Content-Type");
    }
    return null;
}
Also used : MimeHeaders(jakarta.xml.soap.MimeHeaders) SOAPBody(jakarta.xml.soap.SOAPBody) WebServiceException(jakarta.xml.ws.WebServiceException) SOAPException(jakarta.xml.soap.SOAPException) Node(org.w3c.dom.Node)

Example 30 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
    EchoImpl port = new EchoImplService().getEchoImplPort();
    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();
    requestContext.put(SOAPACTION_USE_PROPERTY, Boolean.TRUE);
    requestContext.put(SOAPACTION_URI_PROPERTY, "customSOAPAction");
    port.doSomething();
    requestContext.put(SOAPACTION_USE_PROPERTY, false);
    port.doSomething();
    requestContext.put(SOAPACTION_USE_PROPERTY, null);
    requestContext.put(SOAPACTION_URI_PROPERTY, "");
    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=\"http://server.jaxws1049.bugs/\"/></S:Body></S:Envelope>";
    EchoImplService service = new EchoImplService();
    Dispatch<SOAPMessage> dispatch = service.createDispatch(new QName("http://server.jaxws1049.bugs/", "EchoImplPort"), SOAPMessage.class, Service.Mode.MESSAGE);
    Map<String, List> headersMap = new HashMap<String, List>();
    headersMap.put("X-ExampleHeader2", Collections.singletonList("Value"));
    dispatch.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, headersMap);
    MimeHeaders mhs = new MimeHeaders();
    mhs.addHeader("My-Content-Type", "text/xml");
    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) List(java.util.List)

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