[ 
https://issues.apache.org/jira/browse/WINK-284?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12869167#action_12869167
 ] 

David Calavera commented on WINK-284:
-------------------------------------

Actually I don't want to add the context. I think an example can explaint it 
better:

I have a resource that needs a context parameter which interface is 
FooInterface.class:

{code}
class FooResource {
  @GET
  public Foo getFoo(@Context FooInteface fooContext) {...}
}
{code}

I can't inject that context attribute because the array of parameters to that 
method has already been created when the code arrives to my handler. Or even I 
suppose that code didn't work at all because when the 
CreateInvocationParametersHandler creates the parameters there is not any 
attribute in the context with that interface.

A real example, my workaround to use a custom LinksBuilder. I have a custom 
LinksBuilder that I want to inject to the resource method parameters. I can't 
do just this:

{code}
context.setAttribute(LinksBuilder.class, new CustomLinksBuilder.new(context));
{code}

I also need to add this because the SearchResult object already has the 
parameters array intialized :

{code}
SearchResult searchResult = context.getAttribute(SearchResult.class);
        Object[] parameters = searchResult.getInvocationParameters();
        Collection<Object> newParameters = new ArrayList<Object>();
        if (parameters != null && parameters.length > 0)
        {
            for (Object parameter : parameters)
            {
                if (parameter instanceof LinkBuilders)
                {
                    newParameters.add(builder);
                }
                else
                {
                    newParameters.add(parameter);
                }
            }
        }
        searchResult.setInvocationParameters(newParameters
            .toArray(new Object[newParameters.size()]));
{code}

> User handlers can't add context attributes to get them in resources invocation
> ------------------------------------------------------------------------------
>
>                 Key: WINK-284
>                 URL: https://issues.apache.org/jira/browse/WINK-284
>             Project: Wink
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 1.1
>            Reporter: David Calavera
>         Attachments: deploymentConfiguration.patch
>
>
> The creation of the invocation parameters occurs before executing the user 
> handlers, so it's not be able to add context attributes to use in the 
> resources later.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to