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:
>
> 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 (IncompatibleRemoteServiceException 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/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:36006com_google_gwt_user_client_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/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:14354com_google_gwt_user_client_rpc_impl_AbstractSerializationStreamReader_$readObject__Lcom_google_gwt_user_client_rpc_impl_AbstractSerializationStreamReader_2Ljava_lang_Object_2@
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:35554com_google_gwt_user_client_rpc_impl_RequestCallbackAdapter_onResponseReceived__Lcom_google_gwt_http_client_Request_2Lcom_google_gwt_http_client_Response_2V@
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:35810com_google_gwt_http_client_Request_$fireOnResponseReceived__Lcom_google_gwt_http_client_Request_2Lcom_google_gwt_http_client_RequestCallback_2V@
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:27307com_google_gwt_http_client_RequestBuilder$1_onReadyStateChange__Lcom_google_gwt_xhr_client_XMLHttpRequest_2V@
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:27464com_google_gwt_xhr_client_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/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:41345com_google_gwt_core_client_impl_Impl_apply__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2@
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:23703com_google_gwt_core_client_impl_Impl_entry0__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_Object_2@
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:23743com_google_gwt_core_client_impl_Impl_entry__Lcom_google_gwt_core_client_JavaScriptObject_2Lcom_google_gwt_core_client_JavaScriptObject_2/<@
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.html:23730__gwt$exception:
>>  <skipped> fileName: 
>> http://127.0.0.1:8888/fundwave/3214F6C013E9480AD0BA8FA2C08F3CF9.cache.htmllineNumber:
>>  36006 columnNumber: 2: this$static[signature][0] is not a 
>> function
>>
>> 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+unsubscr...@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.

Reply via email to