-
-
Notifications
You must be signed in to change notification settings - Fork 754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't get AtmosphereFramework from servlet context on JBoss EAP 6.1 #1716
Comments
So you do you need exactly? We need to improve the documentation? |
In future, for properly interaction with atmosphere, I need getting AtmosphereFramework from servlet context as described in document. |
JBoss EAP is using an old version of Servlet (2.5) I suspect. Can you confirm? That's the issue |
As described in p.1.2.1.1 official documentation (https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Application_Platform/6.1/pdf/Development_Guide/JBoss_Enterprise_Application_Platform-6.1-Development_Guide-en-US.pdf): The my web.xml specified as standard for Servlet 3.0: <web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true"
id="WSCallAdmin">
...
</web-app> My atmosphere app is work correctly, except only impossibility getting AtmosphereFramework from servlet context. |
OK, but how do you try to access it? Are you starting Atmosphere the way it is described in the document? |
In web.xml: <servlet>
<servlet-name>AtmosphereServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<async-supported>true</async-supported>
<init-param>
<param-name>org.atmosphere.useNative</param-name>
<!-- false is default. In 2.2.x this property is ignored. The native mode requires some
additional libs (atmosphere-runtime-native.jar, atmosphere-compat-xxx.jar) and settings
for JBoss (Tomcat) container. See:
https://github.com/Atmosphere/atmosphere/wiki/Installing-AtmosphereServlet-with-or-without-native-support -->
<param-value>false</param-value>
</init-param>
<!-- For JBoss: ClasspathResourceConfig -->
<init-param>
<param-name>com.sun.jersey.config.property.resourceConfigClass</param-name>
<param-value>com.sun.jersey.api.core.ClasspathResourceConfig</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.config.property.classpath</param-name>
<param-value>/WEB-INF/classes/ru/mda/calladmin/controller</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet> in Java code: import org.atmosphere.util.ServletContextFactory;
...
final ServletContext ctx = ServletContextFactory.getDefault().getServletContext();
...
AtmosphereFramework framework = (AtmosphereFramework) ctx.getAttribute("AtmosphereServlet");
BroadcasterFactory broadcasterFactory = framework.getBroadcasterFactory(); // NPE!
... |
Which document to read?
On pure Tomcat 7 the code from above is worked. On JBoss EAP 6.1 is not. |
Quote in post above from this wiki. |
Ok fair enough. It seems to be a bug with JBoss. But don't use the |
FYI.
|
@master-den Please open another issue for the WELD. Make sure you are using 2.3.0-SNAPSHOT |
A @Producer works in eap 6.3. I expect it would work in eap 6.1 as well. Does it have to be more complicated? package in.your.package;
// don't forget the beans.xml file!
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.servlet.ServletContext;
import org.atmosphere.cpr.AtmosphereFramework;
import org.atmosphere.cpr.BroadcasterFactory;
import org.atmosphere.util.ServletContextFactory;
@ApplicationScoped
public class Producer {
// TODO: cache the framework in a static?
@Produces
public BroadcasterFactory getBroadcastFactory() {
// TODO: replace deprecated getServletContext()....with what?
ServletContext servletContext = ServletContextFactory.getDefault().getServletContext();
AtmosphereFramework framework = (AtmosphereFramework) servletContext.getAttribute("AtmosphereServlet");
BroadcasterFactory broadcasterFactory = framework.getBroadcasterFactory();
return broadcasterFactory;
}
} |
@jjfraney Not following you here. What do you means? |
Ok, I googled how to cdi @Inject a BrodcasterFactory and came here. Read the discussion about how it does not work due to bug in Weld. Find it hard to believe (Weld is reference implementation of CDI). Anyway, I could not find a sample in any other google result. I only want to cut-n-paste so not to spend too much time, but alas. So, I played around. I took the time to figure out how to build a BroadcasterFactory and wrote it as a cdi @Producer. Now, I can @Inject BroadcasterFactory. I thought others would like to know. I don't think an issue raised in jboss against Weld should block someone from injecting a BroadcasterFactory. |
Yes. Its not the same. I have a separate rest service. Its not an atmosphere @managedservice. It is just a jax-rs compliant rest service. When a POST method arrives, I want to broadcast, and want to @Inject BroadcasterFactory. This pages seems to imply it just works, but it didn't: https://github.com/Atmosphere/atmosphere/wiki/Getting-BroadcasterFactory-and-AtmosphereResourceFactory-with-2.2-and-newer Then, I found the sample you refer to. I added atmosphere-cdi to the project. I got an 'AbstractMethodException' due to a method missing from CDIObjectFactory. Obviously, I got versioning screwed up, but didn't have patience to resolve. I looked at the Object Factory code and tried to imagine how it could work. I'm not an expert, but I could not find a hook in CDI implementation such that the Factory would be used to resolve beans. I think maybe the cdi bean resolver runs at deploy time and maybe the Factory is not available then. Also, the lack of a beans.xml file in the atmosphere jar kind of drops my confidence that it can work: In CDI, the Factory pattern is implemented with @Producer and without a beans.xml file, there exists NO operative @producers in the atmosphere-cdi jar. Further, if the solution is provided by one of my @Producer, then, I think its simpler than using the atmosphere provided CDIObjectFactory, atmosphere-cdi and then trying to get it all to work. Is there some disadvantage to using a @Producer in my app? Is there a fault in the code above? |
@jjfraney There is a bean.xml in that sample. I've tested with 12:02:31,773 INFO [org.wildfly.extension.undertow] (MSC service thread 1-2) JBAS017534: Registered web context: /atmosphere-chat-cdi
12:02:31,802 INFO [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "atmosphere-chat-cdi.war" (runtime-name : "atmosphere-chat-cdi.war")
12:02:32,053 INFO [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
12:02:32,054 INFO [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
12:02:32,054 INFO [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.2.0.Final "Tweek" started in 4905ms - Started 282 of 336 services (92 services are lazy, passive or on-demand)
12:02:32,174 INFO [org.atmosphere.cpr.AtmosphereFramework] (Thread-81) Latest version of Atmosphere's JavaScript Client 2.2.6
12:02:32,174 INFO [org.atmosphere.cpr.AtmosphereFramework] (Thread-81)
Current version of Atmosphere 2.3.0-SNAPSHOT
Newest version of Atmosphere available 2.2.4
12:02:53,112 INFO [org.atmosphere.samples.chat.CDIChat] (default task-14) Browser 15c6aba9-ce06-4098-92e3-ee1923f2c17e connected.
12:02:53,113 INFO [org.atmosphere.samples.chat.CDIChat] (default task-14) Injected Factory org.atmosphere.cpr.DefaultBroadcasterFactory connected.
12:04:53,116 INFO [org.atmosphere.samples.chat.CDIChat] (default task-15) Browser 15c6aba9-ce06-4098-92e3-ee1923f2c17e closed the connection
12:04:53,139 INFO [org.atmosphere.samples.chat.CDIChat] (default task-16) null just send is inactive and closed the connection. Will reconnect in 5000
12:04:58,117 INFO [org.atmosphere.samples.chat.CDIChat] (default task-17) Browser 15c6aba9-ce06-4098-92e3-ee1923f2c17e connected.
12:04:58,117 INFO [org.atmosphere.samples.chat.CDIChat] (default task-17) Injected Factory org.atmosphere.cpr.DefaultBroadcasterFactory connected.
12:05:57,511 INFO [org.atmosphere.samples.chat.CDIChat] (default task-18) dasds just send dasds
12:05:57,985 INFO [org.atmosphere.samples.chat.CDIChat] (default task-19) dasds just send dsa |
Can someone provide a solution to the original problem: how to get AtmosphereFramework in 2.2.x without using servlet context and AtmosphereResource?
|
@rooseveltlai what is the |
I also encountered a similar problem. I added beans.xml but the problem remains unresolved. I use Red Hat JBoss Enterprise Application Platform - Version 6.3.0.GA |
Hi!
Version Atmosphere is 2.2.1 - 2.3.0-snapshot, JDK 7, JBoss EAP 6.1, Windows Server 2008R2.
I need getting BroadcasterFactory. I’m getting it as described in p.Servlet in
https://github.com/Atmosphere/atmosphere/wiki/Getting-BroadcasterFactory-and-AtmosphereResourceFactory-with-2.2-and-newer
But, on JBoss EAP 6.1 (BIO connector) in servlet context not contained AtmosphereFramework.
The AtmosphereServlet configured as described in article by link above for getting it from servlet context.
However, in servlet context I found a broadcaster factory, which should be getting from atmosphere framework. In result, I'm getting BroadcasterFactory directly from servlet context.
The text was updated successfully, but these errors were encountered: