<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>6312</title>
	<atom:link href="http://jfarcand.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jfarcand.wordpress.com</link>
	<description>You are not very near, but a, you are not very far non plus</description>
	<lastBuildDate>Wed, 11 Jan 2012 21:54:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='jfarcand.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>6312</title>
		<link>http://jfarcand.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://jfarcand.wordpress.com/osd.xml" title="6312" />
	<atom:link rel='hub' href='http://jfarcand.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Writing WebSocket Clients using AsyncHttpClient</title>
		<link>http://jfarcand.wordpress.com/2011/12/21/writing-websocket-clients-using-asynchttpclient/</link>
		<comments>http://jfarcand.wordpress.com/2011/12/21/writing-websocket-clients-using-asynchttpclient/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 15:54:27 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Async Http client]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=942</guid>
		<description><![CDATA[The AsyncHttpClient version newly released 1.7.0 now supports WebSocket. Both Netty and Grizzly provider supports the latest version of the specification. Like HTTP support with AHC, WebSoket is quite simple. Starting with AHC 1.7, a new interface called UpgradeHandler is available to the client so any kind of protocol can be used. You can event [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=942&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="https://github.com/sonatype/async-http-client">AsyncHttpClient</a> version <a href="http://is.gd/bhOTtR">newly released 1.7.0</a> now supports <a href="http://en.wikipedia.org/wiki/WebSocket">WebSocket</a>. Both <a href="http://netty.io/">Netty</a> and <a href="http://grizzly.java.net/">Grizzly</a> provider supports the latest version of the specification.</p>
<p><a href="http://jfarcand.files.wordpress.com/2011/12/untitled-2.jpg"><img class="alignnone  wp-image-952" title="Untitled 2" src="http://jfarcand.files.wordpress.com/2011/12/untitled-2.jpg?w=743&#038;h=557" alt="" width="743" height="557" /></a></p>
<p>Like HTTP support with AHC, WebSoket is quite simple. Starting with AHC 1.7, a new interface called <a href="https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/UpgradeHandler.java#L21">UpgradeHandler</a> is available to the client so any kind of protocol can be used. You can event replace the actual WebSocket implementation with your in case you don&#8217;t like mine <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<pre>public interface UpgradeHandler&lt;T&gt; {

    /**
     * If the HTTP Upgrade succeed (response's status code equals 101),
     * the {@link AsyncHttpProvider} will invoke that
     * method
     *
     * @param t an Upgradable entity
     */
    void <span style="color:#ff9900;">onSuccess</span>(T t);

    /**
     * If the upgrade fail.
     * @param t a {@link Throwable}
     */
    void <span style="color:#ff9900;">onFailure</span>(Throwable t);</pre>
<p>For WebSocket, I wrote a simple one called <a href="https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/websocket/WebSocketUpgradeHandler.java#L27">WebSocketUpgradeHandler</a> which extends the usual <a href="https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/AsyncHandler.java#L45">AsyncHandler</a> (always required with AHC) and UpgradeHandler. The interesting part is the WebSocketUpgradeHandler.Builder, which allow you to add listeners and WebSocket properties:</p>
<pre>        /**
         * Add a {@link WebSocketListener} that
         * will be added to the {@link WebSocket}
         *
         * @param listener a {@link WebSocketListener}
         * @return this
         */
        public Builder <span style="color:#ff9900;">addWebSocketListener</span>(<a href="https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/websocket/WebSocketByteListener.java">WebSocketListener</a> listener) {
            l.add(listener);
            return this;
        }

        /**
         * Remove a {@link WebSocketListener}
         *
         * @param listener a {@link WebSocketListener}
         * @return this
         */
        public Builder <span style="color:#ff9900;">removeWebSocketListener</span>(WebSocketListener listener) {
            l.remove(listener);
            return this;
        }

        /**
         * Set the WebSocket protocol.
         *
         * @param protocol the WebSocket protocol.
         * @return this
         */
        public Builder <span style="color:#ff9900;">setProtocol</span>(String protocol) {
            this.protocol = protocol;
            return this;
        }

        /**
         * Set the max size of the WebSocket byte message that will be sent.
         *
         * @param maxByteSize max size of the WebSocket byte message
         * @return this
         */
        public Builder <span style="color:#ff9900;">setMaxByteSize</span>(long maxByteSize) {
            this.maxByteSize = maxByteSize;
            return this;
        }

        /**
         * Set the max size of the WebSocket text message that will be sent.
         *
         * @param maxTextSize max size of the WebSocket byte message
         * @return this
         */
        public Builder <span style="color:#ff9900;">setMaxTextSize</span>(long maxTextSize) {
            this.maxTextSize = maxTextSize;
            return this;
        }

        /**
         * Build a {@link WebSocketUpgradeHandler}
         * @return a {@link WebSocketUpgradeHandler}
         */
        public WebSocketUpgradeHandler <strong><span style="color:#ff9900;">build</span></strong>() {
            return new WebSocketUpgradeHandler(this);
        }</pre>
<p>You can add several type of listeners like <a href="https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/AsyncHandler.java#L45tWebSocketText">WebSocketTextListener</a>, <a href="https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/AsyncHandler.java#L45tWebSocketText">WebSocketByteListener</a>, etc. To create a <a href="https://github.com/sonatype/async-http-client/blob/master/src/main/java/com/ning/http/client/AsyncHandler.java#L45tWebSocketText">WebSocket</a>, you just need to do:</p>
<pre>        AsyncHttpClient c = new AsyncHttpClient();
           // or new AsyncHttpClient(new <strong>GrizzlyAsyncHttpprovider</strong>(config))

        WebSocket websocket = c.prepareGet("ws://something:port)
                .execute(
                  new WebSocketUpgradeHandler.Builder().addWebSocketListener(
                     new <span style="color:#ff9900;">WebSocketByteListener</span>() {

                    @Override
                    public void <span style="color:#ff9900;">onOpen</span>(WebSocket websocket) {
                    }

                    @Override
                    public void <span style="color:#ff9900;">onClose</span>(WebSocket websocket) {
                    }

                    @Override
                    public void <span style="color:#ff9900;">onError</span>(Throwable t) {
                    }

                    @Override
                    public void <span style="color:#ff9900;">onMessage</span>(byte[] message) {
                    }

                    @Override
                    public void <span style="color:#ff9900;">onFragment</span>(byte[] fragment, boolean last) {
                    }
                }).build()).get();</pre>
<p>The AHC Future returned is a WebSocket, and it is returned as soon as the handshake is successful. The WebSocket API is also simple:</p>
<pre>public interface WebSocket {

    /**
     * Sen a byte message.
     * @param message a byte message
     * @return this
     */
    WebSocket <span style="color:#ff9900;">sendMessage</span>(byte[] message);

    /**
     * Send a text message
     * @param message a text message
     * @return this.
     */
    WebSocket <span style="color:#ff9900;">sendTextMessage</span>(String message);

    /**
     * Add a {@link WebSocketListener}
     * @param l a {@link WebSocketListener}
     * @return this
     */
    WebSocket <span style="color:#ff9900;">addMessageListener</span>(WebSocketListener l);

    /**
     * Close the WebSocket.
     */
    void <span style="color:#ff9900;">close</span>();
}</pre>
<p>Conclusion, writing WebSocket is super simple!!! Here is a fully asynchronous echo client</p>
<pre>        WebSocket websocket = c.prepareGet("ws://localhost:80")
                .execute(
                  new WebSocketUpgradeHandler.Builder()
                    .addWebSocketListener(new <span style="color:#ff9900;">WebSocketTextListener</span>() {

                    @Override
                    public void <span style="color:#ff9900;">onMessage</span>(String message) {
                        System.out.println(message);
                    }

                    @Override
                    public void <span style="color:#ff9900;">onFragment</span>(String fragment, boolean last) {
                    }

                    @Override
                    public void <span style="color:#ff9900;">onOpen</span>(WebSocket websocket) {
                        websocket
                          .sendTextMessage("ECHO")
                          .sendTextMessage("ECHO");
                    }

                    @Override
                    public void <span style="color:#ff9900;">onClose</span>(WebSocket websocket) {
                    }

                    @Override
                    public void <span style="color:#ff9900;">onError</span>(Throwable t) {
                        t.printStackTrace();

                    }
                }).build()).get();</pre>
<p>For any questions you can use our <a href="https://groups.google.com/forum/#!forum/asynchttpclient">Google Group</a>, irc.freenode.net #asynchttpclient or use <a href="http://twitter.com/jfarcand">Twitter</a> to reach me! You can <a href="http://github.com/sonatype/async-http-client">checkout the code</a> on Github as well!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/942/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/942/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/942/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/942/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/942/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/942/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/942/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/942/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/942/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/942/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/942/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/942/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/942/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/942/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=942&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/12/21/writing-websocket-clients-using-asynchttpclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/12/untitled-2.jpg?w=300" medium="image">
			<media:title type="html">Untitled 2</media:title>
		</media:content>
	</item>
		<item>
		<title>Atmosphere 0.8: Jersey on Steroid, WebSocket Sub Protocol, Native WebSocket, JQuery Plugin CORS, REST over HTTP</title>
		<link>http://jfarcand.wordpress.com/2011/11/25/atmosphere-0-8-jersey-on-steroid-websocket-sub-protocol-native-websocket-jquery-plugin-cors-rest-over-http/</link>
		<comments>http://jfarcand.wordpress.com/2011/11/25/atmosphere-0-8-jersey-on-steroid-websocket-sub-protocol-native-websocket-jquery-plugin-cors-rest-over-http/#comments</comments>
		<pubDate>Fri, 25 Nov 2011 17:41:04 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=926</guid>
		<description><![CDATA[The Atmosphere Framework 0.8 version has been released. This is our biggest release ever! This blog will describe the new feature covered by this fantastic release. Jersey on Steroid with WebSocket The Jersey Framework can now be fully run on top of a WebSocket connection seamlessly. A single WebSocket connection can now be used to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=926&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="https://github.com/Atmosphere/atmosphere">Atmosphere Framework</a> 0.8 version <a href="http://groups.google.com/group/atmosphere-framework/browse_thread/thread/4700bb4068325495">has been released</a>. This is our biggest release ever! This blog will describe the new feature covered by this fantastic release.</p>
<p><a href="http://jfarcand.files.wordpress.com/2011/11/untitled1.jpg"><img class="alignnone  wp-image-936" title="Untitled" src="http://jfarcand.files.wordpress.com/2011/11/untitled1.jpg?w=620&#038;h=464" alt="" width="620" height="464" /></a></p>
<h2>Jersey on Steroid with WebSocket</h2>
<p>The <a href="http://jersey.java.net/">Jersey Framework</a> can now be fully run on top of a WebSocket connection seamlessly. A single WebSocket connection can now be used to invoke Jersey. That&#8217;s open the door to request pipeline and asynchronous processing of REST call transparently. This will be discussed soon in more details, but this feature is implemented via the new WebSocketProtocol API.</p>
<h2>Browser WebSocket Support</h2>
<p>Atmosphere fully support Opera, Firefox (MozWebSocket), Chrome, Safari and IE 10 Preview WebSocket transparently when used with the Atmosphere JQuery Plug In. Safari on iOS is also supported.</p>
<h2>Native WebSocket Support</h2>
<p>It is now possible to write native WebSocket application. A simple PubSub application can consist only of:</p>
<pre>    public AtmosphereRequest onMessage(WebSocket webSocket, String message) {
        AtmosphereResource r = (AtmosphereResource) webSocket.resource();
        Broadcaster b = lookupBroadcaster(r.getRequest().getPathInfo());

        b.broadcast(message);

        //Do not dispatch to another Container
        return null;
    }

    public void onOpen(WebSocket webSocket) {
        // Accept the handshake by suspending the response.
        AtmosphereResource r = (AtmosphereResource) webSocket.resource();
        Broadcaster b = lookupBroadcaster(r.getRequest().getPathInfo());
        r.setBroadcaster(b);
        r.addEventListener(new WebSocketEventListenerAdapter());

        // Keep Alive the WebSocket Connection Forever
        r.suspend(-1);
    }

    public void onClose(WebSocket webSocket) {
        webSocket.resource().resume();
    }

    public void onError(WebSocket webSocket,
                        WebSocketProcessor.WebSocketException t) {
        logger.error(t.getMessage() + " Status {} Message {}",
                     t.response().getStatus(),
                     t.response().getStatusMessage());
    }</pre>
<h2>WebSocket Sub Protocol Implementation Support</h2>
<p>Writing WebSocket sub protocol on top of a WebSocket connection is now extremely simple, thanks to the WebSocketProtocol API</p>
<pre>public interface WebSocketProtocol extends AsyncProtocol{

    /**
     * Allow an implementation to query the
     * AtmosphereConfig of init-param, etc.
     */
    void configure(AtmosphereServlet.AtmosphereConfig config);

    /**
     * Parse the WebSocket message, and delegate the processing
     * to the {@link org.atmosphere.cpr.AtmosphereServlet#cometSupport} or
     * to any existing technology. Invoking
     * {@link org.atmosphere.cpr.AtmosphereServlet#cometSupport} will
     * delegate the request processing
     * to the {@link org.atmosphere.cpr.AtmosphereHandler} implementation.
     * Returning null means this implementation will
     * handle itself the processing/dispatching of the WebSocket's request;
     * /
    AtmosphereRequest onMessage(WebSocket webSocket, String data);

    AtmosphereRequest onMessage(WebSocket webSocket, byte[] data, int offset, int length);

    /**
     * Invoked when a WebSocket is opened
     * @param webSocket {@link WebSocket}
     */
    void onOpen(WebSocket webSocket);

    /**
     * Invoked when a WebSocket is closed
     * @param webSocket {@link WebSocket}
     */
    void onClose(WebSocket webSocket);

    /**
     * Invoked when an error occurs.
     * @param webSocket {@link WebSocket}
     * @param t a WebSocketProcessor.WebSocketException
     */
    void onError(WebSocket webSocket, WebSocketProcessor.WebSocketException t);</pre>
<p>By default, Atmosphere uses the <a href="http://atmosphere.github.com/atmosphere/apidocs/org/atmosphere/websocket/protocol/SimpleHttpProtocol.html">SimpleHttpProtocol</a> to dispatch WebSocket message to Servlet based container. As an example, Atmosphere dispatch WebSockets messages to Jersey by wrapping the message inside an HttpServletRequest and  an asynchronous I/O HttpServletResponse. By default message are considered as POST when dispatched to Jersey, but all HTTP property are configurable (content-type, headers, cookies, etc.). Another example is the EchoProtocol, which just echo message to all connected WebSocket.</p>
<h2>Improved Cross-Origin Resource Sharing (CORS) Support</h2>
<p>The Atmosphere JQuery Plug In has an improved support for CORS, specially with IE 8/9. You can either turn it on globally or per request. As simple as:</p>
<pre>                    jQuery.atmosphere.subscribe(
                        this.url,
                        this.atmosphereCallback,
                        jQuery.atmosphere.request = {
                            method : 'POST',
                            data : json,
                            transport: "websocket" ,
                            fallbackMethod: "POST",
                            <span style="color:#000000;"><strong>enableXDR : 'true',</strong>
 attachHeadersAsQueryString: true });</span></pre>
<h2>Trackability Support and Multi Tab</h2>
<p>Trackability of remote AtmosphereResource was available in previous version only with Jersey. With 0.8, Trackability is now available to all modules and natively implemented in the JQuery Atmosphere Plug In. When the Plug In execute a request, a unique ID is assigned to the request. The server will read that unique id and will try to look up an AtmosphereResource linked to that ID. That allow application to remotely manipulate AtmosphereResource without the need to keep track, inside the application itself, a list of AtmosphereResource. That allow an application to suspend more than one AtmosphereResource per connection, opening the possibility to implement Browser multi-tab support by assigning a unique ID per tab, represented by different AtmosphereResource on the server side.</p>
<p>Atmosphere also support Trackable injection like:</p>
<pre>  @Path("/subscribe")
  @POST def subscribeAndPublish(
    @HeaderParam(X_ATMOSPHERE_TRACKING_ID) trackedResource:
                    TrackableResource[AtmosphereResource[_, _]],
    @HeaderParam(X_ATMOSPHERE_TRACKING_ID) trackingID: String,
    @HeaderParam(X_ATMOSPHERE_TRANSPORT) transport: String, message: String)
            : SuspendResponse[TrackableResource[AtmosphereResource[_, _]]] =
    {
     ....
    }</pre>
<h2>Headers as Query String</h2>
<p>Some environment are just allowing the GET operation. An example if the WebSocket Handshake operation, which by default execute a GET without allowing the client to configure any headers. IE CORS also only support this model. The good news is Atmosphere can encode the headers as a QueryString and decode it on the server side as header, allowing application to pass information during the handshake operation. As simple as:</p>
<pre>                    jQuery.atmosphere.subscribe(
                        this.url,
                        this.atmosphereCallback,
                        jQuery.atmosphere.request = {
                            method : 'POST',
                            data : json,
                            transport: "websocket" ,
                            fallbackMethod: "POST",
                            <strong>attachHeadersAsQueryString: true</strong>

                        });</pre>
<p>There is much more new features, take a look at the <a href="https://github.com/Atmosphere/atmosphere/blob/master/CHANGELOGS.txt#L1">changes log for more info</a>.</p>
<p>For any questions or to download Atmosphere Client and Server Framework, go to our <a href="http://github.com/Atmosphere/atmosphere">main site</a>, use our <a href="http://groups.google.com/group/atmosphere-framework">Google Group forum</a>, <a href="http://twitter.com/atmo_framework">follow the team</a> or <a href="http://twitter.com/jfarcand">myself</a> and tweet your questions there! .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/926/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/926/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/926/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/926/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/926/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/926/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/926/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/926/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/926/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/926/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/926/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/926/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/926/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/926/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=926&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/11/25/atmosphere-0-8-jersey-on-steroid-websocket-sub-protocol-native-websocket-jquery-plugin-cors-rest-over-http/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/11/untitled1.jpg?w=300" medium="image">
			<media:title type="html">Untitled</media:title>
		</media:content>
	</item>
		<item>
		<title>Hitchiker Guide to the Atmosphere Framework using WebSocket, Long-Polling and Http Streaming</title>
		<link>http://jfarcand.wordpress.com/2011/11/07/hitchiker-guide-to-the-atmosphere-framework-using-websocket-long-polling-and-http-streaming/</link>
		<comments>http://jfarcand.wordpress.com/2011/11/07/hitchiker-guide-to-the-atmosphere-framework-using-websocket-long-polling-and-http-streaming/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 17:15:18 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=904</guid>
		<description><![CDATA[The Atmosphere Framework easily allow the writing of web application that support, transparently, WebSocket, Long-Polling and Http Streaming. The Atmosphere Framework also hide the complexity of the current asynchronous API, which differ from Server to Server and make your application portable among them. More important, it is much more easy to write an Atmosphere application [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=904&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/Atmosphere/atmosphere">The Atmosphere Framework</a> easily allow the writing of web application that support, transparently, WebSocket, Long-Polling and Http Streaming. The Atmosphere Framework also hide the complexity of the current asynchronous API, which differ from Server to Server and make your application portable among them. More important, it is <a href="http://jfarcand.wordpress.com/2009/11/06/servlet-3-0-asynchronous-api-or-atmosphere-easy-decision/">much more easy</a> to write an Atmosphere application than using the Servlet 3.0 API.<br />
<a href="http://jfarcand.files.wordpress.com/2011/11/untitled.jpg"><img class="alignnone size-medium wp-image-918" title="Untitled" src="http://jfarcand.files.wordpress.com/2011/11/untitled.jpg?w=699&#038;h=524" alt="" width="699" height="524" /></a><br />
There are several APIs available in Atmosphere to write an asynchronous application: AtmosphereHandler, Meteor or using <a href="http://jersey.java.net/">Jersey</a>&#8216;s Atmosphere extension. In this blog I will take the <a href="http://jfarcand.wordpress.com/2010/06/15/using-atmospheres-jquery-plug-in-to-build-applicationsupporting-both-websocket-and-comet/">famous JQuery PubSub sample</a> to demonstrate those APIs. Note that I will not discuss the JQuery Atmosphere Plugin as it is the same for all APIs. Important, all code snippet below support WebSocket, Long-Polling and Streaming by default. Only the last section only support WebSocket.</p>
<p>The JQuery PubSub Application is quite simple. You enter a topic to subscribe, you select a transport to use (WebSocket, Streaming or Long-Polling) or let the plug in decide for you, and then you are ready to publish message. You can use Redis on the server side to cluster your application among servers. The subscribe operation is done using a GET, the publish using a POST (in the form of message=&#8221;something&#8221;). If the WebSocket transport is used, the message is wrapped as a POST and delivered as a normal HTTP request. Note that this feature is configurable in Atmosphere</p>
<h2>PubSub using AtmosphereHandler</h2>
<p>The AtmosphereHandler  is a low level API that can be used to write an asynchronous application. An application just have to implement that interface. This API is usually used by other framework in order to integrate with Atmosphere (GWT, Jersey, Vaading, etc.) but it can also be used if you want to write Servlet style code.  So, with an <a href="https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/cpr/AtmosphereHandler.java#L115">AtmosphereHandler</a>, the PubSub implementation will take the form of:</p>
<pre>public class AtmosphereHandlerPubSub
      extends <a href="https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/handler/AbstractReflectorAtmosphereHandler.java#L60">AbstractReflectorAtmosphereHandler</a> {

    @Override
    public void <span style="color:#ff6600;">onRequest</span>
       (AtmosphereResource r)
          throws IOException {

        HttpServletRequest req = r.getRequest();
        HttpServletResponse res = r.getResponse();
        String method = req.getMethod();

        // Suspend the response.
        if ("GET".equalsIgnoreCase(method)) {
            String trackingId = trackingId(req);

            // Log all events on the console, including WebSocket events.
            r.addEventListener(new <a href="https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/websocket/WebSocketEventListenerAdapter.java#L30">WebSocketEventListenerAdapter</a>());

            res.setContentType("text/html;charset=ISO-8859-1");

            Broadcaster b = lookupBroadcaster(req.getPathInfo());
            r.setBroadcaster(b);

            if (req.getHeader(X_ATMOSPHERE_TRANSPORT)
                    .equalsIgnoreCase(LONG_POLLING_TRANSPORT)) {
                req.setAttribute(RESUME_ON_BROADCAST, Boolean.TRUE);
                r.<span style="color:#0000ff;">suspend</span>(-1, false);
            } else {
                r.suspend(-1);
            }
        } else if ("POST".equalsIgnoreCase(method)) {
            Broadcaster b = lookupBroadcaster(req.getPathInfo());

            String message = req.getReader().readLine();

            if (message != null &amp;&amp; message.indexOf("message") != -1) {
                b.<span style="color:#0000ff;">broadcast</span>(message.substring("message=".length()));
            }
        }
    }

    @Override
    public void <span style="color:#ff6600;">destroy</span>() {
    }

    Broadcaster <span style="color:#ff6600;">lookupBroadcaster</span>(String pathInfo) {
        String[] decodedPath = pathInfo.split("/");
        Broadcaster b = BroadcasterFactory.getDefault()
              .<span style="color:#0000ff;">lookup</span>(decodedPath[decodedPath.length - 1], <span style="color:#0000ff;">true</span>);
        return b;
    }

}</pre>
<p>When a GET is received, we lookup a Broadcaster and then suspend the response based on the path info (REST style). Here we need a make sure we aren&#8217;t sending padding data (required for WebKit browser) when long polling is used. That&#8217;s the only required conditional evaluation needed in terms of transport. With the POST we just look up the Broadcaster (which represent a pubsub topic) and broadcast the request&#8217;s body. That;s it.</p>
<h2>PubSub using Meteor</h2>
<p>The Meteor is another low level API that can be used with existing Servlet application. As an example, the ADF framework use Meteor in order to integrate Atmosphere support.</p>
<pre>public class <a href="https://github.com/Atmosphere/atmosphere/blob/master/samples/jquery-meteor-pubsub/src/main/java/org/atmosphere/samples/pubsub/MeteorPubSub.java#L39">MeteorPubSub</a> extends HttpServlet {

    @Override
    public void <span style="color:#ff6600;">doGet</span>(HttpServletRequest req, HttpServletResponse res)
       throws IOException {
        // Create a Meteor
        Meteor m = Meteor.build(req);

        // Log all events on the console, including WebSocket events.
        m.addListener(new WebSocketEventListenerAdapter());

        res.setContentType("text/html;charset=ISO-8859-1");

        Broadcaster b = lookupBroadcaster(req.getPathInfo());
        m.setBroadcaster(b);

        if (req.getHeader(X_ATMOSPHERE_TRANSPORT)
                .equalsIgnoreCase(LONG_POLLING_TRANSPORT)) {
            req.setAttribute(RESUME_ON_BROADCAST, Boolean.TRUE);
            m.<span style="color:#0000ff;">suspend</span>(-1, false);
        } else {
            m.<span style="color:#0000ff;">suspend</span>(-1);
        }
    }

    public void <span style="color:#ff6600;">doPost</span>(HttpServletRequest req, HttpServletResponse res)
        throws IOException {

        Broadcaster b = lookupBroadcaster(req.getPathInfo());
        String message = req.getReader().readLine();

        if (message != null &amp;&amp; message.indexOf("message") != -1) {
            b.<span style="color:#0000ff;">broadcast</span>(message.substring("message=".length()));
        }
    }

    Broadcaster <span style="color:#ff6600;">lookupBroadcaster</span>(String pathInfo) {
        String[] decodedPath = pathInfo.split("/");
        Broadcaster b = BroadcasterFactory.getDefault()
              .<span style="color:#0000ff;">lookup</span>(decodedPath[decodedPath.length - 1], <span style="color:#0000ff;">true</span>);
        return b;
    }
}</pre>
<p>When a GET is received, we create a Meteor and use that Meteor to suspend the response, again using the path info. For post, we do the same as with AtmosphereHandler, e.g retrieve the Broadcaster and broadcast the message.</p>
<h2>PubSub using Jersey&#8217;s Atmosphere Extension</h2>
<p>With the Jersey extension, we can either use annotations or the programmatic API. As simple as&#8221;</p>
<pre>@Path("/pubsub/{topic}")
@Produces("text/html;charset=ISO-8859-1")
public class <a href="https://github.com/Atmosphere/atmosphere/blob/master/samples/jquery-pubsub/src/main/java/org/atmosphere/samples/pubsub/JQueryPubSub.java#L57">JQueryPubSub</a> {

    private
    @PathParam("topic")
    Broadcaster topic;

    @GET
    public SuspendResponse <span style="color:#ff6600;">subscribe</span>() {
        return new <span style="color:#0000ff;">SuspendResponse.SuspendResponseBuilder</span>()
                .broadcaster(topic)
                .outputComments(true)
                .addListener(new EventsLogger())
                .build();
    }

    @POST
    @Broadcast
    public Broadcastable <span style="color:#ff6600;">publish</span>(@FormParam("message") String message) {
        return new <span style="color:#0000ff;">Broadcastable</span>(message, "", topic);
    }
}</pre>
<p>The GET could have been handled using the @Suspend annotation:</p>
<pre>    @GET
    @Suspend(listeners = EventsLogger.class, outputComments = true)
    public Broadcastable <span style="color:#ff6600;">subscribe</span>(){
        return new Broadcastable(topic);
    }</pre>
<p>As you can see, it is quite simpler that with Meteor and AtmosphereHandler.<br />
PubSub.</p>
<h2>PubSub using WebSocket only</h2>
<p>If you are planning to write pure WebSocket application and don&#8217;t plan to support normal HTTP, you can also write your own WebSocket sub protocol. It is quote important to note here that only WebSocket will be supported.</p>
<pre>public class <a href="https://github.com/Atmosphere/atmosphere/blob/master/samples/jquery-websocketprotocol-pubsub/src/main/java/org/atmosphere/samples/pubsub/WebSocketPubSub.java#L47">WebSocketPubSub</a> implements WebSocketProtocol {

    private AtmosphereResource r;

    @Override
    public HttpServletRequest <span style="color:#ff6600;">onMessage</span>(<a href="https://github.com/Atmosphere/atmosphere/blob/master/modules/cpr/src/main/java/org/atmosphere/websocket/WebSocket.java#L50">WebSocket</a> webSocket, String message) {
        Broadcaster b = lookupBroadcaster(r.getRequest().getPathInfo());

        if (message != null &amp;&amp; message.indexOf("message") != -1) {
            b.<span style="color:#0000ff;">broadcast</span>(message.substring("message=".length()));
        }

        //Do not dispatch to another Container like Jersey
        return null;
    }

    @Override
    public void <span style="color:#ff6600;">onOpen</span>(WebSocket webSocket) {
        // Accept the handshake by suspending the response.
        r = (AtmosphereResource)
              webSocket.atmosphereResource();

        Broadcaster b = lookupBroadcaster(r.getRequest().getPathInfo());
        r.setBroadcaster(b);
        r.addEventListener(new WebSocketEventListenerAdapter());

        r.<span style="color:#0000ff;">suspend</span>(-1);
    }

    @Override
    public void <span style="color:#ff6600;">onClose</span>(WebSocket webSocket) {
        webSocket.atmosphereResource().resume();
    }

    Broadcaster <span style="color:#ff6600;">lookupBroadcaster</span>(String pathInfo) {
        String[] decodedPath = pathInfo.split("/");
        Broadcaster b = BroadcasterFactory.getDefault().
                 <span style="color:#0000ff;">lookup</span>(decodedPath[decodedPath.length - 1], <span style="color:#0000ff;">true</span>);
        return b;
    }</pre>
<p>The important method here is onOpen (for accepting the handshake) and the onMessage, which is were the messages are received.</p>
<h2>Conclusion</h2>
<p>It is quite important to pick the best API when writing Atmosphere application as it can save you a lot of time! You can <a href="https://oss.sonatype.org/content/repositories/snapshots/org/atmosphere/samples/">download</a> all samples from here.</p>
<p>For any questions or to download Atmosphere Client and Server Framework, go to our <a href="http://github.com/Atmosphere/atmosphere">main site</a>, use our <a href="http://groups.google.com/group/atmosphere-framework">Google Group forum</a>, <a href="http://twitter.com/atmo_framework">follow the team</a> or <a href="http://twitter.com/jfarcand">myself</a> and tweet your questions there! .</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/904/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/904/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/904/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=904&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/11/07/hitchiker-guide-to-the-atmosphere-framework-using-websocket-long-polling-and-http-streaming/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/11/untitled.jpg?w=300" medium="image">
			<media:title type="html">Untitled</media:title>
		</media:content>
	</item>
		<item>
		<title>Configuring HAProxy for WebSocket</title>
		<link>http://jfarcand.wordpress.com/2011/10/06/configuring-haproxy-for-websocket/</link>
		<comments>http://jfarcand.wordpress.com/2011/10/06/configuring-haproxy-for-websocket/#comments</comments>
		<pubDate>Thu, 06 Oct 2011 22:35:02 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=878</guid>
		<description><![CDATA[A lot of peoples (including myself at Wordnik) needed to configure HAProxy in order to make WebSocket working. For my Atmosphere Framework project, I&#8217;m using: $ cat /etc/haproxy/haproxy.cfg global maxconn 4096 # Total Max Connections. This is dependent on ulimit nbproc 1 defaults mode http frontend all 0.0.0.0:80 timeout client 86400000 default_backend www_backend acl is_websocket hdr(Upgrade) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=878&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A lot of peoples (including myself at <a href="http://www.wordnik.com/">Wordnik</a>) needed to configure HAProxy in order to make WebSocket working. For my <a href="http://github.com/Atmosphere/atmosphere">Atmosphere Framework</a> project, I&#8217;m using:</p>
<pre>$ cat /etc/haproxy/haproxy.cfg
global
    maxconn     4096 # Total Max Connections. This is dependent on ulimit
    nbproc      1

defaults
    mode        http

frontend all 0.0.0.0:80
    timeout client 86400000
    default_backend www_backend
    acl is_websocket hdr(Upgrade) -i WebSocket
    acl is_websocket hdr_beg(Host) -i ws

    use_backend socket_backend if is_websocket

backend www_backend
    balance roundrobin
    option forwardfor # This sets X-Forwarded-For
    timeout server 30000
    timeout connect 4000
    server apiserver 127.0.0.1:8080 weight 1 maxconn 1024 check

backend socket_backend
    balance roundrobin
    option forwardfor # This sets X-Forwarded-For
    timeout queue 5000
    timeout server 86400000
    timeout connect 86400000
    server apiserver targetserver:7777 weight 1 maxconn 1024 check</pre>
<p>Thanks to Matthias L. Jugel for sharing &#8230; see his use of Atmosphere at <a href="http://twimpact.com/">twimpact.com</a>.</p>
<p>For any questions or to download Atmosphere Client and Server Framework, go to our <a href="http://github.com/Atmosphere/atmosphere">main site</a>, use our <a href="http://groups.google.com/group/atmosphere-framework">Google Group forum</a>, <a href="http://twitter.com/atmo_framework">follow the team</a> or <a href="http://twitter.com/jfarcand">myself</a> and tweet your questions there! You can also checkout the code on <a href="http://github.com/jfarcand/atmosphere">Github</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/878/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/878/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/878/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/878/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/878/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/878/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/878/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/878/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/878/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/878/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/878/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/878/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/878/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/878/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=878&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/10/06/configuring-haproxy-for-websocket/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>
	</item>
		<item>
		<title>Atmosphere.next Update: WebSocket, Javascript, full docs and 1.0.0 on the horizon!</title>
		<link>http://jfarcand.wordpress.com/2011/09/08/atmosphere-next-update-websocket-javascript-full-docs-and-1-0-0-on-the-horizon/</link>
		<comments>http://jfarcand.wordpress.com/2011/09/08/atmosphere-next-update-websocket-javascript-full-docs-and-1-0-0-on-the-horizon/#comments</comments>
		<pubDate>Thu, 08 Sep 2011 18:15:52 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=870</guid>
		<description><![CDATA[I took this summer off in order to explore what can be done with the Atmosphere Framework. I have to admit I was extremely surprised about the number of emails I did received for supports, new features, venture capital stuff etc. As you may already know, I&#8217;ve decided to join Wordnik.com to pursue the work [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=870&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I took this summer off in order to explore what can be done with <a href="https://github.com/Atmosphere/atmosphere">the Atmosphere Framework</a>. I have to admit I was extremely surprised about the number of emails I did received for supports, new features, venture capital stuff etc. As you may already know, I&#8217;ve <a href="http://blog.wordnik.com/welcome-jeanfrancois">decided to join Wordnik.com</a> to pursue the work on Atmosphere.</p>
<p><a href="http://jfarcand.files.wordpress.com/2011/09/303875_182871058448757_100001775938170_368156_988111_n.jpg"><img class="alignnone size-medium wp-image-871" title="303875_182871058448757_100001775938170_368156_988111_n" src="http://jfarcand.files.wordpress.com/2011/09/303875_182871058448757_100001775938170_368156_988111_n.jpg?w=704&#038;h=528" alt="" width="704" height="528" /></a></p>
<p>The future of Atmosphere has never been brighter than now&#8230;starting mid September, I will be allowed as much as 50% of my time to work on Atmosphere. That&#8217;s A LOT, more time than I ever got allowed at Sun, Ning and Sonatype. For the last two years I&#8217;ve innovated on my own time, helped growing the community, do some talks, but I had never a chance to spend the time I wanted on the project. Not anymore!!</p>
<p>So soon I will restart contributing (created a lot of great things over the summer) and work on Atmosphere 1.0, which I hope I can do before next year. The roadmap is simple: stabilize, documents (quite needed), merge all the pull requests/donations for the client side, push the Socket.IO supports, etc. Since I haven&#8217;t received what I wanted from Oracle on Atmosphere, I will also rewrite some part of the framework completely to get rid of the CDDL/LGPL stuff in favor or a pure APL licensing (more than 75% is APL right now anyway). And of course the project will stay under Github, and Twitter will still be used for communicating news (either <a href="https://twitter.com/atmo_framework">atmo_framework</a> or<a href="https://twitter.com/jfarcand"> jfarcand</a>). Stay tuned, the future is bright for Atmosphere!</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/870/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/870/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/870/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/870/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/870/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/870/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/870/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/870/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=870&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/09/08/atmosphere-next-update-websocket-javascript-full-docs-and-1-0-0-on-the-horizon/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/09/303875_182871058448757_100001775938170_368156_988111_n.jpg?w=300" medium="image">
			<media:title type="html">303875_182871058448757_100001775938170_368156_988111_n</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick Tip: Using Apache Shiro with your Atmosphere&#8217;s WebSocket/Comet app.</title>
		<link>http://jfarcand.wordpress.com/2011/07/13/quick-tip-using-apache-shiro-with-your-atmospheres-websocketcomet-app/</link>
		<comments>http://jfarcand.wordpress.com/2011/07/13/quick-tip-using-apache-shiro-with-your-atmospheres-websocketcomet-app/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 13:00:30 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=858</guid>
		<description><![CDATA[Apache Shiro is a powerful and easy-to-use Java security framework that performs authentication, authorization, cryptography, and session management. When used with The Atmosphere Framework and a Servlet based Container, the security context of the thread that will execute the async operation may not carry the same SecurityContext, causing some unexpected issues. As an example, let&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=858&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://shiro.apache.org/">Apache Shiro</a> is a powerful and easy-to-use Java security framework that performs authentication, authorization, cryptography, and session management. When used with The <a href="https://github.com/Atmosphere/atmosphere">Atmosphere Framework</a> and a Servlet based Container, the security context of the thread that will execute the async operation may not carry the same SecurityContext, causing some unexpected issues.</p>
<p><a href="http://jfarcand.files.wordpress.com/2011/07/canot-035.jpg"><img class="alignnone size-medium wp-image-862" title="canot 035" src="http://jfarcand.files.wordpress.com/2011/07/canot-035.jpg?w=595&#038;h=444" alt="" width="595" height="444" /></a></p>
<p>As an example, let&#8217;s say you want to retrieve the user principal after you have suspended your request. Normally all you need to do is:</p>
<pre>Subject currentUser = SecurityUtils.getSubject();</pre>
<p>This work perfectly well when the request gets executed using the calling thread of the HTTP request, e.g. when the Servlet Container execute your <strong><em>Servlet.service</em></strong> method. Now when using the Atmosphere Framework, you may need to lookup the Subject once the async operation occurs: when a Broadcast (server side events) gets executed or when the suspended connection resume. Under that condition, doing SecurityUtils.getSubject() will NOT return the same value as when the call gets executed using the calling thread and hence can cause unexpected issues. The async Thread used in that case may be provided by the Servlet Container itself or by the Atmosphere&#8217;s BroadcasterConfig ExecutorServices. In both case, the security context is NOT the same as the original HTTP request thread, hence you should not call SecurityUtils API. Instead, one solution is to use the request attribute map and store the information required in it. As simple as:</p>
<pre>request.setAttribute("subject", SecurityUtils.getSubject());</pre>
<p>Then when the request resume or when a broadcast event occurs (inside your <em>AtmosphereHandler#onStateChange</em> method, your <em>BroadcastFilter</em> etc,), you can easily retrieve that information by doing:</p>
<pre>Subject subject = request.getAttribute("subject");</pre>
<p>The Request object is *always* the original object constructed by the Servlet Container when handling the HTTP request, hence attributes (and session) will always be available. This is a safe way to store Apache Shiro information.</p>
<p>For any questions or to download Atmosphere Client and Server Framework, go to our <a href="http://github.com/Atmosphere/atmosphere">main site</a>, use our <a href="http://groups.google.com/group/atmosphere-framework">Google Group forum</a>, <a href="http://twitter.com/atmo_framework">follow the team</a> or <a href="http://twitter.com/jfarcand">myself</a> and tweet your questions there! You can also checkout the code on <a href="http://github.com/jfarcand/atmosphere">Github</a>.</p>
<pre>
</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/858/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/858/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/858/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=858&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/07/13/quick-tip-using-apache-shiro-with-your-atmospheres-websocketcomet-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/07/canot-035.jpg?w=300" medium="image">
			<media:title type="html">canot 035</media:title>
		</media:content>
	</item>
		<item>
		<title>REST + WebSocket applications? Why not using the Atmosphere Framework</title>
		<link>http://jfarcand.wordpress.com/2011/06/29/rest-websocket-applications-why-not-using-the-atmosphere-framework/</link>
		<comments>http://jfarcand.wordpress.com/2011/06/29/rest-websocket-applications-why-not-using-the-atmosphere-framework/#comments</comments>
		<pubDate>Wed, 29 Jun 2011 00:30:12 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=818</guid>
		<description><![CDATA[The Atmosphere Framework easily allow the creation of REST applications &#8230; using WebSocket. This time I will describe a super simple example on how to do it. The Atmosphere Framework supports transparently both WebSocket and Comet transport and brings portability to any Java based application. An application written using Atmosphere can be deployed in any [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=818&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://atmosphere.java.net">Atmosphere Framework</a> easily allow the creation of REST applications &#8230; using WebSocket. This time I will describe a super simple example on how to do it.</p>
<p><a href="http://jfarcand.files.wordpress.com/2011/06/img_07241.jpg"><img class="alignnone size-medium wp-image-846" title="IMG_0724" src="http://jfarcand.files.wordpress.com/2011/06/img_07241.jpg?w=572&#038;h=429" alt="" width="572" height="429" /></a></p>
<p>The Atmosphere Framework supports transparently both WebSocket and Comet transport and brings portability to any Java based application. An application written using Atmosphere can be deployed in any WebServer and Atmosphere will transparently make it work.  Atmosphere is also able to transparently select the best transport to use, e.g. WebSocket or Comet. Now let&#8217;s write a very simple REST application with Comet support as we normally write:</p>
<pre>@<span style="color:#ff6600;">Path</span>("/pubsub/{topic}")
@Produces("text/html;charset=ISO-8859-1")
public class JQueryPubSub {

    private @<span style="color:#ff6600;">PathParam</span>("topic") Broadcaster topic;

    <span style="color:#0000ff;">@GET</span>
    public SuspendResponse&lt;String&gt; subscribe() {
        return new SuspendResponse.SuspendResponseBuilder&lt;String&gt;()
                .broadcaster(topic)
                .outputComments(true)
                .addListener(new EventsLogger())
                .build();
    }

    <span style="color:#0000ff;">@POS</span>T
    @Broadcast
    public Broadcastable publish(@FormParam("message") String message) {
        return new Broadcastable(message, "", topic);
    }
}</pre>
<p>Doing</p>
<blockquote><p><span style="color:#0000ff;">GET /pubsub/something</span></p></blockquote>
<p>will invoked the SuspendResponse. To make the exercise simple, all we do there is suspend the connection (e.g. do not return any response, wait for an event). If you want to make this exercise more difficult, you can always implements the ETag trick! Once the connection is suspended, we need to use a second connection in order to post some data</p>
<blockquote><p>POST /pubsub/something<br />
message=<span style="color:#0000ff;">I love Comet</span></p></blockquote>
<p>Executing the POST request will result in the invocation of the publish method. The @Broadcast annotation means the FormParam value will be broadcasted to all suspended connections.</p>
<h3>WebSocket to rule them all</h3>
<p>OK so let&#8217;s assume we now deploy your application in a WebServer that supports WebSocket like Jetty or GlassFish. Now Atmosphere will auto detect WebSockets are supported and use it when a WebSocket request is done. Now let&#8217;s assume we build the client using the <a href="http://jfarcand.wordpress.com/2010/06/15/using-atmospheres-jquery-plug-in-to-build-applicationsupporting-both-websocket-and-comet/">Atmosphere JQuery Plug</a> In and execute the GET request using Chrome (which support Websocket).The Atmosphere Javascript library is able to challenge the remote server and discover if the server and client support WebSocket, and use it.</p>
<p>In that scenario, suspending the connection will tell Atmosphere to execute the WebSocket handshake. Now the POST will be executed on the same connection, and the public method will be invoked this time.  This is not a POST as you see normally with normal HTTP. Since WebSocket is used, only the form param will be send over the wire:</p>
<blockquote><p>message=<span style="color:#0000ff;">I love WebSocket</span></p></blockquote>
<p>All of this occurs without any modification of your REST application. All you need to do to enable WebSocket is to &#8220;suspend&#8221; the connection when a @GET occurs. Transparent, is it <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  You can download the current version of the sample<a href="https://oss.sonatype.org/content/repositories/snapshots/org/atmosphere/samples/atmosphere-jquery-pubsub/0.8-SNAPSHOT/"> here</a>.</p>
<p>Now what Atmosphere is doing under the hood is wrapping the WebSocket message into an HttpServletRequest so any framework like Jersey, Wicket, etc, works as it is. If you are familiar with Atmosphere, your AtmosphereHandler implementation will get invoked with an instance of HttpServletRequest that contains the WebSocket message, so you can use it as your will normally do using Comet or normal HTTP request.</p>
<p>For any questions or to download Atmosphere Client and Server Framework, go to our <a href="http://atmosphere.java.net">main site</a>, use our <a href="http://n2.nabble.com/Atmosphere-users-mailling-list-f2493822.html">Nabble forum</a>, <a href="http://twitter.com/atmo_framework">follow the team</a> or <a href="http://twitter.com/jfarcand">myself</a> and tweet your questions there! You can also checkout the code on <a href="http://github.com/jfarcand/atmosphere">Github</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/818/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/818/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/818/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=818&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/06/29/rest-websocket-applications-why-not-using-the-atmosphere-framework/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/06/img_07241.jpg?w=300" medium="image">
			<media:title type="html">IMG_0724</media:title>
		</media:content>
	</item>
		<item>
		<title>Improving HTTP Long Polling performance using ETag</title>
		<link>http://jfarcand.wordpress.com/2011/06/16/improving-http-long-polling-performance-using-etag/</link>
		<comments>http://jfarcand.wordpress.com/2011/06/16/improving-http-long-polling-performance-using-etag/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 14:53:58 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=781</guid>
		<description><![CDATA[The Comet technique called &#8220;long polling&#8221; is the most widely used technique. In this blog I will explain a way optimize this technique using the well know etag HTTP header using the Atmosphere Framework. There are many ways to optimally implement the long polling technique, and how events get cached on the server side. In [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=781&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://jfarcand.wordpress.com/2007/05/15/new-adventures-in-comet-polling-long-polling-or-http-streaming-with-ajax-which-one-to-choose/">Comet technique called &#8220;long polling&#8221;</a> is the most widely used technique. In this blog I will explain a way optimize this technique using the well know etag HTTP header using the <a href="http://atmosphere.java.net">Atmosphere Framework</a>.</p>
<p><a href="http://jfarcand.files.wordpress.com/2011/06/img_1007.jpg"><img class="alignnone size-medium wp-image-811" title="IMG_1007" src="http://jfarcand.files.wordpress.com/2011/06/img_1007.jpg?w=544&#038;h=408" alt="" width="544" height="408" /></a></p>
<p>There are many ways to optimally implement the long polling technique, and how events get cached on the server side. In most frameworks/applications, events are getting cached to prevent clients from missing them when reconnecting. When the client reconnect, missed events are retrieved using custom techniques like:</p>
<ul>
<li>Use a special header containing the last time the client has connected. Based on that time stamp, the server can retrieve all events that occurred after that time.</li>
<li>Use a special header container an event counter, and retrieve the missed events based on that count</li>
</ul>
<p>A better approach consist of using the well know Etag HTTP header. Wikipedia defines Etag as:</p>
<blockquote><p>An <strong>ETag</strong>, or <strong>entity tag</strong>, is part of <a title="Hypertext Transfer Protocol" href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a>, the protocol for the <a title="World Wide Web" href="http://en.wikipedia.org/wiki/World_Wide_Web">World Wide Web</a>. It is one of several mechanisms that HTTP provides for <a title="Web cache" href="http://en.wikipedia.org/wiki/Web_cache">cache validation</a>, and which allows a client to make conditional requests. This allows caches to be more efficient, and saves bandwidth, as a web server does not need to send a full response if the content has not changed. .</p></blockquote>
<p>That&#8217;s exactly what we need to optimize our long polling request, e.g use an Etag to:</p>
<ol>
<li>Decide when to long poll the connection</li>
<li>Decide to long poll the connection even if some events where cached since the last connection. Aggreate the cached events with the new one.</li>
<li>Avoid long polling the connection, return immediately.</li>
</ol>
<p>Before going into the details, let&#8217;s describe how an ETag can be generated from the server side. A simple but very powerful way to generate an Etag is to generate it based on a MD5 Message-Digest Algorithm. That value will be regenerated every time events get cached, and that value will be used as an Etag send back to the client.</p>
<p>The client will use the ETag value and send it back to the server using the &#8220;If-None-Match&#8221; header. On the server side, the value will be compared with the last generated ETag value. If the client&#8217;s ETag match the server one, that means no event occurred since the last time the client was connected. Two actions can be taken:</p>
<ul>
<li>Long poll (suspend) the connection until the ETag gets regenerated, which means a new events occurred on the server side.</li>
<li>Return an HTTP status code of 204: The server successfully processed the request, but is not returning any content. Returning a 204 could be used when the number of long polled connections is really high to prevent out of memory errors or to reduce the memory footprint. In that case the client could reconnect later (polling the server).</li>
</ul>
<p>If the ETag values aren&#8217;t matching, that mean events occurred since the last time the client connected. Two actions can be taken:</p>
<ul>
<li>Sent back the cached events to the client. In that case we don&#8217;t long poll the connection.</li>
<li>long poll the connection (suspend) until the next events occurs. Then combine the cached events with the new one and resume the connection.</li>
</ul>
<p>Note that every time a new events occurs, a new ETag value needs to be regenerated.</p>
<p>Now how can this be implemented? Using the Atmosphere Framework it is as simple as:</p>
<p>
<pre><code>@Produces("application/json")
public SuspendResponse optimalLongPolling(final @Context Request request){
    final String eTagString = server.getETag();
    final Response.ResponseBuilder responseBuilder =
        request.evaluatePreconditions(new EntityTag(eTagString));

    if (responseBuilder != null){
        return new SuspendResponse.SuspendResponseBuilder()
                .broadcaster(broadcaster)
                .addListener(new AtmosphereEventsListener())
                .outputComments(false)
                .resumeOnBroadcast(true)
                .period(30, TimeUnit.MILLISECONDS)
                .build();
    } else {
        throw new WebApplicationException(
                Response.status(Response.Status.NO_CONTENT).build());
    }
}
</code></pre>
</p>
<p>Very simple.</p>
<p>For any questions or to download Atmosphere Client and Server Framework, go to our <a href="http://atmosphere.java.net">main site</a>, use our <a href="http://n2.nabble.com/Atmosphere-users-mailling-list-f2493822.html">Nabble forum</a>, <a href="http://twitter.com/atmo_framework">follow the team</a> or <a href="http://twitter.com/jfarcand">myself</a> and tweet your questions there! You can also checkout the code on <a href="http://github.com/jfarcand/atmosphere">Github</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/781/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/781/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/781/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/781/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/781/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/781/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/781/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/781/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/781/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/781/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/781/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/781/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/781/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/781/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=781&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/06/16/improving-http-long-polling-performance-using-etag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/06/img_1007.jpg?w=300" medium="image">
			<media:title type="html">IMG_1007</media:title>
		</media:content>
	</item>
		<item>
		<title>Small Survival guide when debugging your Comet/WebSocket application.</title>
		<link>http://jfarcand.wordpress.com/2011/04/11/small-survival-guide-when-debugging-your-cometwebsocket-application/</link>
		<comments>http://jfarcand.wordpress.com/2011/04/11/small-survival-guide-when-debugging-your-cometwebsocket-application/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 14:51:09 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Atmosphere]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[Websocket]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=774</guid>
		<description><![CDATA[Under my Atmosphere&#8217;s Project works, I&#8217;m getting a lot of questions about how to debug WebSocket/Comet applications. Here is some simple tools and trick  I use. ngrep.sourceforge.net A lot of people use wireshark, I much prefer using ngrep for snooping the network packet. As simple as: sudo ngrep -d en0 -q -W byline port 8080 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=774&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Under my <a href="http://gtihub.com/Atmosphere/atmosphere">Atmosphere&#8217;s Project</a> works, I&#8217;m getting a lot of questions about how to debug WebSocket/Comet applications. Here is some simple tools and trick  I use.</p>
<h2><a href="http://jfarcand.files.wordpress.com/2011/04/img_1005.jpg"><img class="alignnone size-medium wp-image-778" title="IMG_1005" src="http://jfarcand.files.wordpress.com/2011/04/img_1005.jpg?w=597&#038;h=447" alt="" width="597" height="447" /></a></h2>
<h2>ngrep.sourceforge.net</h2>
<p>A lot of people use wireshark, I much prefer using <a href="http://ngrep.sourceforge.net">ngrep</a> for snooping the network packet. As simple as:</p>
<pre><code>sudo ngrep -d en0 -q -W byline port 8080</code></pre>
<p>For WebSocket it helps seeing what&#8217;s being sent being the client and the server. Of course you can always use <a href="http://getfirebug.com/">FireBug</a> or <a href="http://code.google.com/chrome/devtools/">Chrome dev tool</a> for debugging inside the browser,  but it is much easier IMO to see the interaction between the browser and the server from a terminal window:</p>
<pre><code>T 127.0.0.1:61265 -&gt; 127.0.0.1:8080 [AP]
GET /atmosphere-jquery-pubsub/pubsub/chat HTTP/1.1.
Upgrade: WebSocket.
Connection: Upgrade.
Host: 127.0.0.1:8080.
Origin: http://127.0.0.1:8080.
Sec-WebSocket-Key1: Z      mZ1  4 9 0W75 50!p13.
Sec-WebSocket-Key2: .mx1674Dy@ 69K  %K027C9:m.
.
.TQ..34.

T 127.0.0.1:8080 -&gt; 127.0.0.1:61265 [AP]
HTTP/1.1 101 WebSocket Protocol Handshake.
Upgrade: WebSocket.
Connection: Upgrade.
Sec-WebSocket-Origin: http://127.0.0.1:8080.
Sec-WebSocket-Location:
    ws://127.0.0.1:8080/atmosphere-jquery-pubsub/pubsub/chat.
.

T 127.0.0.1:8080 -&gt; 127.0.0.1:61265 [AP]
B...%...K....[..</code></pre>
<h2>Using curl</h2>
<p>If you are using curl to test your Comet application (or Websocket to test the initial handshake). make sure you pass the -N option as without, curl will buffer the server&#8217;s response and will not display it until the connection gets dropped by the server:</p>
<pre><code> curl -N http://127.0.0.1:8080/atmosphere-jquery-pubsub/pubsub/chat</code></pre>
<p><code> </code></p>
<p>Without the -N option any real time update will not get display live in the console:</p>
<pre><code>curl -N http://127.0.0.1:8080/atmosphere-jquery-pubsub/pubsub/chat
&lt;!--                                  http://github.com/Atmosphere                                      --&gt;
&lt;!-- Welcome to the Atmosphere Framework. To work with
all the browsers when suspending connection, Atmosphere must output some
data to makes WebKit based browser working.--&gt;
&lt;!-- EOD --&gt;</code></pre>
<p>For any questions, use <a href="http://twitter.com/jfarcand">Twitter</a> to reach me!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/774/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/774/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/774/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/774/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/774/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/774/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/774/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/774/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/774/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/774/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/774/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/774/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/774/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/774/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=774&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/04/11/small-survival-guide-when-debugging-your-cometwebsocket-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/04/img_1005.jpg?w=300" medium="image">
			<media:title type="html">IMG_1005</media:title>
		</media:content>
	</item>
		<item>
		<title>Writing powerful REST Client using the AsyncHttpClient Library and Jersey</title>
		<link>http://jfarcand.wordpress.com/2011/03/24/writing-powerful-rest-client-using-the-asynchttpclient-library-and-jersey/</link>
		<comments>http://jfarcand.wordpress.com/2011/03/24/writing-powerful-rest-client-using-the-asynchttpclient-library-and-jersey/#comments</comments>
		<pubDate>Thu, 24 Mar 2011 13:34:24 +0000</pubDate>
		<dc:creator>Jeanfrancois Arcand</dc:creator>
				<category><![CDATA[Async Http client]]></category>

		<guid isPermaLink="false">http://jfarcand.wordpress.com/?p=733</guid>
		<description><![CDATA[The Jersey Client Framework is a powerful library that easily allow the writing of client based REST client.  Recently I&#8217;ve implemented a new transport for the framework based on the AsyncHttpClient library. You can now get the best of both worlds: an easy REST Client API powered by a poweful http client library. Currently the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=733&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://jersey.java.net/nonav/documentation/latest/user-guide.html#client-api">Jersey Client Framework</a> is a powerful library that easily allow the writing of client based REST client.  Recently I&#8217;ve implemented a new transport for the framework based on the <a href="https://github.com/sonatype/async-http-client">AsyncHttpClient</a> library. You can now get the best of both worlds: an easy REST Client API powered by a poweful http client library.<br />
<a href="http://jfarcand.files.wordpress.com/2011/03/img_0872.jpg"><img class="alignnone size-medium wp-image-754" title="IMG_0872" src="http://jfarcand.files.wordpress.com/2011/03/img_0872.jpg?w=628&#038;h=471" alt="" width="628" height="471" /></a></p>
<p>Currently the Jersey Client Framework ships with two transport, one based on the infamous URLConnection, and one based on Apache Http Client.  Recently I needed to replace Wink with Jersey in one of my Sonatype project (guess one?) and  at the same time realized the Jersey Client features was quite limited in terms of what you can do and what is exposed to the client. I understand the original design was to abstract the underlying transport, but unfortunately all http library aren&#8217;t supporting the same set of features. Now if you are familiar with the Jersey client, creating a resource is as simple as (see <a href="http://jersey.java.net/nonav/documentation/latest/user-guide.html#d4e592">here</a> for the complete tutorial):</p>
<pre><code>    Client c = Client.create(); </code></pre>
<p>Now if you want to customize the client a little, you can do (complete info <a href="http://jersey.java.net/nonav/documentation/latest/user-guide.html#client-api">here</a>):</p>
<pre><code>    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(
        ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
    Client c = Client.create(cc); </code></pre>
<p>Next step is as simple as:</p>
<pre><code>     WebResource r = c.resource(“http://localhost:8080/xyz”);
     ClientResponse response = r.get(ClientResponse.class);
     EntityTag e = response.getEntityTag();
     String entity = response.getEntity(String.class);</code></pre>
<p>Very simple. Now in order to take advantage of AHC (AsyncHttpClient) features, all you need to do is to first get the library from here, and then just do get a reference to the <a href="http://asynchttpclient.github.com/async-http-client/apidocs/com/ning/http/client/AsyncHttpClientConfig.html">AsyncHttpClient&#8217;s Config class</a> (if you aren&#8217;t familiar with AHC, take a look at <a href="http://jfarcand.wordpress.com/2010/12/21/going-asynchronous-using-asynchttpclient-the-basic/">this introduction</a>)</p>
<pre><code>     DefaultAhcConfig config = new DefaultAhcConfig();
     config.getAsyncHttpClientConfigBuilder().setRealm(
           new Realm.RealmBuilder()
               .setScheme(Realm.AuthScheme.SPNEGO)
               .setUsePreemptiveAuth(false)
               .build());
     Client c = Client.create(config);
     WebResource r = c.resource(getUri().build());</code></pre>
<p>You just added Kerberos support to Jersey Client! The trick here consists of getting a reference to the AsyncHttpClientConfig and configure all the <a href="http://jfarcand.wordpress.com/2011/01/04/going-asynchronous-using-asynchttpclient-the-complex/">cool</a> stuff offered by AHC. As an example, you can add resumable support, Request/Response or IOException Filter by just doing:</p>
<pre><code>     config.getAsyncHttpClientConfigBuilder()
        .addIOExceptionFilter(new ResumableIOExceptionFilter());</code></pre>
<p>For any questions, use <a href="http://twitter.com/jfarcand">Twitter</a> to reach me! You can <a href="http://github.com/sonatype/jersey-ahc-client">checkout the code</a> on Github, download the jars from Maven Central or use Maven:</p>
<pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.sonatype.spice&lt;/groupId&gt;
    &lt;artifactId&gt;jersey-ahc-client&lt;/artifactId&gt;
    &lt;version&gt;1.0.0&lt;/version&gt;
&lt;/dependency&gt;</code></pre>
<p></code></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/jfarcand.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/jfarcand.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/jfarcand.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/jfarcand.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/jfarcand.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/jfarcand.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/jfarcand.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/jfarcand.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/jfarcand.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/jfarcand.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/jfarcand.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/jfarcand.wordpress.com/733/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/jfarcand.wordpress.com/733/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/jfarcand.wordpress.com/733/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=jfarcand.wordpress.com&amp;blog=11001265&amp;post=733&amp;subd=jfarcand&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://jfarcand.wordpress.com/2011/03/24/writing-powerful-rest-client-using-the-asynchttpclient-library-and-jersey/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9ae00d1d5f0b4479065431c13ca54013?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">jfarcand</media:title>
		</media:content>

		<media:content url="http://jfarcand.files.wordpress.com/2011/03/img_0872.jpg?w=300" medium="image">
			<media:title type="html">IMG_0872</media:title>
		</media:content>
	</item>
	</channel>
</rss>
