cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a.@apache.org
Subject cxf git commit: use a non-empty context-path for samples/jax_rs/websocket sample
Date Wed, 23 Mar 2016 13:24:18 GMT
Repository: cxf
Updated Branches:
  refs/heads/master ac9b9b189 -> 5f4317c54


use a non-empty context-path for samples/jax_rs/websocket sample


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

Branch: refs/heads/master
Commit: 5f4317c540b753b224fd9fa44478cabe58da0858
Parents: ac9b9b1
Author: Akitoshi Yoshida <ay@apache.org>
Authored: Wed Mar 23 14:23:03 2016 +0100
Committer: Akitoshi Yoshida <ay@apache.org>
Committed: Wed Mar 23 14:24:12 2016 +0100

----------------------------------------------------------------------
 .../release/samples/jax_rs/websocket/README.txt | 26 ++++++++---------
 .../src/main/java/demo/jaxrs/client/Client.java | 29 ++++++++-----------
 .../src/main/java/demo/jaxrs/server/Server.java |  4 ++-
 .../websocket/src/main/resources/index.html     |  4 +--
 .../websocket/src/test/resources/client.js      | 30 +++++++++++---------
 5 files changed, 46 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5f4317c5/distribution/src/main/release/samples/jax_rs/websocket/README.txt
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/websocket/README.txt b/distribution/src/main/release/samples/jax_rs/websocket/README.txt
index f1d3455..8df709e 100644
--- a/distribution/src/main/release/samples/jax_rs/websocket/README.txt
+++ b/distribution/src/main/release/samples/jax_rs/websocket/README.txt
@@ -3,7 +3,7 @@ JAX-RS WebSocket Demo
 
 This is a websocket transport version of JAX-RS Basic Demo.
 
-A RESTful customer service is provided on URL ws://localhost:9000/customers. 
+A RESTful customer service is provided on URL ws://localhost:9000/demo
 Users access this URI to operate on customer.
 
 This sample includes two convenient clients: a plain javascript browser client
@@ -13,12 +13,12 @@ and a node.js client based on atmosphere.
 Connecting to the server
 ---------------------------------------
 
-Open a websocket to ws://localhost:9000/ and send requests over the websocket.
+Open a websocket to ws://localhost:9000/demo and send requests over the websocket.
 
-A GET request to path /customerservice/customers/123
+A GET request to path /demo/customerservice/customers/123
 
 ------------------------------------------------------------------------
-GET /customerservice/customers/123
+GET /demo/customerservice/customers/123
 ------------------------------------------------------------------------
 
 returns a customer instance whose id is 123. The XML document returned:
@@ -30,10 +30,10 @@ returns a customer instance whose id is 123. The XML document returned:
 </Customer>
 ------------------------------------------------------------------------
 
-A GET request to path /customerservice/orders/223/products/323
+A GET request to path /demo/customerservice/orders/223/products/323
 
 ------------------------------------------------------------------------
-GET /customerservice/orders/223/products/323
+GET /demo/customerservice/orders/223/products/323
 ------------------------------------------------------------------------
 
 returns product 323 that belongs to order 223. The XML document returned:
@@ -48,7 +48,7 @@ returns product 323 that belongs to order 223. The XML document returned:
 A POST request to path /customerservice/customers
 
 ------------------------------------------------------------------------
-POST /customerservice/customers
+POST /demo/customerservice/customers
 Content-Type: text/xml; charset="utf-8"
 ------------------------------------------------------------------------
 
@@ -63,7 +63,7 @@ with the data:
 adds a customer whose name is Jack 
 
 
-A PUT request to path /customerservice/customers
+A PUT request to path /demo/customerservice/customers
 
 ------------------------------------------------------------------------
 PUT /customerservice/customers
@@ -82,20 +82,20 @@ with the data:
 updates the customer instance whose id is 123
 
 
-A GET request to path /monitor with id monitor-12345
+A GET request to path /demo/monitor with id monitor-12345
 
 ------------------------------------------------------------------------
-GET /customerservice/monitor
+GET /demo/customerservice/monitor
 requestId: monitor-12345
 ------------------------------------------------------------------------
 
 returns a continuous event stream on the customer
 activities. Try invoking some customer related operations.
 
-A GET request to path /unmonitor with id monitor-12345
+A GET request to path /demo/unmonitor with id monitor-12345
 
 ------------------------------------------------------------------------
