cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot capture the exception generated by EJB components.

Former Member
0 Kudos

Hi, All:

I got a strange problem when developing EJB application under SAP WAS server. I developed an EJB as below:

public class UserAccountBean implements SessionBean{

String getUserEmail(String accountID) throws SAPSystemException{

... ...

if(error){

throw new SAPSystemException("Specified user not found.");

}

}

}

Exception I defined as below.

public class SAPSystemException extends Exception {

/**

  • @param message

*/

public SAPSystemException(String message) {

super(message);

}

}

In client side I code as below:

public String getUserMail(String accountID){

... ...

UserAccount bean = home.create();

try{

String email = bean.getUserEmail(accountID);

}catch(SAPSystemException e){

// do something here;

}catch(Exception e){

// do some other thing here;

}

}

It is strange that the SAPSystemException I throw out in the bean cannot be caught by the block catch(SAPSystemException e), it is only captured as general exception and it is said as UndeclaredThrowableException.

When I deployed EJB components and Web components together, the exception can be captured successfully. But when I deployed them separately, it has problem for exception capture. I think it must be the protocol problem. Before I only use RMI-IIOP but SAP WAS server using RMI-P4. Is anything I can do to solve this problem?

I packed the remote and home interface for the EJB and common classes like value objects and exceptions in both components. Is there anything I forgot to set for the deployment?

Thanks in advance.

Message was edited by: Weimin Guo

Message was edited by: Weimin Guo

Accepted Solutions (1)

Accepted Solutions (1)

former_member184385
Active Participant
0 Kudos

Hi Weimin,

you can get the client jar, which will contain all EJBs of a given J2EE application as follow:

- open Visual Administrator and there the Deploy Service, navigating as follow in the cluster tree:

Server 0 / Services / Deploy

- in the Runtime Tab of Deploy Service navigate to your J2EE App., as follow

Server 0 / EJBContainer / <your J2EE app>

- using the button "Get Client Jar", get the client jar

You are apparently aware about the options to talk to a NW hosted EJB, either using P4 or IIOP.

Using IIOP, you stay mainstream and can use the standard JDK built-in CORBA facilities to talk to your EJBs.

N.B: To use IIOP communication, you have to additionally enable it (this can be done, getting to your J2EE app via the EJB Container path).

Good luck!

Gregor

Former Member
0 Kudos

Thank you very much Gregor. The problem solved. That's strange that RMI-P4 still requires client jar package which is not required according to the doc. Anyway, we found the reason.

We are still in developing phase. I just include EJB jar file with web components temporarily and it works (only a little bigger than client jar file). I will get client jar file when we build release version.

Thanks

Answers (1)

Answers (1)

former_member184385
Active Participant
0 Kudos

Hi Weimin,

the EJBs remote interfaces defines your bean methods (ifaik always) as throwing RemoteException. Your implementation is throwing the SAPSystemException, your client is talking through a stub with a generated skeleton on the server site. That is why, ifiak, you can't catch the mentioned, specific exception .. but the received RemoteException should have as content your original one!

Regards

Gregor

Former Member
0 Kudos

Thank you very much Gregor. In fact, I already defined this throws exception in the remote object interface.

public interface UserAccount extends EJBObject {

... ...

public String getUserEmail(String accountID) throws RemoteException, SAPSystemException;

... ...

}

This is application-specific interface and this mechanism works well in my previous in other application server.

I checked the SAP document and found if you using RMI-IIOP, you need to get the client package for your deployed EJBs and put in the path accessible by the WEB components. Based on this suggestion, I put the EJB jar file together with WEB application (Sure the EJB application still deployed in other host and JNDI point to that host. I remembered one book mentioned that if you don't want generate the client package from EJB containter, you can do it this way. For me, I just haven't found the way to get the client package with Administrator Tool it said.), It works!!!. I checked the remote object generated by home object, it is different with EJB jar file there or not. But in the document SAP said that only if you use RMI-IIOP you need do this way, for RMI-P4, you don't need that. Anyway, it seems that RMI-P4 use same way as RMI-IIOP(You only don't need narrow the home object after lookup).

I'll try to find how to get EJB client package from WAS server. For this is my first time to use SAP WAS Server, things a little strange.

Thank you very much for your great help.

Cheers.

Former Member
0 Kudos

The narrow does nothing more but guarantee that the object you received from the lookup is of the right class.

Enjoy

Former Member
0 Kudos

Thank you Brandelik:

I knew that narrow is used to gurantee the object to the right class. For this is my first time to use RMI-P4 protocol. It's a little strange for me that the exception cannot be captured correctly by the client.

Thanks again.