incubator-amber-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1433867 - in /incubator/amber/trunk/oauth-2.0/client-demo/src/main: java/org/apache/amber/oauth2/client/demo/ java/org/apache/amber/oauth2/client/demo/controller/ java/org/apache/amber/oauth2/client/demo/model/ webapp/WEB-INF/views/
Date Wed, 16 Jan 2013 09:21:53 GMT
Author: asanso
Date: Wed Jan 16 09:21:53 2013
New Revision: 1433867

URL: http://svn.apache.org/viewvc?rev=1433867&view=rev
Log:
AMBER-73 - Update the client demo web app in order to leverage the new API in AMBER-70 

Modified:
    incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java
    incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java
    incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java
    incubator/amber/trunk/oauth-2.0/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp

Modified: incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java?rev=1433867&r1=1433866&r2=1433867&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java
(original)
+++ incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/Utils.java
Wed Jan 16 09:21:53 2013
@@ -42,6 +42,10 @@ public final class Utils {
 
     public static final String REG_TYPE_PULL = "pull";
     public static final String REG_TYPE_PUSH = "push";
+    
+    public static final String REQUEST_TYPE_QUERY= "queryParameter";
+    public static final String REQUEST_TYPE_HEADER= "headerField";
+    public static final String REQUEST_TYPE_BODY= "bodyParameter";
 
     public static final String GENERIC = "generic"; 
     

Modified: incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java?rev=1433867&r1=1433866&r2=1433867&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java
(original)
+++ incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/controller/ResourceController.java
Wed Jan 16 09:21:53 2013
@@ -20,16 +20,17 @@
  */
 
 package org.apache.amber.oauth2.client.demo.controller;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URL;
+ 
 import javax.servlet.http.HttpServletRequest;
-
+import org.apache.amber.oauth2.client.OAuthClient;
+import org.apache.amber.oauth2.client.URLConnectionClient;
 import org.apache.amber.oauth2.client.demo.Utils;
 import org.apache.amber.oauth2.client.demo.model.OAuthParams;
-import org.apache.amber.oauth2.common.utils.OAuthUtils;
-import org.apache.amber.oauth2.common.OAuth;
+import org.apache.amber.oauth2.client.request.OAuthBearerClientRequest;
+import org.apache.amber.oauth2.client.request.OAuthClientRequest;
+import org.apache.amber.oauth2.client.response.OAuthResourceResponse;
+import org.apache.amber.oauth2.common.exception.OAuthProblemException;
+import org.apache.amber.oauth2.common.exception.OAuthSystemException;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -49,23 +50,31 @@ public class ResourceController {
                                   HttpServletRequest req) {
 
         try {
-            String tokenName = OAuth.OAUTH_TOKEN_DRAFT_0;
-            if (Utils.SMART_GALLERY.equals(oauthParams.getApplication())) {
-                tokenName = OAuth.OAUTH_TOKEN;
-            }
-            URL url = new URL(
-                oauthParams.getResourceUrl() + "?" + tokenName + "=" + oauthParams.getAccessToken());
-            HttpURLConnection conn = (HttpURLConnection)url.openConnection();
-            if (conn.getResponseCode() == 200) {
-                oauthParams.setResource(OAuthUtils.saveStreamAsString(conn.getInputStream()));
-            } else {
-                oauthParams.setErrorMessage(
-                    "Could not access resource: " + conn.getResponseCode() + " " + conn.getResponseMessage());
-            }
-        } catch (IOException e) {
-            oauthParams.setErrorMessage(e.getMessage());
-        }
-
+			OAuthClientRequest request=null; 
+			
+			if (Utils.REQUEST_TYPE_QUERY.equals(oauthParams.getRequestType())){
+				request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildQueryMessage();
+			}else if (Utils.REQUEST_TYPE_HEADER.equals(oauthParams.getRequestType())){
+				request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildHeaderMessage();
+			}else if (Utils.REQUEST_TYPE_BODY.equals(oauthParams.getRequestType())){
+				request= new OAuthBearerClientRequest(oauthParams.getResourceUrl()).setAccessToken(oauthParams.getAccessToken()).buildBodyMessage();
+			}			
+			
+			OAuthClient client = new OAuthClient(new URLConnectionClient());
+			OAuthResourceResponse resourceResponse= client.resource(request, oauthParams.getRequestMethod(),
OAuthResourceResponse.class);
+			
+			if (resourceResponse.getResponseCode()==200){			
+				oauthParams.setResource(resourceResponse.getBody());
+			}else{
+				oauthParams.setErrorMessage(
+	                    "Could not access resource: " + resourceResponse.getResponseCode() +
" " + resourceResponse.getBody());
+			}
+		} catch (OAuthSystemException e) {
+			 oauthParams.setErrorMessage(e.getMessage());
+		} catch (OAuthProblemException e) {
+			 oauthParams.setErrorMessage(e.getMessage());
+		}
+  
         return new ModelAndView("resource");
 
 

Modified: incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java?rev=1433867&r1=1433866&r2=1433867&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java
(original)
+++ incubator/amber/trunk/oauth-2.0/client-demo/src/main/java/org/apache/amber/oauth2/client/demo/model/OAuthParams.java
Wed Jan 16 09:21:53 2013
@@ -42,6 +42,8 @@ public class OAuthParams {
     private String resourceUrl;
     private String resource;
     private String application;
+    private String requestType;
+    private String requestMethod;
 
     private String errorMessage;
 
@@ -160,4 +162,20 @@ public class OAuthParams {
     public void setApplication(String application) {
         this.application = application;
     }
+
+	public String getRequestType() {
+		return requestType;
+	}
+
+	public void setRequestType(String requestType) {
+		this.requestType = requestType;
+	}
+
+	public String getRequestMethod() {
+		return requestMethod;
+	}
+
+	public void setRequestMethod(String requestMethod) {
+		this.requestMethod = requestMethod;
+	}
 }

Modified: incubator/amber/trunk/oauth-2.0/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/oauth-2.0/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp?rev=1433867&r1=1433866&r2=1433867&view=diff
==============================================================================
--- incubator/amber/trunk/oauth-2.0/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp
(original)
+++ incubator/amber/trunk/oauth-2.0/client-demo/src/main/webapp/WEB-INF/views/get_resource.jsp
Wed Jan 16 09:21:53 2013
@@ -52,6 +52,21 @@
             <td><form:input size="70" path="resourceUrl"/></td>
         </tr>
         <tr>
+            <td>Authenticated Request Type:</td>
+            <td><form:select path="requestType">
+                <form:option value="queryParameter"/>
+                <form:option value="headerField"/>
+                <form:option value="bodyParameter"/>
+            </form:select></td>
+        </tr>
+        <tr>
+            <td>Request Method:</td>
+            <td><form:select path="requestMethod">
+                <form:option value="GET"/>
+                <form:option value="POST"/>
+            </form:select></td>
+        </tr>
+        <tr>
             <td>Access Token:</td>
             <td><form:input size="70" path="accessToken" readonly="true"/></td>
         </tr>



Mime
View raw message