users@jax-rpc.java.net

accessing resources in different webapps

From: John L. Fjellstad <john_at_PRODEXNET.COM>
Date: Wed, 16 Oct 2002 10:19:06 -0700

I have a webapp called FooBar. FooBar has a resource named Foo in the
namespace /comp/env/foobar
To get Foo in FooBar, I do a ctx.lookup("java:/comp/env/foobar/Foo");

My server.xml has the following entries:

...
<Resource name="foobar/manager" auth="Container"
     type="com.company.FooManager"/>
  ...
</Resource>

<Resource name="foobar/Foo" auth="Container" type="com.company.FooImpl"/>
<description>
Object factory for Foo
</description>
<ResourceParams name="foobar/Foo">
    <parameter>
        <name>factory</name>
         <value>com.company.FooObjectFactory</value>
     </parameter>
    <parameter>
        <name>manager</name>
        <value>foobar/manager</value>
     </parameter>
</ResourceParams>

I have no problems accessing the resource Foo from this application.

I want to expose the interface to foobar as a webservice.

I created the endpoints etc. I can see the endpoints at
http://localhost:8080/manager/list

My web.xml for the endpoint is:
...
<resource-env-ref>
      <resource-env-ref-name>foobar/Foo</resource-env-ref-name>

<resource-env-ref-type>foobar/com.company.FooImpl</resource-env-ref-type>
</resource-env-ref>

When I try to retrieve an instance of Foo from my client app, I get a
namingexception (inside the RemoteException).
Printing out the binding for foobar/Foo (on the server side), I get
Binding1: ChannelFactory: org.apache.naming.ResourceEnvRef:Reference
Class Name: prodex.netgather.channel.ChannelFactoryImpl

Classname: org.apache.naming.factory.ResourceEnvFactory

So, it doesn't work. I change the entry in web.xml to

<resource-ref>
    <description>Object factory for Foo</description>
    <res-ref-name>foobar/Foo</res-ref-name>
    <res-type>com.company.FooImpl</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

I now get "javax.naming.NamingException: Cannot create resource
instance" when doing a ctx.lookup("java:/comp/env/foobar/Foo")
Looking inside the binding, I see

Classname: com.company.FooImpl
Object:
ResourceRef[className=com.company.FooImpl,factoryClassLocation=null,factoryClassName=org.apache.naming.factory.ResourceFactory,{type=description,content=Object
factory for Foo
instances},{type=scope,content=Shareable},{type=auth,content=Container}]

Basically, instead of my factory com.company.FooObjectFactory, I get the
generic org.apache.naming.factory.ResourceFactory, which doesn't know
anything about Foo, of course. So, what is wrong, and how can I fix it?

Thanks,

--
John L. Fjellstad,  Software Engineer
ProdEx Technologies
14471 Big Basin Way, Suite E
Saratoga, CA 95070
USA
Phone: (408) 872-3100