GWT HTTP RequestBuilder

388 views
Skip to first unread message

karun

unread,
Nov 11, 2011, 2:43:09 PM11/11/11
to Google Web Toolkit
Hi

I am using GWT HTTP RequestBuilder in my application to exchange
information between 2 servers, out of which 1 server hosts my GWT
application and another is general server which hosts j2ee application

both servers domains are as follows

server 1. http://factory-dev03.example.com:8111/

server 2. http://factory-dev109.example.com:8111/

in IE browser i am getting response with status code as '200' from
server 2 but in FireFox and Safari i am getting response with status
code as '0'.

i have gone through same origin policy (http://code.google.com/
webtoolkit/doc/2.0/
FAQ_Server.html#What_is_the_Same_Origin_Policy,_and_how_does_it_affect_GWT)

and i also added <add-linker name="xs"/> in application.gwt.xml file
but no luck.

below is my code for reference

String url="http://factory-dev03.example.com:8111/CustomerUI-dev03/
ims_ui/ui/WizardJavaScriptUpdated.jsp";

RequestBuilder builder = new RequestBuilder(RequestBuilder.GET,
URL.encode(url));

Request request = builder.sendRequest("", new RequestCallback() {

public void onError(Request request, Throwable exception) {
Window.alert("Request Builder Failed");
}

public void onResponseReceived(Request request, Response response) {
Window.alert("Request Builder
passed"+response.getStatusCode());

}

});


Thanks
kumar

Jens

unread,
Nov 11, 2011, 3:55:08 PM11/11/11
to google-we...@googlegroups.com
Sure you got a 200 in IE? IE should also give some error if you try to make a request to a different domain/port. Also shouldn't your code snippet use factory-dev109.example.com if server 2 is the server you want to request?

Well but in general you have three options to make cross domain requests:

1.) You have to use a reverse proxy so you can make requests to external servers without leaving the domain which serves the GWT application.
2.) Make a GWT request to server 1 (works because there is no SOP) and then let your server side code on server 1 do a request to server 2 using plain java.
3.) Use JsonpRequestBuilder. But this would require some rewrite of your "server 2" code as you now need to provide your data as JSON and also wrap this JSON data in a javascript callback function whose name is send by GWT to your server 2 via a GET parameter.


-- J.

karun

unread,
Nov 13, 2011, 1:59:38 PM11/13/11
to Google Web Toolkit
Hi Jens

Yes i am sure, i got response code as 200 and the jsp from J2EE server
is also getting displayed,

sorry for typo my application is in server 2 and J2EE application is
in server 1.

to overcome SOP only, we have setup the 2 servers in above format. so
that domain name and port are same, both servers end with

1. example.com

2. and also both servers have same port no. 8111

when i went through the sop policy in gwt documentation, i came across
below way of loading images and javascript files from different
server. which i felt is similiar to our setup.

part of documentation is pasted below:

"However, many organizations setup their deployment platform in such a
way that their main host HTML page is served up from http://mydomain.com/,
but any other resources such as images and JavaScript files are served
up from a separate static server under http://static.mydomain.com/. In
older versions of GWT, this configuration would not be possible as the
SOP prevented the GWT bootstrap process from allowing script from
files that were added from a different server to access the iframe in
the main host HTML page. As of GWT 1.5, the bootstrap model now
provides support for this kind of server configuration via the cross-
site linker (xs-linker).

When using the cross-site linker the compiler will still generate a
<module>.nocache.js that you will want to reference within your
index.html. The difference though, is that the <module>.nocache.js
produced by the cross-site linker will link in a cache.js file for
each of your permutations rather than a cache.html file.

To enable the cross-site linking simply add the following to your
<module>.gwt.xml and include a reference to your <module>.nocache.js
in your index.html as you normally would.

<add-linker name="xs"/>
"
according to this doesn't our setup overcome SOP.

Thanks
kumar

Thomas Broyer

unread,
Nov 13, 2011, 2:24:05 PM11/13/11
to google-we...@googlegroups.com


On Sunday, November 13, 2011 7:59:38 PM UTC+1, karun wrote:
Hi Jens

Yes i am sure, i got response code as 200 and the jsp from J2EE server
is also getting displayed,

sorry for typo  my application is in server 2 and J2EE application is
in server 1.

to overcome SOP only, we have setup the 2 servers in above format. so
that domain name and port are same, both servers end with

1. example.com

2. and also both servers have same port no. 8111

That's not enough: factory-dev03.example.com is different from factory-dev109.example.com, so they're different origins.
 
when i went through the sop policy in gwt documentation,

 
i came across
below way of  loading images and javascript files from different
server. which i felt is similiar to our setup.

 part of documentation is pasted below:

