[Note from Isomorphic: this approach should no longer be used. If you want to use the SC server functionality (including the HttpProxy servlet) you should download SmartGWT Pro/EE, in which case use of the HttpProxy is automatic ].
Note: This applies to GWT 1.5
For GWT 1.6, see here
I thought I'd share the following information - maybe somebody will find it useful:
I recently tried to write a SmartGWT application that needed to call a webservice.
When finished, my SmartGWT app would be running on the same server that also hosted the webservice. But during development, my SmartGWT app would mostly run inside the GWT hosted mode browser (which uses GWT's own tomcat instance running on localhost:8888), while the webservice would run on a different domain (different server and/or port).
You probably know that browser security policies prohibit cross-domain webservice calls - cross-domain XmlHttpRequests (XHR) to be excact. In my case, those policies prevented my SmartGWT app from calling the webservice while running inside the GWT hosted mode browser, which was quite annoying.
I order to work around that restriction, the SmartClient library uses a server-side HttpProxy servlet (which comes with the SmartClient server) when making cross-domain webservice calls. The client-side SmartClient code detects cross-domain webservice calls and redirects them back to server where the SmartClient app is hosted. The server then routes the call through a special HttpProxy servlet, which forwards the call to the actual webservice without being restricted by any browser security policy.
But that only works when using the SmartClient server - which is part of the SmartClient SDK. But when developing SmartGWT apps, you're usually using the GWT server, which doesn't contain the HttpProxy.
The good news is that since both GWT's and the SmartClient's server are Tomcat servers, it's possible to integrate the HttpProxy servlet that comes with the SmartClient server into a GWT project and thereby enable cross-domain webservice calls during SmartGWT development.
All you need to do is the following:
1. Download and install the SmartClient SDK
2. Copy the following files to your GWT project directory (which you'll find in the SmartClientSDK dir):
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\isomorphic\system\schema\builtinTypes.xml
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\classes\log4j.isc.config.xml
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-codec-1_3.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-httpclient-3_0_1.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-jxpath-1_2.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-pool-1_3.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\isc-jakarta-oro-2_0_6.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\isomorphic_core_rpc.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\log4j-1_2_11.jar
3. Add the following lines at the beginning of the file <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\web.xml, right after the <web-app> tag:
4. Tell SmartClient to use the proxy servlet by calling
somewhere in your application before making the actual webservice call.
That's it. Now your SmartGWT project should be able to make cross-domain webservice calls at development time. The console output will even show the XML that's being passed through the HttpProxy servlet.
Note: This applies to GWT 1.5
For GWT 1.6, see here
I thought I'd share the following information - maybe somebody will find it useful:
I recently tried to write a SmartGWT application that needed to call a webservice.
When finished, my SmartGWT app would be running on the same server that also hosted the webservice. But during development, my SmartGWT app would mostly run inside the GWT hosted mode browser (which uses GWT's own tomcat instance running on localhost:8888), while the webservice would run on a different domain (different server and/or port).
You probably know that browser security policies prohibit cross-domain webservice calls - cross-domain XmlHttpRequests (XHR) to be excact. In my case, those policies prevented my SmartGWT app from calling the webservice while running inside the GWT hosted mode browser, which was quite annoying.
I order to work around that restriction, the SmartClient library uses a server-side HttpProxy servlet (which comes with the SmartClient server) when making cross-domain webservice calls. The client-side SmartClient code detects cross-domain webservice calls and redirects them back to server where the SmartClient app is hosted. The server then routes the call through a special HttpProxy servlet, which forwards the call to the actual webservice without being restricted by any browser security policy.
But that only works when using the SmartClient server - which is part of the SmartClient SDK. But when developing SmartGWT apps, you're usually using the GWT server, which doesn't contain the HttpProxy.
The good news is that since both GWT's and the SmartClient's server are Tomcat servers, it's possible to integrate the HttpProxy servlet that comes with the SmartClient server into a GWT project and thereby enable cross-domain webservice calls during SmartGWT development.
All you need to do is the following:
1. Download and install the SmartClient SDK
2. Copy the following files to your GWT project directory (which you'll find in the SmartClientSDK dir):
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\isomorphic\system\schema\builtinTypes.xml
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\classes\log4j.isc.config.xml
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-codec-1_3.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-httpclient-3_0_1.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-jxpath-1_2.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\commons-pool-1_3.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\isc-jakarta-oro-2_0_6.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\isomorphic_core_rpc.jar
* <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\lib\log4j-1_2_11.jar
3. Add the following lines at the beginning of the file <GWT_PROJECT_DIR>\tomcat\webapps\ROOT\WEB-INF\web.xml, right after the <web-app> tag:
Code:
<web-app> <!-- Enable HttpProxy servlet begin --> <servlet> <servlet-name>httpproxy</servlet-name> <servlet-class>com.isomorphic.servlet.HttpProxyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>httpproxy</servlet-name> <url-pattern>/com.yourcompany.yourproject/sc/HttpProxy</url-pattern> </servlet-mapping> <!-- Enable HttpProxy servlet end --> ... </web-app>
Code:
RPCManager.setUseHttpProxy(true);
That's it. Now your SmartGWT project should be able to make cross-domain webservice calls at development time. The console output will even show the XML that's being passed through the HttpProxy servlet.
Comment