You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by cc...@apache.org on 2009/05/13 07:21:26 UTC

svn commit: r774209 - in /servicemix/smx4/features/trunk: assembly/src/main/filtered-resources/ examples/ examples/cxf-jaxrs/ examples/cxf-jaxrs/src/ examples/cxf-jaxrs/src/main/ examples/cxf-jaxrs/src/main/java/ examples/cxf-jaxrs/src/main/java/org/ e...

Author: ccustine
Date: Wed May 13 05:21:24 2009
New Revision: 774209

URL: http://svn.apache.org/viewvc?rev=774209&view=rev
Log:
SMX4-279 - Provide cxf-jaxrs feature and associated demo

Added:
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/README.txt
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/pom.xml
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Customer.java
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/CustomerService.java
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Order.java
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Product.java
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/client/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/client/Client.java
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/META-INF/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/META-INF/spring/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/META-INF/spring/beans.xml
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/add_customer.xml
    servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/update_customer.xml
Modified:
    servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/features.xml
    servicemix/smx4/features/trunk/examples/itests/pom.xml
    servicemix/smx4/features/trunk/examples/itests/src/test/java/org/apache/servicemix/examples/IntegrationTest.java
    servicemix/smx4/features/trunk/examples/pom.xml

Modified: servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/features.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/features.xml?rev=774209&r1=774208&r2=774209&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/features.xml (original)
+++ servicemix/smx4/features/trunk/assembly/src/main/filtered-resources/features.xml Wed May 13 05:21:24 2009
@@ -75,6 +75,13 @@
         <bundle>mvn:org.ops4j.pax.web-extender/pax-web-ex-whiteboard/${pax.web.extender.version}</bundle>
         <bundle>mvn:org.apache.servicemix.cxf/org.apache.servicemix.cxf.transport.osgi/${version}</bundle>
     </feature>
+    <feature name="cxf-jaxrs" version="${version}">
+        <feature version="${version}">cxf-osgi</feature>
+        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.abdera/${abdera.version}</bundle>
+        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jettison/${jettison.version}</bundle>
+        <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xmlbeans/${xmlbeans.version}</bundle>
+        <bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jsr311-api-${jaxrs.api.version}/${servicemix.specs.version}</bundle>
+    </feature>
     <feature name="cxf-nmr" version="${version}">
         <feature version="${cxf.version}">cxf</feature>
         <feature version="${servicemix.nmr.version}">nmr</feature>
@@ -121,6 +128,10 @@
         <feature version="${version}">cxf-osgi</feature>
         <bundle>mvn:org.apache.servicemix.examples/cxf-osgi/${version}</bundle>
     </feature>
