JAXWS problem without namespace prefix using Jboss 4.2.3ga - web-services

I have a java service published as a JAXWS webservice using #WebServiceannotation. The service is well deployed on Jboss application server 4.2.3ga (with Jax-ws implementation provided by the application server).
The service works well when the Soap message look like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:pref="mynamespace">
<soapenv:Header/>
<soapenv:Body>
<pref:mymethod>
<arg0>value</arg0>
</pref:mymethod>
</soapenv:Body>
</soapenv:Envelope>
And failed when the Soap message look like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="mynamespace">
<soapenv:Header/>
<soapenv:Body>
<mymethod>
<arg0>value</arg0>
</mymethod>
</soapenv:Body>
</soapenv:Envelope>
By fail I mean "mymethod" is invoked, but arg0 is null.
Does anybody know if it is the expected behaviour of JAX-WS api or a bug ? I found no reference to one or to the other.
Does anybody experienced the same problem (or success) using another JAX-WS stack ?

In the working code there is no default namespace and <mymethod> is bound to mynamespace with a prefix.
Because the <arg0> element has no prefix, it is in null namespace.
In the failing code mynamespace is set as the default namespace. Because <mymethod> and <arg0> do not have any prefix, they both have mynamespace as their namespace URI.
It is not allowed to bind the empty namespace URI to any prefix. Therefore you either need to continue to use a namespace prefix in <mymethod> or you need to override the default namespace in <arg0> like this:
<arg0 xmlns="">
Note that this sets all the unprefixed child elements of <arg0> to null namespace unless you override the default namespace again.

Related

Sending file with SOAP MTOM using PowerShell

I am attempting to send a SOAP message with PowerShell that uses MTOM to attach an XML file. MTOM is the method specified by the web service so I don't have the option to include the XML file inline.
I'm getting confused when it comes to actually attaching the file to the SOAP message. I understand that the file is attached using the <xop:Include> element in the SOAP message. But how do I specify the value that should be included for the href attribute (i.e. how do I determine the string that should replace xxxxxxxxx?
In all the examples that I've seen up to now the value for href is always specified as something like 0ccceb3ce8deda6a3a666b587962a26a7524fe64d35d73ea#apache.org but I don't understand how this is generated.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<ns1:RequestAttInfo xmlns:ns1="urn:abb.com:project/isem/types">
<requestType xmlns="">mp.report</requestType>
<adminRole xmlns="">false</adminRole>
<requestDataCompressed xmlns="">false</requestDataCompressed>
<requestDataType xmlns="">XML</requestDataType>
<sendRequestDataOnSuccess xmlns="">true</sendRequestDataOnSuccess>
<sendResponseDataCompressed xmlns="">false</sendResponseDataCompressed>
<requestSignature xmlns="">yyyyyyyyy</requestSignature>
<requestData xmlns="">
<xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:xxxxxxxxx"></xop:Include>
</requestData>
</ns1:RequestAttInfo>
</soapenv:Body>
</soapenv:Envelope>

How to pass "complex" multiple parts params as SOAP Request to Mule SOAP Client

I would like to know how pass complex params to Mule SOAP Client, in a simple form, similar to Web Service Consumer component. I can't to use component because the Web Service has several parts and it does not work with n parts.
I tried to do like this: https://docs.mulesoft.com/mule-user-guide/v/3.7/consuming-web-services-with-cxf but does not clear how to make input complex params.
I am using Mule CE 3.7.
In SoapUI, the envelop request is:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.abcde.com">
<soapenv:Header/>
<soapenv:Body>
<ser:obterCliente>
<user>name.surname</user>
<password>xxxxx</password>
<encryption>0</encryption>
<parameters>
<!--Optional:-->
<codigoCli>1</codigoCli>
</parameters>
</ser:obterCliente>
</soapenv:Body>
</soapenv:Envelope>
Is there any example about how to pass complex params to SOAP in Mule?

How can I add WSSE Header to my Web Service Client?

I want to add wsse Security header to my web service client on ASP 3.5. I test the web service from SoapUI using this Soap Envelope and get an answer:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:comp="http://myCompany.org.tr"> <soapenv:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"/>
<wsse:Username>MyUsername</wsse:Username>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
(Body Info.)
</soapenv:Body>
</soapenv:Envelope>
I want to create this envelope through classic Web Service Reference which created by Visual Studi 2012. Which class should I use to add Username Info to my envelope?
Thank you John, and Ladislav.
Turns out that you should add the header via web.config file to get properly ordered SOAP message. Otherwise .Net tries to nest your code with its own capsulation (even you dont ask for it), and sends some rubbish as a result.

SOAP re-declaring qname inside body

