...
import com.google.gwt.user.client.rpc.ServiceDefTarget;
...
public class StandardDispatchAsync extends AbstractDispatchAsync {
private static final StandardDispatchServiceAsync realService =
GWT.create( StandardDispatchService.class );
// NEW
private static final String baseUrl =
((ServiceDefTarget)realService).getServiceEntryPoint() + "?";
public StandardDispatchAsync( ExceptionHandler exceptionHandler )
{
super( exceptionHandler );
}
public <A extends Action<R>, R extends Result> void execute( final
A action, final AsyncCallback<R> callback ) {
// NEW Append extra path info for logs
((ServiceDefTarget)realService).setServiceEntryPoint(baseUrl +
action.getClass().getSimpleName());
realService.execute( action, new AsyncCallback<Result>() {
public void onFailure( Throwable caught ) {
StandardDispatchAsync.this.onFailure( action, caught,
callback );
}
@SuppressWarnings({"unchecked"})
public void onSuccess( Result result ) {
StandardDispatchAsync.this.onSuccess( action, (R)
result, callback );
}
} );
}
}
Previously, my request logs showed only
/app/dispatch
whereas now they show
/app/dispatch?SomeAction
Is this useful to anyone else? Is it worth making standard behavior?
Seems spiffy to me.
- Stephen
/dmc
/dmc
Here's the bit of substring code if desired:
// Append extra path info for logs
String className = action.getClass().getName();
int namePos = className.lastIndexOf(".") + 1;
className = className.substring(namePos);
((ServiceDefTarget)realService).setServiceEntryPoint(baseUrl +
className);
Sorry for all the noise, especially since I just realized I'm in the
wrong group, anyway. Will try again in gwt-dispatch.
Is it Friday yet?
/dmc
All I changed from the previous example was "?" to "/" and the servlet
mapping to ".../dispatch/*"
Thanks again,
/dmc
http://turbomanage.wordpress.com
David
Index: StandardDispatchAsync.java
===================================================================
--- StandardDispatchAsync.java (revision 118)
+++ StandardDispatchAsync.java (working copy)
@@ -2,6 +2,8 @@
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.rpc.ServiceDefTarget;
+
import net.customware.gwt.dispatch.client.AbstractDispatchAsync;
import net.customware.gwt.dispatch.client.DispatchAsync;
import net.customware.gwt.dispatch.client.ExceptionHandler;
@@ -19,12 +21,19 @@
public class StandardDispatchAsync extends AbstractDispatchAsync {
private static final StandardDispatchServiceAsync realService =
GWT.create( StandardDispatchService.class );
-
+ private static final String baseUrl =
((ServiceDefTarget)realService).getServiceEntryPoint() + "/";
+
public StandardDispatchAsync( ExceptionHandler exceptionHandler ) {
super( exceptionHandler );
}
public <A extends Action<R>, R extends Result> void execute(
final A action, final AsyncCallback<R> callback ) {
+ // Append action class name as extra path info
+ String className = action.getClass().getName();
+ int namePos = className.lastIndexOf(".") + 1;
+ className = className.substring(namePos);
+ ((ServiceDefTarget)realService).setServiceEntryPoint(baseUrl
+ className);
+
realService.execute( action, new AsyncCallback<Result>() {
public void onFailure( Throwable caught ) {
StandardDispatchAsync.this.onFailure( action, caught,
callback );
Depending on how you make this configurable, you should probably
include a comment about changing the dispatch servlet mapping. I'm a
little nervous about making it default behavior because I think it
would introduce confusion about how action handlers actually get
mapped: i.e., if I saw the action name in the logs, I might assume the
extra path info is used by the dispatch servlet to find the
appropriate ActionHandler.
Secondly, it is not safe to use the extra path info for security "as
is" because the extra path info in the HTTP request can be very, very
easily tampered (unlike the serialized Action class in the RPC, which
is probably possible, but harder). In order to allow this use safely,
we would need to modify StandardDispatchServlet to match the RPC
Action against the classname in the extra path info and throw an
exception if they don't match.
/dmc