[Adding Azeez]

Hi,

In relation to the offline discussion we had, it was clear that the above
functionality is not sufficient for your requirement. As per the offline
discussion, the suggested approach was to use custom contexts. [1] </>, [2]
<https://www.blackpepper.co.uk/blog/custom-context-providers-for-cxf-with-the-context-annotation>
describes
an Apache CXF example of using custom contexts.

Currently in MSF4J using @Context annotation we can inject the Request,
Response, HttpStreamer, FormParamIterator and MultivaluedMap instances.
However, these are not accessible via interceptors as per the current
implementation. The approach we were using to inject values is by using the
approach I have explained in the previous email.

Therefore to solve the above problem, there are 2 solutions we can
introduce to MSF4J.

   1. *Introduce custom injection and lifecycle management [1]
   <https://jersey.java.net/documentation/latest/ioc.html>, [2]
   
<https://www.blackpepper.co.uk/blog/custom-context-providers-for-cxf-with-the-context-annotation>
   to MSF4J.*

Using this approach what you should basically do is:


   - Write a custom context provider of your own which will describe how
      the injected value is generated by implementing a certain interface.
      - Register the custom context provider to the MSF4J
      - Inject the value using @Context annotation (Ex:- @Context(String
      key) Object[] arguments)


   1. *Have a Map<String, Object> map that could be injected using @Context
   annotation*

Using this approach what you basically do is:


   - Add the arguments you need to inject using the @Context annotation
      using @SetContext(String key, Object value). This can be done inside
      interceptors or HTTP methods
      - Inject the value to using @Context(String key)

WDYT?

[1] Custom Injection and Lifecycle Management
<https://jersey.java.net/documentation/latest/ioc.html>
[2] Custom Context Providers for CXF with the Context Annotation
<https://www.blackpepper.co.uk/blog/custom-context-providers-for-cxf-with-the-context-annotation>

On Mon, Feb 27, 2017 at 9:59 AM, Vidura Nanayakkara <vidu...@wso2.com>
wrote:

> Hi Malintha,
>
> You can access the `Request` instance from the interceptors. You also can
> access the same Request instance from the HTTP resource by injecting the
> request to the HTTP method (`@Context Request request`). You also can set
> any argument in the request using `request.setProperty(String key, Object
> value)` method and retrieve the value using `request.getProperty(String
> key)` method. Will this be sufficient for your requirement?
>
>
>
> On Mon, Feb 27, 2017 at 5:55 AM, Thusitha Thilina Dayaratne <
> thusit...@wso2.com> wrote:
>
>> Hi Malintha,
>>
>> Thank you very much for the PR. We did some restructuring for the
>> interceptors to cater product requirementsts[1]. Therefore we won't be able
>> to directly merge this. But surely we will check what we can do with this.
>>
>> [1] - https://github.com/wso2/msf4j/pull/338
>>
>> Thanks
>> Thusitha
>>
>> On Sun, Feb 26, 2017 at 4:04 PM, Malintha Amarasinghe <malint...@wso2.com
>> > wrote:
>>
>>> Hi,
>>>
>>> Currently in MSF4J Interceptor level, we can get the HTTP handler method
>>> which would be invoked by calling  serviceMethodInfo.getMethod().
>>>
>>> Additionally, It will be useful to have request parameters as well in
>>> order to perform various types of request validations in Interceptor level
>>> such as Bean validation and ETag validation.
>>>
>>> Tried to do a fix which adds a new field to ServiceMethodInfo class as
>>> args[] [1]. But this required some API changes.
>>>
>>> Thanks!
>>>
>>> [1] https://github.com/wso2/msf4j/pull/356
>>>
>>> --
>>> Malintha Amarasinghe
>>> Software Engineer
>>> *WSO2, Inc. - lean | enterprise | middleware*
>>> http://wso2.com/
>>>
>>> Mobile : +94 712383306P
>>>
>>
>>
>>
>> --
>> Thusitha Dayaratne
>> Software Engineer
>> WSO2 Inc. - lean . enterprise . middleware |  wso2.com
>>
>> Mobile  +94712756809 <+94%2071%20275%206809>
>> Blog      alokayasoya.blogspot.com
>> About    http://about.me/thusithathilina
>> <http://wso2.com/signature>
>>
>>
>> _______________________________________________
>> Dev mailing list
>> Dev@wso2.org
>> http://wso2.org/cgi-bin/mailman/listinfo/dev
>>
>>
>
>
> --
> Best Regards,
>
> *Vidura Nanayakkara*
> Software Engineer
>
> Email : vidu...@wso2.com
> Mobile : +94 (0) 717 919277 <+94%2071%20791%209277>
> Web : http://wso2.com
> Blog : https://medium.com/@viduran <http://wso2.com/>
> Twitter : http://twitter.com/viduranana
> LinkedIn : https://lk.linkedin.com/in/vidura-nanayakkara
> <http://wso2.com/>
>



-- 
Best Regards,

*Vidura Nanayakkara*
Software Engineer

Email : vidu...@wso2.com
Mobile : +94 (0) 717 919277
Web : http://wso2.com
Blog : https://medium.com/@viduran <http://wso2.com/>
Twitter : http://twitter.com/viduranana
LinkedIn : https://lk.linkedin.com/in/vidura-nanayakkara <http://wso2.com/>
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to