cancel
Showing results for 
Search instead for 
Did you mean: 

getConnection Exception--EP6 SP2 with patch3

Former Member
0 Kudos

Hi,

I am trying to connect to SAP as per the Connector FrameWork sample code documentatation. The code is as shown below,

import com.sapportals.htmlb.page.DynPage;

import com.sapportals.htmlb.page.PageException;

import com.sapportals.portal.htmlb.page.JSPDynPage;

import com.sapportals.portal.htmlb.page.PageProcessorComponent;

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

import com.sapportals.portal.prt.runtime.PortalRuntime;

import com.sapportals.portal.prt.logger.ILogger;

import com.sapportals.portal.prt.logger.Level;

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

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

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

import com.sapportals.connector.connection.IConnection;

public class MySAPParProject extends PageProcessorComponent {

public DynPage getPage() {

return new MyDynPage();

}

public class MyDynPage extends JSPDynPage {

public MyDynPage() {

this.setTitle("MySAPParProject-->SAP Connection");

}

public void doInitialization() {

}

public void doProcessAfterInput() throws PageException {

}

public void doProcessBeforeOutput() throws PageException {

IPortalComponentRequest request = (IPortalComponentRequest) this.getRequest();

// all coding concerning the connection is included in this method.

doSAPConnection(request);

//doSAPDirectConnect(request);

}

private void doSAPConnection(IPortalComponentRequest request) {

ILogger logger = PortalRuntime.getLogger();

logger.setLevel(Level.SEVERE);

logger.severe("MySAPParProject--->doSAPConnection");

String sapSystem = "CE8N";

// sample code for a connection to a SAP system

IConnection connection = null;

ConnectionProperties conprop = null;

try { // get the Connector Gateway Service

Object connectorservice = PortalRuntime.getRuntimeResources().getService( IConnectorService.KEY);

logger.severe("MySAPParProject->doJCoConnectiongetService");

IConnectorGatewayService cgService =(IConnectorGatewayService) connectorservice;

logger.severe("MySAPParProject->doJCoConnectionconnectorservice");

if (cgService == null) {

logger.severe("Error in get Connector Gateway Service <br>");

}

try {

ConnectionProperties cp =

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

logger.severe("User ID= " + cp.getUser());

logger.severe("Locale ID= " + cp.getLocale());

logger.severe("Log Path= " + cp.getLogPath());

//logger.severe("MySAPParProject-->Before Key = " + cgService.getKey().toString());

connection = cgService.getConnection(sapSystem,cp);

//logger.severe("MySAPParProject-->After Key = " + cgService.getKey());

} catch (Exception e) {

logger.severe("MySAPParProject-->Connection to SAP system failed " + e.getMessage() + "<br>");

}

if (connection == null) {

logger.severe("MySAPParProject-->Connection is null to " + sapSystem + " System <br>");

}

else {

logger.severe("MySAPParProject-->Connection succesful");

}

} catch (Exception e) {

logger.severe("MySAPParProject-->Exception occured" + e.getMessage() + "<br>");

}

}

}

}

The portalapp.xml file entries as shown below

<?xml version="1.0" encoding="ISO-8859-1"?>

<application>

<application-config>

<property name="SharingReference" value="com.sap.portal.ivs.connectorservice,htmlb"/>

</application-config>

<components>

<component name="default">

<component-config>

<property name="ClassName" value="MySAPParProject"/>

<property name="SecurityZone" value="com.sap.portal.pdk/low_safety"/>

</component-config>

<component-profile>

<property name="SystemIdentifier" value="PDK_R3_BACKEND">

<property name="personalization" value="dialog"/>

</property>

<property name="tagLib" value="/SERVICE/htmlb/taglib/htmlb.tld"/>

</component-profile>

</component>

</components>

<services/>

</application>

Here the code fails at the line,

connection = cgService.getConnection(sapSystem,cp);

It throws an exception as

getConnectionFactoryName()- parameter com.sap.portal.reserved.system.ConnectionFactoryClass not found.

This error we didn't get when had patch2 installed. We applied patch 3 since we were getting connection = null after executing cgService.getConnection(sapSystem,cp);. Can you please me help in resolving this issue. Thanks in advance.

Thanks

Ajoy

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

thanks karsten..

"sounds like the SharingReference to com.sap.portal.ivs.connectorservice is missing." had the nail on target.

Divakar

Former Member
0 Kudos

Hi,

First of all thanks for the quick response.

The code below throws a ClassCastException.

/************************************************/

Object tempCon = PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);

iConnectorGatewayService cgService = (IConnectorGatewayService) tempCon;

/************************************************/

Version: EP6 SP11

Unable to find whats wrong.

Divakar

Message was edited by: Divakar Salla

Former Member
0 Kudos

Hi Divakar,

sounds like the SharingReference to com.sap.portal.ivs.connectorservice is missing.

Regards, Karsten

Former Member
0 Kudos

Hi Divakar,

You have to Cast to the specific service <i>IConnectorService</i> when you are getting the Service reference.

Try this piece of code:


IConnection con = null;

        try
        {
            IConnectorService cService = <b>(IConnectorService)</b> PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY);
            IConnectorGatewayService cgService = cService.getIConnectorGatewayService();
            
            if (cgService == null)
            {
		System.out.println("Error in get Connector Gateway Service");
            }
            
            con = cgService.getConnection(systemAlias, request);
            
            if (con == null)
            {
		System.out.println("Warning: connection is null");
                throw new InvalidConnectionException("connection is null");
            }
        }
        catch (InvalidConnectionException e)
        {
	   throw e;
        }

Note: Also, check whether your portalapp.xml file has

<b>ServicesReference</b> to <i>com.sap.portal.ivs.connectorservice</i>

Hope it helps.

Regards,

Sai.

PS: Plz do assign points for helpful answers in Sdn!

Message was edited by: Sai Krishna T

Former Member
0 Kudos

> You have to Cast to the specific service

> ce <i>IConnectorService</i> when you are getting the

> Service reference.

No, that's not necessary. If you call PortalRuntime.getRuntimeResources().getService(IConnectorService.KEY) you will get a class that implements the IConnectorGatewayService interface.

> Note: Also, check whether your portalapp.xml file has

>

> <b>ServicesReference</b> to

> <i>com.sap.portal.ivs.connectorservice</i>

>

ServicesReference is the EP5 term for SharingReference, so it's the same as I said before.

The ClassCastException comes up, because the interface com.sap.portal.services.api.connectorgateway.IConnectorGatewayService

is lying on the classpath anyways.(-> portal_services_api_lib.jar).

This interface doesn't extend IService, so you can't use it like a portal service (-> ClassCastException). The usage looks ok (https://media.sdn.sap.com/javadocs/NW04/SP12/prtsupp/com/sapportals/portal/ivs/cg/IConnectorGatewayService.html), but I think the reference is missing.

Former Member
0 Kudos

I am unable to find the jar containing IConnection Class.

can you let me know the same.

Former Member
0 Kudos

Hi Divakar,

for SP2 I would look here:

\usr\sap\<sid>\j2ee\<instance>\cluster\server\additional-lib\com\sapportals\connectorframework\framework\GenericConnector.jar

for current NW portals:

\usr\sap\<sid>\<instance>\j2ee\cluster\server0\bin\ext\tcconnconnectorframework\GenericConnector.jar

For the others: Did you check SAP Note 751270?

Regards, Karsten