You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2008/01/10 09:27:09 UTC
svn commit: r610710 - in
/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs:
basic/src/demo/jaxrs/client/ basic/src/demo/jaxrs/server/
basic_https/src/demo/jaxrs/client/ basic_https/src/demo/jaxrs/server/
content_negotiation/ content_neg...
Author: jliu
Date: Thu Jan 10 00:27:03 2008
New Revision: 610710
URL: http://svn.apache.org/viewvc?rev=610710&view=rev
Log:
Added a new demo to show how to do content negotiation in JSR-311. updated other Jsr-311 demos.
Added:
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/README.txt (with props)
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml (with props)
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/Client.java (with props)
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Customer.java (with props)
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/CustomerService.java (with props)
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Server.java (with props)
Removed:
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/Order.java
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/Product.java
Modified:
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/client/Client.java
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/server/CustomerService.java
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/client/Client.java
incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/CustomerService.java
Modified: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/client/Client.java?rev=610710&r1=610709&r2=610710&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/client/Client.java (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/client/Client.java Thu Jan 10 00:27:03 2008
@@ -53,12 +53,14 @@
System.out.println(getStringFromInputStream(in));
// Sent HTTP GET request to query sub resource product info
+ System.out.println("\n");
System.out.println("Sent HTTP GET request to query sub resource product info");
url = new URL("http://localhost:9000/customerservice/orders/223/products/323");
in = url.openStream();
System.out.println(getStringFromInputStream(in));
// Sent HTTP PUT request to update customer info
+ System.out.println("\n");
System.out.println("Sent HTTP PUT request to update customer info");
Client client = new Client();
String inputFile = client.getClass().getResource("update_customer.txt").getFile();
@@ -80,10 +82,12 @@
}
// Sent HTTP POST request to add customer
+ System.out.println("\n");
System.out.println("Sent HTTP POST request to add customer");
inputFile = client.getClass().getResource("add_customer.txt").getFile();
input = new File(inputFile);
PostMethod post = new PostMethod("http://localhost:9000/customerservice/customers");
+ post.addRequestHeader("Accept" , "text/xml");
entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
httpclient = new HttpClient();
@@ -99,13 +103,7 @@
post.releaseConnection();
}
- // Sent HTTP GET request to query customer info, expect JSON.
- System.out.println("Sent HTTP GET request to query customer info");
- url = new URL("http://localhost:9000/customerservice/customersjson/123");
- in = url.openStream();
- System.out.println(getStringFromInputStream(in));
-
-
+ System.out.println("\n");
System.out.println("Client Invoking is succeeded!");
System.exit(0);
}
Modified: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/server/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/server/CustomerService.java?rev=610710&r1=610709&r2=610710&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/server/CustomerService.java (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic/src/demo/jaxrs/server/CustomerService.java Thu Jan 10 00:27:03 2008
@@ -22,17 +22,12 @@
import java.util.Map;
import javax.ws.rs.HttpMethod;
-import javax.ws.rs.ProduceMime;
import javax.ws.rs.UriParam;
import javax.ws.rs.UriTemplate;
-import javax.ws.rs.core.HttpContext;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
@UriTemplate("/customerservice/")
public class CustomerService {
- @HttpContext UriInfo uriInfo;
-
long currentId = 123;
Map<Long, Customer> customers = new HashMap<Long, Customer>();
Map<Long, Order> orders = new HashMap<Long, Order>();
@@ -45,16 +40,6 @@
@UriTemplate("/customers/{id}/")
public Customer getCustomer(@UriParam("id") String id) {
System.out.println("----invoking getCustomer, Customer id is: " + id);
- long idNumber = Long.parseLong(id);
- Customer c = customers.get(idNumber);
- return c;
- }
-
- @HttpMethod("GET")
- @UriTemplate("/customersjson/{id}/")
- @ProduceMime("application/json")
- public Customer getCustomerJSON(@UriParam("id") String id) {
- System.out.println("----invoking getCustomerJSON, Customer id is: " + id);
long idNumber = Long.parseLong(id);
Customer c = customers.get(idNumber);
return c;
Modified: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/client/Client.java?rev=610710&r1=610709&r2=610710&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/client/Client.java (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/client/Client.java Thu Jan 10 00:27:03 2008
@@ -49,18 +49,7 @@
System.out.println("Sent HTTPS GET request to query customer info");
HttpClient httpclient = new HttpClient();
GetMethod httpget = new GetMethod("https://localhost:9000/customerservice/customers/123");
- try {
- httpclient.executeMethod(httpget);
- System.out.println(httpget.getResponseBodyAsString());
- } finally {
- httpget.releaseConnection();
- }
-
- // Sent HTTP GET request to query sub resource product info
- System.out.println("\n");
- System.out.println("Sent HTTPS GET request to query sub resource product info");
-
- httpget = new GetMethod("https://localhost:9000/customerservice/orders/223/products/323");
+ httpget.addRequestHeader("Accept" , "text/xml");
try {
httpclient.executeMethod(httpget);
System.out.println(httpget.getResponseBodyAsString());
@@ -88,10 +77,12 @@
}
// Sent HTTP POST request to add customer
+ System.out.println("\n");
System.out.println("Sent HTTPS POST request to add customer");
inputFile = client.getClass().getResource("add_customer.txt").getFile();
input = new File(inputFile);
PostMethod post = new PostMethod("https://localhost:9000/customerservice/customers");
+ post.addRequestHeader("Accept" , "text/xml");
entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
post.setRequestEntity(entity);
@@ -106,18 +97,7 @@
post.releaseConnection();
}
- // Sent HTTP GET request to query customer info, expect JSON.
System.out.println("\n");
- System.out.println("Sent HTTPS GET request to query customer info in JSON");
-
- httpget = new GetMethod("https://localhost:9000/customerservice/customersjson/123");
- try {
- httpclient.executeMethod(httpget);
- System.out.println(httpget.getResponseBodyAsString());
- } finally {
- httpget.releaseConnection();
- }
-
System.out.println("Client Invoking is succeeded!");
System.exit(0);
}
Modified: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/CustomerService.java?rev=610710&r1=610709&r2=610710&view=diff
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/CustomerService.java (original)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/basic_https/src/demo/jaxrs/server/CustomerService.java Thu Jan 10 00:27:03 2008
@@ -22,20 +22,14 @@
import java.util.Map;
import javax.ws.rs.HttpMethod;
-import javax.ws.rs.ProduceMime;
import javax.ws.rs.UriParam;
import javax.ws.rs.UriTemplate;
-import javax.ws.rs.core.HttpContext;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
@UriTemplate("/customerservice/")
public class CustomerService {
- @HttpContext UriInfo uriInfo;
-
long currentId = 123;
Map<Long, Customer> customers = new HashMap<Long, Customer>();
- Map<Long, Order> orders = new HashMap<Long, Order>();
public CustomerService() {
init();
@@ -50,16 +44,6 @@
return c;
}
- @HttpMethod("GET")
- @UriTemplate("/customersjson/{id}/")
- @ProduceMime("application/json")
- public Customer getCustomerJSON(@UriParam("id") String id) {
- System.out.println("----invoking getCustomerJSON, Customer id is: " + id);
- long idNumber = Long.parseLong(id);
- Customer c = customers.get(idNumber);
- return c;
- }
-
@HttpMethod("PUT")
@UriTemplate("/customers/")
public Response updateCustomer(Customer customer) {
@@ -105,24 +89,11 @@
return r;
}
- @UriTemplate("/orders/{orderId}/")
- public Order getOrder(@UriParam("orderId") String orderId) {
- System.out.println("----invoking getOrder, Order id is: " + orderId);
- long idNumber = Long.parseLong(orderId);
- Order c = orders.get(idNumber);
- return c;
- }
-
final void init() {
Customer c = new Customer();
c.setName("John");
c.setId(123);
customers.put(c.getId(), c);
-
- Order o = new Order();
- o.setDescription("order 223");
- o.setId(223);
- orders.put(o.getId(), o);
}
}
Added: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/README.txt
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/README.txt?rev=610710&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/README.txt (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/README.txt Thu Jan 10 00:27:03 2008
@@ -0,0 +1,130 @@
+JAX-RS Content Negotiation Demo
+===============================
+
+The demo shows how to do content negotiation so that the same resource can
+be served using multiple representations.
+
+A RESTful customer service is provided on URL http://localhost:9000/customers.
+Users access this URI to operate on customer.
+
+A HTTP GET request to URL http://localhost:9000/customerservice/customers/123
+with Accept header set to "application/xml" returns a customer instance in XML
+format. The XML document returned:
+
+<Customer>
+ <id>123</id>
+ <name>John</name>
+</Customer>
+
+A HTTP GET request to URL http://localhost:9000/customerservice/customers/123
+with Accept header set to "application/json" returns a customer instance in JSON
+format. The JSON document returned:
+
+{"Customer":{"id":"123","name":"John"}}
+
+A HTTP GET request to URL http://localhost:9000/customerservice/customers/123
+without setting Accept header explicitly returns a customer instance in JSON
+format. This is because the Accept header will be absent from the request when using
+HTTP Client, in which case the CXF will treat the Accept content type as "*/*".
+The JSON document returned:
+
+{"Customer":{"id":"123","name":"John"}}
+
+Please review the README in the samples directory before
+continuing.
+
+
+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.
+
+Using either UNIX or Windows:
+
+ ant server (from one command line window)
+ ant client (from a second command line window)
+
+
+To remove the code generated from the WSDL file and the .class
+files, run "ant clean".
+
+
+Building the demo using wsdl2java and javac
+-------------------------------------------
+
+From the base directory of this sample (i.e., where this README file is
+located), first create the target directory build/classes and then
+compile the provided client and server applications with the commands:
+
+For UNIX:
+ mkdir -p build/classes
+
+ export CLASSPATH=$CLASSPATH:$CXF_HOME/lib/cxf-manifest-incubator.jar:./build/classes
+ javac -d build/classes src/demo/jaxrs/client/*.java
+ javac -d build/classes src/demo/jaxrs/server/*.java
+
+For Windows:
+ mkdir build\classes
+ Must use back slashes.
+
+ set classpath=%classpath%;%CXF_HOME%\lib\cxf-manifest-incubator.jar;.\build\classes
+ javac -d build\classes src\demo\jaxrs\client\*.java
+ javac -d build\classes src\demo\jaxrs\server\*.java
+
+
+Finally, copy resource files into the build/classes directory with the commands:
+
+For UNIX:
+ cp ./src/demo/jaxrs/client/*.xml ./build/classes/demo/jaxrs/client
+ cp ./src/demo/jaxrs/server/*.xml ./build/classes/demo/jaxrs/server
+
+For Windows:
+ copy src\demo\jaxrs\client\*.xml build\classes\demo\jaxrs\client
+ copy src\demo\jaxrs\server\*.xml build\classes\demo\jaxrs\server
+
+
+Running the demo using java
+---------------------------
+
+From the samples/jax-rs/content_negotiation directory run the following commands. They
+are entered on a single command line.
+
+For UNIX (must use forward slashes):
+ java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
+ demo.jaxrs.server.Server &
+
+ java -Djava.util.logging.config.file=$CXF_HOME/etc/logging.properties
+ demo.jaxrs.client.Client
+
+The server process starts in the background. After running the client,
+use the kill command to terminate the server process.
+
+For Windows (may use either forward or back slashes):
+ start
+ java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
+ demo.jaxrs.server.Server
+
+ java -Djava.util.logging.config.file=%CXF_HOME%\etc\logging.properties
+ demo.jaxrs.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.
+
+To remove the code generated from the WSDL file and the .class
+files, either delete the build directory and its contents or run:
+
+ ant clean
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/README.txt
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/README.txt
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml?rev=610710&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml Thu Jan 10 00:27:03 2008
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project name="JAX-RS content_negotiation demo" default="build" basedir=".">
+ <property name="codegen.notrequired" value="true"/>
+
+ <import file="../../common_build.xml"/>
+
+ <target name="client" description="run demo client" depends="build">
+ <cxfrun classname="demo.jaxrs.client.Client"/>
+ </target>
+
+ <target name="server" description="run demo server" depends="build">
+ <cxfrun classname="demo.jaxrs.server.Server"/>
+ </target>
+
+</project>
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/build.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/Client.java?rev=610710&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/Client.java (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/Client.java Thu Jan 10 00:27:03 2008
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package demo.jaxrs.client;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+public final class Client {
+
+ private Client() {
+ }
+
+ public static void main(String args[]) throws Exception {
+ // Sent HTTP GET request to query customer info, expect XML
+ System.out.println("Sent HTTP GET request to query customer info, expect XML");
+ GetMethod get = new GetMethod("http://localhost:9000/customerservice/customers/123");
+ get.addRequestHeader("Accept" , "application/xml");
+ HttpClient httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(get);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ System.out.println(get.getResponseBodyAsString());
+ } finally {
+ get.releaseConnection();
+ }
+
+ // Sent HTTP GET request to query customer info, expect JSON.
+ System.out.println("\n");
+ System.out.println("Sent HTTP GET request to query customer info, expect JSON");
+ get = new GetMethod("http://localhost:9000/customerservice/customers/123");
+ get.addRequestHeader("Accept" , "application/json");
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(get);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ System.out.println(get.getResponseBodyAsString());
+ } finally {
+ get.releaseConnection();
+ }
+
+ // Sent HTTP GET request to query customer info, expect JSON.
+ System.out.println("\n");
+ System.out.println("Sent HTTP GET request to query customer info, expect JSON");
+ //The default behavior without setting Accept header explicitly is depending on your client.
+ //In the case of HTTP Client, the Accept header will be absent. The CXF server will treat this
+ //as "*/*", JSON format is returned
+ get = new GetMethod("http://localhost:9000/customerservice/customers/123");
+ httpclient = new HttpClient();
+
+ try {
+ int result = httpclient.executeMethod(get);
+ System.out.println("Response status code: " + result);
+ System.out.println("Response body: ");
+ System.out.println(get.getResponseBodyAsString());
+ } finally {
+ get.releaseConnection();
+ }
+
+ System.out.println("\n");
+ System.out.println("Client Invoking is succeeded!");
+ System.exit(0);
+ }
+}
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/Client.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/client/Client.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Customer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Customer.java?rev=610710&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Customer.java (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Customer.java Thu Jan 10 00:27:03 2008
@@ -0,0 +1,43 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demo.jaxrs.server;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Customer")
+public class Customer {
+ private long id;
+ private String name;
+
+ public long getId() {
+ return id;
+ }
+
+ public void setId(long id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Customer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Customer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/CustomerService.java?rev=610710&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/CustomerService.java (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/CustomerService.java Thu Jan 10 00:27:03 2008
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package demo.jaxrs.server;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.HttpMethod;
+import javax.ws.rs.ProduceMime;
+import javax.ws.rs.UriParam;
+import javax.ws.rs.UriTemplate;
+
+@UriTemplate("/customerservice/")
+public class CustomerService {
+ long currentId = 123;
+ Map<Long, Customer> customers = new HashMap<Long, Customer>();
+
+ public CustomerService() {
+ init();
+ }
+
+ @HttpMethod("GET")
+ @UriTemplate("/customers/{id}/")
+ public Customer getCustomer(@UriParam("id") String id) {
+ System.out.println("----invoking getCustomer, Customer id is: " + id);
+ long idNumber = Long.parseLong(id);
+ Customer c = customers.get(idNumber);
+ return c;
+ }
+
+ @HttpMethod("GET")
+ @UriTemplate("/customersjson/{id}/")
+ @ProduceMime("application/json")
+ public Customer getCustomerJSON(@UriParam("id") String id) {
+ System.out.println("----invoking getCustomerJSON, Customer id is: " + id);
+ long idNumber = Long.parseLong(id);
+ Customer c = customers.get(idNumber);
+ return c;
+ }
+
+ final void init() {
+ Customer c = new Customer();
+ c.setName("John");
+ c.setId(123);
+ customers.put(c.getId(), c);
+ }
+
+}
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/CustomerService.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/CustomerService.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Server.java?rev=610710&view=auto
==============================================================================
--- incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Server.java (added)
+++ incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Server.java Thu Jan 10 00:27:03 2008
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package demo.jaxrs.server;
+
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+
+public class Server {
+
+ protected Server() throws Exception {
+ JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+ sf.setResourceClasses(CustomerService.class);
+ sf.setResourceProvider(CustomerService.class, new SingletonResourceProvider());
+ sf.setAddress("http://localhost:9000/");
+
+ sf.create();
+ }
+
+ public static void main(String args[]) throws Exception {
+ new Server();
+ System.out.println("Server ready...");
+
+ Thread.sleep(5 * 60 * 1000);
+ System.out.println("Server exiting");
+ System.exit(0);
+ }
+}
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Server.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/cxf/trunk/distribution/src/main/release/samples/jax_rs/content_negotiation/src/demo/jaxrs/server/Server.java
------------------------------------------------------------------------------
svn:keywords = Rev Date