Return-Path: Delivered-To: apmail-incubator-amber-commits-archive@minotaur.apache.org Received: (qmail 89082 invoked from network); 18 Dec 2010 16:43:13 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 18 Dec 2010 16:43:13 -0000 Received: (qmail 89442 invoked by uid 500); 18 Dec 2010 16:43:13 -0000 Delivered-To: apmail-incubator-amber-commits-archive@incubator.apache.org Received: (qmail 89424 invoked by uid 500); 18 Dec 2010 16:43:13 -0000 Mailing-List: contact amber-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: amber-dev@incubator.apache.org Delivered-To: mailing list amber-commits@incubator.apache.org Received: (qmail 89417 invoked by uid 99); 18 Dec 2010 16:43:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Dec 2010 16:43:13 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 18 Dec 2010 16:43:12 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7502C23889E1; Sat, 18 Dec 2010 16:42:52 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1050667 - in /incubator/amber/trunk/oauth-2.0/oauth2-httpclient4: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/amber/ src/main/java/org/apache/amber/oauth2/ src/main/java/org/apache... Date: Sat, 18 Dec 2010 16:42:52 -0000 To: amber-commits@incubator.apache.org From: tommaso@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101218164252.7502C23889E1@eris.apache.org> Author: tommaso Date: Sat Dec 18 16:42:51 2010 New Revision: 1050667 URL: http://svn.apache.org/viewvc?rev=1050667&view=rev Log: [AMBER-11] - import of Leelo OAuth 2.0 implementation - oauth2-httpclient4 module Added: incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/ (with props) incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/pom.xml (with props) incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java (with props) Propchange: incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/ ------------------------------------------------------------------------------ --- svn:ignore (added) +++ svn:ignore Sat Dec 18 16:42:51 2010 @@ -0,0 +1 @@ +target Added: incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/pom.xml URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/pom.xml?rev=1050667&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/pom.xml (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/pom.xml Sat Dec 18 16:42:51 2010 @@ -0,0 +1,59 @@ + + + + + + 4.0.0 + oauth2-httpclient4 + jar + Apache Amber: OAuth 2.0 Implementation - HttpClient + + + amber-oauth2-parent + org.apache.amber + 0.2-SNAPSHOT + + + + oauth2-httpclient4 + + + 4.0.1 + + + + + org.apache.amber + oauth2-client + ${project.version} + + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + + + + Propchange: incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Added: incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java?rev=1050667&view=auto ============================================================================== --- incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java (added) +++ incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java Sat Dec 18 16:42:51 2010 @@ -0,0 +1,108 @@ +/** + * Copyright 2010 Newcastle University + * + * http://research.ncl.ac.uk/smart/ + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.amber.oauth2.httpclient4; + +import java.net.URI; +import java.util.Map; + +import org.apache.amber.oauth2.client.HttpClient; +import org.apache.amber.oauth2.client.request.OAuthClientRequest; +import org.apache.amber.oauth2.common.exception.OAuthProblemException; +import org.apache.amber.oauth2.common.utils.OAuthUtils; +import org.apache.http.Header; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpRequestBase; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.util.EntityUtils; +import org.apache.amber.oauth2.client.response.OAuthClientResponseFactory; + +import org.apache.amber.oauth2.client.response.OAuthClientResponse; +import org.apache.amber.oauth2.common.OAuth; +import org.apache.amber.oauth2.common.exception.OAuthSystemException; + + +/** + * Exemplar HttpClient4 + * + * @author Maciej Machulak (m.p.machulak@ncl.ac.uk) + * @author Lukasz Moren (lukasz.moren@ncl.ac.uk) + * @author Aad van Moorsel (aad.vanmoorsel@ncl.ac.uk) + */ +public class HttpClient4 implements HttpClient { + + private org.apache.http.client.HttpClient client = new DefaultHttpClient(); + + public HttpClient4() { + } + + public HttpClient4(org.apache.http.client.HttpClient client) { + this.client = client; + } + + public T execute(OAuthClientRequest request, + Map headers, + String requestMethod, + Class responseClass) + throws OAuthSystemException, OAuthProblemException { + + try { + URI location = new URI(request.getLocationUri()); + HttpRequestBase req = null; + String responseBody = ""; + + if (!OAuthUtils.isEmpty(requestMethod) && OAuth.HttpMethod.POST.equals(requestMethod)) { + req = new HttpPost(location); + HttpEntity entity = new StringEntity(request.getBody()); + ((HttpPost)req).setEntity(entity); + } else { + req = new HttpGet(location); + } + if (headers != null && !headers.isEmpty()) { + for (Map.Entry header : headers.entrySet()) { + req.setHeader(header.getKey(), header.getValue()); + } + } + HttpResponse response = client.execute(req); + Header contentTypeHeader = null; + HttpEntity entity = response.getEntity(); + if (entity != null) { + responseBody = EntityUtils.toString(entity); + contentTypeHeader = entity.getContentType(); + } + String contentType = null; + if (contentTypeHeader != null) { + contentType = contentTypeHeader.toString(); + } + + return OAuthClientResponseFactory + .createCustomResponse(responseBody, contentType, response.getStatusLine().getStatusCode(), + responseClass); + } catch (Exception e) { + throw new OAuthSystemException(e); + } + + } +} Propchange: incubator/amber/trunk/oauth-2.0/oauth2-httpclient4/src/main/java/org/apache/amber/oauth2/httpclient4/HttpClient4.java ------------------------------------------------------------------------------ svn:eol-style = native