dev@glassfish.java.net

Re: How to handle callbacks in jsr311

From: Farjola Zaloshnja <farjola.zaloshnja_at_gmail.com>
Date: Wed, 18 Mar 2009 12:01:57 +0100

Hi Paul,

Thank you for the response.

I will try to clarify better the question by putting some code ( this always
works :-))
If I have this resource class:


@Provider
@Produces( { "text/xml", "application/json" })
@Consumes( { "text/xml", "application/json" })
@Path("/epg")
public class WebBean {

   @Context
    protected UriInfo uriInfo;
    private IWebEjb webEjb;

    public WebBean() {

        try {
            InitialContext ctx = new InitialContext();
            webEjb = (IWebEjb) ctx.lookup("ejb/WebEjb");
        } catch (NamingException e) {
            logger.log(Level.SEVERE,"Failed to initate EPGWebBean",e);
        }
    }


    @GET
    @Path("nowandnext")
    public Asset shownowandnext() {
        String startTime =
uriInfo.getQueryParameters().get("starttime").get(0);
        String stopTime =
uriInfo.getQueryParameters().get("stoptime").get(0);
        return (webEjb.showNowAndNext(Long.valueOf(startTime),
Long.valueOf(stopTime)));

    }

When an Ajax/javascript client sends an HTTP GET and the response is a json
object ( Asset is an entity, POJO decorated with the necessary annotations),
the client request is to have a callback on this object, and by callback
means that the json object looks like:
( {"ids": "id" : {type: x} } );
As I was told this is a cross domain security issue in javascript which is
solvable by callbacks. (I am not a client ajax/javascript developer, far
from it) but I am asked to handle this on the server, and I have never done
such a thing, so I was curious if anyone has tried and there are some
guidelines on how to handle this in the resource classes.

Thank you once again, hope it's clearer,

/Farjola





On Wed, Mar 18, 2009 at 10:26 AM, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:

> Hi Farjola,
>
> On Mar 17, 2009, at 10:05 PM, Farjola Zaloshnja wrote:
>
> Hi,
>>
>> I am trying to support callback functionality in my web bean, which
>> consumes and produces application/json in my server all complaint with java
>> ee technologies, has anyone around a simple example or information if it's
>> possible and how please ?
>>
>
> Could you provide a concrete Java example of what you would like to do? I
> do not understand your question. For example, i do not know what you mean by
> "web bean" and "callback".
>
> Do you want to create a resource class that works correctly within a Java
> EE 5 compliant container like GF v2.x? Do you want to use a session bean as
> a resource class?
>
> In general it is very easy to use JAX-RS/Jersey in any compliant Web
> container. But i need more information on what EE technologies you want to
> use and integrate with to help you.
>
> Note that JAX-RS does not specify support for JSON, so you will need to
> utilize additional features of a JAX-RS implementation for that.
>
> Paul.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: dev-help_at_glassfish.dev.java.net
>
>