@Inject ServletContext in @PushEndpoint Annotated class

UI Components for JSF
Post Reply
Miguel Cubells
Posts: 99
Joined: 25 Feb 2015, 11:02

12 May 2015, 04:41

Hi all.

I have seen in some examples, like the Chat Application Showcase, or even in books ( like PrimeFaces Blueprints ), that it should be possible to inject the ServletContext, or the HttpServletRequest, in a PrimeFaces Java Class annotated with @PushEndpoint.

Just like this:

Code: Select all

@PushEndpoint("/{room}/{user}")
@Singleton
public class ChatResource {
   ...
   @Inject
   private ServletContext ctx;
  ...
}
and then use it in the @OnOpen or @OnClose methods.

Code: Select all

@OnClose
public void onClose(RemoteEndpoint r, EventBus eventBus) {
     ChatUsers users= (ChatUsers) ctx.getAttribute("chatUsers");
     ...
However, in the application I'm developing, the injection of the ServletContext is always NULL, and nothing can be retrieved.
The Java class is located in a WAR file ( so the ServletContext should be available ).

I am using WildFly 8.2.0.Final.
The problem happens with both PF 5.1 + Atmosphere 2.2.6 , or PF 5.2 + Atmosphere 2.3.0

Does anyone know how can the ServletContext be injected in a @PushEndpoint annotated class ??
At the end, what I want is to access a parameter in the Request that contains an Apache Shiro subject, injected by the Atmosphere ShiroInterceptor.

Thanks a lot in advance !!

Miguel Cubells
PrimeFaces 6.1 / PF Extensions 6.1.1 / Atmosphere 2.4.3
Apache Mojarra 2.2.13+
WildFly 10.1.0.Final

Miguel Cubells
Posts: 99
Joined: 25 Feb 2015, 11:02

13 May 2015, 03:51

Actually we found that there is a way to get the ServletContext without trying to inject it, by using

Code: Select all

ServletContext servletContext = ServletContextFactory.getDefault().getServletContext();
which is an Atmosphere utility method.

However, we just found that what we really need is to get access to the HttpServletRequest everytime the @PushEndpoint bean is instantiated.

We tried the solution adopted in the below StackOverflow question:
http://stackoverflow.com/questions/1818 ... coped-bean

because we are using JEE 6 , not JEE 7.

But no matter how do we try to get access to the HttpServletRequest, it is always NULL inside the @PushEndpoint class.

Is there a way to get access to the HttpServletRequest in the @PushEndpoint class ?
Furthermore, is there a way to access the AtmosphereResource or AtmosphereRequest directly ??
From the RemoteEndpoint parameter of the @OnOpen or @OnClose methods, there is no way to get access to them.

Any help would be greatly appreciated !

Miguel
PrimeFaces 6.1 / PF Extensions 6.1.1 / Atmosphere 2.4.3
Apache Mojarra 2.2.13+
WildFly 10.1.0.Final

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

06 Jun 2015, 04:09

Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 33 guests