[
https://issues.apache.org/jira/browse/OLTU-130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13855524#comment-13855524
]
Christian commented on OLTU-130:
--------------------------------
Or am I missing something and there is already an official way to update
resources?
> 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: 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. Please
> add it.
>
> I'm trying to figure out a way and will share it with you, so that this
> feature gets build in near future.
> Right now, I'm overriding OAuthBearerClientRequest to allow setting a message
> body. But there is still a problem with the content type, which is
> "application/x-www-form-urlencoded". I haven't found a solution yet to set it.
>
> Best regards,
> Christian
>
> ---
>
> class MyRequest extends OAuthBearerClientRequest {
> private Object body;
>
> protected MyRequest(String url) {
> super(url);
> }
>
> @Override
> public MyRequest setAccessToken(String accessToken) {
> super.setAccessToken(accessToken);
> return this;
> }
>
> public MyRequest setBody(Object body) {
> this.body = body;
> return this;
> }
>
> /**
> * 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.");
> }
>
> public OAuthClientRequest buildHeaderMessage() throws
> OAuthSystemException {
> OAuthClientRequest request = super.buildHeaderMessage();
> try {
> ObjectMapper objectMapper = new ObjectMapper();
> request.setBody(objectMapper.writeValueAsString(body));
> return request;
> } catch (IOException e) {
> throw new OAuthSystemException("Cannot serialize body (" +
> (body != null ? "class: " +
> body.getClass().getSimpleName() : "is null") + ").", e);
> }
> }
> }
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)