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 6218969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:41:57+00:00 2026-05-24T07:41:57+00:00

I am trying to expose one method as webservice from backend using JAX-WS with

  • 0

I am trying to expose one method as webservice from backend using JAX-WS with Tomcat.
The backend method is something like below (in CompanyFacade class):

public Company findCompanyById(Long id) throws Exception{
    Company c = null;       
    try{
        if(id == null){
            throw new Exception("Failed to get company ID");
        }
        c = baseFacade.load(Company.class, id);
        if(c == null || c.getId() == null){
            throw new Exception("No company found");
        }
    }
    catch(Exception e){
        throw new Exception(e.getMessage());
    }
    finally{
        return c;
    }       
}

As for the webservice class, there’s a WebMethod invokes the above method:

@WebMethod(operationName = "findCompanyById", action = "urn:findCompanyById")
@WebResult(name = "Company")
public Company findCompanyById(@WebParam(name = "id") Long id) throws Exception{
    return CompanyFacade.findCompanyById(id);                           
}

Below is the respond message I got, which is supposed to have the exception message:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
  <S:Body>
    <ns2:findCompanyByIdResponse xmlns:ns2="http://site.com/api/ws"/>
  </S:Body>
</S:Envelope>

The webservice works fine, the only problem is about the exception (e.g. No company found), the exception messages can be displayed in the Tomcat console, but not in the SOAP response message, it seems that the invoked method in the WebMethod doesn’t return any exception. So the question is: how to parse the exception message from the method in backend to the SOAP response message OR is there any other design pattern? Thanks in advance!

  • 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-24T07:41:58+00:00Added an answer on May 24, 2026 at 7:41 am

    SOAP doesn’t deal with exceptions – it only knows about SOAP faults. In your case, the exception thrown by the findCompanyById method is wrapped in a SOAPFault and thrown back to the user.

    You must create a class annotated with @WebFault and that class must extend Exception – this is the exception that your service should throw. Web Services don’t know about runtime exceptions, so throwing unchecked exceptions from your service will not have any effect.

    Alternatively, you can create a FaultBean, which can be specified in @WebFault annotation, and will carry information about the specific error. The fields that you include in the FaultBean will be mapped to fields in the detail tag of the SOAP response, whilst the message of your exception will be mapped to the faultstring tag in your SOAP response.

    An example follows:

    @WebFault(faultBean = 'com.company.services.FaultBean')
    public class NoCompanyFoundException extends Exception {
        private FaultBean faultBean;
        //getters, setters, etc
    }
    
    public class FaultBean {
        // message and error code are totally arbitrary, other fields could be used
        private String message;
        private String errorCode;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send the events from one Java class to Activity. Scenario
HI ALL I am trying to expose spring webservice i am facing one problem
I am trying to write our own RIA services provider to expose data from
This question is similar to this one: Restrict method access to a specific class
I'm trying to abstract case classes in a module using dependent method types and
I'm trying to learn some C#.net. I'm just trying to expose the AdventureWorks database
I’ve been trying to wrap my head around how to expose my domain objects
Trying to get my css / C# functions to look like this: body {
I'm trying to write a class which contains several std::vectors as data members, and
I'm trying to write a web app that needs to expose some methods that

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.