Guice and Resteasy

1,774 views
Skip to first unread message

Moandji Ezana

unread,
Jun 5, 2013, 5:49:04 AM6/5/13
to google...@googlegroups.com

Resteasy 3.0 (JBoss's JAX-RS implementation) is coming out soon. I just wanted to let people know that I and a few others have been giving its Guice integration some much-needed attention and new features for the first time in years.

Some of the interesting new features:
- Guice 3.0 (believe it or not)
- Handle Injector creation yourself
- @PostContruct and @PreDestroy handlers for modules
- @RequestScoped

So if you're not using CDI with JAX-RS, Guice is a pretty viable option.

Documentation: http://www.jboss.org/resteasy/docs
Source: https://github.com/Resteasy/resteasy/tree/master/jaxrs/resteasy-guice

Mwanji

Cédric Beust ♔

unread,
Jun 5, 2013, 10:50:43 AM6/5/13
to google...@googlegroups.com
Hi Moandji,

Any "real" documentation available, besides github links?

-- 
Cédric


-- 
Cédric



--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice...@googlegroups.com.
To post to this group, send email to google...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Moandji Ezana

unread,
Jun 5, 2013, 11:00:22 AM6/5/13
to google...@googlegroups.com

The first link was to the official doc, which contains a Guice chapter. Sorry, didn't think to link to it directly.

http://docs.jboss.org/resteasy/docs/3.0-beta-6/userguide/html_single/index.html#Guice1

Mwanji

Cédric Beust ♔

unread,
Jun 5, 2013, 11:16:16 AM6/5/13
to google...@googlegroups.com
Ah cool, thanks.


-- 
Cédric

Filipe Sousa

unread,
Jun 5, 2013, 12:28:02 PM6/5/13
to google...@googlegroups.com
Hi, 

Do I have to declare my modules in web.xml? 

Filipe Sousa

unread,
Jun 5, 2013, 12:28:08 PM6/5/13
to google...@googlegroups.com
Hi, 

Do I have to declare my modules in web.xml? 

On Wednesday, June 5, 2013 10:49:04 AM UTC+1, Moandji Ezana wrote:

Moandji Ezana

unread,
Jun 5, 2013, 1:26:38 PM6/5/13
to google...@googlegroups.com

> Do I have to declare my modules in web.xml? 
>

That's no longer the only choice. In beta-6, you can override the ServletContextListener's getModules() method and do it yourself. In rc-1 (currently only on github) you can also override withInjector(Injector) to interact with it after its creation.

I added the latter to be able to start Guice-Persist's PersistService.

Mwanji

Mark Derricutt

unread,
Jun 5, 2013, 2:13:08 PM6/5/13
to google...@googlegroups.com

You don't by any chance know what state there is for OSGi integration for Resteasy/Guice 3 do you?

Currently reevaluating our usage of Restlet...

Mark

Sent from an Android...

--

Filipe Sousa

unread,
Jun 5, 2013, 2:17:13 PM6/5/13
to google...@googlegroups.com
Hi,

I can't find withInjector on github. I could override getModules() but not getStage(). But even so, I still have do add jersey specific things to web.xml. With jersey-guice is as simple as serve("/rest/*").with(GuiceContainer.class);

Thanks.

Moandji Ezana

unread,
Jun 5, 2013, 2:33:27 PM6/5/13
to google...@googlegroups.com

OSGwhat? ;)

Moandji Ezana

unread,
Jun 5, 2013, 2:39:50 PM6/5/13
to google...@googlegroups.com

> I can't find withInjector on github.

You're right. I got a bit ahead of myself: it's in a pull request of mine that hasn't been merged yet. Sorry.

>I could override getModules() but not getStage().

You can still set Stage in the web.xml.

>But even so, I still have do add jersey specific things to web.xml. With jersey-guice is as simple as serve("/rest/*").with(GuiceContainer.class);

With Jersey, you don't put *anything* in the web.xml? Even in a non-JEE context?

To be honest, I'm not using Jersey because, like 99% of the java.net projects that I try out, either I can't figure out from the docs how it works or the site is down.

Mwanji

Filipe Sousa

unread,
Jun 5, 2013, 5:00:02 PM6/5/13
to google...@googlegroups.com
The only thing needed is the GuiceFilter and a listener. Take a look at this random project in github

