java - Atmosphere broadcasts don't reach client when running in Tomcat -



java - Atmosphere broadcasts don't reach client when running in Tomcat -

substantial update below (october 15, 2014)

========== original posting ===================

i have notification service webapp using atmosphere , jersey. trying run in tomcat on linux, , have run problem. (note works fine when running in tomcat-embedded-within-eclipse, it's possible it's tomcat configuration problem.)

the problem broadcast messages seem queued up, or buffered, , not delivered client until shut downwards tomcat. @ point received client @ once.

i have tried number of things found in various postings seek solve this, efforts scattershot because don't know causing problem:

i have tried explicitly using tomcat's nio protocol. i have tried explicitly disabling text , binary buffering, , have queued plenty responses trigger flush if buffering cause. i tried running in tomcat 8 instead (but had different unrelated problems.) i have added atmosphere-runtime-native, atmosphere-compat-jbossweb, , atmosphere-compat-tomcat dependencies.

none of these has changed behavior of service. and, again, seems work fine when running in eclipse.

environment: ubuntu 14.04 lts. tomcat 7.0.54. atmosphere 2.1.5. client, i'm using telnet @ moment.

(this code bit more complicated samples because have number of different routes want support, , i'm using method proposed this answer, seems working nicely. i'm returning notification objects rather strings. seems working fine. i've stripped out of authentication stuff clarity.)

pom.xml:

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.clearcaptial</groupid> <artifactid>notifications</artifactid> <packaging>war</packaging> <version>0.0.1-snapshot</version> <name>notifications maven webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupid>org.atmosphere</groupid> <artifactid>atmosphere-jersey</artifactid> <version>2.1.5</version> </dependency> <dependency> <groupid>com.sun.jersey</groupid> <artifactid>jersey-json</artifactid> <version>1.17.1</version> </dependency> <dependency> <groupid>org.atmosphere</groupid> <artifactid>atmosphere-runtime-native</artifactid> <version>2.1.5</version> </dependency> <dependency> <groupid>org.atmosphere</groupid> <artifactid>atmosphere-compat-jbossweb</artifactid> <version>2.0.1</version> </dependency> <dependency> <groupid>org.atmosphere</groupid> <artifactid>atmosphere-compat-tomcat</artifactid> <version>2.0.1</version> </dependency> </dependencies> <build> <finalname>notifications</finalname> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>

web.xml:

<?xml version="1.0" encoding="utf-8"?> <!-- web.xml file not required when using servlet 3.0 container, see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:j2ee="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3.0.xsd"> <servlet> <servlet-name>atmosphereservlet</servlet-name> <servlet-class>org.atmosphere.cpr.atmosphereservlet</servlet-class> <load-on-startup>1</load-on-startup> <async-supported>true</async-supported> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>com.clearcapital.notifications</param-value> </init-param> <init-param> <param-name>com.sun.jersey.api.json.pojomappingfeature</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>org.atmosphere.usewebsocketandservlet3</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>atmosphereservlet</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>

from validationsrouter.java:

@path("/validations") public class validationsrouter { @context private atmosphereresource atmosphereresource; @get public suspendresponse<validationnotification> subscribe(@context uriinfo uri) throws urisyntaxexception, namingexception, ioexception { homecoming new validationsresource().subscribe(uri, atmosphereresource); } @broadcast @post @consumes(mediatype.application_json) @produces(mediatype.application_json) public broadcastable broadcast(validationnotification message, @context uriinfo uri) { homecoming new validationsresource().broadcast(message, uri); } }

from validationsresource.java:

public class validationsresource extends resourcebase<validationnotification> { // bunch of authentication stuff omitted clarity. }

from resourcebase.java:

public abstract class resourcebase<t> { public suspendresponse<t> subscribe(uriinfo uri, atmosphereresource atmosphereresource) throws urisyntaxexception, namingexception, ioexception { broadcaster mybroadcaster = broadcasterfactory.getdefault().lookup(uri.getpath(), true); homecoming new suspendresponse.suspendresponsebuilder<t>().broadcaster(mybroadcaster).outputcomments(true) .addlistener(new eventslogger()).type(mediatype.application_json_type).build(); } public broadcastable broadcast(t message, uriinfo uri) { broadcaster mybroadcaster = broadcasterfactory.getdefault().lookup(uri.getpath(), true); homecoming new broadcastable(message, "", mybroadcaster); } }

============ end of original post ======================

updated oct 15, 2014:

i've come problem after time on different project. after updating project new version of atmosphere (2.2.3), find no difference in behavior. still case that, when running service on different computer client running on, atmosphere broadcasts not received client until tomcat shuts down. when running client , service on same computer, works expected.

so, determine problem lies, have started using 1 of atmosphere sample apps in testing. using jersey-pubsub sample app (with minor updates compile), because that's 1 that's closest i'm trying do. have created brand new server environment run sample app, minimize variables based on linux configuration. here new steps -- maybe can replicate behavior.

to new server tomcat7 installed (i'm using vagrant , virtualbox these tests):

host$ vagrant init ubuntu/trusty64 host$ nano vagrantfile

change network config known ip: config.vm.network :private_network, ip: "10.1.1.2"

host$ vagrant box add together https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/1/providers/virtualbox.box host$ vagrant ------------------ vagrant$ sudo apt-get update vagrant$ sudo apt-get upgrade vagrant$ sudo apt-get install tomcat7

following these steps, ended tomcat 7.0.52, , ubuntu 14.04

i have re-create of jersey-pubsub project (without parent project etc.) build using

host$ mvn clean install

and deploy

host$ cp target/jersey-pubsub.war ../../vagrants/trusty64/ vagrant$ sudo cp /vagrant/jersey-pubsub.war /var/lib/tomcat7/webapps

i can test using telnet, example:

host$ telnet 10.1.1.2 8080 <return> /jersey-pubsub/pubsub/foo http/1.0 <return> <return>

at point, telnet continues wait data. in tomcat server log, can see entry:

20:33:55.805 [http-bio-8080-exec-1] info o.a.samples.pubsub.eventslogger - onsuspend(): 10.1.1.1:59357

i send post request server. i'm using postman this, don't think matters.

post http://10.1.1.2:8080/jersey-pubsub/pubsub/foo accept: text/html content-type: application/x-www-form-urlencoded message: <html><body><p>this test!</p></body></html>

in server log can see server believes broadcast message:

20:34:06.990 [atmosphere-shared-asyncop-0] info o.a.samples.pubsub.eventslogger - onbroadcast(): <html><body><p>this test!</p></body></html>

but nil shows in telnet client. can repeat advertisement infinitum , see no result, until shut downwards tomcat, @ point of broadcast messages received telnet immediately.

in contrast, if deploy service on tomcat instance running on host machine, or if run telnet within vagrant instance, works expected:

vagrant$ telnet localhost 8080 <return> /jersey-pubsub/pubsub/foo http/1.0 <return> <return>

if send same post request, receive broadcast message in telnet. behavior seems if service , client not on same computer, network traffic held while tomcat running.

here's source code re-create of jersey-pubsub sample, plenty changes compile , build standalone project.

eventslogger.java: (unchanged except remove @override in 2 places eclipse stop complaining)

fileresource.java: (unchanged)

jerseypubsub.java: (unchanged)

web.xml: (unchanged)

pom.xml (modified build standalone, without reference parent pom):

<project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelversion>4.0.0</modelversion> <groupid>org.atmosphere.samples</groupid> <artifactid>atmosphere-jersey-pubsub</artifactid> <packaging>war</packaging> <version>0.0.1-snapshot</version> <name>atmosphere-jersey-pubsub</name> <url>http://maven.apache.org</url> <properties> <atmosphere-version>2.2.3</atmosphere-version> <client-version>2.2.3</client-version> <logback-version>1.0.13</logback-version> </properties> <repositories> <repository> <id>oss.sonatype.org</id> <url>http://oss.sonatype.org/content/repositories/releases</url> </repository> <repository> <id>oss.sonatype.org-snapshot</id> <url>http://oss.sonatype.org/content/repositories/snapshots</url> </repository> <!-- <repository> <id>scala-tools.org</id> <name>scala-tools maven2 repository</name> <url>http://scala-tools.org/repo-releases</url> </repository> --> <repository> <id>jboss</id> <url>https://repository.jboss.org/nexus/content/groups/public/</url> </repository> <repository> <id>codehaus</id> <name>repository.codehaus.org</name> <url>http://repository.codehaus.org</url> </repository> <repository> <id>codehaus-snapshots</id> <url>http://snapshots.repository.codehaus.org</url> </repository> <repository> <id>maven.java.net</id> <url>https://maven.java.net/content/groups/public/</url> </repository> </repositories> <dependencymanagement> <dependencies> <dependency> <groupid>org.atmosphere</groupid> <artifactid>atmosphere-runtime</artifactid> <version>${atmosphere-version}</version> </dependency> <dependency> <groupid>org.apache.geronimo.specs</groupid> <artifactid>geronimo-servlet_3.0_spec</artifactid> <version>1.0</version> <scope>provided</scope> </dependency> <dependency> <groupid>ch.qos.logback</groupid> <artifactid>logback-classic</artifactid> <version>${logback-version}</version> </dependency> </dependencies> </dependencymanagement> <dependencies> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupid>org.atmosphere.client</groupid> <artifactid>javascript</artifactid> <version>${client-version}</version> <type>war</type> </dependency> <dependency> <groupid>org.atmosphere</groupid> <artifactid>atmosphere-jersey</artifactid> <version>${atmosphere-version}</version> </dependency> <dependency> <groupid>org.apache.geronimo.specs</groupid> <artifactid>geronimo-servlet_3.0_spec</artifactid> </dependency> <dependency> <groupid>ch.qos.logback</groupid> <artifactid>logback-classic</artifactid> </dependency> <dependency> <groupid>ch.qos.logback</groupid> <artifactid>logback-core</artifactid> <version>${logback-version}</version> </dependency> </dependencies> <build> <finalname>jersey-pubsub</finalname> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>

are running tomcat behind apache proxy? is apache running http 1.1? some more apache things seek here

java tomcat jersey atmosphere

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -