How to return (custom) SOAPFault from Axis web service?

I have a WSDL from which I need to create a web service implementation. I use Eclipse and Axis1.4 and work on Weblogic9.2.

Creating server stubs is going fine and I implemented the code I need. However, for compatibility with the exising implementation, we emulate, I need to return SOAP errors for some specific error conditions.

That is, I need the body of the SOAP response to look like this:

<soapenv:Body> <soapenv:Fault> <faultcode xmlns:ns1="foobar">ns1:1234</faultcode> <faultstring>The supplied parameter name ABCD is not recognised.</faultstring> <detail> <FaultDetail>An error processing the web service [MyService]: Unknown parameter:ABCD</FaultDetail> <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">planet</ns2:hostname> </detail> </soapenv:Fault> </soapenv:Body> 

From the (many) googling, I think I would have to do this by throwing a SOAPFaultException. But the message stub only throws java.rmi.RemoteException, so I tried to throw a SOAPFaultExceptionException. This gives me something like this:

  <soapenv:Body> <soapenv:Fault> <faultcode>soapenv:Server.userException</faultcode> <faultstring>java.rmi.RemoteException: My remote exception; nested exception is: javax.xml.rpc.soap.SOAPFaultException: soap fault string</faultstring> <detail> <ns1:hostname xmlns:ns1="http://xml.apache.org/axis/">myhostname</ns1:hostname> </detail> </soapenv:Fault> </soapenv:Body> 

... in other words, this did not result in a SOAP error.

I tried a lot of other things and I got pretty stuck. So can someone tell me (ideally, an example) how to return a SOAP error response with content that I can specify in my environment?

I am not attached to using Axis (but I have more experience with this than with anything else). If you are offering an alternative, please note that I need you to call another (authenticated) web service in the web service method, and I managed to get this to work in Axis1.4 ...

+6
source share
1 answer

The second code post is a SOAP error (pay attention to soapenv:Fault inside soapenv:Body ).

Basically, all the default behavior in the framework is to return a standard SOAP error and letting you enter your own information in the field of the error code, error line, and detailed information about the malfunctions.

See Axis 1 exception docs: http://ws.apache.org/axis/java/apiDocs/org/apache/axis/AxisFault.html

It has constructors for setting the qname of various fields, so you should be able to reference your own elements there.

Many people will use the error detail field and serialize their own XML type inside it using the DOM.

Last, but not least, the main time Axis1 was around 2000-2004, it will be difficult for you to get answers and support it. Most people have moved from Axis1 to Apache CXF , Axis2 , or just straight up to JAX-WS (now it is included in JDK6 +). There is also a Spring Web Services project that provides full customization of all actions on the stack (sorting, which bean gets executed, etc.).

Only all of these frameworks use WSS4J to secure their web services and can support the standard username token, x509 token, etc. However, once you get the basic messages sent back and forth, you probably have to work through the details of WS-Security.

+3
source

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


All Articles