cancel
Showing results for 
Search instead for 
Did you mean: 

How to get exception message from a web service session bean based

Former Member
0 Kudos

Greetz. I cannot get the error message from a custom exception thrown by my web service, inside my webdynpro application.

The web service is as simple as the auto-generated from this session bean:

public class TestExceptionSessionBean implements SessionBean {

private SessionContext myContext;

public void setSessionContext(SessionContext context) {

myContext = context;

}

public void ejbRemove() {}

public void ejbActivate() {}

public void ejbPassivate() {}

public void ejbCreate() throws CreateException {}

public void throwException() throws TestException {

throw new TestException("Hi, I'm the new exception");

}

}

This is my custom exception :

public class TestException extends Exception {

public TestException(String message) {

super(message);

}

public TestException(Throwable cause) {

super(cause);

}

public TestException(String message, Throwable cause) {

super(message, cause);

}

public TestException() {

super();

}

}

I added the exception to the method signature in the remote interface (the only one I declared for the bean).

When I test the web service with NW Web Service Navigator, and run the throwException method, I get only:

test.TestException

(I can see in the xml response that my string is in the faultstring and detail area).

And when I catch the exception in the component controller and try to show the message of the exception in the MessageManager, I only got an empty string!!

What's the problem? What am I doing wrong?

Thanks in advance.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

To encourage people, I include the text of the xml response from the test of Web Service Navigator window :

HTTP/1.1 500 Internal Server Error

Connection: close

Server: SAP J2EE Engine/6.40

Content-Type: text/xml; charset=UTF-8

Set-Cookie: <value is hidden>

Date: Mon, 27 Mar 2006 09:30:50 GMT

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >

<SOAP-ENV:Body>

<SOAP-ENV:Fault>

<faultcode>SOAP-ENV:Client</faultcode>

<faultstring>Hi, I'm the new exception</faultstring>

<detail>

<ns1:throwException_com.sap.demo.testexception.TestException xmlns:ns1='urn:TestExceptionServiceWsd/TestExceptionServiceVi' xmlns:pns='urn:com.sap.demo.testexception'>

<pns:message>Hi, I'm the new exception</pns:message>

</ns1:throwException_com.sap.demo.testexception.TestException>

</detail>

</SOAP-ENV:Fault>

</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

I've found too a strange workaround :

The fact seems that you have to design your session bean without throwing custom exceptions, then generates the VI and after that, adding the custom exceptions throws.

Or if you don't want to modify the bussiness methods.

The point is to eliminate the exceptions (faults) sections from the VI and WS deployment descriptor.

You have to access from Package Explorer, and edit with a Text Editor the following files :

*.videf from the package, and remove <Function.Faults> sections

ws-deployments-descriptor.xml in META-INF, and remove <fault> sections

After that, the WS Configurations will give an error, so delete the configuration and remake it. Now, the VI stills looks bad, so close the project, close NetViewer and reopen it to flush whatever cache it seems to keep.

Now, your VI will looks better without exceptions, and you'll get their messages when you catch them in the WebDynpro applicattion.

So, now the question is: Could anybody explain me why ?

Former Member
0 Kudos

All you have to do is throw your own Exception class from your Session Bean, i.e. EmployeeException.

Also you must try to write your code better.

I hope this will help you.

Regards