Author: jliu
Date: Sun Dec 10 23:36:59 2006
New Revision: 485539

URL: http://svn.apache.org/viewvc?view=rev&rev=485539
Log:
Update restful sample, remove the presence of wsdl file from client side. 

Modified:
    incubator/cxf/trunk/distribution/src/main/release/samples/restful/README.txt
    incubator/cxf/trunk/distribution/src/main/release/samples/restful/build.xml
    
incubator/cxf/trunk/distribution/src/main/release/samples/restful/src/demo/restful/client/Client.java
    
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java

Modified: 
incubator/cxf/trunk/distribution/src/main/release/samples/restful/README.txt
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful/README.txt?view=diff&rev=485539&r1=485538&r2=485539
==============================================================================
--- 
incubator/cxf/trunk/distribution/src/main/release/samples/restful/README.txt 
(original)
+++ 
incubator/cxf/trunk/distribution/src/main/release/samples/restful/README.txt 
Sun Dec 10 23:36:59 2006
@@ -38,7 +38,7 @@
 <Customer>
   <id>1234</id>
   <name>John</name>
-  <phoneNumber>234567</phoneNumber>
+  <phoneNumber>123456</phoneNumber>
 </Customer>
 
 updates customer 1234 with the data provided. 
@@ -140,7 +140,7 @@
          demo.restful.server.Server &
 
     java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
-         demo.restful.client.Client ./wsdl/hello_world_xml_wrapped.wsdl
+         demo.restful.client.Client
 
 The server process starts in the background.  After running the client,
 use the kill command to terminate the server process.
@@ -151,7 +151,7 @@
          demo.restful.server.Server
 
     java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
-       demo.restful.client.Client .\wsdl\hello_world_xml_wrapped.wsdl
+       demo.restful.client.Client
 
 A new command windows opens for the server process.  After running the
 client, terminate the server process by issuing Ctrl-C in its command window.

