jquery AJAX Post call to the Broker

529 views
Skip to first unread message

Punit Shah

unread,
Nov 24, 2014, 8:43:52 PM11/24/14
to druid-de...@googlegroups.com
I'm having a real hard time making a successful post call to the Broker.  The call works when I'm using the chrome rest client.  But as soon as I fire off an ajax call from javascript I get an error on the server side in the AbstractWadlGeneratorGrammarGenerator class where it can't find a bunch of grammar elements.  Here's my call I'm making from my javascript class:

            var postReq = {};
            postReq.queryType = "topN";
            postReq.dataSource = "stc";
            postReq.granularity = "day";
            postReq.dimension = "DIP";
            postReq.threshold = "1";
            postReq.metric = "Dur";
            postReq.aggregations = [{"type": "doubleSum", "name": "Dur", "fieldName": "Duration"}];
            postReq.intervals = ["2014-10-10/2014-10-18"];


                $.ajax({
                    url: "http://192.168.1.8:8080/druid/v2/",
                    beforeSend: function(xhrObj){
                        xhrObj.setRequestHeader("Access-Control-Allow-Origin","*");
                        xhrObj.setRequestHeader("Accept","*/*");
                        xhrObj.setRequestHeader("Content-Type","application/json");
                        xhrObj.setRequestHeader("Access-Control-Allow-Headers","origin, content-type, accept, authorization");
                    },
                    type: 'post',
                    contentType: 'application/json',
                    data: JSON.stringify(postReq),
                    success: function (data, textStatus, jQxhr) {
                        alert("data = " + data);
                    },
                    error: function (jqXhr, textStatus, errorThrown) {
                        alert("error = " + errorThrown);
                   }});

Eric Tschetter

unread,
Nov 25, 2014, 12:23:33 PM11/25/14
to druid-de...@googlegroups.com
Punit,

Nothing is jumping out at me about that javascript right now, could
you share the stacktrace for the server-side error?

--Eric
> --
> You received this message because you are subscribed to the Google Groups
> "Druid Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to druid-developm...@googlegroups.com.
> To post to this group, send email to druid-de...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/druid-development/64c569b1-3b7a-483e-9ef1-6379e74bb55b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Punit

unread,
Nov 25, 2014, 1:26:02 PM11/25/14
to druid-de...@googlegroups.com
Eric,

Thanks for your response.

Spent quite a few hours on this.  I finally had to resort to a work-around.  I managed to get this working by writing a server-side proxy that acts as the intermediary between the javascript call and the broker.  I initially had a similar problem with my web-app, which I created to handle this javascript.  I ended up implementing a filter in the web-app to handle cross-site AJAX calls.  Once this was done I could then communicate with the Broker via the intermediary web-app.

But as an FYI here is what I was seeing:
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class io.druid.server.StatusResource$Status
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class java.lang.Iterable
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class java.util.Map
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class java.lang.Iterable
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class java.lang.Iterable
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class javax.ws.rs.core.Response
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class javax.ws.rs.core.Response
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class javax.ws.rs.core.Response
Nov 25, 2014 6:22:36 PM com.sun.jersey.server.wadl.generators.AbstractWadlGeneratorGrammarGenerator attachTypes
INFO: Couldn't find grammar element for class javax.ws.rs.core.Response

Eric Tschetter

unread,
Nov 25, 2014, 2:42:45 PM11/25/14
to druid-de...@googlegroups.com
Hrm, I wonder if perhaps there is some handling of javascript requests
in Jersey for like CORS or other type things that causes it to
traverse extra code paths than just curl'ing requests. If so, the fix
is probably just including some set of Jersey extension jars on the
classpath, but I'm not sure which ones they would be...

--Eric
> https://groups.google.com/d/msgid/druid-development/cfce9241-bb9a-405e-8256-5558ba6834f5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages