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 2007/10/14 17:11:01 UTC
svn commit: r584553 - in /incubator/cxf/branches/jliu/distribution: ./
bundle/ manifest/
src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/
src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/
Author: jliu
Date: Sun Oct 14 08:11:01 2007
New Revision: 584553
URL: http://svn.apache.org/viewvc?rev=584553&view=rev
Log:
Some hacks to get sample build
Modified:
incubator/cxf/branches/jliu/distribution/bundle/pom.xml
incubator/cxf/branches/jliu/distribution/manifest/pom.xml
incubator/cxf/branches/jliu/distribution/pom.xml
incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java
incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java
incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Server.java
Modified: incubator/cxf/branches/jliu/distribution/bundle/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/bundle/pom.xml?rev=584553&r1=584552&r2=584553&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/bundle/pom.xml (original)
+++ incubator/cxf/branches/jliu/distribution/bundle/pom.xml Sun Oct 14 08:11:01 2007
@@ -211,7 +211,12 @@
<version>${pom.version}</version>
<optional>true</optional>
</dependency>
-
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${pom.version}</version>
+ <optional>true</optional>
+ </dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
Modified: incubator/cxf/branches/jliu/distribution/manifest/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/manifest/pom.xml?rev=584553&r1=584552&r2=584553&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/manifest/pom.xml (original)
+++ incubator/cxf/branches/jliu/distribution/manifest/pom.xml Sun Oct 14 08:11:01 2007
@@ -209,6 +209,11 @@
</dependency>
<dependency>
<groupId>${pom.groupId}</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
<artifactId>cxf-bundle</artifactId>
<version>${pom.version}</version>
</dependency>
@@ -217,6 +222,16 @@
<artifactId>jettison</artifactId>
<version>1.0-RC2</version>
</dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <version>3.1-rc1</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ <version>0.9</version>
+ </dependency>
</dependencies>
<build>
Modified: incubator/cxf/branches/jliu/distribution/pom.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/pom.xml?rev=584553&r1=584552&r2=584553&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/pom.xml (original)
+++ incubator/cxf/branches/jliu/distribution/pom.xml Sun Oct 14 08:11:01 2007
@@ -212,6 +212,11 @@
<version>${pom.version}</version>
</dependency>
<dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.0-RC2</version>
@@ -226,6 +231,11 @@
<artifactId>commons-httpclient</artifactId>
<version>3.1-rc1</version>
</dependency>
+ <dependency>
+ <groupId>javax.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ <version>0.9</version>
+ </dependency>
</dependencies>
<build>
Modified: incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java?rev=584553&r1=584552&r2=584553&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java (original)
+++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java Sun Oct 14 08:11:01 2007
@@ -19,9 +19,13 @@
package demo.jaxrs.client;
+import java.io.ByteArrayOutputStream;
import java.io.File;
+import java.io.InputStream;
import java.net.URL;
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.io.CachedOutputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.FileRequestEntity;
import org.apache.commons.httpclient.methods.PostMethod;
@@ -43,14 +47,14 @@
*/
// Sent HTTP GET request to query customer info
- url = new URL("http://localhost:9000/customers/1234");
+ URL url = new URL("http://localhost:9000/customers/1234");
System.out.println("Invoking server through HTTP GET to query customer info");
- in = url.openStream();
- source = new StreamSource(in);
- printSource(source);
+ InputStream in = url.openStream();
+ System.out.println(getStringFromInputStream(in));
// Sent HTTP PUT request to update customer info
- String inputFile = getClass().getResource("update_customer.txt").getFile();
+ Client client = new Client();
+ String inputFile = client.getClass().getResource("update_customer.txt").getFile();
File input = new File(inputFile);
PutMethod put = new PutMethod("http://localhost:9000/customers");
RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
@@ -58,11 +62,10 @@
HttpClient httpclient = new HttpClient();
try {
- int result = httpclient.executeMethod(post);
- assertEquals(200, result);
+ int result = httpclient.executeMethod(put);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
- System.out.println(post.getResponseBodyAsString());
+ System.out.println(put.getResponseBodyAsString());
} finally {
// Release current connection to the connection pool once you are
// done
@@ -70,7 +73,7 @@
}
// Sent HTTP POST request to add customer
- inputFile = getClass().getResource("add_customer.txt").getFile();
+ inputFile = client.getClass().getResource("add_customer.txt").getFile();
input = new File(inputFile);
PostMethod post = new PostMethod("http://localhost:9000/customers");
entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
@@ -79,7 +82,6 @@
try {
int result = httpclient.executeMethod(post);
- assertEquals(200, result);
System.out.println("Response status code: " + result);
System.out.println("Response body: ");
System.out.println(post.getResponseBodyAsString());
@@ -92,23 +94,14 @@
System.out.println("Client Invoking is succeeded!");
System.exit(0);
}
-
- private static void printSource(Source source) {
- try {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- StreamResult sr = new StreamResult(bos);
- Transformer trans = TransformerFactory.newInstance().newTransformer();
- Properties oprops = new Properties();
- oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
- trans.setOutputProperties(oprops);
- trans.transform(source, sr);
- System.out.println("**** Response ******");
- System.out.println(bos.toString());
- bos.close();
- System.out.println();
- } catch (Exception e) {
- e.printStackTrace();
- }
+
+ 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();
}
}
Modified: incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java?rev=584553&r1=584552&r2=584553&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java (original)
+++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/CustomerService.java Sun Oct 14 08:11:01 2007
@@ -18,24 +18,25 @@
*/
package demo.jaxrs.server;
+import java.util.Map;
+import java.util.HashMap;
+
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;
+import javax.ws.rs.core.UriInfo;
@UriTemplate("/customers/")
public class CustomerService {
- @HttpContext
- UriInfo uriInfo;
+ @HttpContext UriInfo uriInfo;
long currentId = 1;
Map<Long, Customer> customers = new HashMap<Long, Customer>();
- public CustomerServiceImpl() {
+ public CustomerService() {
Customer customer = createCustomer();
customers.put(customer.getId(), customer);
}
@@ -50,7 +51,7 @@
@HttpMethod("PUT")
@UriTemplate("/customers/")
- void updateCustomer(Customer customer) {
+ public Response updateCustomer(Customer customer) {
System.out.println("----invoking updateCustomer, Customer name is: " + customer.getName());
Customer c = customers.get(customer.getId());
Response r;
@@ -70,7 +71,7 @@
System.out.println("----invoking addCustomer, customer name is: " + customer.getName());
customer.setId(++currentId);
- customers.add(customer);
+ customers.put(customer.getId(), customer);
return Response.Builder.ok(customer).build();
}
@@ -86,7 +87,7 @@
Response r;
if (c != null) {
r = Response.Builder.ok().build();
- customers.remove(i);
+ customers.remove(idNumber);
} else {
r = Response.Builder.notModified().build();
}
Modified: incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Server.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Server.java?rev=584553&r1=584552&r2=584553&view=diff
==============================================================================
--- incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Server.java (original)
+++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/Server.java Sun Oct 14 08:11:01 2007
@@ -26,7 +26,7 @@
protected Server() throws Exception {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
- sf.setResourceClasses(BookStore.class);
+ sf.setResourceClasses(CustomerService.class);
sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
sf.setAddress("http://localhost:9080/xml/");
Re: svn commit: r584553 - in
/incubator/cxf/branches/jliu/distribution: ./ bundle/ manifest/
src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/
src/main/release/samples/restful_jaxrs/src/demo/jaxrs/server/
Posted by Glen Mazza <gl...@verizon.net>.
Am Sonntag, den 14.10.2007, 15:11 +0000 schrieb jliu@apache.org:
> Author: jliu
> Date: Sun Oct 14 08:11:01 2007
> New Revision: 584553
>
> ==============================================================================
> --- incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java (original)
> +++ incubator/cxf/branches/jliu/distribution/src/main/release/samples/restful_jaxrs/src/demo/jaxrs/client/Client.java Sun Oct 14 08:11:01 2007
> @@ -19,9 +19,13 @@
>
> + 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();
Are you sure here? AFAICT[1] bos.getOut() should be null or empty after
you call bos.close().
[1]
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/io/CachedOutputStream.java?revision=583575&view=markup
Regards,
Glen
> }
>
> }