I have a SOAP request of this form:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:myqname="http://example.com/hello"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<myqname:MyRequest xmlns:myqname="http://example.com/hello">
...
</myqname:MyRequest>
</soapenv:Body>
</soapenv:Envelope>
If I ask SOAPUI to "Format XML" this request,
it removes the second declaration of myqname, so I get this:
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:myqname="http://example.com/hello"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header/>
<soapenv:Body>
<myqname:MyRequest>
...
</myqname:MyRequest>
</soapenv:Body>
</soapenv:Envelope>
The original request works fine,
but the Application Servers fails with the modified request with this error:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Unmarshalling Error: UndeclaredPrefix: Cannot resolve 'myqname:MyRequest' as a QName: the prefix 'myqname' is not declared.</faultstring>
</soap:Fault>
</soap:Body>
</soap:Envelope>
According to the web services specification,
is it mandatory for the qname to be re-declared inside the soapenv:Body node?
Is this a SOAPUI bug, or an Application Server bug? or a misunderstanding from my part?
SOAPUI 4.0.1, WebLogic Server Version: 10.3.2.0
Edit: ups, even if using WebLogic application server, I was using the CXF web services framework. I posted the issue there. issues.apache.org/jira/browse/CXF-4026
So: SOAPUI 4.0.1, CXF 2.5.0
I'd describe it as a bug in the code that strips the SOAP envelope; it should preserve the namespace context yet it isn't doing so, and that's breaking the XML. I guess that's because it is doing the stripping by taking a substring rather than operating at the DOM element level (whether or not it's using DOM processing to do the stripping is beside the point). I'm not sure which component is doing that stripping because of the way these things can be nested, but I suspect it's WebLogic…
[EDIT]: I've checked the SOAP specification and it does not say that the contents of the body has to directly declare the namespace used (see §5.3.1), though it does say that it SHOULD be namespaced. Because of that, normal XML namespacing rules apply — the whole SOAP message is simply an XML document — and that would make WebLogic's behavior a bug.

Move namespace declaration from payload to envelope on an axis created web service

I just created a web service client using axis and eclipse that does not work with my web service provider. The message created by the web service client looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<enviarMensajeRequest
xmlns="http://www.springframework.org/spring-ws/Imk-Zenkiu-Services">
<usuario>someuser</usuario>
<clave>somepassword</clave>
<mensaje>somemessage</mensaje>
<contacto>
<buzonSMS>somenumber</buzonSMS>
<primerNombre>somefirstname</primerNombre>
<primerApellido>somelastname</primerApellido>
</contacto>
</enviarMensajeRequest>
</soapenv:Body>
</soapenv:Envelope>
I see nothing wrong with the message but my provider insists the message should be:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:imk="http://www.springframework.org/spring-ws/Imk-Zenkiu-Services">
<soapenv:Body>
<imk:enviarMensajeRequest>
<imk:usuario>someuser</imk:usuario>
<imk:clave>somepassword</imk:clave>
<imk:mensaje>somemessage</imk:mensaje>
<imk:contacto>
<imk:buzonSMS>somenumber</imk:buzonSMS>
<imk:primerNombre>somefirstname</imk:primerNombre>
<imk:primerApellido>somelastname</imk:primerApellido>
</imk:contacto>
</imk:enviarMensajeRequest>
</soapenv:Body>
</soapenv:Envelope>
Notice the namespace declaration moving from the enviarMensajeRequest to the soapenv:Envelope and the qualification with imk: on the parameters. I've tried many combinations on the process but my web service, wsdl and xml knowledge is very limited. The provider says that they can't help beyond telling me this. Any ideas? Perhaps a different framework that I can use to create the correct client.
Your provider is wrong, the messages are semantically equivalent; yours is unqualified, theirs is qualified. Are you using Axis or Axis2? If you're using Axis, I suggest you switch to Axis2 for a more robust, standards-compliant SOAP stack (both products are bad, but Axis2 is less-bad).
I assume you are creating your client with wsdl2java? If you can't get this tool to generate the message the way you like, then your best bet is to generate the message programmatically.
With Axis2, you can do this with the AXIOM API. See this link for some example API usage. Note that with most of the methods, e.g. createOMElement, you optionally pass the namespace prefix. So, if your provider requires it, then you could pass a String containing "imk" as the namespacePrefix parameter.
If you end up doing this programmatically and you are only going to be writing a simple client, then I STRONGLY suggest you abandon the Axis/Axis2 approach and use the JAX-WS stack instead, as it is part of Java since 1.6. The API is cleaner and the documentation is better. For example, following is a very simple client I wrote to send a SOAP request to our JIRA server. The sample code creates both qualified and unqualified elements.
QName port = new QName(endpoint, "subversionsoapservice-v2");
QName serviceName = new QName(endpoint, "ISubversionSoapServiceService");
Service service = Service.create(serviceName);
service.addPort(port, SOAPBinding.SOAP11HTTP_BINDING, endpoint);
Dispatch<SOAPMessage> dispatch = service.createDispatch(port, SOAPMessage.class, Service.Mode.MESSAGE);
MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
SOAPMessage request = factory.createMessage();
SOAPBody body = request.getSOAPBody();
SOAPElement reindexRepository = body.addChildElement("reindexRepository", "jira", "http://soap.ext.plugin.jira.atlassian.com");
SOAPElement in0 = reindexRepository.addChildElement("in0");
in0.addTextNode("test");
request.saveChanges();
dispatch.invoke(request);
The XML sent by the client looks like this:
<?xml version="1.0"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<jira:reindexRepository xmlns:jira="http://soap.ext.plugin.jira.atlassian.com">
<in0>test</in0>
</jira:reindexRepository>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>