Thanks Thomas. That worked as you suggested! I was almost sure it was a compiler / dev library issue since it worked in dev mode.
Just curious, what could be the reason that GWT would ignore serialization of the runtimeexception type from the source folders?
Now, the custom AccessDeniedException is purely cosmetic on the service interface as it is always thrown outside the method by Spring Security.
Thanks again for your help!
On Thursday, 17 April 2014 17:27:44 UTC+5:30, Thomas Broyer wrote:
-- Just curious, what could be the reason that GWT would ignore serialization of the runtimeexception type from the source folders?
Now, the custom AccessDeniedException is purely cosmetic on the service interface as it is always thrown outside the method by Spring Security.
Thanks again for your help!
On Thursday, 17 April 2014 17:27:44 UTC+5:30, Thomas Broyer wrote:
Is the AccessDeniedException declared in a throws clause in any RemoteService interface?IIRC you have to declare exceptions explicitly for them to be included in the serialization policies. I can't tell why it works in DevMode but not in prod mode though.
On Thursday, April 17, 2014 1:32:47 PM UTC+2, Mohit Garg wrote:Hi, I have spent almost a couple of days trying to resolve this issue to no avail, so any help would be much appreciated.
I am intercepting GWT calls using Spring MVC through a custom GwtRpcController class. The method of interest is as follows:
@Override
public String processCall(String payload) throws SerializationException {
try {
RPCRequest rpcRequest = RPC.decodeRequest(payload, this.remoteServiceClass);
// delegate work to the spring injected service
return RPC.invokeAndEncodeResponse(this.remoteService, rpcRequest.getMethod(), rpcRequest.getParameters() );
} catch (IncompatibleRemoteServiceExcep tion ex) {
getServletContext().log("An IncompatibleRemoteServiceException was thrown while processing this call.", ex);
return RPC.encodeResponseForFailure(null, ex);
} catch (UnexpectedException ex) {
if (ex.getCause() instanceof org.springframework.security.access.AccessDeniedException) {
AccessDeniedException clientEx = new AccessDeniedException();
getServletContext().log("A Spring AccessDeniedException was thrown while processing this call.", clientEx);
return RPC.encodeResponseForFailure(null, clientEx);
} else {
throw ex;
}
}
}
As you can see, I am catching the Spring Access Denied Exception which comes from the @PreAuthorize annotation in my methods, and using RPC.encodeResponseForFailure to pass my custom Exception (extends RuntimeException(as does GWT's own InvocationException), implements IsSerializable, and has a zero argument constructor). Here's the code if you want to refer:
package com.fundwave.fundadmin.shared;
import com.google.gwt.user.client.rpc.IsSerializable;
public class AccessDeniedException extends java.lang.RuntimeException implements IsSerializable {
private static String AUTHORIZATION_ERROR = "Authorization Error: ";
private String message;
public AccessDeniedException() {
super(AUTHORIZATION_ERROR+"Your account does not have the rights to perform this action.");
this.message = AUTHORIZATION_ERROR+"Your account does not have the rights to perform this action.";
}
public AccessDeniedException(String msg) {
super(AUTHORIZATION_ERROR+msg);
this.message = AUTHORIZATION_ERROR+msg;
}
public AccessDeniedException(Throwable t) {
super(t);
}
public AccessDeniedException(String msg, Throwable t) {
super(AUTHORIZATION_ERROR+msg, t);
this.message = AUTHORIZATION_ERROR+msg;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
On the client side, my code painlessly catches my custom exception in the development mode:
caught.printStackTrace();
if (caught instanceof AccessDeniedException) {
serverResponseLabel.setText("Error: " + caught.getMessage());
}
Surprisingly, after compiling, I get the following error:
Error: (TypeError) stack: com_google_gwt_user_client_rpc_impl_SerializerBase$ MethodMap_$instantiate__Lcom_ google_gwt_user_client_rpc_ impl_SerializerBase$MethodMap_ 2Lcom_google_gwt_user_client_ rpc_SerializationStreamReader_ 2Ljava_lang_String_2Ljava_ lang_Object_2@http://127.0.0. 1:8888/fundwave/ com_google_gwt_user_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:36006 rpc_impl_SerializerBase_$ instantiate__Lcom_google_gwt_ user_client_rpc_impl_ SerializerBase_2Lcom_google_ gwt_user_client_rpc_ SerializationStreamReader_ 2Ljava_lang_String_2Ljava_ lang_Object_2@http://127.0.0. 1:8888/fundwave/ com_google_gwt_user_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:14354 rpc_impl_ AbstractSerializationStreamRea der_$readObject__Lcom_google_ gwt_user_client_rpc_impl_ AbstractSerializationStreamRea der_2Ljava_lang_Object_2@http: //127.0.0.1:8888/fundwave/ com_google_gwt_user_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:35554 rpc_impl_ RequestCallbackAdapter_ onResponseReceived__Lcom_ google_gwt_http_client_ Request_2Lcom_google_gwt_http_ client_Response_2V@http://127. 0.0.1:8888/fundwave/ com_google_gwt_http_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:35810 Request_$ fireOnResponseReceived__Lcom_ google_gwt_http_client_ Request_2Lcom_google_gwt_http_ client_RequestCallback_2V@http ://127.0.0.1:8888/fundwave/ com_google_gwt_http_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:27307 RequestBuilder$1_ onReadyStateChange__Lcom_ google_gwt_xhr_client_ XMLHttpRequest_2V@http://127. 0.0.1:8888/fundwave/ com_google_gwt_xhr_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:27464 XMLHttpRequest_$ setOnReadyStateChange__Lcom_ google_gwt_xhr_client_ XMLHttpRequest_2Lcom_google_ gwt_xhr_client_ ReadyStateChangeHandler_2V/ this$static. onreadystatechange<@http:// 127.0.0.1:8888/fundwave/ com_google_gwt_core_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:41345 impl_Impl_apply__Ljava_lang_ Object_2Ljava_lang_Object_ 2Ljava_lang_Object_2Ljava_ lang_Object_2@http://127.0.0. 1:8888/fundwave/ com_google_gwt_core_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:23703 impl_Impl_entry0__Ljava_lang_ Object_2Ljava_lang_Object_ 2Ljava_lang_Object_2Ljava_ lang_Object_2@http://127.0.0. 1:8888/fundwave/ com_google_gwt_core_client_3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:23743 impl_Impl_entry__Lcom_google_ gwt_core_client_ JavaScriptObject_2Lcom_google_ gwt_core_client_ JavaScriptObject_2/<@http:// 127.0.0.1:8888/fundwave/ __gwt$exception: <skipped> fileName: http://127.0.0.1:8888/3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html:23730 fundwave/ lineNumber: 36006 columnNumber: 2: this$static[signature][0] is not a function3214F6C013E9480AD0BA8FA2C08F3C F9.cache.html
If it runs great in dev mode, what could cause the issue after compilation? I have tried with the latest GWT release (2.6) as well as the penultimate release.
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment