Author: jliu
Date: Wed Nov 14 23:29:00 2007
New Revision: 595229
URL: http://svn.apache.org/viewvc?rev=595229&view=rev
Log:
More on restfu_http_binding demo refactoring: Using HttpClient instead of
jax-ws style APIs to show how to access RESTful services because a). jax-ws
style client API does not work properly with CXF HTTP binding RESTful services
b). We do not have plan to support this anyway.
Added:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/README.txt
(with props)
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/Client.java
- copied, changed from r595226,
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/ClientMain.java
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Server.java
- copied, changed from r595226,
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Main.java
Removed:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/com/
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/ClientMain.java
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Main.java
Modified:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/build.xml
Added:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/README.txt
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/README.txt?rev=595229&view=auto
==============================================================================
---
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/README.txt
(added)
+++
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/README.txt
Wed Nov 14 23:29:00 2007
@@ -0,0 +1,67 @@
+RESTful HTTP Binding Demo
+========================
+
+This demo shows how to create RESTful services using CXF's HTTP binding.
+The server in the demo creates 3 different endpoints: a RESTful XML
+endpoint, a RESTful JSON endpoint, and a SOAP endpoint.
+
+
+Prerequisites
+-------------
+
+If your environment already includes cxf-manifest-incubator.jar on the
+CLASSPATH, and the JDK and ant bin directories on the PATH
+it is not necessary to set the environment as described in
+the samples directory README. If your environment is not
+properly configured, or if you are planning on using wsdl2java,
+javac, and java to build and run the demos, you must set the
+environment.
+
+
+Building and running the demo using Ant
+---------------------------------------
+
+From the base directory of this sample (i.e., where this README file is
+located), the Ant build.xml file can be used to build and run the demo.
+The server and client targets automatically build the demo.
+
+The demo has a class called demo.restful.server.Server which starts up various
+endpoints. To start this server run the command:
+
+Using either UNIX or Windows:
+ ant server (from one command line window)
+
+The demo also includes a Client class which accesses data using
+HTTP. To run this client, do:
+
+Using either UNIX or Windows:
+ ant client (from a second command line window)
+
+Once it is running try going to the following URLs:
+
+http://localhost:8080/xml/customers
+http://localhost:8080/json/customers
+http://localhost:8080/xml/customers/123
+http://localhost:8080/json/customers/123
+
+These will serve out XML and JSON representation of the resources.
+
+There is an HTML page that is served by CXF so you can try using the
+JSON service via Javascript. Just go to:
+
+http://localhost:8080/test.html
+
+Included are some example JSON and XML files so you can add or update
+customers using wget. Try the following commands and look at the results:
+
+wget --post-file add.json http://localhost:8080/json/customers
+wget --post-file add.xml http://localhost:8080/xml/customers
+wget --post-file update.xml http://localhost:8080/xml/customers/123
+
+And if you are interested in SOAP you can try the SOAP endpoint:
+
+http://localhost:8080/soap?wsdl
+
+
+To remove the code generated from the WSDL file and the .class
+files, run "ant clean".
\ No newline at end of file
Propchange:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/README.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/build.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/build.xml?rev=595229&r1=595228&r2=595229&view=diff
==============================================================================
---
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/build.xml
(original)
+++
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/build.xml
Wed Nov 14 23:29:00 2007
@@ -23,11 +23,11 @@
<import file="../common_build.xml"/>
<target name="client" description="run demo client" depends="build">
- <cxfrun classname="demo.restful.client.ClientMain"/>
+ <cxfrun classname="demo.restful.client.Client"/>
</target>
<target name="server" description="run demo server" depends="build">
- <cxfrun classname="demo.restful.server.Main"/>
+ <cxfrun classname="demo.restful.server.Server"/>
</target>
</project>
Copied:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/Client.java
(from r595226,
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/ClientMain.java)
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/Client.java?p2=incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/Client.java&p1=incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/ClientMain.java&r1=595226&r2=595229&rev=595229&view=diff
==============================================================================
---
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/ClientMain.java
(original)
+++
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/client/Client.java
Wed Nov 14 23:29:00 2007
@@ -18,32 +18,30 @@
*/
package demo.restful.client;
-import org.apache.cxf.binding.http.HttpBindingFactory;
-import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+import java.io.InputStream;
+import java.net.URL;
-import demo.restful.server.CustomerService;
-import demo.restful.server.Customers;
-import demo.restful.server.Customer;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.io.CachedOutputStream;
-public final class ClientMain {
- private ClientMain() { }
+public final class Client {
+ private Client() { }
public static void main(String[] args) throws Exception {
- JaxWsProxyFactoryBean sf = new JaxWsProxyFactoryBean();
- sf.setServiceClass(CustomerService.class);
-
- // Turn off wrapped mode to make our xml prettier
- sf.getServiceFactory().setWrapped(false);
-
- // Use the HTTP Binding which understands the Java Rest Annotations
-
sf.getClientFactoryBean().setBindingId(HttpBindingFactory.HTTP_BINDING_ID);
- sf.setAddress("http://localhost:8080/xml/");
- CustomerService cs = (CustomerService)sf.create();
-
- Customers customers = cs.getCustomers();
- for (Customer c : customers.getCustomer()) {
- System.out.println("Found customer " + c.getName());
- }
+ // Sent HTTP GET request to query customer info
+ System.out.println("Sent HTTP GET request to query customer info");
+ URL url = new URL("http://localhost:8080/xml/customers");
+ InputStream in = url.openStream();
+ System.out.println(getStringFromInputStream(in));
+ }
+
+ private static String getStringFromInputStream(InputStream in) throws
Exception {
+ CachedOutputStream bos = new CachedOutputStream();
+ IOUtils.copy(in, bos);
+ in.close();
+ bos.close();
+ //System.out.println(bos.getOut().toString());
+ return bos.getOut().toString();
}
}
Copied:
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Server.java
(from r595226,
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Main.java)
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Server.java?p2=incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Server.java&p1=incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Main.java&r1=595226&r2=595229&rev=595229&view=diff
==============================================================================
---
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Main.java
(original)
+++
incubator/cxf/trunk/distribution/src/main/release/samples/restful_http_binding/src/demo/restful/server/Server.java
Wed Nov 14 23:29:00 2007
@@ -44,8 +44,8 @@
import org.codehaus.jettison.mapped.MappedXMLInputFactory;
import org.codehaus.jettison.mapped.MappedXMLOutputFactory;
-public final class Main {
- private Main() { }
+public final class Server {
+ private Server() { }
public static void main(String[] args) throws Exception {
CustomerServiceImpl bs = new CustomerServiceImpl();