cancel
Showing results for 
Search instead for 
Did you mean: 

Typecast exception for DestinationService

Former Member
0 Kudos

Hello everybody,

I want to use RFC destinations in my application.

I have used JCO in my EJB to connect to the R/3 system. I donot want to hardcode connection values in code.So, i have set RFC destination for that.

For this purpose i have written following code:

InitialContext ctx = new InitialContext();

DestinationService dstService = (DestinationService)

ctx.lookup(DestinationService.JNDI_KEY);

if (dstService == null)

{

throw new NamingException("Destination Service not available");

}

RFCDestination dst =

(RFCDestination) dstService.getDestination("RFC", "RFCTEST");

int maxPoolSize = dst.getMaxPoolSize();

long maxWaitTime = dst.getMaxWaitTime();

Properties jcoProperties = dst.getJCoProperties();

JCO.Client client = JCO.createClient(jcoProperties);

client.connect();

But, i am getting Class cast exception when i tried to cast my lookup object into DestinationService class.

What should be the problem in this?

Regards,

Bhavik

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Bhavik,

I guess its either returning null instead of the object you are expecting, which obviosuly you cant cast to n DestinationService.

Try:


Object service dstService = ctx.lookup(DestinationService.JNDI_KEY);

if(service instanceof DetsinationService)
{
   DestinationService destinationService = (DestinationService) service;

   ...continue your success path here
}
else
{
    ...do some error handling here
}

At least if the returned object is not a DestinationService or null then you can see what it is returning.

Steve

Former Member
0 Kudos

Hi Steve,

Thanks for your response.

But, I have checked it already. Lookup returns me the Object, but when i try to cast it in DestinationService, it gives me Typecase exception.

Even when i checkd with <b>instanceof</b> it is returning false value.

I have checked Object's class value and it is showing "Proxy100". I have checked the same inside visual administrator under JNDI registry. There also i found the same.

So, i guess i can successfully lookup for JNDI. But, i cant type cast from Object to DestinationService.

I guess, one of the reason behind is the version mismatch. My NWDS is of SP12 and WAS of SP13.

As WAS vesrion is higher than NWDS it should not be the problem?

Do you have any idea?

Thanks,

Bhavik

former_member182372
Active Contributor
0 Kudos

Hello Bhavik,

You have to specify reference in your J2EE application to destination service:

META-INF\application-j2ee-engine.xml:

<application-j2ee-engine>

...

<reference

reference-type="hard">

<reference-target

provider-name="sap.com"

target-type="service">destination</reference-target>

</reference>

...

</application-j2ee-engine>

Restart your server after deployment of new archive in case not immediately success.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Hi Maksim,

What is destination here? I have specified tc/sec/destinations/interface and security.class references in this file?

But, i can't find anything related to destination as reference.

What is the exact name of it?

Regards,

Bhavik

former_member182372
Active Contributor
0 Kudos

Hello Bhavik,

Sorry, name of service is "tcsecdestinations~service".

<reference

reference-type="hard">

<reference-target

provider-name="sap.com"

target-type="service">tcsecdestinations~service</reference-target>

</reference>

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Never mind. Dumb question.

Former Member
0 Kudos

Hi all,

I don't kwnow why this post is stopped, I'm afraid. I'have the same problem on my Web application. I inserted the follow <b>additional libraries</b>:

- security.class

- tc/sec/detsinations/interfaces

- tc/sec/securitystorage/service

- come.sap.security.core.sda

- com.sap.security.api.sda

- com.sap.exception

<b>Here my import:</b>

import java.rmi.RemoteException;

import javax.naming.InitialContext;

import javax.naming.NamingException;

import javax.rmi.PortableRemoteObject;

import com.sap.examples.calculator.Calculator;

import com.sap.examples.calculator.CalculatorHome;

import com.sap.security.core.server.destinations.api.ConfigurationException;

import com.sap.security.core.server.destinations.api.Destination;

import com.sap.security.core.server.destinations.api.DestinationException;

import com.sap.security.core.server.destinations.api.DestinationService;

import com.sap.security.core.server.destinations.api.HTTPDestination;

<b>Here my code:</b>

public String connectToHTTPDestination()
	{
		String res = "start";
		
		try{		
		InitialContext ctx = new InitialContext();
			try{
			DestinationService dstService = (DestinationService) ctx.lookup(DestinationService.JNDI_KEY);
			if (dstService == null)
			throw new NamingException("Destination Service not available");
			Destination destination = dstService.getDestination("HTTP","dst-1");
			
			// for HTTP destination: cast
			HTTPDestination httpDestination = (HTTPDestination) destination;
			// obtain a HTTPUrlConnection from the destinationHttpURLConnection
				try {
				java.net.HttpURLConnection httpConnection = httpDestination.getURLConnection();
				res = httpConnection.toString();
				} catch (ConfigurationException e) {res = e.getMessage();
													return res;};
			}catch (DestinationException e) {res = e.getMessage();
											 return res;}
		 	catch (RemoteException e) {res = e.getMessage();
									   return res;};
		} catch (NamingException e) {res = e.getMessage();
									 return res;};
		
		return res;
	}

<b>Here the problem:</b>

Line

DestinationService dstService = (DestinationService) ctx.lookup(DestinationService.JNDI_KEY);

doesn't works!!!!

It's a cast error; Object's class value and it is showing "Proxy100"

Does someone knows how to solve?? Thanks a lot.

Vito P.

Answers (1)

Answers (1)

0 Kudos

I had the same problem.

I found the answer in this note:

http://help.sap.com/saphelp_nw04/helpdata/en/17/d609b48ea5f748b47c0f32be265935/frameset.htm

which says:

Your application needs classloader references to tcsecdestinationsservice and tcsecdestinationsinterface.

· For J2EE applications, add the references in the Developer Studio as described in Structure linkReferencing Libraries in Applications.

· For Web Dynpro applications, add the components security.class and tc/sec/destinations/interface to your projectsu2019 classpaths as described in Structure linkImplementing the Server Abstraction Layer. Add the references as service and interface references accordingly.

So I added this to my application-j2ee-engine.xml file:

tcsecdestinations~servicetcsecdestinations~interface</reference-target>

</reference>

That fixed mine.

Regards,

Alan Gustin