-
1. Re: Customize Server Error Handling
jfuerth Mar 25, 2013 11:56 AM (in response to peter.probst)Hi Peter,
While it's true that Errai doesn't provide its own server-side RPC interceptor facility, we do support CDI interceptors for RPC calls.
The Weld reference guide has a chapter about interceptors: http://docs.jboss.org/weld/reference/latest/en-US/html/interceptors.html
Here's the CDI interceptor code from our test suite. You could implement something similar in your app:
First, make an interceptor binding annotation:
@InterceptorBinding @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) public @interface InterceptedRpc { }
Then create the interceptor for that binding (note the custom @InterceptedRpc interceptor binding annotation at the class level):
@InterceptedRpc @Interceptor public class RpcInterceptor { @AroundInvoke public Object aroundInvoke(InvocationContext ctx) throws Exception { String parm = (String) ctx.getParameters()[0]; parm += "_intercepted"; ctx.setParameters(new Object[]{parm}); return ctx.proceed(); } }
Finally, for each server-side service impl method you want your interceptor to operate on, apply your custom interceptor binding annotation:
@Service @ApplicationScoped public class InterceptedRemoteImpl implements MyInterceptedRemote { @Override @InterceptedRpc public String interceptedCall(String callString) { return callString; } }
Hope that helps!
-Jonathan
-
2. Re: Customize Server Error Handling
peter.probst Mar 26, 2013 6:49 AM (in response to jfuerth)Hello Jonathan,
thank you for your valuable information. We have tested this solution and it works like a charm. Problem solved!
Thanks,
-Peter