+1 to have this. In a normal JAX-RS app, the same requirement to access servlet session object is by using "@Context HttpServletRequest request" within the resource methods. I believe we are using our own session object here right?
Can you also explain how can we process annotations independently with this model? On Wed, Feb 10, 2016 at 2:23 PM, Samiyuru Senarathne <[email protected]> wrote: > *What is an MSF4J Interceptor?* > In MSF4J interceptors are capable of processing an Http request before or > after the Http request arrives a resource methods. Interceptors implement > the *org.wso2.msf4j.Interceptor* interface. > > public interface Interceptor { > > boolean preCall(HttpRequest request, HttpResponder responder, > ServiceMethodInfo serviceMethodInfo); > > void postCall(HttpRequest request, HttpResponseStatus status, > ServiceMethodInfo serviceMethodInfo); > } > > > > *Problem* > With the current implementation of MSF4J, there is no way for MSF4J > interceptors to communicate with resource methods. That means, if an > interceptor is preprocessing a request and creates an object model out of > the request that needs to be accessible to the corresponding resource > method, how can the interceptor pass the created object model to the > resource method? > > One example of this situation is implementing an interceptor for handling > sessions. In this case, the session interceptor will process the http > request and create a session object. This session object should then be > passed to the resource methods. With current implementation there is no > proper way to do this. > > *Suggested Solution* > Currently the *ServiceMethodInfo* parameter in > *org.wso2.msf4j.Interceptor* contains only an attribute map and > *a java.lang.reflect.Method* type reference to the resource method. > > We can improve this class to support type based parameter injection to the > resource method. That means, > > - We rename *ServiceMethodInfo* class to a name similar to > *ServiceMethodContext* > - Then we introduce an *inject(Object parameter)* method to this > context class. Interceptors can use this method to inject the objects that > they create to the resource method context. > > IE: If we consider a session interceptor, > > servicemethodCtx.inject(session) // session object is is injected to the > resource method context > > Further we can introduce methods to *ServiceMethodInfo* to query the > resource method's parameter support. This helps to limit processing > information in interceptors that resource methods does not accept. > > > - Resource methods can use the *@Context* annotation to consume the > available objects in the resource method's context as shown bellow. > > @GET > > public Response helloService(@Context Session session) { > > // If the session interceptor is available the session will be injected to > the resource method by matching the type of the @Context > annotated parameters > > .... > > } > > Further, with this solution, we can even consider to break current > centralised annotation processing logic into individual interceptors that > process a certain kind of annotation. This will improve modularity, > scalability as well as the consistency of the design. > > WDYT? > > > Best Regards, > Samiyuru > > > -- > Samiyuru Senarathne > *Software Engineer* > Mobile : +94 (0) 71 134 6087 > [email protected] > -- *Kishanthan Thangarajah* Associate Technical Lead, Platform Technologies Team, WSO2, Inc. lean.enterprise.middleware Mobile - +94773426635 Blog - *http://kishanthan.wordpress.com <http://kishanthan.wordpress.com>* Twitter - *http://twitter.com/kishanthan <http://twitter.com/kishanthan>*
_______________________________________________ Architecture mailing list [email protected] https://mail.wso2.org/cgi-bin/mailman/listinfo/architecture
