openejb-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thiago Veronezi <thi...@veronezi.org>
Subject Re: locator
Date Fri, 11 Feb 2011 11:27:27 GMT
Hi,
Service-locator is just a fancy way to mount your lookup string to query and
find your sessionbean on your application server. Check the example below...
(Note that I'm using the built-in naming standard)

//-----------------------------------------------------------------------------------------------------------------
public static <T> T interfaceLookup(
Context ctx,
final Class<T> cls) {
final String implName = cls.getSimpleName().substring(1);

final String lookupStr = implName.substring(0,
implName.lastIndexOf("Service"))
+ "ImplRemote";

if (LOG.isDebugEnabled()) {
LOG.debug("\tTrying to find the interface impl. lookupStr: \""
+ lookupStr + "\". Interface class: \""
+ cls.getSimpleName() + "\"");
}

final Object implObj;
try {
implObj = ctx.lookup(lookupStr);
} catch (NamingException e) {
LOG.error(e);
throw new InterfaceLookupException(e, cls, lookupStr);
}

if (LOG.isDebugEnabled()) {
LOG.debug("\tInterface impl found: " + implObj);
}
 final Object proxyObj = PortableRemoteObject.narrow(implObj,cls);
return cls.cast(proxyObj);
}
//-----------------------------------------------------------------------------------------------------------------

This is the service locator that I've created for my project. Note that to
be able to use it I need to follow some rules while naming my sessionbeans
interfaces and concrete classes.
These are the rules for my project:
* SessionBean concrete classes naming should follow -> <ServiceName>Impl
* SessionBean interfaces naming should follow -> I<ServiceName>ServiceRemote

To use the service locator above, I need to pass the "interface" of the
sessionbean I want to find as parameter... and I get a reference to my
remote sessionbean.

[]s,
Thiago

On Fri, Feb 11, 2011 at 6:23 AM, Nicola Dellisanti <
nicola.dellisanti@gmail.com> wrote:

> Hi,
>
> I don't understand how "service locator" works (
> http://openejb.apache.org/service-locator.html ).
>
> I have a jar in webapps tomcat folder, this is my project ejb and I can
> correctly invoke my ejb methods from http://localhost:8080/openejb/
> Can I use the ejb functions in my jar from a web application in the tomcat
> webapps/testweb folder using "service locator" decribed in
> http://openejb.apache.org/service-locator.html ?
>
> Thanks,
>
> N.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message