Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1046583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:10:06+00:00 2026-05-16T16:10:06+00:00

I’ve created a webservice and used Axis2 to generate all skeleton java classes. Then

  • 0

I’ve created a webservice and used Axis2 to generate all “skeleton” java classes. Then I of course implemented the service operations myself.

In the implementation, I can throw a MyException which is then caught by the generated classes and converted to an AxisFault object, which in turn is converted to a soap fault (deep down in the Axis framework) with the attribute <faultcode>soapenv:Server</faultcode>

My problem is I would like a custom dynamic faultcode, not “soapenv:Server”.

I tried to manually create an AxisFault object and throw this, but AxisFault is a RemoteException, and the generated interface which my implementation must implement, does not allow to throw RemoteException.

Is it possible to get some kind of hook or filter on the output, so that I can change the faultcode? Or any other way to control the faultcode?

Thanks in advance
Ulrik

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T16:10:06+00:00Added an answer on May 16, 2026 at 4:10 pm

    The SOAP specification describes how custom fault information appears under the detail tag. The faultcode is a fixed set of value dealing with where in the SOAP processing the error was thrown.

    The following is an example of throwing a custom fault message

    WSDL

    Declare the faults in your WSDL so that the associated classes are generated:

    <wsdl:definitions targetNamespace="http://example"
        xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:tns="http://example"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <wsdl:types>
            <schema elementFormDefault="qualified" targetNamespace="http://example"
                xmlns="http://www.w3.org/2001/XMLSchema"
                xmlns:apachesoap="http://xml.apache.org/xml-soap"
                xmlns:tns="http://example" xmlns:intf="http://example"
                xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    
                <element name="withdraw">
                    <complexType>
                        <sequence>
                            <element name="account" type="xsd:string"/>
                            <element name="amount" type="xsd:int"/>
                        </sequence>
                    </complexType>
                </element>
    
                <element name="withdrawResponse">
                    <complexType>
                        <sequence>
                            <element name="balance" type="xsd:int"/>
                        </sequence>
                    </complexType>
                </element>
    
                <element name="AccountNotExistFault">
                    <complexType>
                        <sequence>
                            <element name="account" type="xsd:string"/>
                        </sequence>
                    </complexType>
                </element>
    
                <element name="InsufficientFundFault">
                    <complexType>
                        <sequence>
                            <element name="account" type="xsd:string"/>
                            <element name="balance" type="xsd:int"/>
                            <element name="requestedFund" type="xsd:int"/>
                        </sequence>
                    </complexType>
                </element>
    
            </schema>
        </wsdl:types>
    
        <wsdl:message name="withdrawRequest">
            <wsdl:part element="tns:withdraw" name="parameters"/>
        </wsdl:message>
    
        <wsdl:message name="withdrawResponse">
            <wsdl:part element="tns:withdrawResponse" name="return"/>
        </wsdl:message>
    
        <wsdl:message name="InsufficientFundFaultMessage">
            <wsdl:part element="tns:InsufficientFundFault" name="fault"/>
        </wsdl:message>
    
        <wsdl:message name="AccountNotExistFaultMessage">
            <wsdl:part element="tns:AccountNotExistFault" name="fault"/>
        </wsdl:message>
    
        <wsdl:portType name="Bank">
            <wsdl:operation name="withdraw">
                <wsdl:input message="tns:withdrawRequest" name="withdrawRequest"/>
                <wsdl:output message="tns:withdrawResponse" name="withdrawResponse"/>
                <wsdl:fault message="tns:AccountNotExistFaultMessage" name="AccountNotExistException"/>
                <wsdl:fault message="tns:InsufficientFundFaultMessage" name="InsufficientFundException"/>
            </wsdl:operation>
        </wsdl:portType>
    
        <wsdl:binding name="BankSoapBinding" type="tns:Bank">
            <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
            <wsdl:operation name="withdraw">
                <wsdlsoap:operation soapAction=""/>
                <wsdl:input name="withdrawRequest">
                    <wsdlsoap:body use="literal"/>
                </wsdl:input>
                <wsdl:output name="withdrawResponse">
                    <wsdlsoap:body use="literal"/>
                </wsdl:output>
                <wsdl:fault name="InsufficientFundException">
                    <wsdlsoap:fault name="InsufficientFundException" use="literal"/>
                </wsdl:fault>
                <wsdl:fault name="AccountNotExistException">
                    <wsdlsoap:fault name="AccountNotExistException" use="literal"/>
                </wsdl:fault>
            </wsdl:operation>
        </wsdl:binding>
    
        <wsdl:service name="BankService">
            <wsdl:port binding="tns:BankSoapBinding" name="Bank">
                <wsdlsoap:address location="http://localhost:8080/bank/services/Bank"/>
            </wsdl:port>
        </wsdl:service>
    
    </wsdl:definitions>
    

    Service code

    The following code demonstrates how the custom fault messages are thrown:

    package example;
    
    public class BankServiceSkeleton {
    
        public  WithdrawResponse withdraw(Withdraw param1) throws InsufficientFundFaultMessage, AccountNotExistFaultMessage {
    
            //
            // Parameter handling
            //
            String account = param1.getAccount();
            int amount     = param1.getAmount();
    
            //
            // Error checks
            //
            if ("13".equals(account)) {
                AccountNotExistFault fault = new AccountNotExistFault();
    
                fault.setAccount(account);
    
                AccountNotExistFaultMessage ex = new AccountNotExistFaultMessage("Account does not exist!");
                ex.setFaultMessage(fault);
                throw ex;
            }
    
            if (amount > 1000) {
                InsufficientFundFault fault = new InsufficientFundFault();
    
                fault.setAccount(account);
                fault.setBalance(1000);
                fault.setRequestedFund(amount);
    
                InsufficientFundFaultMessage ex = new InsufficientFundFaultMessage("Insufficient funds");
                ex.setFaultMessage(fault);
                throw ex;
            }
    
            //
            // Normal response
            //
            WithdrawResponse response = new WithdrawResponse();
    
            response.setBalance(1000 - amount);
    
            return response;
        }
    }
    

    TESTING

    The following SOAP message

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:exam="http://example">
       <soapenv:Header/>
       <soapenv:Body>
          <exam:withdraw>
             <exam:account>10</exam:account>
             <exam:amount>2000</exam:amount>
          </exam:withdraw>
       </soapenv:Body>
    </soapenv:Envelope>
    

    Generates the following SOAP fault response

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
          <soapenv:Fault>
             <faultcode>soapenv:Server</faultcode>
             <faultstring>Insufficient funds</faultstring>
             <detail>
                <ns1:InsufficientFundFault xmlns:ns1="http://example">
                   <ns1:account>10</ns1:account>
                   <ns1:balance>1000</ns1:balance>
                   <ns1:requestedFund>2000</ns1:requestedFund>
                </ns1:InsufficientFundFault>
             </detail>
          </soapenv:Fault>
       </soapenv:Body>
    </soapenv:Envelope>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.