title: How do I return a (custom) SOAPFault from an Axis web service?
body: <p>I have some WSDL from which I need to generate a web service implementation. I'm using Eclipse, and Axis1.4, and running on Weblogic9.2.</p>
  
  <p>Generating the server stubs goes fine, and I've implemented the code I need to. However, for compatibility with the exising implementation we are emulating, I need to return SOAP faults for some specified error conditions.</p>
  
  <p>That is, I need the SOAP body of the response to look like this example:</p>
  
  <pre><code>&lt;soapenv:Body&gt;
      &lt;soapenv:Fault&gt;
          &lt;faultcode xmlns:ns1="foobar"&gt;ns1:1234&lt;/faultcode&gt;
          &lt;faultstring&gt;The supplied parameter name ABCD is not recognised.&lt;/faultstring&gt;
          &lt;detail&gt;
              &lt;FaultDetail&gt;An error processing the web service [MyService]: Unknown parameter:ABCD&lt;/FaultDetail&gt;
              &lt;ns2:hostname xmlns:ns2="http://xml.apache.org/axis/"&gt;planet&lt;/ns2:hostname&gt;
          &lt;/detail&gt;
      &lt;/soapenv:Fault&gt;
  &lt;/soapenv:Body&gt;
  </code></pre>
  
  <p>From (much) googling, I think I should be able to do this by throwing a SOAPFaultException. But the message stub throws only java.rmi.RemoteException, so I've tried passing the SOAPFaultException to the RemoteException. That gives me something like this:</p>
  
  <pre><code>   &lt;soapenv:Body&gt;
        &lt;soapenv:Fault&gt;
           &lt;faultcode&gt;soapenv:Server.userException&lt;/faultcode&gt;
           &lt;faultstring&gt;java.rmi.RemoteException: My remote exception; nested exception is: 
      javax.xml.rpc.soap.SOAPFaultException: soap fault string&lt;/faultstring&gt;
           &lt;detail&gt;
              &lt;ns1:hostname xmlns:ns1="http://xml.apache.org/axis/"&gt;myhostname&lt;/ns1:hostname&gt;
           &lt;/detail&gt;
        &lt;/soapenv:Fault&gt;
     &lt;/soapenv:Body&gt;
  </code></pre>
  
  <p>... in other words, it hasn't resulted in a SOAP fault.</p>
  
  <p>I've tried a lot of other stuff, and I'm pretty much stuck. So can someone tell me (ideally with an example) how to return a SOAP fault response with content I can specify, in my environment?</p>
  
  <p>I'm not wedded to using Axis (but I've more experience with that than anything else). If you suggest an alternative, please note I need in the web service method to invoke another (authenticated) web service, and I've only been able to get that to work in Axis1.4...</p>