My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
GWT  
How to integrate with GWT.
Featured
Updated Jan 11, 2011 by marc.la...@gmail.com

Decode, invoke and encode

IMPORTANT: This is using GWT 2.1.1! Before that you have to use SerializableException, even though the documentation tells you not to, to encode a failure!

Add this inner class below to GreetingServiceImpl.java in the generated GWT start app and replace the REPLACE string in both places with the name of your project/jar (might not be the same in both places). Also remove these servlet specific lines:

String serverInfo = getServletContext().getServerInfo();
String userAgent = getThreadLocalRequest().getHeader("User-Agent");

Then add gwt-user.jar to the classpath, deploy the war file as a jar to rupy and everything will just magically work.

NOTE: You should still develop using devmode because the compiler takes 30 sec. to compile the smallest app.

import java.io.*;
import java.lang.reflect.*;
import se.rupy.http.*;
import com.google.gwt.user.server.rpc.*;
import com.google.gwt.user.client.rpc.*;

public static class Call extends Service {
	public String path() { return "/REPLACE/greet"; }
	public void filter(Event event) throws Event, Exception {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		Deploy.pipe(event.input(), out);
		String req = out.toString();

		Thread.currentThread().setContextClassLoader(event.daemon().archive("REPLACE"));
		RPCRequest rpc = RPC.decodeRequest(req, GreetingService.class);		  

		String res = null;

		try {
			Object response = rpc.getMethod().invoke(new GreetingServiceImpl(), rpc.getParameters());
			res = RPC.encodeResponseForSuccess(rpc.getMethod(), response);
		}
		catch(InvocationTargetException e) {
			res = RPC.encodeResponseForFailure(rpc.getMethod(), e.getCause());
		}

		event.output().print(res);
	}
}

Also add the http.jar dependency to the classpath and bundle and deploy the war in build.xml:

<path id="project.class.path">
	...
	<pathelement location="lib/http.jar"/>
</path>

<target name="gwtc" depends="javac" ...>
	...
	<mkdir dir="bin"/>
	<jar jarfile="bin/book.jar">
		<manifest>
			<attribute name="Built-By" value="${user.name}"/>
		</manifest>
		<fileset dir="war"/>
	</jar>
	<java fork="yes" classname="se.rupy.http.Deploy" classpath="lib/http.jar">
		<arg line="localhost:8000"/>
		<arg line="bin/book.jar"/>
		<arg line="secret"/>
  	</java>
</target>

Don't forget to add gwt-user.jar to the classpath!

java -classpath "lib\http.jar;lib\gwt-user.jar" se.rupy.http.Daemon -verbose -pass secret -log

Sign in to add a comment
Powered by Google Project Hosting