incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
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 GMT
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 @@
+<!--
+
+          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.
+
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+
+    <modelVersion>4.0.0</modelVersion>
+    <artifactId>oauth2-httpclient4</artifactId>
+    <packaging>jar</packaging>
+    <name>Apache Amber: OAuth 2.0 Implementation - HttpClient</name>
+
+    <parent>
+        <artifactId>amber-oauth2-parent</artifactId>
+        <groupId>org.apache.amber</groupId>
+       <version>0.2-SNAPSHOT</version>
+    </parent>
+
+    <build>
+        <finalName>oauth2-httpclient4</finalName>
+    </build>
+    <properties>
+        <httpclient.version>4.0.1</httpclient.version>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.amber</groupId>
+            <artifactId>oauth2-client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>${httpclient.version}</version>
+        </dependency>
+    </dependencies>
+
+</project>

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 extends OAuthClientResponse> T execute(OAuthClientRequest request,
+                                                     Map<String, String> headers,
+                                                     String requestMethod,
+                                                     Class<T> 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<String, String> 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



Mime
View raw message