cancel
Showing results for 
Search instead for 
Did you mean: 

EJB call BAPI with JCA (problem)

Former Member
0 Kudos

Hello all,

I've ventured into the world of EJB development and wanted to call a BAPI in R/3 using JCA.

I've written the Java code that does this in the enterprise portal but writing it for an EJB (which as you know runs on the J2EE server outwith the portal) is proving more difficult.

From a pdf that I found here on SDN I get the initial lines:

Context ctx = new InitialContext();
IConnectionFactory conFac = (IConnectionFactory)ctx.lookup("deployedAdapters/SAPFactory/shareable/SAPFactory");

This always throws a ClassCastExepction though.

Perhaps the fault lies with the types I'm using, the imports I'm using are:

import javax.naming.Context;
import javax.naming.InitialContext;
import com.sapportals.connector.connection.IConnectionFactory;

Is there something obvious I'm doing wrong?

Any and all help is greatly appreciated.

Thanks for your time,

Patrick.

Accepted Solutions (1)

Accepted Solutions (1)

guru_subramanianb
Active Contributor
0 Kudos

Hi Patrick,

Refer this following thread in SDN which has answers for resolving Classcast exception.

Hope it helps.

Regards,

Guru

P.S :- Pls don't forget to awards points if the answer to your query is useful.

Former Member
0 Kudos

Hello Guru,

Thanks for the link. Although it hasn't solved my problem it has helped me understand more about the process.

The class that comes back from

ctx.lookup("deployedAdapters/SAPFactory/shareable/SAPFactory")

is of type com.sapportals.connectors.SAPCFConnector.connection.SAPCFConnectorConnectionFactory

It is when I try to cast this to IConnectionFactory that the class cast exception is raised.

Perhaps I'm looking up the wrong thing? Since the type that comes back from this lookup has .sapportals. in its name I'm thinking that I shouldn't be using it when connecting an EJB to R/3. The pdf I'm using to help me with the JCA code was specificaly about connecting the portal to R/3 so I guess the name is wrong.

Do you know what exactly I should be looking up to get the R/3 connector?

Essentialy this is just to call a BAPI in R/3 from an EJB using JCA. Writing the code that'll run inside the portal, where we have user-mapping and all sorts of neat objects that help, isn't a problem at all. However, the code to connect from an EJB is proving difficult.

Any further help that can be provided will be appreciated.

Patrick.

Former Member
0 Kudos

Hi again,

So I've thrown out the idea of trying to connect to R3 from an EJB using JCA.

Instead I'm using the SAP Connectivity -> SAP Enterprise Connector wizard in NWDS to generate the JCo proxy classes to call the BAPI in which I am interested. I've run through the wizard and the necessary classes have all been generated inside my EJB project.

At this point it's my understanding that I must (from within the business method in my EJB) create a JCo client and pass this to my proxy (_PortType) class, with code somewhat akin to;

JCO.Client client = JCO.createClient("020", "user", "pass", "en", "SAPDEV", "00");
R3Conn_PortType r3Conn = new R3Conn_PortType();
r3Conn.messageSpecifier.setJcoClient(client);

The first line there throws an exception each time, not a very descriptive exception either, simply "Exception in method getEmployeeData".

Try/catch doesn't catch, evidenced by the following code;

try{
  JCO.Client client = JCO.createClient("020", "user", "pass", "en", "SAPDEV", "00");
}catch(Exception e){
  result = "Hello: " + e.getMessage();
}

My business method simply returns this 'result' String. Except that it doesn't return it in this case, instead I get the error message "An error has occurred. Maybe the request is not accepted by the server: Exception in method getEmployeeData".

Is there anything special I (or a sys admin) must do with the WebAS to allow connections to R3? Is it even possible to use JCo from an EJB? It is a stateless session bean btw. Can beans call BAPI's at all? Am I missing something here?

Any help is greatly appreciated, thanks.

Patrick.

Former Member
0 Kudos

A response by Vladimir Pavlov in this thread

put me on the right track. I had to add a JCo reference in my application-j2ee-engine.xml file.

So thankyou Vladimir.

Answers (0)