"However, many organizations setup their deployment platform in such a
way that their main host HTML page is served up from http://mydomain.com/,
but any other resources such as images and JavaScript files are served
up from a separate static server under http://static.mydomain.com/. In
older versions of GWT, this configuration would not be possible as the
SOP prevented the GWT bootstrap process from allowing script from
files that were added from a different server to access the iframe in
the main host HTML page. As of GWT 1.5, the bootstrap model now
provides support for this kind of server configuration via the cross-
site linker (xs-linker).

When using the cross-site linker the compiler will still generate a
<module>.nocache.js that you will want to reference within your
index.html. The difference though, is that the <module>.nocache.js
produced by the cross-site linker will link in a cache.js file for
each of your permutations rather than a cache.html file.

To enable the cross-site linking simply add the following to your
<module>.gwt.xml and include a reference to your <module>.nocache.js
in your index.html as you normally would.

<add-linker name="xs"/>
"
according to this doesn't our setup overcome SOP.

That's only about serving the GWT files from another server, it doesn't change anything about RPC/RequestFactory/RequestBuilder: they have to be issued by the same origin (your HTML host page) as the one they try to reach (or they can use CORS in non-IE browsers).
In other words, the URL you see in your browser should be factory-dev109 if your servlets are on that server; you can serve the *.nocache.js and associated *.cache.* files from the factory-dev03 server.

Also, note that the "xs" linker is being deprecated in favor of the "xsiframe" linker.

karun

unread,
Nov 14, 2011, 5:30:19 PM11/14/11
to Google Web Toolkit
Thanks Thomas and jens for your help

i am planning to use CORS for time being. later i will use reverse
proxy approach.

Regards
kumar

On Nov 14, 12:24 am, Thomas Broyer <t.bro...@gmail.com> wrote:
> On Sunday, November 13, 2011 7:59:38 PM UTC+1, karun wrote:
>
> > Hi Jens
>
> > Yes i am sure, i got response code as 200 and the jsp from J2EE server
> > is also getting displayed,
>
> > sorry for typo  my application is in server 2 and J2EE application is
> > in server 1.
>
> > to overcome SOP only, we have setup the 2 servers in above format. so
> > that domain name and port are same, both servers end with
>
> > 1. example.com
>
> > 2. and also both servers have same port no. 8111
>
> That's not enough: factory-dev03.example.com is different from
> factory-dev109.example.com, so they're different origins.
>
> > when i went through the sop policy in gwt documentation,
>
> Seehttp://en.wikipedia.org/wiki/Same_origin_policy, andhttp://www.schemehostport.com/2011/10/foundations-origin.html
>
>
>
>
>
> > i came across
> > below way of  loading images and javascript files from different
> > server. which i felt is similiar to our setup.
>
> >  part of documentation is pasted below:
>
> > "However, many organizations setup their deployment platform in such a
> > way that their main host HTML page is served up fromhttp://mydomain.com/,
>
> > but any other resources such as images and JavaScript files are served
> > up from a separate static server underhttp://static.mydomain.com/. In
> > older versions of GWT, this configuration would not be possible as the
> > SOP prevented the GWT bootstrap process from allowing script from
> > files that were added from a different server to access the iframe in
> > the main host HTML page. As of GWT 1.5, the bootstrap model now
> > provides support for this kind of server configuration via the cross-
> > site linker (xs-linker).
>
> > When using the cross-site linker the compiler will still generate a
> > <module>.nocache.js that you will want to reference within your
> > index.html. The difference though, is that the <module>.nocache.js
> > produced by the cross-site linker will link in a cache.js file for
> > each of your permutations rather than a cache.html file.
>
> > To enable the cross-site linking simply add the following to your
> > <module>.gwt.xml and include a reference to your <module>.nocache.js
> > in your index.html as you normally would.
>
> > <add-linker name="xs"/>
> > "
> > according to this doesn't our setup overcome SOP.
>
> That's only about serving the GWT files from another server, it doesn't
> change anything about RPC/RequestFactory/RequestBuilder: they have to be
> issued by the same origin (your HTML host page) as the one they try to
> reach (or they can use CORS in non-IE browsers).
> In other words, the URL you see in your browser should be factory-dev109 if
> your servlets are on that server; you can serve the *.nocache.js and
> associated *.cache.* files from the factory-dev03 server.
>
> Also, note that the "xs" linker is being deprecated in favor of the
> "xsiframe" linker.- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

karun

unread,
Nov 17, 2011, 2:30:57 PM11/17/11
to Google Web Toolkit
Hi Thomas,

CORS has solved SOP problem,

i am displaying the http response JSP by creating a html using
response.getText() method and adding that html to PopupPanel.

The problem is the elements in html page are misaligned/not formed
properly, when compared to the same JSP opened directly in the
browser. any solution how to over some this.

Thanks
karun
Reply all
Reply to author
Forward
0 new messages