Return-Path: X-Original-To: apmail-oltu-dev-archive@www.apache.org Delivered-To: apmail-oltu-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 9FF6310E42 for ; Mon, 30 Dec 2013 14:03:05 +0000 (UTC) Received: (qmail 92644 invoked by uid 500); 30 Dec 2013 14:03:02 -0000 Delivered-To: apmail-oltu-dev-archive@oltu.apache.org Received: (qmail 92367 invoked by uid 500); 30 Dec 2013 14:02:54 -0000 Mailing-List: contact dev-help@oltu.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@oltu.apache.org Delivered-To: mailing list dev@oltu.apache.org Received: (qmail 92238 invoked by uid 99); 30 Dec 2013 14:02:51 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Dec 2013 14:02:51 +0000 Date: Mon, 30 Dec 2013 14:02:50 +0000 (UTC) From: "Christian (JIRA)" To: dev@oltu.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Updated] (OLTU-130) POST to resource server with authentication MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/OLTU-130?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Christian updated OLTU-130: --------------------------- Description: 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} was: 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); } } } > 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. 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.1.5#6160)