From 60f09566bbbfa77ef51b7ac1b10c4fd2e639d226 Mon Sep 17 00:00:00 2001 From: Ryan Mills Date: Sat, 4 Apr 2015 21:09:57 +0900 Subject: [PATCH] Fixes #62 --- GwtGrailsPlugin.groovy | 2 +- README.md | 1 + .../grails/plugins/gwt/GwtController.groovy | 3 + src/docs/guide/1. Introduction.gdoc | 4 +- src/docs/guide/2. Getting Started.gdoc | 7 +++ src/docs/guide/3. Server RPC.gdoc | 7 +++ src/docs/guide/5. Configuration.gdoc | 4 +- src/docs/ref/Command Line/run-gwt-client.gdoc | 2 +- .../ref/Command Line/run-gwt-codeserver.gdoc | 4 +- .../server/GrailsRemoteServiceServlet.java | 62 +++++++++++++++++++ .../aether/grails-app/conf/BuildConfig.groovy | 2 +- 11 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 src/java/grails/plugins/gwt/server/GrailsRemoteServiceServlet.java diff --git a/GwtGrailsPlugin.groovy b/GwtGrailsPlugin.groovy index 6eb7a3e..64fd27b 100644 --- a/GwtGrailsPlugin.groovy +++ b/GwtGrailsPlugin.groovy @@ -19,7 +19,7 @@ import org.codehaus.groovy.grails.plugins.gwt.DefaultGwtServiceInterfaceGenerato import org.codehaus.groovy.grails.web.plugins.support.WebMetaUtils class GwtGrailsPlugin { - def version = "1.0.3" + def version = "1.0.4" def grailsVersion = "2.0 > *" def title = "The Google Web Toolkit for Grails." def description = """\ diff --git a/README.md b/README.md index ce8601f..eeab93b 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,5 @@ plugins { transitive=false } } +setProperty('gwt.codeserver.port', '9876') ``` diff --git a/grails-app/controllers/org/codehaus/groovy/grails/plugins/gwt/GwtController.groovy b/grails-app/controllers/org/codehaus/groovy/grails/plugins/gwt/GwtController.groovy index 17eaa87..6150420 100644 --- a/grails-app/controllers/org/codehaus/groovy/grails/plugins/gwt/GwtController.groovy +++ b/grails-app/controllers/org/codehaus/groovy/grails/plugins/gwt/GwtController.groovy @@ -4,9 +4,12 @@ import com.google.gwt.user.client.rpc.SerializationException import com.google.gwt.user.server.rpc.RPC import com.google.gwt.user.server.rpc.RPCRequest import com.google.gwt.user.server.rpc.RemoteServiceServlet +import com.google.gwt.user.server.rpc.SerializationPolicy +import javax.servlet.http.HttpServletRequest import java.lang.reflect.UndeclaredThrowableException import javax.servlet.ServletContext +import java.net.URL; import org.codehaus.groovy.grails.commons.GrailsApplication import org.codehaus.groovy.grails.commons.GrailsClassUtils as GCU import org.codehaus.groovy.grails.web.context.ServletContextHolder diff --git a/src/docs/guide/1. Introduction.gdoc b/src/docs/guide/1. Introduction.gdoc index f8effb7..ec9ebe6 100644 --- a/src/docs/guide/1. Introduction.gdoc +++ b/src/docs/guide/1. Introduction.gdoc @@ -7,6 +7,6 @@ Jan Ehrhardt has kindly created a simple "tutorial":http://code.google.com/p/der You can also join in the discussions about the plugin and ask questions on the "Google Group for GWT/Grails integration":http://groups.google.com/group/grails-gwt/ The plugin host page is at http://grails.org/plugin/gwt -The source code is at https://github.com/dawsonsystems/grails-gwt -Documentation can be found at http://dawsonsystems.github.com/grails-gwt/guide/ +The source code is at https://github.com/simplicityitself/grails-gwt +Documentation can be found at http://simplicityitself.github.com/grails-gwt/guide/ The Google Group can be found at https://groups.google.com/group/grails-gwt \ No newline at end of file diff --git a/src/docs/guide/2. Getting Started.gdoc b/src/docs/guide/2. Getting Started.gdoc index d1cff4b..7a5a354 100644 --- a/src/docs/guide/2. Getting Started.gdoc +++ b/src/docs/guide/2. Getting Started.gdoc @@ -64,6 +64,13 @@ Starting the GWT hosted mode client. … [java] Listening for transport dt_socket at address: 5006 {code} +However, since 2.5.1, a JavaScript based code server method has been implemented, and has become mandatory in 2.7 +{code} +grails run-gwt-codeserver +{code} + +Note: in your BuildConfig.groovy, you must set an the property gwt.codeserver.port for RPC to work properly if you are using the resource plugin + Then, create a launch config in STS: {code} diff --git a/src/docs/guide/3. Server RPC.gdoc b/src/docs/guide/3. Server RPC.gdoc index fefc600..406b3a6 100644 --- a/src/docs/guide/3. Server RPC.gdoc +++ b/src/docs/guide/3. Server RPC.gdoc @@ -98,3 +98,10 @@ into: {code} MyServiceAsync myService = GWT.create(MyService.class); {code} + +h3. For existing Java RPC RemoteServiceServlet implementations + +Because of the resource plugin, the location that GWT is looking for the resource policy is different from the URL. To resolve, GrailsRemoteServiceServlet was create. Extend this instead of RemoteServiceServlet, or provide a custom doGetSerializationPolicy. + + + diff --git a/src/docs/guide/5. Configuration.gdoc b/src/docs/guide/5. Configuration.gdoc index 9cf9850..236f3fc 100644 --- a/src/docs/guide/5. Configuration.gdoc +++ b/src/docs/guide/5. Configuration.gdoc @@ -8,7 +8,7 @@ It will use any repositories that you set up in the main BuildConfig.groovy It *does not* use the dependencies block from BuildConfig, instead you must use the options below. The following options control dependency management -* gwt.version - Set a version number (eg "2.4.0") of GWT to use. +* gwt.version - Set a version number (eg "2.5.1") of GWT to use. * gwt.home (prefer to set a version have have it downloaded) - use the gwt version installed at the given location * gwt.gin.version - download gin and any necessary libraries @@ -19,7 +19,7 @@ gwt { version="2.3.0" gin.version="1.5.0" } - +setProperty("gwt.codeserver.port", "9876") //needed for run-app and run-gwt-codeserver {code} h3. GWT Modules diff --git a/src/docs/ref/Command Line/run-gwt-client.gdoc b/src/docs/ref/Command Line/run-gwt-client.gdoc index f64be52..a4ef15e 100644 --- a/src/docs/ref/Command Line/run-gwt-client.gdoc +++ b/src/docs/ref/Command Line/run-gwt-client.gdoc @@ -1,6 +1,6 @@ h1. run-gwt-client -Run the GWT Development Mode client. +Run the GWT Development Mode client (2.5.1 -> 2.6.1; for 2.7.0, see run-gwt-codeserver) This hosts your GWT code and executes it as Java. You will need the GWT plugin installed in your browser of choice. diff --git a/src/docs/ref/Command Line/run-gwt-codeserver.gdoc b/src/docs/ref/Command Line/run-gwt-codeserver.gdoc index db2cecd..118324d 100644 --- a/src/docs/ref/Command Line/run-gwt-codeserver.gdoc +++ b/src/docs/ref/Command Line/run-gwt-codeserver.gdoc @@ -5,4 +5,6 @@ Run the GWT Super Dev Mode client. This hosts your GWT code and compiles it to Javascript, in draft mode, on demand. This removes the need to have a browser plugin, and speeds up page refreshes if the code hasn't changed. -See https://developers.google.com/web-toolkit/articles/superdevmode \ No newline at end of file +See https://developers.google.com/web-toolkit/articles/superdevmode + +You also need to set gwt.codeserver.port in BuildConfig.groovy for RPC to work properly. \ No newline at end of file diff --git a/src/java/grails/plugins/gwt/server/GrailsRemoteServiceServlet.java b/src/java/grails/plugins/gwt/server/GrailsRemoteServiceServlet.java new file mode 100644 index 0000000..b5bc3dd --- /dev/null +++ b/src/java/grails/plugins/gwt/server/GrailsRemoteServiceServlet.java @@ -0,0 +1,62 @@ +package grails.plugins.gwt.server; + +import com.google.gwt.user.server.rpc.RemoteServiceServlet; +import com.google.gwt.user.server.rpc.SerializationPolicy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.servlet.http.HttpServletRequest; +import java.net.URL; + +/** + * Used to overcome the problem with grails resource plugin conflict with GWT + * + * GWT will use the URL to find resources, but the url has /static in it. + * + * issue#62 https://github.com/simplicityitself/grails-gwt/issues/62 + * + * Created by ryan on 15-04-04. + */ +public class GrailsRemoteServiceServlet extends RemoteServiceServlet { + Logger logger = LoggerFactory.getLogger(GrailsRemoteServiceServlet.class); + /** + * Strip off the /static from the beginning of a module url, then pass to the super's implementation + * + * issue#62 + * + * Does not affect other uses of static + * + * Borrow's from loadSerializationPolicy + * + * @param request + * @param moduleBaseURL + * @param strongName + * @return + */ + @Override + protected SerializationPolicy doGetSerializationPolicy( + HttpServletRequest request, String moduleBaseURL, String strongName) { + //moduleBaseURL.replace("/static", "") is so much easy(lazy) + String returnURL = moduleBaseURL; + logger.debug("doGetSerializationPolicy url:" + moduleBaseURL); + try{ + URL url = new URL(moduleBaseURL); + String host = url.getHost(); + int port = url.getPort(); + String protocol = url.getProtocol(); + String basePath = url.getPath(); + logger.debug("basePath:" + basePath); + if(basePath.startsWith("/static")){ + logger.debug("found static!"); + basePath = basePath.replaceFirst("/static", ""); + URL newUrl = new URL(protocol, host, port, basePath); + returnURL = newUrl.toString(); + } + + } catch(Exception e) { // default implementation will handle this + logger.error("Exception in GrailsRemoteService Servlet parsing url" + e.getMessage()); + } + return super.doGetSerializationPolicy(request, returnURL, strongName); + + } +} diff --git a/test/projects/aether/grails-app/conf/BuildConfig.groovy b/test/projects/aether/grails-app/conf/BuildConfig.groovy index 16f3deb..4402059 100644 --- a/test/projects/aether/grails-app/conf/BuildConfig.groovy +++ b/test/projects/aether/grails-app/conf/BuildConfig.groovy @@ -62,7 +62,7 @@ grails.project.dependency.resolution = { compile ':cache:1.1.1' build ":extended-dependency-manager:0.5.2" - compile ":gwt:1.0-SNAPSHOT", { + compile ":gwt:1.0.3", { transitive=false }