Expand my Community achievements bar.

Exception in casting using PortableRemoteObject.narrow

Avatar

Former Community Member
Dear all, a trivial test code is failing with the exception


java.lang.ClassCastException

at

com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)

at

javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)




The code is as follows:







import javax.naming.InitialContext;

import javax.rmi.PortableRemoteObject;

import com.adobe.service.DataManager;

import com.adobe.service.DataManagerHelper;

import com.adobe.service.ConnectionFactory;

import com.adobe.document.pdf.*;

import com.adobe.document.pdf.PDFFactory;

import com.adobe.document.pdf.PDFFactoryHelper;

import com.adobe.service.FileDataBuffer;



public class ApplyPolicy {



public void test() throws Exception {

InitialContext namingContext = new InitialContext();



Object dmObject = namingContext.lookup("DataManagerService");



/* ************ ERROR HERE ***************** */

ConnectionFactory dmConnectionFactory = (ConnectionFactory)PortableRemoteObject.narrow(dmObject,ConnectionFactory.class);



Object pdfObject = namingContext.lookup("PDFManipulation");

ConnectionFactory pdfConnectionFactory =(ConnectionFactory)PortableRemoteObject.narrow(pdfObject,ConnectionFactory.class);

/* ************ SAME ERROR HERE ***************** */

PDFFactory mPDFFactory = PDFFactoryHelper.narrow((org.omg.CORBA.Object)pdfConnectionFactory.

getConnection());



DataManager mDataManager = DataManagerHelper.narrow((org.omg.CORBA.Object)dmConnectionFactory.

getConnection());



FileDataBuffer pdfFile = mDataManager.createFileDataBufferFromUrl("http://192.168.0.132:8080/tmp/cleanPDF.pdf");



PDFDocument pdf = mPDFFactory.openPDF(pdfFile);

pdf.close();

}



/**

* @param args

*/

public static void main(String[] args) throws Exception {

ApplyPolicy a = new ApplyPolicy();

a.test();

}

}






The output from dmObject.toString is







Reference Class Name: com.adobe.service.ConnectionFactoryManagerPeerImpl

Type: nns

Content: DataManagerService






The program runs stand-alone (is not part of a web application, no deployment) under Linux with Java 1.4.2_06.

Same for the Adobe Policy Server that is installed locally.

Notice that I'm not very skilled in beans/RMI etc.



Any suggestion???
7 Replies

Avatar

Former Community Member
As far as I remeber, you should setup InitalContext parameters to be able to perform lookup. I think it is mentioned somewhere in Adobe docs...

Avatar

Former Community Member
I have exactly the same problem trying to use the beans from outside j2ee.

I have setted the initialcontext parameters in the jndi.properties file with those values:

java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory

java.naming.provider.url= localhost:1099

java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces



What is strange is that the name is found with lookup (if I change name for test, I receive an exception: so it good lookup in naming service), but that's the next step that crash.



Thanks in advance for your help

Avatar

Former Community Member
Have you tried setting the environment explicitly in the call to InitalContext? For example:



Hashtable env = new Hashtable();

env.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");

env.put("java.naming.provider.url","jnp://localhost:1099");

env.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

InitialContext namingContext = new InitialContext(env);

Avatar

Former Community Member
Dear Don,

Thanks for your answer. Yes, I already tried that.

In fact, I have tried to put false informations in those settings and the error change (unable to resolve name). So, I m connected to naming service, but narrow method generate the classcastException later.



Is it a setting in Jboss that could prevent the remote use of beans or something else?

Thanks



Denis

Avatar

Former Community Member
perhaps u have a firewall that prevents u from calling RMI on port 1099 ?

Avatar

Former Community Member
Unfortunately you can't use PDFManipulation or DataManagerService remotely. In order to do so you'd have to code your own EJB or web service that exposes methods that use these API's and then call your EJB or web service from your remote application.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Chris,

Thanks for your answer. It's a bad news, but I will try the solutions you describe.

Thanks

Denis