+    <feature name="examples-cxf-jaxrs" version="${version}">
+        <feature version="${version}">cxf-jaxrs</feature>
+        <bundle>mvn:org.apache.servicemix.examples/cxf-jaxrs/${version}</bundle>
+    </feature>
     <feature name="examples-cxf-nmr" version="${version}">
         <feature version="${version}">cxf-nmr</feature>
         <bundle>mvn:org.apache.servicemix.examples/cxf-nmr/${version}</bundle>

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/README.txt
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/README.txt?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/README.txt (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/README.txt Wed May 13 05:21:24 2009
@@ -0,0 +1,85 @@
+/*
+ * 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.
+ */
+
+Welcome to the ServiceMix cxf JAX-RS example
+============================================
+
+This example leverages CXF and Spring-DM to create a RESTful web service, 
+and then expose it through the OSGi HTTP Service.
+
+Quick steps to install the sample
+---------------------------------
+
+Launch the ServiceMix Kernel by running
+
+  bin/servicemix
+
+in the root dir of this distribution.
+
+When inside the console, just run the following commands to install the
+example:
+
+  features/install examples-cxf-jaxrs
+
+If you have all the bundles available in your local repo, the installation
+of the example will be very fast, otherwise it may take some time to
+download everything needed.
+
+Testing the example
+-------------------
+
+When the feature is installed, output for publishing the cxf endpoint
+is displayed to the console.
+
+Now, just open your browser and go to the following url:
+
+  http://localhost:8080/cxf/crm/customerservice/customers/123
+
+It should display an XML representation for customer 123 (if you use Safari, 
+make sure to right click the window and select 'Show Source', else the page
+will be blank).
+
+Or you can also test it from ServiceMix console using:
+
+  utils/cat http://localhost:8080/cxf/crm/customerservice/customers/123
+
+Or you can launch a programmatic Java client via:
+
+  mvn compile exec:java
+
+which makes a sequence of RESTful invocations and displays the results.
+
+Alternatively, you can use a command line utility such as curl or wget to make 
+the invocations. Here are some example usages with curl, run from 
+features/<branch>/examples/cxf-jaxrs:
+
+# Create a customer
+#
+#
+curl -X POST -T src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/add_customer.xml -H "Content-Type: text/xml" http://localhost:8080/cxf/crm/customerservice/customers
+
+# Retrieve the customer instance with id 123
+#
+curl http://localhost:8080/cxf/crm/customerservice/customers/123
+
+# Update the customer instance with id 123
+#
+curl -X PUT -T src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/update_customer.xml -H "Content-Type: text/xml" http://localhost:8080/cxf/crm/customerservice/customers
+
+# Delete the customer instance with id 123
+#
+curl -X DELETE http://localhost:8079/cxf/crm/customerservice/customers/123

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/pom.xml?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/pom.xml (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/pom.xml Wed May 13 05:21:24 2009
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.servicemix.examples</groupId>
+        <artifactId>examples</artifactId>
+        <version>4.1.0-SNAPSHOT</version>
+    </parent>
+
+    <groupId>org.apache.servicemix.examples</groupId>
+    <artifactId>cxf-jaxrs</artifactId>
+    <packaging>bundle</packaging>
+    <version>4.1.0-SNAPSHOT</version>
+    <name>Apache ServiceMix Example :: CXF JAX-RS OSGI</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.specs</groupId>
+            <artifactId>org.apache.servicemix.specs.jsr311-api-0.8</artifactId>
+            <version>1.3.0</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.specs</groupId>
+            <artifactId>org.apache.servicemix.specs.jaxb-api-2.1</artifactId>
+            <version>${servicemix.specs.version}</version>
+        </dependency>
+
+       <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.commons-httpclient</artifactId>
+            <version>${commons.httpclient.version}</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                        <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+                        <Import-Package>
+                                javax.wsdl,
+                                javax.xml.bind,
+                                javax.xml.bind.annotation,
+                                javax.ws.rs,
+                                META-INF.cxf,
+                                META-INF.cxf.osgi,
+                                org.apache.cxf.bus,
+                                org.apache.cxf.bus.spring,
+                                org.apache.cxf.bus.resource,
+                                org.apache.cxf.resource,
+                                org.apache.cxf.configuration.spring,
+                                org.apache.cxf.binding,
+                                org.apache.cxf.jaxrs.utils,
+                                org.apache.servicemix.cxf.transport.http_osgi,
+                                org.springframework.beans.factory.config,
+                                org.apache.servicemix.examples.cxf.jaxrs
+                        </Import-Package>
+                        <Require-Bundle>org.apache.cxf.cxf-bundle</Require-Bundle>
+                        <Export-Package>org.apache.servicemix.examples.cxf.jaxrs
+                        </Export-Package>
+                        <DynamicImport-Package>javax.ws.rs.*</DynamicImport-Package>
+                     </instructions>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>exec-maven-plugin</artifactId>
+                <configuration>
+                    <mainClass>org.apache.servicemix.examples.cxf.jaxrs.client.Client</mainClass>
+                    <includePluginDependencies>false</includePluginDependencies>
+                </configuration>
+            </plugin>
+
+        </plugins>
+    </build>
+
+</project>

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Customer.java?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Customer.java (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Customer.java Wed May 13 05:21:24 2009
@@ -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 org.apache.servicemix.examples.cxf.jaxrs;
+
+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;
+    }
+}

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/CustomerService.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/CustomerService.java?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/CustomerService.java (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/CustomerService.java Wed May 13 05:21:24 2009
@@ -0,0 +1,116 @@
+/**
+ * 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 org.apache.servicemix.examples.cxf.jaxrs;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+
+@Path("/cxf/crm/customerservice/")
+public class CustomerService {
+    long currentId = 123;
+    Map<Long, Customer> customers = new HashMap<Long, Customer>();
+    Map<Long, Order> orders = new HashMap<Long, Order>();
+
+    public CustomerService() {
+        init();
+    }
+
+    @GET
+    @Path("/customers/{id}/")
+    public Customer getCustomer(@PathParam("id") String id) {
+        System.out.println("----invoking getCustomer, Customer id is: " + id);
+        long idNumber = Long.parseLong(id);
+        Customer c = customers.get(idNumber);
+        return c;
+    }
+
+    @PUT
+    @Path("/customers/")
+    public Response updateCustomer(Customer customer) {
+        System.out.println("----invoking updateCustomer, Customer name is: " + customer.getName());
+        Customer c = customers.get(customer.getId());
+        Response r;
+        if (c != null) {
+            customers.put(customer.getId(), customer);
+            r = Response.ok().build();
+        } else {
+            r = Response.notModified().build();
+        }
+
+        return r;
+    }
+
+    @POST
+    @Path("/customers/")
+    public Response addCustomer(Customer customer) {
+        System.out.println("----invoking addCustomer, Customer name is: " + customer.getName());
+        customer.setId(++currentId);
+
+        customers.put(customer.getId(), customer);
+
+        return Response.ok(customer).build();
+    }
+
+    @DELETE
+    @Path("/customers/{id}/")
+    public Response deleteCustomer(@PathParam("id") String id) {
+        System.out.println("----invoking deleteCustomer, Customer id is: " + id);
+        long idNumber = Long.parseLong(id);
+        Customer c = customers.get(idNumber);
+
+        Response r;
+        if (c != null) {
+            r = Response.ok().build();
+            customers.remove(idNumber);
+        } else {
+            r = Response.notModified().build();
+        }
+
+        return r;
+    }
+
+    @Path("/orders/{orderId}/")
+    public Order getOrder(@PathParam("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: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Order.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Order.java?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Order.java (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Order.java Wed May 13 05:21:24 2009
@@ -0,0 +1,69 @@
+/**
+ * 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  org.apache.servicemix.examples.cxf.jaxrs;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Order")
+public class Order {
+    private long id;
+    private String description;
+    private Map<Long, Product> products = new HashMap<Long, Product>();
+
+    public Order() {
+        init();
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String d) {
+        this.description = d;
+    }
+
+    @GET
+    @Path("products/{productId}/")
+    public Product getProduct(@PathParam("productId")int productId) {
+        System.out.println("----invoking getProduct with id: " + productId);
+        Product p = products.get(new Long(productId));
+        return p;
+    }
+
+    final void init() {
+        Product p = new Product();
+        p.setId(323);
+        p.setDescription("product 323");
+        products.put(p.getId(), p);
+    }
+}

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Product.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Product.java?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Product.java (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/Product.java Wed May 13 05:21:24 2009
@@ -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 org.apache.servicemix.examples.cxf.jaxrs;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "Product")
+public class Product {
+    private long id;
+    private String description;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String d) {
+        this.description = d;
+    }
+}

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/client/Client.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/client/Client.java?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/client/Client.java (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/java/org/apache/servicemix/examples/cxf/jaxrs/client/Client.java Wed May 13 05:21:24 2009
@@ -0,0 +1,112 @@
+/**
+ * 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 org.apache.servicemix.examples.cxf.jaxrs.client;
+
+import java.io.File;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.FileRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.PutMethod;
+import org.apache.commons.httpclient.methods.RequestEntity;
+
+public final class Client {
+
+    private Client() {
+    }
+
+    public static void main(String args[]) throws Exception {
+        // Sent HTTP GET request to query all customer info
+
+        // 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/cxf/crm/customerservice/customers/123");
+        InputStream in = url.openStream();
+        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:8080/cxf/crm/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.xml").getFile();
+        File input = new File(inputFile);
+        PutMethod put = new PutMethod("http://localhost:8080/cxf/crm/customerservice/customers");
+        RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
+        put.setRequestEntity(entity);
+        HttpClient httpclient = new HttpClient();
+
+        try {
+            int result = httpclient.executeMethod(put);
+            System.out.println("Response status code: " + result);
+            System.out.println("Response body: ");
+            System.out.println(put.getResponseBodyAsString());
+        } finally {
+            // Release current connection to the connection pool once you are
+            // done
+            put.releaseConnection();
+        }
+
+        // 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.xml").getFile();
+        input = new File(inputFile);
+        PostMethod post = new PostMethod("http://localhost:8080/cxf/crm/customerservice/customers");
+        post.addRequestHeader("Accept" , "text/xml");
+        entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1");
+        post.setRequestEntity(entity);
+        httpclient = new HttpClient();
+
+        try {
+            int result = httpclient.executeMethod(post);
+            System.out.println("Response status code: " + result);
+            System.out.println("Response body: ");
+            System.out.println(post.getResponseBodyAsString());
+        } finally {
+            // Release current connection to the connection pool once you are
+            // done
+            post.releaseConnection();
+        }
+
+        System.out.println("\n");
+        System.exit(0);
+    }
+
+    private static String getStringFromInputStream(InputStream in) throws Exception {
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        int c = 0;
+        while ((c = in.read()) != -1) {
+            bos.write(c);
+        }
+        in.close();
+        bos.close();
+        return bos.toString();
+    }
+
+}

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/META-INF/spring/beans.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/META-INF/spring/beans.xml?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/META-INF/spring/beans.xml (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/META-INF/spring/beans.xml Wed May 13 05:21:24 2009
@@ -0,0 +1,42 @@
+<?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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xmlns:jaxrs="http://cxf.apache.org/jaxrs"
+        xmlns:osgi="http://www.springframework.org/schema/osgi"
+	xsi:schemaLocation="
+http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
+http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi.xsd">
+
+  <import resource="classpath:META-INF/cxf/cxf.xml" />
+    <import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
+    <import resource="classpath:META-INF/cxf/cxf-extension-http.xml" />
+    <import resource="classpath:META-INF/cxf/osgi/cxf-extension-osgi.xml" />
+
+    <jaxrs:server id="customerService" address="/crm">
+        <jaxrs:serviceBeans>
+            <ref bean="customerSvc"/>
+        </jaxrs:serviceBeans>
+    </jaxrs:server>
+
+    <bean id="customerSvc" class=" org.apache.servicemix.examples.cxf.jaxrs.CustomerService"/>
+
+</beans>

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/add_customer.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/add_customer.xml?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/add_customer.xml (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/add_customer.xml Wed May 13 05:21:24 2009
@@ -0,0 +1,3 @@
+<Customer>
+  <name>Jack</name>
+</Customer> 

Added: servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/update_customer.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/update_customer.xml?rev=774209&view=auto
==============================================================================
--- servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/update_customer.xml (added)
+++ servicemix/smx4/features/trunk/examples/cxf-jaxrs/src/main/resources/org/apache/servicemix/examples/cxf/jaxrs/client/update_customer.xml Wed May 13 05:21:24 2009
@@ -0,0 +1,4 @@
+<Customer>
+  <name>Mary</name>
+  <id>123</id>
+</Customer> 

Modified: servicemix/smx4/features/trunk/examples/itests/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/itests/pom.xml?rev=774209&r1=774208&r2=774209&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/examples/itests/pom.xml (original)
+++ servicemix/smx4/features/trunk/examples/itests/pom.xml Wed May 13 05:21:24 2009
@@ -198,6 +198,11 @@
         </dependency>
         <dependency>
 		    <groupId>org.apache.servicemix.examples</groupId>
+		    <artifactId>cxf-jaxrs</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+		    <groupId>org.apache.servicemix.examples</groupId>
 		    <artifactId>cxf-http-osgi</artifactId>
             <version>${project.version}</version>
         </dependency>
@@ -373,6 +378,32 @@
             <artifactId>org.apache.servicemix.bundles.xmlsec</artifactId>
             <version>${xmlsec.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.commons-codec</artifactId>
+            <version>${commons-codec.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.abdera</artifactId>
+            <version>${abdera.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.jettison</artifactId>
+            <version>${jettison.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.bundles</groupId>
+            <artifactId>org.apache.servicemix.bundles.xmlbeans</artifactId>
+            <version>${xmlbeans.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix.specs</groupId>
+            <artifactId>org.apache.servicemix.specs.jsr311-api-${jaxrs.api.version}</artifactId>
+            <version>${servicemix.specs.version}</version>
+        </dependency>
+
     </dependencies>
 
     <build>

Modified: servicemix/smx4/features/trunk/examples/itests/src/test/java/org/apache/servicemix/examples/IntegrationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/itests/src/test/java/org/apache/servicemix/examples/IntegrationTest.java?rev=774209&r1=774208&r2=774209&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/examples/itests/src/test/java/org/apache/servicemix/examples/IntegrationTest.java (original)
+++ servicemix/smx4/features/trunk/examples/itests/src/test/java/org/apache/servicemix/examples/IntegrationTest.java Wed May 13 05:21:24 2009
@@ -18,7 +18,9 @@
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.InputStream;
 import java.io.PrintWriter;
+import java.net.URL;
 import java.util.jar.Manifest;
 import java.util.HashMap;
 import java.util.Map;
@@ -111,6 +113,11 @@
             getBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.xmlsec"),
             getBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.xmlresolver"),
             getBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.jetty-bundle"),
+            getBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.commons-codec"),
+            getBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.abdera"),
+            getBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.jettison"),
+            getBundle("org.apache.servicemix.bundles", "org.apache.servicemix.bundles.xmlbeans"),
+            getBundle("org.apache.servicemix.specs", "org.apache.servicemix.specs.jsr311-api-1.0"),
             getBundle("org.ops4j.pax.web", "pax-web-bundle"),
             getBundle("org.ops4j.pax.web-extender", "pax-web-ex-whiteboard"),
             getBundle("org.apache.servicemix", "servicemix-utils"),
@@ -127,6 +134,7 @@
             getBundle("org.apache.servicemix.examples", "cxf-soap-handler-osgi"),
             getBundle("org.apache.servicemix.examples", "cxf-handler-cfg"),
             getBundle("org.apache.servicemix.examples", "cxf-ws-addressing"),
+            getBundle("org.apache.servicemix.examples", "cxf-jaxrs"),
             getBundle("org.apache.servicemix.examples", "cxf-nmr-osgi"),
         };
 	}
@@ -278,4 +286,22 @@
          assertTrue(input.toString().indexOf(expectedIn) != -1);
     }
 
+    public void testJaxRS() throws Exception {
+        Thread.sleep(5000);
+        waitOnContextCreation("cxf-jaxrs");
+
+        URL url = new URL("http://localhost:8080/cxf/crm/customerservice/customers/123");
+        InputStream in = url.openStream();
+
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        int c = 0;
+        while ((c = in.read()) != -1) {
+            bos.write(c);
+        }
+        in.close();
+        bos.close();
+        System.out.println(bos.toString());
+        assertEquals("{\"Customer\":{\"id\":123,\"name\":\"John\"}}",
+                     bos.toString());
+    }
 }

Modified: servicemix/smx4/features/trunk/examples/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/features/trunk/examples/pom.xml?rev=774209&r1=774208&r2=774209&view=diff
==============================================================================
--- servicemix/smx4/features/trunk/examples/pom.xml (original)
+++ servicemix/smx4/features/trunk/examples/pom.xml Wed May 13 05:21:24 2009
@@ -44,6 +44,7 @@
         <module>cxf-camel-nmr</module>
         <module>cxf-nmr</module>
         <module>cxf-osgi</module>
+        <module>cxf-jaxrs</module>
         <module>cxf-http-osgi</module>
         <module>cxf-jms-osgi</module>
         <module>cxf-nmr-osgi</module>