JNDI Lookup returns Reference - causes ClassCastException
craigpugsley Oct 13, 2005 12:08 PMHi there. I'm trying to call our web service using standard code outlined in the examples both in the JBoss wiki and in the Sun tutorials.
The problem I'm having occurs when I perform a lookup for our registered service using the JBoss-flavoured initial context:
javax.naming.InitialContext iniCtx = getInitialContext(); Object obj = iniCtx.lookup("java:comp/env/service/PolicyFileMgrService"); javax.xml.rpc.Service service = (javax.xml.rpc.Service)iniCtx.lookup("java:comp/env/service/PolicyFileMgrService"); PolicyFileMgrService policyFileMgrService = (PolicyFileMgrService)service.getPort(PolicyFileMgrService.class); policyFileMgr = policyFileMgrService.getPolicyFileMgr();
The error is obviously on the second line where I have broken down the sample provided code to see what object type is returned. It seems I am returned a 'javax.naming.Reference' object, instead of the 'PolicyFileMgrService' I was expecting when I perform the lookup.
I have been following this thread ('http://www.jboss.com/index.html?module=bb&op=viewtopic&t=54033') and I have tried changing the classpath, without success.
Some context: I am running my client app from Eclipse on a machine that is remote from the server JBoss is running on. I have implemented application-client.xml and jboss-client.xml, jacrpc mapping files and relevant wdsl file, and deployed these on JBoss next to our application EAR that has the services I would like to access.
I can see that the services are being bound in the JNDI:
DEBUG [org.jboss.deployment.MainDeployer] Begin deployment start file:/C:/policymatter/jboss-4.0.3/server/default/deploy/pccAppClient.jar DEBUG [org.jboss.deployment.ClientDeployer] Creating client ENC binding under: PolicyControlCentre DEBUG [org.jboss.webservice.ServiceClientDeployer] Webservice binding: java:comp/env/service/PolicyFileMgrService DEBUG [org.jboss.webservice.ServiceClientDeployer] Webservice binding: java:comp/env/service/PolicyControlCenterService DEBUG [org.jboss.deployment.ClientDeployer] Binding resource: ref_pmuploadprogress to JDNI as: null DEBUG [org.jboss.deployment.ClientDeployer] Binding resource: ref_pmuploadprogressTCF to JDNI as: null DEBUG [org.jboss.deployment.ClientDeployer] Binding resource: ref_pmupload to JDNI as: null DEBUG [org.jboss.deployment.ClientDeployer] Binding resource: ref_pmuploadQCF to JDNI as: null INFO [org.jboss.deployment.ClientDeployer] Client ENC bound under: PolicyControlCentre DEBUG [org.jboss.deployment.MainDeployer] End deployment start on package: pccAppClient.jar DEBUG [org.jboss.deployment.MainDeployer] Deployed package: file:/C:/policymatter/jboss-4.0.3/server/default/deploy/pccAppClient.jar
This is my application-client.xml file:
<?xml version="1.0" encoding="UTF-8"?> <application-client xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd" version="1.4"> <display-name>PolicyControlCentre</display-name> <service-ref> <service-ref-name>service/PolicyControlCenterService</service-ref-name> <service-interface>javax.xml.rpc.Service</service-interface> <wsdl-file>META-INF/wsdl/PolicyControlCenter_jboss.wsdl</wsdl-file> <jaxrpc-mapping-file>META-INF/PolicyControlCenter_mapping_jboss.xml</jaxrpc-mapping-file> <service-qname xmlns:pfx="http://service.repository.policymatter.com">pfx:PolicyControlCenterService</service-qname> <port-component-ref> <service-endpoint-interface>com.policymatter.repository.service.PolicyControlCenter</service-endpoint-interface> </port-component-ref> </service-ref> <service-ref> <service-ref-name>service/PolicyFileMgrService</service-ref-name> <service-interface>javax.xml.rpc.Service</service-interface> <wsdl-file>META-INF/wsdl/PolicyFileMgr_jboss.wsdl</wsdl-file> <jaxrpc-mapping-file>META-INF/PolicyFileMgr_mapping_jboss.xml</jaxrpc-mapping-file> <service-qname xmlns:pfx="http://service.policymatter.com">pfx:PolicyFileMgrService</service-qname> <port-component-ref> <service-endpoint-interface>com.policymatter.service.PolicyFileMgr</service-endpoint-interface> </port-component-ref> </service-ref> <resource-ref id="ResourceRef_1125059009605"> <description> </description> <res-ref-name>ref_pmuploadQCF</res-ref-name> <res-type>javax.jms.QueueConnectionFactory</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <resource-ref id="ResourceRef_1125059426415"> <description> </description> <res-ref-name>ref_pmupload</res-ref-name> <res-type>javax.jms.Queue</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <resource-ref id="ResourceRef_1125059626576"> <description> </description> <res-ref-name>ref_pmuploadprogressTCF</res-ref-name> <res-type>javax.jms.TopicConnectionFactory</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <resource-ref id="ResourceRef_1125059626585"> <description> </description> <res-ref-name>ref_pmuploadprogress</res-ref-name> <res-type>javax.jms.Topic</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </application-client>
I assume this is correct, because the wsdl I include in the deployed JAR is being picked up at 'http://mymachinename/PolicyServerEJB/PolicyFileMgrPort?wsdl'.
Looking in the JMX console at the JNDI, I can see the J2EE client service is deployed:
+- PolicyControlCentre (class: org.jnp.interfaces.NamingContext) | +- service (class: org.jnp.interfaces.NamingContext) | | +- PolicyControlCenterService (class: org.jboss.webservice.client.ServiceReferenceable) | | +- PolicyFileMgrService (class: org.jboss.webservice.client.ServiceReferenceable) | +- ref_pmupload[link -> null] (class: javax.naming.LinkRef) | +- ref_pmuploadprogressTCF[link -> null] (class: javax.naming.LinkRef) | +- ref_pmuploadprogress[link -> null] (class: javax.naming.LinkRef) | +- ref_pmuploadQCF[link -> null] (class: javax.naming.LinkRef)
On the classpath, I have only added 'jbossall-client.jar' in addition to the libraries I had been using before. These libraries are:
xml-apis.jar xercesImpl.jar wsdl4j-1.5.1.jar ui.jar Tidy.jar servlet.jar saaj.jar log4j-1.2.8.jar jmdns.jar jdom.jar jazzy-swing.jar jazzy-core.jar jaxrpc.jar jaxen-1.1-beta-4.jar jakarta-slide-webdavlib-2.1.jar jakarta-slide-commandline-2.1.jar jakarta-regexp-1.3.jar jacob.jar itext-1.3.jar fop.jar filedrop.jar editlivejava.jar commons-transaction-1.0.jar commons-logging-1.0.4.jar commons-lang-2.0.jar commons-httpclient-contrib.jar commons-httpclient.jar commons-discovery-0.2.jar castor-0.9.5.3.jar batik.jar axis-ant.jar axis.jar avalon-framework-cvs-20020806.jar antlr.jar AbsoluteLayout.jar jbossall-client.jar
Previously, we were simply calling the web services via generated proxy objects, but we are looking to move our Java Swing application into a proper J2EE application client and look up dynamic proxies via JNDI.
Any help on this problem would be much appreciated! I'm frantically trying to keep the JBoss flame alive in our organisation, where everyone else seems to want to jump-ship to commercial app servers. Please help me show them that a complex J2EE app client is feasible!
Thanks.