use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.
the class HandlerClient method testReferenceParametersProperty.
public void testReferenceParametersProperty() throws Exception {
String xmlRefParam1 = "<myns:MyParam1 wsa:IsReferenceParameter='true' xmlns:myns=\"http://cptestservice.org/wsdl\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">Hello</myns:MyParam1>";
String xmlRefParam2 = "<myns:MyParam2 wsa:IsReferenceParameter='true' xmlns:myns=\"http://cptestservice.org/wsdl\" xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">There</myns:MyParam2>";
String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\"><S:Header>" + xmlRefParam1 + xmlRefParam2 + "</S:Header><S:Body><Hello xmlns=\"urn:test:types\"><intin>1</intin></Hello></S:Body></S:Envelope>";
QName portQName = new QName("urn:test", "HelloPort");
String endpointAddress = getEndpointAddress("http://localhost:8080/jaxrpc-fromwsdl_handler_simple/hello");
// create service with just qname -- no handlers in that case
QName serviceQName = new QName("urn:test", "Hello");
Service service = Service.create(serviceQName);
service.addPort(portQName, jakarta.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
Dispatch dispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
MessageFactory messageFactory = MessageFactory.newInstance();
MimeHeaders headers = new MimeHeaders();
headers.addHeader("Content-Type", "text/xml");
SOAPMessage soapMsg = messageFactory.createMessage(headers, new ByteArrayInputStream(request.getBytes()));
List<Handler> handlers = new ArrayList<Handler>();
handlers.add(new ReferenceParameterHandler());
dispatch.getBinding().setHandlerChain(handlers);
SOAPMessage msg = (SOAPMessage) dispatch.invoke(soapMsg);
msg.writeTo(System.out);
}
use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.
the class ReferenceParametersTest method testReferenceParametersNsDecl.
/**
* Test where NS decl for ReferenceParameters is on the SOAP envelope
* @throws Exception
*/
public void testReferenceParametersNsDecl() throws Exception {
String xmlRefParam1 = "<myns:MyParam1 wsa:IsReferenceParameter='true' xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">Hello</myns:MyParam1>";
String xmlRefParam2 = "<myns:MyParam2 wsa:IsReferenceParameter='true' xmlns:wsa=\"http://www.w3.org/2005/08/addressing\">There</myns:MyParam2>";
String request = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:myns=\"http://cptestservice.org/wsdl\"><S:Header>" + xmlRefParam1 + xmlRefParam2 + "</S:Header><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()));
// soapMsg.writeTo(System.out);
Packet p = new Packet(new SAAJMessage(soapMsg));
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);
assertEquals("NS Decl did not match", "http://cptestservice.org/wsdl", e.getNamespaceURI());
}
}
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());
}
}
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;
}
use of jakarta.xml.soap.MimeHeaders in project metro-jax-ws by eclipse-ee4j.
the class DispatchTest method testNoContentType.
/*
* Service sends status code 200+no envelope
*/
public void testNoContentType() throws Exception {
BindingProvider bp = (BindingProvider) new Hello_Service().getHelloPort();
String address = (String) bp.getRequestContext().get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY);
Service service = Service.create(new QName("", ""));
service.addPort(new QName("", ""), SOAPBinding.SOAP11HTTP_BINDING, address);
Dispatch<SOAPMessage> d = service.createDispatch(new QName("", ""), SOAPMessage.class, Service.Mode.MESSAGE);
String str = "<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'><S:Body/></S:Envelope>";
MessageFactory fact = MessageFactory.newInstance();
MimeHeaders headers = new MimeHeaders();
SOAPMessage req = fact.createMessage(headers, new ByteArrayInputStream(str.getBytes("UTF-8")));
d.invokeOneWay(req);
}
Aggregations