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

I just created a web service client using an axis and eclipse that do not work with my web service provider. The message generated by the web service client is as follows:

<?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 do not see anything wrong with the message, but my provider insists that 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 enviarMensajeRequest to soapenv:Envelope and the qualification from imk: to parameters. I tried many combinations in the process, but my knowledge of web services, wsdl and xml is very limited. The supplier says that they cannot help without telling me this. Any ideas? Perhaps another structure that I can use to create the right client.

+4
source share
1 answer

Your provider is wrong; messages are semantically equivalent; your unskilled, they are qualified. Are you using Axis or Axis2? If you use 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 that you are creating your client using wsdl2java? If you cannot get this tool to generate a message the way you like, then it's best to create the message programmatically. With Axis2, you can do this using the AXIOM API. See this link for an example use of the API. It should be noted that with most methods, for example, createOMElement , you can pass a namespace prefix. So, if your provider requires this, you can pass a string containing "imk" as the namespacePrefix parameter.


If you finish doing this programmatically and you are going to write a simple client, then I STRONGLY propose to abandon the Axis / Axis2 approach and use JAX-WS , since it has been part of Java since version 1.6. The API is cleaner and the documentation is better. For example, the following is a very simple client that I wrote to send a SOAP request to our JIRA server. The sample code creates both qualified and unskilled 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 is as follows:

 <?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> 
+8
source

Source: https://habr.com/ru/post/1304812/


All Articles