-GET /customerservice/unmonitor/monitor-12345
+GET /demo/customerservice/unmonitor/monitor-12345
 ------------------------------------------------------------------------
 
 unregisters the event stream and returns its status.
@@ -141,7 +141,7 @@ the content. For example, the above POST example should use the Request
 value:
 
 ------------------------------------------------------------------------
-POST /customerservice/customers
+POST /demo/customerservice/customers
 Content-Type: text/xml; charset="utf-8"
 
 <Customer>

http://git-wip-us.apache.org/repos/asf/cxf/blob/5f4317c5/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/client/Client.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/client/Client.java
b/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/client/Client.java
index dbdc589..1b91019 100644
--- a/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/client/Client.java
+++ b/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/client/Client.java
@@ -19,6 +19,8 @@
 
 package demo.jaxrs.client;
 
+import demo.jaxrs.server.Server;
+
 import java.io.InputStream;
 import java.util.List;
 
@@ -31,21 +33,14 @@ public final class Client {
     }
 
     public static void main(String args[]) throws Exception {
-        // Sent HTTP GET request to query all customer info
-        /*
-         * URL url = new URL("http://localhost:9000/customers");
-         * System.out.println("Invoking server through HTTP GET to query all
-         * customer info"); InputStream in = url.openStream(); StreamSource
-         * source = new StreamSource(in); printSource(source);
-         */
 
         // Create a websocket client and connect to the target service
-        WebSocketTestClient client = new WebSocketTestClient("ws://localhost:9000/");
+        WebSocketTestClient client = new WebSocketTestClient(Server.HOST_URL + Server.CONTEXT_PATH);
         client.connect();
 
         // Sent GET request to query customer info
         System.out.println("Sent GET request to query customer info");
-        client.sendTextMessage("GET /customerservice/customers/123");
+        client.sendTextMessage("GET " + Server.CONTEXT_PATH + "/customerservice/customers/123");
         client.await(5);
         List<WebSocketTestClient.Response> responses = client.getReceivedResponses();
         System.out.println(responses.get(0));
@@ -53,7 +48,7 @@ public final class Client {
         // Sent GET request to query sub resource product info
         client.reset(1);
         System.out.println("Sent GET request to query sub resource product info");
-        client.sendTextMessage("GET /customerservice/orders/223/products/323");
+        client.sendTextMessage("GET " + Server.CONTEXT_PATH + "/customerservice/orders/223/products/323");
         client.await(5);
         responses = client.getReceivedResponses();
         System.out.println(responses.get(0));
@@ -62,8 +57,8 @@ public final class Client {
         client.reset(1);
         System.out.println("Sent PUT request to update customer info");
         String inputData = getStringFromInputStream(Client.class.getResourceAsStream("/update_customer.xml"));
-        client.sendTextMessage("PUT /customerservice/customers\r\nContent-Type: text/xml;"
-                               + " charset=ISO-8859-1\r\n\r\n"
+        client.sendTextMessage("PUT " + Server.CONTEXT_PATH + "/customerservice/customers\r\n"
+                               + "Content-Type: text/xml; charset=ISO-8859-1\r\n\r\n"
                                + inputData);
         client.await(5);
         responses = client.getReceivedResponses();
@@ -73,20 +68,20 @@ public final class Client {
         client.reset(1);
         System.out.println("Sent POST request to add customer");
         inputData = getStringFromInputStream(Client.class.getResourceAsStream("/add_customer.xml"));
-        client.sendTextMessage("POST /customerservice/customers\r\nContent-Type: text/xml;
"
+        client.sendTextMessage("POST " + Server.CONTEXT_PATH + "/customerservice/customers\r\nContent-Type:
text/xml; "
                                + "charset=ISO-8859-1\r\nAccept: text/xml\r\n\r\n" + inputData);
         client.await(5);
         responses = client.getReceivedResponses();
         System.out.println(responses.get(0));
 
         // Create another websocket client and connect to the target service
-        WebSocketTestClient client2 = new WebSocketTestClient("ws://localhost:9000/");
+        WebSocketTestClient client2 = new WebSocketTestClient(Server.HOST_URL + Server.CONTEXT_PATH);
         client2.connect();
 
         // Sent GET request to monitor the customer activities
         client2.reset(1);
         System.out.println("Sent GET request to monitor activities");
-        client2.sendTextMessage("GET /customerservice/monitor");
+        client2.sendTextMessage("GET " + Server.CONTEXT_PATH + "/customerservice/monitor");
         client2.await(5);
         responses = client2.getReceivedResponses();
         System.out.println(responses.get(0));
@@ -94,8 +89,8 @@ public final class Client {
         // one retrieval, one delete
         client2.reset(2);
         client.reset(2);
-        client.sendTextMessage("GET /customerservice/customers/123");
-        client.sendTextMessage("DELETE /customerservice/customers/235");
+        client.sendTextMessage("GET " + Server.CONTEXT_PATH + "/customerservice/customers/123");
+        client.sendTextMessage("DELETE " + Server.CONTEXT_PATH + "/customerservice/customers/235");
 
         client2.await(5);
         responses = client2.getReceivedResponses();

http://git-wip-us.apache.org/repos/asf/cxf/blob/5f4317c5/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/server/Server.java
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/server/Server.java
b/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/server/Server.java
index fe59dd0..851a512 100644
--- a/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/server/Server.java
+++ b/distribution/src/main/release/samples/jax_rs/websocket/src/main/java/demo/jaxrs/server/Server.java
@@ -23,13 +23,15 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 
 public class Server {
+    public static final String HOST_URL = "ws://localhost:9000";
+    public static final String CONTEXT_PATH = "/demo";
 
     protected Server() throws Exception {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
         sf.setResourceClasses(CustomerService.class);
         sf.setResourceProvider(CustomerService.class, 
             new SingletonResourceProvider(new CustomerService()));
-        sf.setAddress("ws://localhost:9000/");
+        sf.setAddress(HOST_URL + CONTEXT_PATH);
 
         sf.create();
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/5f4317c5/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html
b/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html
index 87c8eaf..e7d81f4 100644
--- a/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html
+++ b/distribution/src/main/release/samples/jax_rs/websocket/src/main/resources/index.html
@@ -29,14 +29,14 @@
 <div id="output">
   <div id="config" style="float: left;">
     <strong>Service Endpoint URL:</strong><br />
-    <input id="wsUri" size="72" style="width: 100%" value="ws://localhost:9000/"/>
+    <input id="wsUri" size="72" style="width: 100%" value="ws://localhost:9000/demo"/>
     <br/>
     <button id="connect">Connect</button>
     <button id="disconnect">Disconnect</button>
     <br />
     <br />
     <strong>Request:</strong><br />
-    <textarea id="request" rows="10" cols="72" style="width: 100%;">GET /customerservice/customers/123</textarea>
+    <textarea id="request" rows="10" cols="72" style="width: 100%;">GET /demo/customerservice/customers/123</textarea>
     <br/>
     <button id="send">Send</button>
   </div>

http://git-wip-us.apache.org/repos/asf/cxf/blob/5f4317c5/distribution/src/main/release/samples/jax_rs/websocket/src/test/resources/client.js
----------------------------------------------------------------------
diff --git a/distribution/src/main/release/samples/jax_rs/websocket/src/test/resources/client.js
b/distribution/src/main/release/samples/jax_rs/websocket/src/test/resources/client.js
index 8e8d653..2df8d30 100644
--- a/distribution/src/main/release/samples/jax_rs/websocket/src/test/resources/client.js
+++ b/distribution/src/main/release/samples/jax_rs/websocket/src/test/resources/client.js
@@ -8,14 +8,16 @@
 
 "use strict";
 
-var HOST_URL = 'http://localhost:9000/';
+// set the host url and path if the service runs at a different location
+var HOST_URL = 'http://localhost:9000';
+var CONTEXT_PATH = "/demo"
 
 var reader = require('readline');
 var prompt = reader.createInterface(process.stdin, process.stdout);
 
 var atmosphere = require('atmosphere.js');
 
-var request = { url: HOST_URL,
+var request = { url: HOST_URL + CONTEXT_PATH,
                 transport : 'websocket',
                 trackMessageLength: false,
                 dropHeaders: false,
@@ -75,10 +77,10 @@ function doHelp() {
 function doAdd(v) {
     var req;
     if (transport == 'websocket') {
-        req = "POST /customerservice/customers\r\nContent-Type: text/xml; charset='utf-8'\r\nAccept:
text/xml\r\n\r\n" 
+        req = "POST " + CONTEXT_PATH + "/customerservice/customers\r\nContent-Type: text/xml;
charset='utf-8'\r\nAccept: text/xml\r\n\r\n" 
             + createAddCustomerPayload(v[0]);
     } else if (transport == 'sse') {
-        req = {"method": "POST", "url": HOST_URL + "customerservice/customers", "headers":
{"content-type": "text/xml; charset=utf-8", "accept": "text/xml"}, "data": createAddCustomerPayload(v[0])}
+        req = {"method": "POST", "url": HOST_URL + CONTEXT_PATH + "/customerservice/customers",
"headers": {"content-type": "text/xml; charset=utf-8", "accept": "text/xml"}, "data": createAddCustomerPayload(v[0])}
     }
     console.log("TRACE: sending ", req);
     subSocket.push(req);
@@ -87,9 +89,9 @@ function doAdd(v) {
 function doDelete(v) {
     var req;
     if (transport == 'websocket') {
-        req = "DELETE /customerservice/customers/" + v[0];
+        req = "DELETE" + CONTEXT_PATH + "/customerservice/customers/" + v[0];
     } else if (transport == 'sse') {
-        req = {"method": "DELETE", "url": HOST_URL + "customerservice/customers/" + v[0]}
+        req = {"method": "DELETE", "url": HOST_URL + CONTEXT_PATH + "/customerservice/customers/"
+ v[0]}
     }
     console.log("TRACE: sending ", req);
     subSocket.push(req);
@@ -98,9 +100,9 @@ function doDelete(v) {
 function doGet(v) {
     var req;
     if (transport == 'websocket') {
-        req = "GET /customerservice/customers/" + v[0];
+        req = "GET " + CONTEXT_PATH + "/customerservice/customers/" + v[0];
     } else if (transport == 'sse') {
-        req = {"method": "GET", "url": HOST_URL + "customerservice/customers/" + v[0]}
+        req = {"method": "GET", "url": HOST_URL + CONTEXT_PATH + "/customerservice/customers/"
+ v[0]}
     }
     console.log("TRACE: sending ", req);
     subSocket.push(req);
@@ -109,9 +111,9 @@ function doGet(v) {
 function doSubscribe() {
     var req;
     if (transport == 'websocket') {
-        req = "GET /customerservice/monitor\r\nAccept: text/plain\r\n";
+        req = "GET " + CONTEXT_PATH + "/customerservice/monitor\r\nAccept: text/plain\r\n";
     } else if (transport == 'sse') {
-        req = {"method": "GET", "url": HOST_URL + "customerservice/monitor2", "headers":
{"accept": "text/plain"}}
+        req = {"method": "GET", "url": HOST_URL + CONTEXT_PATH + "/customerservice/monitor",
"headers": {"accept": "text/plain"}}
     }
     console.log("TRACE: sending ", req);
     subSocket.push(req);
@@ -120,9 +122,9 @@ function doSubscribe() {
 function doUnsubscribe() {
     var req;
     if (transport == 'websocket') {
-        req = "GET /customerservice/unmonitor/*\r\nAccept: text/plain\r\n";
+        req = "GET " + CONTEXT_PATH + "/customerservice/unmonitor/*\r\nAccept: text/plain\r\n";
     } else if (transport == 'sse') {
-        req = {"method": "GET", "url": HOST_URL + "customerservice/unmonitor2/*", "headers":
{"accept": "text/plain"}}
+        req = {"method": "GET", "url": HOST_URL + CONTEXT_PATH + "/customerservice/unmonitor/*",
"headers": {"accept": "text/plain"}}
     }
     console.log("TRACE: sending ", req);
     subSocket.push(req);
@@ -131,10 +133,10 @@ function doUnsubscribe() {
 function doUpdate(v) {
     var req;
     if (transport == 'websocket') {
-        req = "PUT /customerservice/customers\r\nContent-Type: text/xml; charset='utf-8'\r\nAccept:
text/xml\r\n\r\n" 
+        req = "PUT " + CONTEXT_PATH + "/customerservice/customers\r\nContent-Type: text/xml;
charset='utf-8'\r\nAccept: text/xml\r\n\r\n" 
             + createUpdateCustomerPayload(v[0], v[1]);
     } else if (transport == 'sse') {
-        req = {"method": "PUT", "url": HOST_URL + "customerservice/customers", "headers":
{"content-type": "text/xml; charset=utf-8", "accept": "text/xml"}, "data": createUpdateCustomerPayload(v[0],
v[1])}
+        req = {"method": "PUT", "url": HOST_URL + CONTEXT_PATH + "/customerservice/customers",
"headers": {"content-type": "text/xml; charset=utf-8", "accept": "text/xml"}, "data": createUpdateCustomerPayload(v[0],
v[1])}
     }
     console.log("TRACE: sending ", req);
     subSocket.push(req);


Mime
View raw message