cancel
Showing results for 
Search instead for 
Did you mean: 

JCA connection issue

Former Member
0 Kudos

Hello,

I wrote the SAP example for JCA connection, the problem is that I have an exception on this point:

try {

<b>client = cgService.getConnection(system_alias, prop);</b>

} catch (Exception e) {

app.putValue(

"error",

<b>"Couldn't establish a connection with a target system " + system_alias + ".");</b>

return;

}

The error from the log file is:

<i>There was a problem getting the timestamp of the node: events with internal id: 4294967579

[EXCEPTION]

#1#com.sap.engine.services.dbpool.exceptions.BaseSQLException: ResourceException in method ConnectionFactoryImpl.getConnection(): com.sap.engine.services.connector.exceptions.BaseResourceException: "ConnectionManager" is closed. Possible reasons: 1) <u>connector "SAPJ2EDB" is stopped or not started, 2) Connector service is stopped or has not been started.</u></i>

The problem seems to be on the cgService.getConnection, probabily on the Connector Gateway Service. I will appreciate any suggestion about this, could be a server configuration problem?

Thanks in advance,

Vipa

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi

I have it this way, and that works


IConnectorGatewayService cgService =
				(IConnectorGatewayService) PortalRuntime
					.getRuntimeResources()
					.getService(IConnectorService.KEY);

You use request.getService..........

I don't know if that could be the problem, but try

regards

Peter

Former Member
0 Kudos

No solution yet. Someone any idea?

Thanks a lot.

Vipa

Former Member
0 Kudos

Try debuggin it if u have debugging turned ON on ur server.

Or simple try some response.write() statements to figure out the buggy code.

Regards,

P.

Former Member
0 Kudos

I have the same problem. True, I don't understand. Solutions?

Vipa

Former Member
0 Kudos

Hi boys,

no one able to solve this JCA problem? Possible? I'm going to develop with Web Dynpro but with a lot of limitations.

I will appreciate your help.

Vipa

Former Member
0 Kudos

Now, I have an exception when I execute the JSP:

Errore run-time portal

Request error:

iView : pcd:portal_content/.../iview/JCAExample

Nome componente : JCAExample.SampleComponent

Exception registered.

Exception id: 01:13_30/11/05_0007_8984950

See the details for the exception ID in the log file

Vito

Former Member
0 Kudos

Hi vipa

Replace the line

client = cgService.getConnection(system_alias, prop);

by the code

client = cgservice.getConnection(system_alias, request);

Hope this helps.

Regards,

Yoga

Former Member
0 Kudos

Here attached my code (SAP standard example):

package jca;

/*

  • Portal related API

*/

import com.sapportals.portal.prt.component.AbstractPortalComponent;

import com.sapportals.portal.prt.component.IPortalComponentRequest;

import com.sapportals.portal.prt.component.IPortalComponentResponse;

import com.sapportals.portal.prt.component.IPortalComponentProfile;

import com.sapportals.portal.prt.event.IPortalRequestEvent;

import com.sapportals.portal.prt.resource.IResource;

import com.sap.security.api.IPrincipal;

/*

  • J2SE API

*/

import java.util.Hashtable;

import java.util.Enumeration;

/*

  • Standard JNDI API

*/

import javax.naming.Context;

import javax.naming.NamingException;

import javax.naming.NamingEnumeration;

import javax.naming.NameClassPair;

/*

  • Portal Generic Layer api

  • jar file location:

  • <j2ee engine>\cluster\server\services\servlet_jsp\work\

  • jspTemp\irj\root\WEB-INF\portal\portalapps\com.sap.portal.

  • pcd.glservice\lib\com.sap.portal.pcd.glserviceapi.jar

*/

import com.sapportals.portal.pcd.gl.IPcdContext;

import com.sapportals.portal.pcd.gl.IPcdAttributes;

import com.sapportals.portal.pcd.gl.IPcdAttribute;

/*

  • Portal JNDI support

  • jar file location:

  • <j2ee engine>/cluster/server/services/servlet_jsp/work/

  • jspTemp/irj/root/WEB-INF/lib/prtjndisupport.jar

*/

import com.sapportals.portal.prt.jndisupport.InitialContext;

/*

  • System Landscape service API

  • jar file location:

  • <j2ee engine>/cluster/server/services/servlet_jsp/work/

  • jspTemp/irj/root/WEB-INF/portal/portalapps/com.sap.portal.

  • ivs.systemlandscapeservice/lib/

  • com.sap.portal.ivs.systemlandscapeserviceapi.jar

*/

