oltu-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexander Urmuzov (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (AMBER-51) Guice+Jersey+Amber: Can't correctly create OAuthTokenRequest instance
Date Mon, 02 Apr 2012 14:27:24 GMT

    [ https://issues.apache.org/jira/browse/AMBER-51?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13244222#comment-13244222
] 

Alexander Urmuzov commented on AMBER-51:
----------------------------------------

I found a workaround (without rewriting TokenEndpoint as servlet) that looks like this:

public class OAuthRequestWrapper extends HttpServletRequestWrapper{

    private MultivaluedMap<String, String> form;

    public OAuthRequestWrapper(HttpServletRequest request, MultivaluedMap<String, String>
form) {
        super(request);
        this.form = form;
    }

    @Override
    public String getParameter(String name) {
        String value = super.getParameter(name);
        if (value == null) {
            value = form.getFirst(name);
        }
        return value;
    }
}

and this:

    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public Response authorize(MultivaluedMap<String, String> form) throws OAuthSystemException
{

        OAuthTokenRequest oauthRequest = null;

        try {
            oauthRequest = new OAuthTokenRequest(new OAuthRequestWrapper(requestProvider.get(),
form));

So, maybe, something like
OAuthTokenRequest(javax.servlet.http.HttpServletRequest request, javax.ws.rs.core.MultivaluedMap
form)
or more jax-rs-like
OAuthTokenRequest(javax.ws.rs.core.UriInfo uriInfo, javax.ws.rs.core.MultivaluedMap form)
of course if UriInfo contains all required data.

                
> Guice+Jersey+Amber: Can't correctly create OAuthTokenRequest instance
> ---------------------------------------------------------------------
>
>                 Key: AMBER-51
>                 URL: https://issues.apache.org/jira/browse/AMBER-51
>             Project: Amber
>          Issue Type: Bug
>         Environment: jersey 1.10
> guice 3.0-SNAPSHOT
> amber 0.22-incubating-SNAPSHOT
>            Reporter: Alexander Urmuzov
>
> I've got a problem with creating OAuthTokenRequest.
> It needs an instance of HttpServletRequest on creation, but all instances which I can
get through guice or jersey injections have no post parameters.
> Guice injection example:
>     private final Provider<HttpServletRequest> requestProvider;
>     @Inject
>     public TokenEndpoint(Provider<HttpServletRequest> requestProvider) {
>         this.requestProvider = requestProvider;
>     }
>     @POST
>     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
>     @Produces(MediaType.APPLICATION_JSON)
>     public Response authorize() throws OAuthSystemException {
>         OAuthTokenRequest oauthRequest = null;
>         try {
>             oauthRequest = new OAuthTokenRequest(requestProvider.get());
>     ....
> Jersey injection example:
>     @POST
>     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
>     @Produces(MediaType.APPLICATION_JSON)
>     public Response authorize(@Context HttpServletRequest request) throws OAuthSystemException
{
>         OAuthTokenRequest oauthRequest = null;
>         try {
>             oauthRequest = new OAuthTokenRequest(request);
> Looks like jersey have parsed HttpServletRequest and removed all post parameters from
it.
> If I attach filter that tries to get some parameter from HttpServletRequest before jersey,
my code works, but with exception from jersey.
> But I can retrieve MultivaluedMap of post parameters from jersey with all data and no
errors.
> I think there must be some alternative constructor for such environments. Any thoughts?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message