question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GuiceResteasyBootstrapServletContextListener Guice is initialized before resteasy boots up

See original GitHub issue

Reference: https://stackoverflow.com/questions/61330943/guice-resteasy-jaxrs-integration

I am loading Resteasy Resources through subclass of javax.ws.rs.Application I am using GuiceResteasyBootstrapServletContextListener to initialize Guice So I expect the resteasybootstrap to finish loading before Guice is initialized.

in my module class, I am trying to get all singletons of javax.ws.rs.Application and injectMembers to it.

            MyWebApplication.get().getSingletons().forEach(api -> requestInjection(api));

I found out that MyWebApplication is not yet loaded when the control reaches my Module class as a result I encounter Nullpointer.

Is there any way to wait till the rest resources are loaded to resteasy and then initiate the Guice Injection?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
GedMarccommented, Apr 23, 2020

I really hope I do not get put onto your project - or get your architects on any of mine. ever

But here is the working commit for the servlet module rest easy - This is truly and deeply the wrong path you are taking, especially for starting a new project, and especially that it is a POC. I strongly advise you reconsider your position, and if need be speak to your powers that be and give them the biggest slap across their face that you can possibly manage, maybe use a cricket bat.

NB FOR EVERYONE ELSE!!! - THIS IS THE WRONG IMPLEMENTATION TO GO WITH, DO NOT DO THIS. YOU HAVE BEEN WARNED. YOU WILL NOT GET ANY PERFORMANCE OR ANY BENIFIT AT ALL. YOU WILL MAKE YOUR LIFE HELL IN THE NEAR FUTURE.

@Override
	public void onBind()
	{
		install(new JaxrsModule());
		bind(GuiceResteasyBootstrapServletContextListener.class).in(Singleton.class);
		bind(HttpServletDispatcher.class)
		      .in(Singleton.class);

		if (path == null)
		{
			module.serve$("/*")
			      .with(HttpServletDispatcher.class);
		}
		else
		{
			final Map<String, String> initParams =
					ImmutableMap.of("resteasy.servlet.mapping.prefix", path);
			module.serve$(path + "/*")
			      .with(HttpServletDispatcher.class, initParams);
		}
	}

Then you have to register the handler in your web container, i used undertow

public class RestEasyUndertowServletExtension
		implements ServletExtension
{
	@SuppressWarnings("unchecked")
	@Override
	public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext)
	{
		LogFactory.getLog("RestEasyUndertowRegistration")
		          .config("Registering Rest Easy Servlet Context Listener");
		InstanceFactory guiceInstanceFactory = new ImmediateInstanceFactory<>(GuiceContext.get(GuiceResteasyBootstrapServletContextListener.class));
		deploymentInfo.addListener(new ListenerInfo(GuiceResteasyBootstrapServletContextListener.class, guiceInstanceFactory));
	}
}

https://github.com/GedMarc/GuicedRestServices/commit/278127f1a3f4d8bf4a013ec1104b68ce245edf7b#diff-fcf278d175642d1cc5e1b9a77080bf58R31

I truly hope you fight back, and i will never work with your company, even by gunpoint.

0reactions
deepak229commented, Apr 23, 2020

Closing this issue as per the above comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RESTEasy JAX-RS - JBoss.org
The initialization of RESTEasy can be performed within a ServletContextListener instead of within the Servlet. You may need this if you are writing...
Read more >
Resteasy with Guice configuration issues - Stack Overflow
I'm new to both Resteasy and Guice, but I'm having problems getting the simple tutorial to work. Here are my relevant files.
Read more >
RESTEasy Reference Guide JBoss Enterprise Application ...
A reference guide to RESTEasy for use with JBoss Enterprise Application Platform 5 ... The ResteasyBootstrap listener initializes some of RESTEasy's basic ...
Read more >
io.undertow.servlet.api.ListenerInfo.<init> java code examples
How to use ... ListenerInfo.<init> (Showing top 20 results out of 315) ... addListener(new ListenerInfo(GuiceResteasyBootstrapServletContextListener.class, ...
Read more >
RESTEasy Reference Guide - UserManual.wiki
Tighter integration with JBoss Application Server is also available to make ... Resteasy /* The Resteasy servlet is responsible for initializing some basic ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found