cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: [CXF-6165] Making the demo more concrete, work in progress
Date Tue, 16 Jun 2015 12:04:39 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 0bf06d583 -> 38d843c97


[CXF-6165] Making the demo more concrete, work in progress


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/38d843c9
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/38d843c9
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/38d843c9

Branch: refs/heads/master
Commit: 38d843c9717df592c5f38fc773cf6a5415e879d1
Parents: 0bf06d5
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue Jun 16 13:04:24 2015 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue Jun 16 13:04:24 2015 +0100

----------------------------------------------------------------------
 .../release/samples/jax_rs/big_query/pom.xml    |  4 +-
 .../demo/jaxrs/server/BigQueryResponse.java     | 37 +++++++++++
 .../java/demo/jaxrs/server/BigQueryService.java | 64 +++++++++++++-------
 .../java/demo/jaxrs/server/ShakespeareText.java | 25 ++++++++
 .../main/webapp/WEB-INF/applicationContext.xml  | 29 +++++++--
 .../big_query/src/main/webapp/WEB-INF/web.xml   |  2 +-
 .../src/main/webapp/forms/bigQueryResponse.jsp  | 51 ++++++++++++++++
 .../src/main/webapp/forms/startSearch.jsp       | 46 ++++++++++++++
 8 files changed, 229 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/pom.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/pom.xml b/distribution/src/main/release/samples/jax_rs/big_query/pom.xml
index 6f86228..19196af 100644
--- a/distribution/src/main/release/samples/jax_rs/big_query/pom.xml
+++ b/distribution/src/main/release/samples/jax_rs/big_query/pom.xml
@@ -74,7 +74,7 @@
     </dependencies>
     <build>
         <!-- Name of the generated WAR file -->
-        <finalName>rest</finalName>
+        <finalName>bigquery</finalName>
         <plugins>
             <plugin>
                 <groupId>org.mortbay.jetty</groupId>
@@ -85,7 +85,7 @@
                     <connectors>
                       <connector implementation="org.mortbay.jetty.security.SslSocketConnector">
                          <port>8080</port>
-                         <keystore>${project.build.directory}/rest/WEB-INF/servicestore.jks</keystore>
+                         <keystore>${project.build.directory}/bigquery/WEB-INF/servicestore.jks</keystore>
                          <password>sspass</password>
                          <keyPassword>skpass</keyPassword>
                       </connector>

