CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2004
    Posts
    429

    Question Client catching Web Service User Exceptions [Java 6.0.17]

    I am trying to send an EXCEPTION from a Web Server to a Client using JAX-WS ...
    When the exception is thrown by the server the client does catch it ... but the contents are not the expected message...

    Code:
    [Server.java]
    package pck;
    
    @WebService()
    public class Server
    {
        @WebMethod()
        public function() throws UserException
        {
        throw new UserException(“Something”);
        }
    }
     
    [Exception.java]
    import javax.xml.ws.WebFault;
     
    @WebFault()
    public class UserException
            extends Exception
    {
        private String ErrMessage;
     
        public UserException(String message)
        {
            this.ErrMessage = message;
        }
        
        public String ErrorMessage()
        {
            return this.ErrMessage;
        }
    }
     
    [Client.java]
    public class Client
    {
        public static void main(String[] args) throws Exception
        {
        try
            {
            Server.function();
            }
        catch (UserException ex)
            {
            System.out.println("User Exception: " + ex.ErrorMessage());
            }
        }
    }
    Now, as I mentioned, when the exception is thrown by the server the client does catch it, but ex.ErrorMessage() returns the string “pck.UserException” instead of “Something” which it was created with in the Server... any clues as to why?

    Also, when I run my WebService I keep getting the following messages in the output:
    com.sun.xml.internal.ws.model.RuntimeModeler getExceptionBeanClass
    INFO: Dynamically creating exception bean Class pck.jaxws.UserExceptionBean

    Any clues or help would be much appreciated.
    Thanks,

  2. #2
    Join Date
    Apr 2007
    Posts
    425

    Re: Client catching Web Service User Exceptions [Java 6.0.17]

    http://java.sun.com/javaee/5/docs/ap.../WebFault.html

    should be used on the exception class you want to be marshalled and information included about in your wsdl otherwise the client won't see it, but it will be wrapped in a general soap exception.
    ------
    If you are satisfied with the responses, add to the user's rep!

  3. #3
    Join Date
    Oct 2004
    Posts
    429

    Re: Client catching Web Service User Exceptions [Java 6.0.17]

    UserException has @WebFault already - or is it missing something?
    I catch the exception, and it is in the WSDL, but it looks like either the String ErrorMessage isn't returning correctly...

  4. #4
    Join Date
    Apr 2007
    Posts
    425

    Re: Client catching Web Service User Exceptions [Java 6.0.17]

    what version of metro is this?
    ------
    If you are satisfied with the responses, add to the user's rep!

  5. #5
    Join Date
    Oct 2004
    Posts
    429

    Re: Client catching Web Service User Exceptions [Java 6.0.17]

    What do you mean "Metro"?

  6. #6
    Join Date
    Apr 2007
    Posts
    425

    Re: Client catching Web Service User Exceptions [Java 6.0.17]

    http://java.sun.com/webservices/

    Do you see the soap fault definition in the generated wsdl?

    I would expect the definition to look similar to something like this:

    Code:
    <message name="function">
    <part name="fault" element="tns:UserException"/>
    </message>
    
    ...
    
    <operation name="functionEvent">
    <input message="tns:functionResponseEvent"/>
    <output message="tns:functionEventResponse"/>
    <fault message="tns:UserException" name="UserException"/>
    </operation>
    
    ...
    
    <fault name="UserException">
    <soap:fault name="UserException" use="literal"/>
    </fault>
    Last edited by Deliverance; November 20th, 2009 at 10:59 AM.
    ------
    If you are satisfied with the responses, add to the user's rep!

  7. #7
    Join Date
    Oct 2004
    Posts
    429

    Re: Client catching Web Service User Exceptions [Java 6.0.17]

    Yes I see something similar, the difference is the custom GetMessage() function is not in the WSDL.
    Actually - it looks like using the super (Message) solved the problem ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured