|
From: Ryan J. M. <ry...@da...> - 2008-07-29 12:57:59
|
Jürgen,
I don't think we have this implemented yet, but with RESTEasy, you can
make the EJB itself a resource. Bill has an example of it in the
integration tests folder and I'll be committing and example app that
uses this on Wednesday.
Ryan-
On Jul 27, 2008, at 4:21 AM, Jürgen Zimmermann wrote:
> When using Jersey I could use a provider class to make @EJB available
> (see below). Is there a similar workaround to use RESTeasy with JBoss
> 4.2.3?
>
> import java.lang.reflect.Type;
> import javax.ejb.EJB;
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import javax.naming.NamingException;
> import javax.ws.rs.ext.Provider;
> import com.sun.jersey.api.core.HttpContext;
> import com.sun.jersey.spi.inject.Injectable;
> import com.sun.jersey.spi.inject.InjectableProvider;
> import com.sun.jersey.spi.service.ComponentContext;
> import com.sun.jersey.spi.service.ComponentProvider.Scope;
>
> @Provider
> public class EJBProvider implements InjectableProvider<EJB, Type> {
> private static String JNDI_PREFIX = "hska/";
> private static String JNDI_SUFFIX = "Bean/local";
>
> public Scope getScope() {
> return Scope.Singleton;
> }
>
> public Injectable<Object> getInjectable(ComponentContext
> componentCtx, EJB ejb, Type type) {
> if (!(type instanceof Class))
> return null;
>
> final Class<?> clazz = (Class<?>) type;
> try {
> final Context ctx = new InitialContext();
> final String jndiName = JNDI_PREFIX +
> clazz.getSimpleName() + JNDI_SUFFIX;
> final Object obj = ctx.lookup(jndiName);
>
> return new Injectable<Object>() {
> public Object getValue(HttpContext c) {
> return obj;
> }
> };
> }
> catch (NamingException e) {
> e.printStackTrace();
> return null;
> }
> }
> }
>
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's
> challenge
> Build the coolest Linux based applications with Moblin SDK & win
> great prizes
> Grand prize is a trip for two to an Open Source event anywhere in
> the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Resteasy-developers mailing list
> Res...@li...
> https://lists.sourceforge.net/lists/listinfo/resteasy-developers
|