import com.sapportals.iviewserver.systemlandscape.service.ISystemLandscapeService;

import com.sapportals.iviewserver.systemlandscape.service.IDesigntimeSystemLandscapeService;

import com.sap.portal.pcm.system.ISystems;

import com.sap.portal.pcm.system.ISystem;

/*

  • Connector service API

  • jar file location:

  • <j2ee engine>/cluster/server/services/servlet_jsp/work/

  • jspTemp/irj/root/WEB-INF/portal/portalapps/com.sap.portal.

  • ivs.connectorservice/lib/com.sap.portal.ivs.connectorserviceapi.jar

*/

import com.sapportals.portal.ivs.cg.IConnectorService;

import com.sapportals.portal.ivs.cg.IConnectorGatewayService;

import com.sapportals.portal.ivs.cg.ConnectionProperties;

/*

  • javax.resource.cci

  • jar file location:

  • <j2ee engine>/cluster/server/additional-lib/connector.jar

*/

import javax.resource.cci.MappedRecord;

import javax.resource.cci.RecordFactory;

/*

  • Connector Framework

  • jar file location:

  • <j2ee engine>/cluster/server/additional-lib/com/sapportals/

  • connectorframework/framework/GenericConnector.jar

*/

import com.sapportals.connector.ConnectorException;

// connection

import com.sapportals.connector.connection.IConnection;

import com.sapportals.connector.connection.IConnectionFactory;

// execution.functions

import com.sapportals.connector.execution.functions.IInteraction;

import com.sapportals.connector.execution.functions.IInteractionSpec;

// metadata.functions

import com.sapportals.connector.metadata.functions.IFunction;

import com.sapportals.connector.metadata.functions.IFunctionsMetaData;

// execution.structures

import com.sapportals.connector.execution.structures.IRecord;

import com.sapportals.connector.execution.structures.IStructureFactory;

import com.sapportals.connector.execution.structures.IRecordSet;

