[ANN] REST with Comet support added

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[ANN] REST with Comet support added

Jeanfrancois Arcand
Salut,

included with the latest atmosphere-core-0.2-SNAPSHOT.jar, it is now
possible to write REST with Comet based application. This is as simple as:

>     @Suspend
>     @GET
>     @Produces("text/html")
>     public String cometGet() {
>         return "<!-- Comet is a programming technique that enables web " +
>                     "servers to send data to the client without having any need " +
>                     "for the client to request it. -->\n";
>     }
>
>     @Broadcast
>     @Consumes("application/x-www-form-urlencoded")
>     @POST
>     @Produces("text/html")
>     public String cometPost(MultivaluedMap<String, String> form) {
>         String action = form.getFirst("action");
>         String name = form.getFirst("name");
>
>         if ("login".equals(action)) {
>             return BEGIN_SCRIPT_TAG + toJsonp("System Message", name + " has joined.") + END_SCRIPT_TAG;
>         } else if ("post".equals(action)) {
>             return BEGIN_SCRIPT_TAG + toJsonp(name, form.getFirst("message")) + END_SCRIPT_TAG;
>         } else {
>             throw new WebApplicationException(422);
>         }
>     }
>
>     @OnBroadcast
>     public String cometPush(String s) {
>         System.out.println("cometPush: " + s);
>         return s;
>     }


The full sample can be downloaded from here:

http://download.java.net/maven/2/org/atmosphere/samples/core-rest-chat

Take a look and contribute feedback. In the upcoming days I will add
support for the remaining missing annotation. My goal is to release 0.2
next week.

Thanks!

-- Jeanfrancois

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] REST with Comet support added

Paul Sandoz

On May 21, 2009, at 3:47 AM, Jeanfrancois Arcand wrote:

> Salut,
>
> included with the latest atmosphere-core-0.2-SNAPSHOT.jar, it is now  
> possible to write REST with Comet based application.

Most excellent.


> This is as simple as:
>
>>    @Suspend
>>    @GET
>>    @Produces("text/html")
>>    public String cometGet() {
>>        return "<!-- Comet is a programming technique that enables  
>> web " +
>>                    "servers to send data to the client without  
>> having any need " +
>>                    "for the client to request it. -->\n";
>>    }
>>    @Broadcast
>>    @Consumes("application/x-www-form-urlencoded")
>>    @POST
>>    @Produces("text/html")
>>    public String cometPost(MultivaluedMap<String, String> form) {

   public String cometPost(
      @FormParam("action") String action,
      @FormParam("name") String name,
      MultivaluedMap<String, String> form) {
     ...
   }


>>
>>        String action = form.getFirst("action");
>>        String name = form.getFirst("name");
>>        if ("login".equals(action)) {
>>            return BEGIN_SCRIPT_TAG + toJsonp("System Message", name  
>> + " has joined.") + END_SCRIPT_TAG;
>>        } else if ("post".equals(action)) {
>>            return BEGIN_SCRIPT_TAG + toJsonp(name,  
>> form.getFirst("message")) + END_SCRIPT_TAG;
>>        } else {
>>            throw new WebApplicationException(422);
>>        }
>>    }

Jersey does have JSONP support.

See here:

   https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/api/json/JSONWithPadding.html

Using say a JAXB bean to encapsulate the name and message, or a  
JSONObject instance.

But think it will require some modification to the client side to  
avoid the server side embedding the "script" tag. That would remove a  
fair bit of the code in the example. If this is not sufficient we can  
define a new message body writer, or modify the JSONWithPadding to  
support the HTML wrapping as well.

Paul.

>>
>>    @OnBroadcast
>>    public String cometPush(String s) {
>>        System.out.println("cometPush: " + s);
>>        return s;
>>    }
>
>
> The full sample can be downloaded from here:
>
> http://download.java.net/maven/2/org/atmosphere/samples/core-rest-chat
>
> Take a look and contribute feedback. In the upcoming days I will add  
> support for the remaining missing annotation. My goal is to release  
> 0.2 next week.
>
> Thanks!
>
> -- Jeanfrancois
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] REST with Comet support added

Jeanfrancois Arcand
Salut,

Paul Sandoz wrote:

>
> On May 21, 2009, at 3:47 AM, Jeanfrancois Arcand wrote:
>
>> Salut,
>>
>> included with the latest atmosphere-core-0.2-SNAPSHOT.jar, it is now
>> possible to write REST with Comet based application.
>
> Most excellent.
>
>
>> This is as simple as:
>>
>>>    @Suspend
>>>    @GET
>>>    @Produces("text/html")
>>>    public String cometGet() {
>>>        return "<!-- Comet is a programming technique that enables web
>>> " +
>>>                    "servers to send data to the client without having
>>> any need " +
>>>                    "for the client to request it. -->\n";
>>>    }
>>>    @Broadcast
>>>    @Consumes("application/x-www-form-urlencoded")
>>>    @POST
>>>    @Produces("text/html")
>>>    public String cometPost(MultivaluedMap<String, String> form) {
>
>   public String cometPost(
>      @FormParam("action") String action,
>      @FormParam("name") String name,
>      MultivaluedMap<String, String> form) {
>     ...
>   }

Must better :-)