I have been looking in the last few days for a REST framework that integrates with guice. So far jersey is the easiest. I have only a few issues with an old framework that uses an older version of jersey that do not mix well. Now I'm trying Restlet.

Cédric Beust ♔

unread,
Jun 5, 2013, 5:03:52 PM6/5/13
to google...@googlegroups.com
Same here, we use Guice + Jersey, no complaints.


-- 
Cédric



--

Richard Mutezintare

unread,
Jun 5, 2013, 9:37:29 PM6/5/13
to google...@googlegroups.com
I agree, Guice + Jersey is pretty straightforward. 

Moandji Ezana

unread,
Jun 6, 2013, 4:54:48 AM6/6/13
to google...@googlegroups.com


On Jun 5, 2013 11:00 PM, "Filipe Sousa" <nat...@gmail.com> wrote:
>
> The only thing needed is the GuiceFilter and a listener. Take a look at this random project in github
> https://github.com/robinboehm/guice-jersey

That's quite nice.

Thanks for pointing out the Stage configuration. I'll see if that can be made overrideable.

With that, Resteasy-Guice config should be similar: add the Resteasy filter and a Listener.

Mwanji

Filipe Sousa

unread,
Jun 6, 2013, 5:33:55 AM6/6/13
to google...@googlegroups.com
Hi

Someone in another project is using restlet 3.0 with guice without restlet specifics in web.xml:

Thanks.

Moandji Ezana

unread,
Jun 6, 2013, 6:44:50 AM6/6/13
to google...@googlegroups.com

Instead of a few lines in web.xml, they have a bunch of code copied from Resteasy internals. I don't think that's an improvement.

Why is it so important to not have any web framework config in web.xml, but it's OK to have DI config in there?

Mwanji

--

Filipe Sousa

unread,
Jun 6, 2013, 7:00:54 AM6/6/13
to google...@googlegroups.com

"Guice Servlet provides a complete story for use in web applications and servlet containers. Guice's servlet extensions allow you to completely eliminate web.xml from your servlet application and take advantage of type-safe, idiomatic Java configuration of your servlet and filter components."

Thomas Broyer

unread,
Jun 11, 2013, 8:47:51 AM6/11/13
to google...@googlegroups.com
Am I missing something or each and every resource or provider has to be explicitly bound in the Guice Module?
Couldn't it intercept each and every resource or provider creation instead? (looks like what the CDI integration is doing, and what Ross Judson is describing below)

Moandji Ezana

unread,
Jun 11, 2013, 2:49:13 PM6/11/13
to google...@googlegroups.com
On Tue, Jun 11, 2013 at 2:47 PM, Thomas Broyer <t.br...@gmail.com> wrote:
Am I missing something or each and every resource or provider has to be explicitly bound in the Guice Module?

No, you aren't missing anything. It doesn't seem very different from the standard JAX-RS system, where an Application instance provides resources and providers.
 
Couldn't it intercept each and every resource or provider creation instead? (looks like what the CDI integration is doing, and what Ross Judson is describing below)

If it obsoletes declaring Resources and Providers manually and plays well with a manual Guice Module, it could be interesting. Ross, could you go into a bit more detail about how your implementation works? I've looked at the CDI integration briefly and will look at it some more. Bill Burke has declared that he wants to put out the final release in a week, and I can't guarantee that I'll have time to work on this within such a short time frame.

One question I do have is, if Providers are automatically registered, how do you exclude the ones that are on the classpath, but that you don't actually want?

Mwanji

Thomas Broyer

unread,
Jun 11, 2013, 5:06:46 PM6/11/13
to google...@googlegroups.com
Just to make things clearer: what I want is to be able to @Inject dependencies (services) into my resources and providers that are provided by my Application (or classpath scanning). See § 10.2.7 of JAX-RS 2.0 (JSR 339)
I don't want/need to use Guice bindings to provide resources/providers (which is actually what you do here, and what seems to be done by resteasy-spring too), though I wouldn't mind if it were done in addition to the above.
Also, in case it changes anything, I'm not running in a servlet container (I'm using resteasy-netty).
Reply all
Reply to author
Forward
0 new messages