public class SampleComponent extends AbstractPortalComponent {

/*

  • Generic Layer service

  • */

IPcdContext pcdContext;

/*

  • Data Container

  • */

IPortalComponentProfile app;

/*

  • Refresh "systems" variable which contains a list of R3 system object.

  • This object is shown in the pulldown list on JSP.

*/

public void doContent(IPortalComponentRequest request, IPortalComponentResponse response) {

System.out.println("doContent()");

app = request.getComponentContext().getProfile();

try {

// Get the initial context from JNDI@PRT

pcdContext = getPcdContext(request);

// Get a list of R/3 system object aliases

Hashtable systems = getR3Systems(request);

System.out.println("systems = " + systems);

app.putValue("systems", systems);

} catch (Exception e) {

System.out.println("Caught an exception: \n" + e);

}

IResource jsp = request.getResource(IResource.JSP, "pagelet/index.jsp");

response.include(request, jsp);

}

/**

  • Trigger a Remote Function Module via CCI...

*/

public void doJca(IPortalComponentRequest request, IPortalRequestEvent event) {

System.out.println("doJca()");

Context ctx = null;

IConnectionFactory connectionFactory = null;

IConnection client = null;

ConnectionProperties prop = null;

String rfm_name = "BAPI_COMPANYCODE_GETLIST";

String system_alias = request.getParameter("system");

if (system_alias == null) {

app.putValue(

"error",

"1.Couldn't establish a connection with a target system " + system_alias + ".");

return;

}

System.out.println("system_alias = " + system_alias);

app.putValue("error", "");

app.putValue("exportParams", "");

app.putValue("system_alias", system_alias);

try {

// Obtain the initial JNDI context

// ctx = new InitialContext();

// Perform JNDI lookup to obtain connection factory

// connectionFactory = (IConnectionFactory) ctx.lookup("EISConnections/SAPFactory");

// IConnectionSpec spec = connectionFactory.getConnectionSpec();

//

// ((Map) spec).put("client", "100");

// ((Map) spec).put("UserName", "");

// ((Map) spec).put("Password", "");

// ((Map) spec).put("logonmethod", "UIDPW");

// ((Map) spec).put("Language", "EN");

// ((Map) spec).put("ashost", "");

// ((Map) spec).put("sysnr", "01");

// IConnection client = connectionFactory.getConnectionEx(spec);

IConnectorGatewayService cgService =

(IConnectorGatewayService) request.getService(IConnectorService.KEY);

try {

prop = new ConnectionProperties(request.getLocale(), request.getUser());

} catch (Exception e) {

app.putValue(

"error",

"2.Couldn't establish a connection with the user " + request.getUser() + ".");

return;

}

try {

client = cgService.getConnection(system_alias, prop);

} catch (Exception e) {

app.putValue(

"error",

"3.Couldn't establish a connection with a target system " + system_alias + ".");

return;

}

/*

  • Start Interaction

  • */

IInteraction interaction = client.createInteractionEx();

System.out.println("Starting Interaction...");

IInteractionSpec interactionSpec = interaction.getInteractionSpec();

interactionSpec.setPropertyValue("Name", rfm_name);

/*

  • CCI api only has one datatype: Record

  • */

RecordFactory recordFactory = interaction.getRecordFactory();

MappedRecord importParams = recordFactory.createMappedRecord("CONTAINER_OF_IMPORT_PARAMS");

IFunctionsMetaData functionsMetaData = client.getFunctionsMetaData();

IFunction function = functionsMetaData.getFunction(rfm_name);

if (function == null) {

app.putValue(

"error",

"Couldn't find " + rfm_name + " in a target system " + system_alias + ".");

return;

}

/*

  • How to invoke Function modules

  • */

System.out.println("Invoking... " + function.getName());

MappedRecord exportParams = (MappedRecord) interaction.execute(interactionSpec, importParams);

app.putValue("exportParams", exportParams);

/*

  • How to get structure values

  • */

IRecord exportStructure = (IRecord) exportParams.get("RETURN");

String columnOne = exportStructure.getString("TYPE");

String columnTwo = exportStructure.getString("CODE");

String columnThree = exportStructure.getString("MESSAGE");

System.out.println(" RETURN-TYPE = " + columnOne);

System.out.println(" RETURN-CODE = " + columnTwo);

System.out.println(" RETURN-MESSAGE =" + columnThree);

/*

  • How to get table values

  • */

IRecordSet exportTable = (IRecordSet) exportParams.get("COMPANYCODE_LIST");

exportTable.beforeFirst(); // Moves the cursor before the first row.

while (exportTable.next()) {

String column_1 = exportTable.getString("COMP_CODE");

String column_2 = exportTable.getString("COMP_NAME");

System.out.println(" COMPANYCODE_LIST-COMP_CODE = " + column_1);

System.out.println(" COMPANYCODE_LIST-COMP_NAME = " + column_2);

}

/*

  • Closing the connection

  • */

client.close();

} catch (ConnectorException e) {

//app.putValue("error", e);

System.out.println("Caught an exception: \n" + e);

} catch (Exception e) {

System.out.println("Caught an exception: \n" + e);

}

}

private IPcdContext getPcdContext(IPortalComponentRequest request) {

// System.out.println("getPcdContext()");

IPcdContext pcdContext = null;

try {

Hashtable env = new Hashtable();

env.put(

IPcdContext.INITIAL_CONTEXT_FACTORY,

"com.sapportals.portal.pcd.gl.PcdInitialContextFactory");

env.put(IPcdContext.SECURITY_PRINCIPAL, request.getUser());

pcdContext = (IPcdContext) new InitialContext(env).lookup("");

} catch (Exception e) {

System.out.println("Caught an exception: \n" + e);

}

return pcdContext;

}

private Hashtable getR3Systems(IPortalComponentRequest request) {

// System.out.println("getR3Systems()");

Hashtable systems = new Hashtable();

try {

// get a list of R/3 system aliases

ISystemLandscapeService landscapeService =

(ISystemLandscapeService) request.getService(ISystemLandscapeService.KEY);

IDesigntimeSystemLandscapeService landscape =

landscapeService.getIDesigntimeSystemLandscapeService();

NamingEnumeration enum = landscape.getAliasesNames(request.getUser());

while (enum.hasMore()) {

NameClassPair ncp = (NameClassPair) enum.next();

String path = landscape.getAliasTarget(ncp.getName(), request.getUser());

path = path.substring(4);

IPcdAttributes attrs = (IPcdAttributes) pcdContext.getAttributes(path);

if (attrs.get("SystemType") == null) {

continue;

}

String system_type = (String) attrs.get("SystemType").get();

if (system_type.equals("SAP_R3")) {

systems.put(ncp.getName(), ncp.getName());

}

}

} catch (Exception e) {

System.out.println("Caught an exception: \n" + e);

}

return systems;

}

}