Modified: 
incubator/cxf/trunk/distribution/src/main/release/samples/restful/build.xml
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful/build.xml?view=diff&rev=485539&r1=485538&r2=485539
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/restful/build.xml 
(original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/restful/build.xml 
Sun Dec 10 23:36:59 2006
@@ -22,8 +22,7 @@
     <import file="../common_build.xml"/>        
         
     <target name="client" description="run demo client" depends="build">
-        <cxfrun classname="demo.restful.client.Client"
-            param1="${basedir}/wsdl/hello_world_xml_wrapped.wsdl"/>
+        <cxfrun classname="demo.restful.client.Client"/>
     </target> 
         
     <target name="server" description="run demo server" depends="build">

Modified: 
incubator/cxf/trunk/distribution/src/main/release/samples/restful/src/demo/restful/client/Client.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful/src/demo/restful/client/Client.java?view=diff&rev=485539&r1=485538&r2=485539
==============================================================================
--- 
incubator/cxf/trunk/distribution/src/main/release/samples/restful/src/demo/restful/client/Client.java
 (original)
+++ 
incubator/cxf/trunk/distribution/src/main/release/samples/restful/src/demo/restful/client/Client.java
 Sun Dec 10 23:36:59 2006
@@ -53,42 +53,13 @@
     }
 
     public static void main(String args[]) throws Exception {
-        if (args.length == 0) {
-            System.out.println("please specify wsdl");
-            System.exit(1);
-        }
-
-        URL wsdlURL;
-        File wsdlFile = new File(args[0]);
-        if (wsdlFile.exists()) {
-            wsdlURL = wsdlFile.toURL();
-        } else {
-            wsdlURL = new URL(args[0]);
-        }
-
-        System.out.println(wsdlURL + "\n\n");
-
         QName serviceName = new 
QName("http://apache.org/hello_world_xml_http/wrapped";,
                                                 "cutomerservice");
         QName portName = new 
QName("http://apache.org/hello_world_xml_http/wrapped";,
                                              "RestProviderPort");
-
-        Cutomerservice cutomerservice = new Cutomerservice(wsdlURL, 
serviceName);
-
-        Client client = new Client();
-        InputStream is = 
client.getClass().getResourceAsStream("CustomerJohnReq.xml");
-        Document doc = XMLUtils.parse(is);
-        DOMSource reqMsg = new DOMSource(doc);
-
-        // Sent HTTP POST request to update customer info
-        Dispatch<DOMSource> disp = cutomerservice.createDispatch(portName, 
DOMSource.class,
-                                   Service.Mode.PAYLOAD);
-        System.out.println("Invoking server through HTTP POST to update 
customer info");
-        DOMSource result = disp.invoke(reqMsg);
-        printSource(result);
+        String endpointAddress = 
"http://localhost:9000/customerservice/customer";;
 
         // Sent HTTP GET request to query all customer info
-        String endpointAddress = 
"http://localhost:9000/customerservice/customer";;
         URL url = new URL(endpointAddress);
         System.out.println("Invoking server through HTTP GET to query all 
customer info");
         InputStream in = url.openStream();
@@ -96,31 +67,42 @@
         printSource(source);
 
         // Sent HTTP GET request to query customer info
-        endpointAddress = "http://localhost:9000/customerservice/customer";;
         url = new URL(endpointAddress + "?id=1234");
         System.out.println("Invoking server through HTTP GET to query customer 
info");
         in = url.openStream();
         source = new StreamSource(in);
         printSource(source);
 
-        // Use Dispatch to send GET request to query customer info
-        endpointAddress =
-            "http://localhost:9000/customerservice/customer";;
-        Service service = Service.create(serviceName);
+        // Sent HTTP GET request to query customer info using JAX-WS Dispatch
         URI endpointURI = new URI(endpointAddress.toString());
         String path = null;
         if (endpointURI != null) {
             path = endpointURI.getPath();
         }
-        service.addPort(portName, HTTPBinding.HTTP_BINDING, 
endpointAddress.toString());
-        Dispatch<Source> dispatch = service.createDispatch(portName, 
Source.class, Service.Mode.PAYLOAD);
-        Map<String, Object> requestContext = dispatch.getRequestContext();
+
+        Service service = Service.create(serviceName);
+        service.addPort(portName, HTTPBinding.HTTP_BINDING,  endpointAddress);
+        Dispatch<DOMSource> dispatcher = service.createDispatch(portName, 
DOMSource.class, Service.Mode.PAYLOAD);
+        Map<String, Object> requestContext = dispatcher.getRequestContext();
+
         requestContext.put(MessageContext.HTTP_REQUEST_METHOD, new 
String("GET"));
         requestContext.put(MessageContext.QUERY_STRING, "id=1234");
         requestContext.put(MessageContext.PATH_INFO, path);
-        System.out.println("Invoking Restful GET Request with query string ");
-        Source returnSource = dispatch.invoke(null);
+        System.out.println("Invoking server through HTTP GET to query customer 
info using JAX-WS Dispatch");
+        DOMSource returnSource = dispatcher.invoke(null);
         printSource(returnSource);
+
+        // Sent HTTP POST request to update customer info using JAX-WS Dispatch
+        Client client = new Client();
+        InputStream is = 
client.getClass().getResourceAsStream("CustomerJohnReq.xml");
+        Document doc = XMLUtils.parse(is);
+        DOMSource reqMsg = new DOMSource(doc);
+
+        requestContext.put(MessageContext.HTTP_REQUEST_METHOD, "POST");
+        System.out.println("Invoking server through HTTP POST to update 
customer info using JAX-WS Dispatch");
+        DOMSource result = dispatcher.invoke(reqMsg);
+        printSource(result);
+
         System.out.println("Client Invoking is succeeded!");
         System.exit(0);
     }

Modified: 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java?view=diff&rev=485539&r1=485538&r2=485539
==============================================================================
--- 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java
 (original)
+++ 
incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/rest/RestClientServerTest.java
 Sun Dec 10 23:36:59 2006
@@ -35,6 +35,7 @@
 
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.ws.Dispatch;
 
 import javax.xml.ws.Service;
@@ -67,9 +68,9 @@
                 assertTrue("server did not launch correctly", 
launchServer(Server.class));
             }
         };
-    }
-
-    public void testHttpPOSTDispatch() throws Exception {
+    }    
+   
+    public void testHttpPOSTDispatchWithWSDL() throws Exception {
         URL wsdl = 
getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");
         assertNotNull(wsdl);
 
@@ -97,7 +98,20 @@
        
     }
 
-   
+    public void testHttpPOSTDispatch() throws Exception {
+        Service service = Service.create(serviceName);
+        service.addPort(portName, HTTPBinding.HTTP_BINDING,
+                        
"http://localhost:9023/XMLService/RestProviderPort/Customer";);
+        Dispatch<Source> dispatcher = service.createDispatch(portName, 
Source.class, Service.Mode.MESSAGE);
+        Map<String, Object> requestContext = dispatcher.getRequestContext();
+        requestContext.put(MessageContext.HTTP_REQUEST_METHOD, "POST");
+        InputStream is = 
getClass().getResourceAsStream("resources/CustomerJohnReq.xml");
+        Source result = dispatcher.invoke(new StreamSource(is));
+        String tempstring = source2String(result);
+        assertTrue("Result should start with Customer", 
tempstring.startsWith("<ns4:Customer"));
+        assertTrue("Result should have CustomerID", 
tempstring.lastIndexOf("CustomerID>123456<") > 0);
+    }
+    
     @SuppressWarnings("unchecked")
     public void testHttpGETDispatcher() throws Exception { 
         String endpointAddress =


Reply via email to