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

Christian commented on OLTU-130:
--------------------------------

[~asanso] Probably you made a file search and noticed that this is the only 
occurence of "post". UrlConnectionClient is standard implementation of the 
HttpClient. You could use it to make POST requests, but it isn't realted to 
Oltu.

The example in the Oltu Client documentation shows how to GET a user profile 
from Facebook:
{code}OAuthClientRequest bearerClientRequest = new 
OAuthBearerClientRequest("https://graph.facebook.com/me";)
         .setAccessToken(accessToken).buildQueryMessage();
 
OAuthResourceResponse resourceResponse = 
oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.GET, 
OAuthResourceResponse.class);{code}

But how would you [post a picture to 
Facebook|https://developers.facebook.com/docs/graph-api/reference/album#photos]?
{code}
OAuthClientRequest bearerClientRequest = new 
OAuthBearerClientRequest("https://graph.facebook.com/{album-id}/photos";)
         .setAccessToken(accessToken)
         .setMimeType("multipart/form-data").setBody(photo) // TODO: These 
methods don't exist.
         .buildQueryMessage();
 
OAuthResourceResponse resourceResponse = 
oAuthClient.resource(bearerClientRequest, OAuth.HttpMethod.POST, 
OAuthResourceResponse.class);
{code}

I don't think it's possible right now to set the request body in 
OAuthBearerClientRequest.

> POST to resource server with authentication
> -------------------------------------------
>
>                 Key: OLTU-130
>                 URL: https://issues.apache.org/jira/browse/OLTU-130
>             Project: Apache Oltu
>          Issue Type: New Feature
>          Components: oauth2-client
>    Affects Versions: oauth2-0.31
>            Reporter: Christian
>              Labels: features
>
> There seems to be no feature to post a resource to the server with 
> authentication. But that's something almost every application needs. Below 
> you'll find my current solution. 
> I would provide a patch, but I find the client code very confusing (nested 
> classes in OAuthClientRequest; inconsistent naming of OAuthRequestBuilder and 
> subclass OAuthBearerClientRequest; overengineered OAuthParametersApplier and 
> its subclasses).
>  
> Best regards,
> Christian
>   
> {code:title=OAuthBearerClientPostRequest.java|borderStyle=solid}
> package org.apache.oltu.oauth2.client.request;
> import org.apache.oltu.oauth2.client.request.OAuthBearerClientRequest;
> import org.apache.oltu.oauth2.client.request.OAuthClientRequest;
> import org.apache.oltu.oauth2.common.OAuth;
> import org.apache.oltu.oauth2.common.exception.OAuthSystemException;
> class OAuthBearerClientPostRequest extends OAuthBearerClientRequest {
>     private String contentType;
>     private String body;
>     protected OAuthBearerClientPostRequest(String url) {
>         super(url);
>     }
>     // Override to get the interface of this subclass.
>     @Override
>     public OAuthBearerClientPostRequest setAccessToken(String accessToken) {
>         super.setAccessToken(accessToken);
>         return this;
>     }
>     public OAuthBearerClientPostRequest setContentType(String contentType) {
>         this.contentType = contentType;
>         return this;
>     }
>     public OAuthBearerClientPostRequest setBody(String body) {
>         this.body = body;
>         return this;
>     }
>     public OAuthClientRequest buildHeaderMessage() throws 
> OAuthSystemException {
>         OAuthClientRequest request = super.buildHeaderMessage();
>         request.setBody(this.body);
>         request.setHeader(OAuth.HeaderType.CONTENT_TYPE, this.contentType);
>         return request;
>     }
>     /**
>      * Not supported. Use #buildHeaderMessage() instead.
>      *
>      * @throws UnsupportedOperationException always
>      */
>     public OAuthClientRequest buildQueryMessage() throws OAuthSystemException 
> {
>         throw new UnsupportedOperationException("Not supported. Use 
> #buildHeaderMessage() instead.");
>     }
>     /**
>      * Not supported. Use #buildHeaderMessage() instead.
>      *
>      * @throws UnsupportedOperationException always
>      */
>     public OAuthClientRequest buildBodyMessage() throws OAuthSystemException {
>         throw new UnsupportedOperationException("Not supported. Use 
> #buildHeaderMessage() instead.");
>     }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to