You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by Parth Chandra <pa...@apache.org> on 2015/09/01 07:18:44 UTC

Re: Cross Origin REST API calls in embedded mode (for testing)

Your error means that you cannot invoke a script from a location that is
different from the location of your original script, i.e. the scripts must
be from the same 'origin'.
'Origin' is different even if the ports the scripts are served from are
different, which is probably the case here.
Unfortunately Drill's REST API does not have support for either a more
relaxed cross origin policy or CORS (you might want to put in an
enhancement request for that).
I haven't tried these myself, but something here might help :
http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy



On Sun, Aug 30, 2015 at 8:49 PM, Tomer Shiran <ts...@dremio.com> wrote:

> Can you post the script that you're using? Is this a client-side
> JavaScript?
>
> On Sun, Aug 30, 2015 at 12:51 PM, Nira Amit <am...@gmail.com> wrote:
>
> > Hello Drill developers,
> > I'm implementing a module that reads data from Drill and feeds it into a
> > visualization tool. I have a working embedded Drill installation with my
> > data on it and when I query it with curl it works just fine:
> >
> > curl --header "Content-type: application/json" --request POST --data
> > @post.json http://localhost:8047/query.json
> >
> > where post.json contatins:
> > {"queryType" : "SQL", "query" : "select * from
> >  vzb.dev.`/bigdata/parquet_basic_indicators` limit 1"}
> >
> > returns:
> > {
> >   "columns" : [ "TIME", "GEO", "GDP_PER_CAP", "LEX", "POP", "GEO_NAME",
> > "GEO_CAT", "GEO_REGION" ],
> >   "rows" : [ {
> >     "GEO" : "world",
> >     "POP" : "5858793283",
> >     "GDP_PER_CAP" : "8780.9",
> >     "GEO_NAME" : "World",
> >     "GEO_CAT" : "planet",
> >     "TIME" : "1990",
> >     "GEO_REGION" : "\r",
> >     "LEX" : "65.76"
> >   } ]
> > }
> >
> > however, if I try to invoke such a Post request from a script, I'm
> getting:
> > XMLHttpRequest cannot load http://localhost:8047/query.json. Origin
> > file://
> > is not allowed by Access-Control-Allow-Origin.
> >
> > So my question is: can I configure the embedded server to accept the
> > request? I can rebuild Drill in my local environment if necessary, I just
> > need to know what to change in the code/configuration for it to work.
> >
> > Thanks!
> > Nira.
> >
>
>
>
> --
> Tomer Shiran
>

Re: Cross Origin REST API calls in embedded mode (for testing)

Posted by Jacques Nadeau <ja...@dremio.com>.
Drill uses Jetty internally.  You can insert a ServletFilter that provides
the additional headers required to allow a cross origin policy in the code
by updating the Jetty initialization.  The code for the server is here:

https://github.com/apache/drill/blob/master/exec/java-exec/src/main/java/org/apache/drill/exec/server/Drillbit.java#L214

It shouldn't be too bad, I think there are some guides on stack overflow
for adding filters to Jetty and what type of filter to add for cross origin
purposes.

--
Jacques Nadeau
CTO and Co-Founder, Dremio

On Mon, Aug 31, 2015 at 10:18 PM, Parth Chandra <pa...@apache.org> wrote:

> Your error means that you cannot invoke a script from a location that is
> different from the location of your original script, i.e. the scripts must
> be from the same 'origin'.
> 'Origin' is different even if the ports the scripts are served from are
> different, which is probably the case here.
> Unfortunately Drill's REST API does not have support for either a more
> relaxed cross origin policy or CORS (you might want to put in an
> enhancement request for that).
> I haven't tried these myself, but something here might help :
>
> http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy
>
>
>
> On Sun, Aug 30, 2015 at 8:49 PM, Tomer Shiran <ts...@dremio.com> wrote:
>
> > Can you post the script that you're using? Is this a client-side
> > JavaScript?
> >
> > On Sun, Aug 30, 2015 at 12:51 PM, Nira Amit <am...@gmail.com> wrote:
> >
> > > Hello Drill developers,
> > > I'm implementing a module that reads data from Drill and feeds it into
> a
> > > visualization tool. I have a working embedded Drill installation with
> my
> > > data on it and when I query it with curl it works just fine:
> > >
> > > curl --header "Content-type: application/json" --request POST --data
> > > @post.json http://localhost:8047/query.json
> > >
> > > where post.json contatins:
> > > {"queryType" : "SQL", "query" : "select * from
> > >  vzb.dev.`/bigdata/parquet_basic_indicators` limit 1"}
> > >
> > > returns:
> > > {
> > >   "columns" : [ "TIME", "GEO", "GDP_PER_CAP", "LEX", "POP", "GEO_NAME",
> > > "GEO_CAT", "GEO_REGION" ],
> > >   "rows" : [ {
> > >     "GEO" : "world",
> > >     "POP" : "5858793283",
> > >     "GDP_PER_CAP" : "8780.9",
> > >     "GEO_NAME" : "World",
> > >     "GEO_CAT" : "planet",
> > >     "TIME" : "1990",
> > >     "GEO_REGION" : "\r",
> > >     "LEX" : "65.76"
> > >   } ]
> > > }
> > >
> > > however, if I try to invoke such a Post request from a script, I'm
> > getting:
> > > XMLHttpRequest cannot load http://localhost:8047/query.json. Origin
> > > file://
> > > is not allowed by Access-Control-Allow-Origin.
> > >
> > > So my question is: can I configure the embedded server to accept the
> > > request? I can rebuild Drill in my local environment if necessary, I
> just
> > > need to know what to change in the code/configuration for it to work.
> > >
> > > Thanks!
> > > Nira.
> > >
> >
> >
> >
> > --
> > Tomer Shiran
> >
>