>
>
>>>
>>>        String action = form.getFirst("action");
>>>        String name = form.getFirst("name");
>>>        if ("login".equals(action)) {
>>>            return BEGIN_SCRIPT_TAG + toJsonp("System Message", name +
>>> " has joined.") + END_SCRIPT_TAG;
>>>        } else if ("post".equals(action)) {
>>>            return BEGIN_SCRIPT_TAG + toJsonp(name,
>>> form.getFirst("message")) + END_SCRIPT_TAG;
>>>        } else {
>>>            throw new WebApplicationException(422);
>>>        }
>>>    }
>
> Jersey does have JSONP support.
>
> See here:
>
>  
> https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/api/json/JSONWithPadding.html 
>
>
> Using say a JAXB bean to encapsulate the name and message, or a
> JSONObject instance.
>
> But think it will require some modification to the client side to avoid
> the server side embedding the "script" tag. That would remove a fair bit
> of the code in the example. If this is not sufficient we can define a
> new message body writer, or modify the JSONWithPadding to support the
> HTML wrapping as well.

I would like to avoid changing the client as it use behavior/prototype
and I suspect the majority of peoples will expect the script tag. But I
will give a try and look at your recommendation.

A+

-- Jeanfrancois


>
> Paul.
>
>>>
>>>    @OnBroadcast
>>>    public String cometPush(String s) {
>>>        System.out.println("cometPush: " + s);
>>>        return s;
>>>    }
>>
>>
>> The full sample can be downloaded from here:
>>
>> http://download.java.net/maven/2/org/atmosphere/samples/core-rest-chat
>>
>> Take a look and contribute feedback. In the upcoming days I will add
>> support for the remaining missing annotation. My goal is to release
>> 0.2 next week.
>>
>> Thanks!
>>
>> -- Jeanfrancois
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [ANN] REST with Comet support added

Paul Sandoz
On May 21, 2009, at 4:01 PM, Jeanfrancois Arcand wrote:

>
>>>>
>>>>       String action = form.getFirst("action");
>>>>       String name = form.getFirst("name");
>>>>       if ("login".equals(action)) {
>>>>           return BEGIN_SCRIPT_TAG + toJsonp("System Message",  
>>>> name + " has joined.") + END_SCRIPT_TAG;
>>>>       } else if ("post".equals(action)) {
>>>>           return BEGIN_SCRIPT_TAG + toJsonp(name,  
>>>> form.getFirst("message")) + END_SCRIPT_TAG;
>>>>       } else {
>>>>           throw new WebApplicationException(422);
>>>>       }
>>>>   }
>> Jersey does have JSONP support.
>> See here:
>>  https://jersey.dev.java.net/nonav/apidocs/1.1.0-ea/jersey/com/sun/jersey/api/json/JSONWithPadding.html 
>>  Using say a JAXB bean to encapsulate the name and message, or a  
>> JSONObject instance.
>> But think it will require some modification to the client side to  
>> avoid the server side embedding the "script" tag. That would remove  
>> a fair bit of the code in the example. If this is not sufficient we  
>> can define a new message body writer, or modify the JSONWithPadding  
>> to support the HTML wrapping as well.
>
> I would like to avoid changing the client as it use behavior/
> prototype and I suspect the majority of peoples will expect the  
> script tag.

Then we should try and abstract that out, because there are two layers  
of encoding being performed at the string level, HTML then JSON and it  
makes for bugs. E.g. with something like a JSONP message body writer  
that wraps the JSON expression around the HTML script tags. Then the  
return from cometPost and parameter of cometPush would be a higher  
level type. Perhaps that makes sense as part of Atmosphere?


> But I will give a try and look at your recommendation.
>

OK!

Paul.

> A+
>
> -- Jeanfrancois
>
>
>> Paul.
>>>>
>>>>   @OnBroadcast
>>>>   public String cometPush(String s) {
>>>>       System.out.println("cometPush: " + s);
>>>>       return s;
>>>>   }
>>>
>>>
>>> The full sample can be downloaded from here:
>>>
>>> http://download.java.net/maven/2/org/atmosphere/samples/core-rest-chat
>>>
>>> Take a look and contribute feedback. In the upcoming days I will  
>>> add support for the remaining missing annotation. My goal is to  
>>> release 0.2 next week.
>>>
>>> Thanks!
>>>
>>> -- Jeanfrancois
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...