http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryResponse.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryResponse.java
b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryResponse.java
new file mode 100644
index 0000000..32030a6
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryResponse.java
@@ -0,0 +1,37 @@
+package demo.jaxrs.server;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class BigQueryResponse {
+    private String userName;
+    private String searchWord;
+    private List<ShakespeareText> texts = new LinkedList<ShakespeareText>();
+    
+    public BigQueryResponse() {
+        
+    }
+    public BigQueryResponse(String userName, String searchWord) {
+        this.userName = userName;
+        this.searchWord = searchWord;
+    }
+    
+    public String getUserName() {
+        return userName;
+    }
+    public void setUserName(String userName) {
+        this.userName = userName;
+    }
+    public String getSearchWord() {
+        return searchWord;
+    }
+    public void setSearchWord(String searchWord) {
+        this.searchWord = searchWord;
+    }
+    public List<ShakespeareText> getTexts() {
+        return texts;
+    }
+    public void setTexts(List<ShakespeareText> texts) {
+        this.texts = texts;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryService.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryService.java
b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryService.java
index 3f5f050..11662a9 100644
--- a/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryService.java
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/BigQueryService.java
@@ -18,39 +18,59 @@
  */
 package demo.jaxrs.server;
 
+import java.util.List;
+import java.util.Map;
+
 import javax.ws.rs.GET;
-import javax.ws.rs.NotAuthorizedException;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Context;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.ResponseBuilder;
 
-import org.apache.cxf.rs.security.oidc.common.IdToken;
-import org.apache.cxf.rs.security.oidc.common.UserInfo;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.jaxrs.provider.json.JsonMapObject;
+import org.apache.cxf.rs.security.oauth2.common.ClientAccessToken;
 import org.apache.cxf.rs.security.oidc.rp.OidcClientTokenContext;
 
-@Path("/service")
+@Path("/search")
 public class BigQueryService {
 
+    private WebClient bigQueryClient;
+    
     @GET
-    @Path("/bigquery/complete")
-    @Produces("application/xml,application/json,text/html")
-    public Response completeBigQuery(@Context OidcClientTokenContext context) {
-        // This IdToken check can be skipped and UserInfo checked for null instead
-        // given that UserInfo can only be obtained if IdToken is valid; shown here
-        // to demonstrate the properties of OidcClientTokenContext
-        IdToken idToken = context.getIdToken();
-        if (idToken == null) {
-            throw new NotAuthorizedException(Response.Status.UNAUTHORIZED);
-        }
+    @Path("/complete")
+    @Produces("text/html")
+    public BigQueryResponse completeBigQuery(@Context OidcClientTokenContext context) {
+        
+        ClientAccessToken accessToken = context.getToken();
+        bigQueryClient.authorization(accessToken);
+        
+        String searchWord = "brave";
+        String maxResults = "10";
+        String bigQuerySelect = "SELECT corpus,corpus_date FROM publicdata:samples.shakespeare
WHERE word=\\\"" 
+            + searchWord + "\\\"";
+        String bigQueryRequest = "{" +
+            "\"kind\": \"bigquery#queryRequest\"," 
+            + "\"query\": \"" + bigQuerySelect + "\","
+            + "\"maxResults\": " + Integer.parseInt(maxResults)
+            + "}";
         
-        UserInfo userInfo = context.getUserInfo();
+        
+        JsonMapObject jsonMap = bigQueryClient.post(bigQueryRequest, JsonMapObject.class);
+        BigQueryResponse bigQueryResponse = new BigQueryResponse(context.getUserInfo().getName(),
+                                                                 searchWord);
+        
+        List<Map<String, Object>> rows = CastUtils.cast((List<?>)jsonMap.getProperty("rows"));
+        for (Map<String, Object> row : rows) {
+            List<Map<String, Object>> fields = CastUtils.cast((List<?>)row.get("f"));
+            ShakespeareText text = new ShakespeareText((String)fields.get(0).get("v"),
+                                                       (String)fields.get(1).get("v"));
+            bigQueryResponse.getTexts().add(text);
+        }
+        return bigQueryResponse;
+    }
 
-        ResponseBuilder rb = Response.ok().type("application/json");
-        Response r = rb.entity(
-                "{\"email\":\"" + userInfo.getEmail() + "\"}")
-                .build();
-        return r;
+    public void setBigQueryClient(WebClient bigQueryClient) {
+        this.bigQueryClient = bigQueryClient;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/ShakespeareText.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/ShakespeareText.java
b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/ShakespeareText.java
new file mode 100644
index 0000000..a3ef3de
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/java/demo/jaxrs/server/ShakespeareText.java
@@ -0,0 +1,25 @@
+package demo.jaxrs.server;
+
+public class ShakespeareText {
+    private String text;
+    private String date;
+    public ShakespeareText() {
+        
+    }
+    public ShakespeareText(String text, String date) {
+        this.text = text;
+        this.date = date;
+    }
+    public String getText() {
+        return text;
+    }
+    public void setText(String text) {
+        this.text = text;
+    }
+    public String getDate() {
+        return date;
+    }
+    public void setDate(String date) {
+        this.date = date;
+    }
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/applicationContext.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/applicationContext.xml
b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/applicationContext.xml
index ab23cac..2dab000 100644
--- a/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/applicationContext.xml
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/applicationContext.xml
@@ -100,16 +100,36 @@
      </bean>
      
      <bean id="oidcRequestFilter" class="org.apache.cxf.rs.security.oidc.rp.OidcClientCodeRequestFilter">
-         <property name="scopes" value="openid email profile"/>
+         <property name="scopes" value="openid email profile https://www.googleapis.com/auth/bigquery.readonly"/>
          <property name="accessTokenServiceClient" ref="atServiceClient"/>
          <property name="userInfoClient" ref="userInfoClient"/>
          <property name="consumer" ref="consumer"/>
          <property name="authorizationServiceUri" value="https://accounts.google.com/o/oauth2/auth"/>
-         <property name="startUri" value="service/bigquery"/>
-         <property name="completeUri" value="service/bigquery/complete"/>
+         <property name="startUri" value="search"/>
+         <property name="completeUri" value="search/complete"/>
      </bean>
      
-     <bean id="bigQueryService" class="demo.jaxrs.server.BigQueryService"/>
+     <bean id="bigQueryService" class="demo.jaxrs.server.BigQueryService">
+         <property name="bigQueryClient" ref="bigQueryClient"/>
+     </bean>
+     
+     <!-- BigQuery WebClient -->
+     <jaxrsclient:client id="bigQueryClient" threadSafe="true" 
+        address="https://www.googleapis.com/bigquery/v2/projects/${project_id}/queries"
+        serviceClass="org.apache.cxf.jaxrs.client.WebClient">
+        <jaxrsclient:headers>
+            <entry key="Accept" value="application/json"/>
+            <entry key="Content-Type" value="application/json"/>
+        </jaxrsclient:headers>
+        <jaxrsclient:providers>
+           <bean class="org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider"/>
+        </jaxrsclient:providers>
+     </jaxrsclient:client>
+     
+     <bean id="searchView" class="org.apache.cxf.jaxrs.provider.RequestDispatcherProvider">
+         <property name="useClassNames" value="true"/>
+         <property name="locationPrefix" value="/forms/"/>
+     </bean>
      
      <jaxrs:server id="bigQueryServer" address="/">
         <jaxrs:serviceBeans>
@@ -117,6 +137,7 @@
         </jaxrs:serviceBeans>
         <jaxrs:providers>
            <ref bean="oidcRequestFilter"/>
+           <ref bean="searchView"/>
            <bean class="org.apache.cxf.rs.security.oauth2.client.ClientTokenContextProvider"/>
         </jaxrs:providers>
         <jaxrs:features>

http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/web.xml
b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/web.xml
index 2d46709..05b9f32 100644
--- a/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/web.xml
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/WEB-INF/web.xml
@@ -31,7 +31,7 @@
     </servlet>
     <servlet-mapping>
         <servlet-name>RESTServlet</servlet-name>
-        <url-pattern>/*</url-pattern>
+        <url-pattern>/service/*</url-pattern>
     </servlet-mapping>
     <session-config>
         <session-timeout>60</session-timeout>

http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/bigQueryResponse.jsp
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/bigQueryResponse.jsp
b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/bigQueryResponse.jsp
new file mode 100644
index 0000000..19c6c55
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/bigQueryResponse.jsp
@@ -0,0 +1,51 @@
+<%@ page import="javax.servlet.http.HttpServletRequest, demo.jaxrs.server.BigQueryResponse,
demo.jaxrs.server.ShakespeareText" %>
+
+<%
+    BigQueryResponse bgResponse = (BigQueryResponse) request.getAttribute("bigqueryresponse");
+    String basePath = request.getContextPath() + request.getServletPath();
+    if (!basePath.endsWith("/")) {
+        basePath += "/";
+    }
+%>
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <title>Shakespeare texts</title>
+    <STYLE TYPE="text/css">
+	<!--
+	  div.padded {  
+         padding-left: 15em;  
+      }   
+	-->
+</STYLE>
+</head>
+<body>
+<div class="padded">
+<h2>Texts containing a word "<%= bgResponse.getSearchWord() %>"</h2>
+<em></em>
+<p>
+<big><big>
+<%= bgResponse.getUserName() %>, here is a list of texts:
+</big></big>
+</p>
+<table border="1">
+    <tr><th><big><big>Text</big></big></th><th><big><big>Date</big></big></th></tr>

+    <%
+       for (ShakespeareText entry : bgResponse.getTexts()) {
+    %>
+       <tr>
+           <td><big><big><%= entry.getText() %></big></big></td>
+           <td><big><big><%= entry.getDate() %></big></big></td>
+       </tr>
+    <%   
+       }
+    %> 
+</table>
+
+<br/>
+<p>
+Back to <a href="<%= basePath %>forms/startSearch.jsp">Search Service</a>.
+</p>
+</big></big>
+</div>
+</body>
+</html>

http://git-wip-us.apache.org/repos/asf/cxf/blob/38d843c9/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/startSearch.jsp
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/startSearch.jsp
b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/startSearch.jsp
new file mode 100644
index 0000000..d19f911
--- /dev/null
+++ b/distribution/src/main/release/samples/jax_rs/big_query/src/main/webapp/forms/startSearch.jsp
@@ -0,0 +1,46 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+    <title>Shakespeare Text Search</title>
+    <STYLE TYPE="text/css">
+	<!--
+	  input {font-family:verdana, arial, helvetica, sans-serif;font-size:20px;line-height:40px;}
+	  div.padded {  
+         padding-left: 15em;  
+      } 
+	-->
+</STYLE>
+</head>
+<body>
+<div class="padded">
+<h1>Welcome to Shakespeare Text Search Service</h1>
+<em></em>
+<p>
+ <table>
+     <form action="https://localhost:8080/bigquery/service/search" method="POST">
+        <tr>
+            <td><big><big><big>Text Word:</big></big></big></td>
+            <td>
+              <input type="text" name="word" value="brave"/>
+            </td>
+        </tr>
+        <tr>
+            <td><big><big><big>Max Results:</big></big></big></td>
+            <td>
+              <input type="text" name="maxResults" value="10"/>
+            </td>
+        </tr>
+        <tr>
+            <td>
+                &nbsp;
+            </td>
+        </tr>
+        <tr>
+            <td colspan="2">
+                <input type="submit" value="        Find Texts       "/>
+            </td>
+        </tr>
+  </form>
+ </table> 
+</div> 
+</body>
+</html>


Mime
View raw message