开发者

GWT with -noserver

开发者 https://www.devze.com 2022-12-17 10:52 出处:网络
I\'m making a GWT project that uses PHP to connect to a DB2 database. When I compile the project and deploy it to the server (copy the contents of the WAR directory over), it works fine, obviously in

I'm making a GWT project that uses PHP to connect to a DB2 database. When I compile the project and deploy it to the server (copy the contents of the WAR directory over), it works fine, obviously in hosted mode I run into the SOP issue since GWT is on port 8888 while the php script is running on port 80.

I'm trying to get the -noserver option to work but I must be missing something.. I went back and created the basic sample app from the command line (webApplicationCreator -out /home/mike/gwt/sample1) I edited the build.xml to include the -noserver and -port 80 arguements for devmode. I want my app to be hosted at localhost/sample1 so I edited the -startupUrl to the whole URL I want to use: http://localhost/sample1/sample1.html

I compiled (ant), copied over the sample1.html, sample1.css from war to the webserver sample1 directory, and the (md5).gwt.rpc, clear.cache.gif, sample1.nocache.js and hosted.html files from the war/sample1 to sample1/sample1 directory as described in the GWT documentation (no history.html file was created). I then run ant devmode from the project directory (/home/mike/gwt/sample1) I can get to the sample1.html page, but when I click the button to send the name to the server it returns with

Remote Procedure Call - Failure

Server replies: An error occ开发者_高级运维urred while attempting to contact the server. Please check your network connection and try again.

I turned on firebug and it's returning a 404 for http://localhost/sample1/sample1/greet. This is where I'm stuck.. this file obviously doesn't exist on my webserver.. but why? Isn't this something that is supposed to be getting compiled by GWT?

Can anyone give me a hand? Thanks!


So, basically you've copied over the client-side of a client/server application. When your GWT client application attempts to make a Remote Procedure Call (RPC) to the server to a greeting service that is part of the initial sample, it can't find that service.

If you wanted to copy that service over, you'd need to have a Java application server, copy over the GreetingService, the web.xml that references it and possibly a few other things (I'd have to check in more detail). That doesn't sound like what you actually want, so either you'll want to build a GWT-RPC service in PHP that responds to that URL, or remove the reference in the GWT code to RPC call to the greeting service.

With a PHP back-end, you're probably not going to use GWT-RPC, I'm guessing that you're more likely to use JSON or XML, and if that's the case, then I'd go with removing the RPC call altogether for now.

Does this all make sense? Feel free to ask for further clarification.


To solve the SOP issue, I used the HttpProxyServlet to proxy the HTTP requests to my webserver through the development server.

Download httpProxyPackage.jar, copy it into WEB-INF/lib/, and configure it like so in WEB-INF/web.xml (this is for the StockWatcher tutorial, assuming your web root is the folder that contains the StockWatcher directory):

<servlet>
  <servlet-name>jsonStockData</servlet-name> 
  <servlet-class>com.jsos.httpproxy.HttpProxyServlet</servlet-class> 
  <init-param> 
    <param-name>host</param-name> 
    <param-value>http://localhost/StockWatcher/war/stockPrices.php</param-value> 
  </init-param> 
</servlet>

<servlet-mapping> 
  <servlet-name>jsonStockData</servlet-name>
  <!--
    http://127.0.0.1:8888/stockPrices.php in dev mode
    http://gwt/StockWatcher/war/stockPrices.php in prod mode
  -->
  <url-pattern>/stockPrices.php</url-pattern>
</servlet-mapping>

Then redefine your JSON URL as:

    GWT.getHostPageBaseURL() + "stockPrices.php?q=";

instead of:

    GWT.getModuleBaseURL() + "stockPrices.php?q=";

It’s maybe not the best way, but if it can get someone else started… There was another way using php-cgi, but I didn’t have it installed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号