Author: ningjiang
Date: Fri Jun  5 03:07:51 2009
New Revision: 781899

URL: http://svn.apache.org/viewvc?rev=781899&view=rev
Log:
CAMEL-1672 added the example of camel-cxfrs component

Added:
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/CamelRouterBuilder.java
   (with props)
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXRSClient.java
   (with props)
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXWSClient.java
   (with props)
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/Book.java
   (with props)
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundDetails.java
   (with props)
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundFault.java
   (with props)
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStore.java
   (with props)
    
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStoreImpl.java
   (with props)
    camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties  
 (with props)
Modified:
    camel/trunk/examples/camel-example-cxf/pom.xml

Modified: camel/trunk/examples/camel-example-cxf/pom.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/pom.xml?rev=781899&r1=781898&r2=781899&view=diff
==============================================================================
--- camel/trunk/examples/camel-example-cxf/pom.xml (original)
+++ camel/trunk/examples/camel-example-cxf/pom.xml Fri Jun  5 03:07:51 2009
@@ -38,6 +38,12 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-core</artifactId>
     </dependency>
+    
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-spring</artifactId>
+    </dependency>
+    
 
     <dependency>
       <groupId>org.apache.camel</groupId>
@@ -60,6 +66,12 @@
       <artifactId>cxf-rt-transports-jms</artifactId>
       <version>${cxf-version}</version>
     </dependency>
+    
+    <dependency>
+      <groupId>org.apache.cxf</groupId>
+      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
+      <version>${cxf-version}</version>
+    </dependency>
 
     <dependency>
       <groupId>org.apache.activemq</groupId>

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/CamelRouterBuilder.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/CamelRouterBuilder.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/CamelRouterBuilder.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/CamelRouterBuilder.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,137 @@
+/**
+ * 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.camel.example.cxf.jaxrs;
+
+import java.lang.reflect.Method;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.bean.BeanInvocation;
+import org.apache.camel.component.cxf.CxfConstants;
+import org.apache.camel.example.cxf.jaxrs.resources.Book;
+import org.apache.camel.example.cxf.jaxrs.resources.BookStore;
+import org.apache.camel.example.cxf.jaxrs.resources.BookStoreImpl;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spring.Main;
+
+public class CamelRouterBuilder extends RouteBuilder {
+    private static final String SOAP_ENDPOINT_URI = 
"cxf://http://localhost:9000/soap";
+        + 
"?serviceClass=org.apache.camel.example.cxf.jaxrs.resources.BookStore";
+    private static final String REST_ENDPOINT_URI = 
"cxfrs://http://localhost:9002/rest";
+        + 
"?resourceClasses=org.apache.camel.example.cxf.jaxrs.resources.BookStoreImpl";
+    
+    /**
+     * Allow this route to be run as an application
+     *
+     * @param args
+     * @throws Exception 
+     */
+    public static void main(String[] args) throws Exception {
+        CamelContext context = new DefaultCamelContext();
+        context.start();
+        context.addRoutes(new CamelRouterBuilder());
+        Thread.sleep(1000);
+        // JAXWSClient invocation
+        JAXWSClient jaxwsClient = new JAXWSClient();
+        BookStore bookStore = jaxwsClient.getBookStore();
+        
+        bookStore.addBook(new Book("Camel User Guide", 234L));
+        Book book = bookStore.getBook(123L);
+        System.out.println("Get the book with id 123. " + book);       
+      
+        try {
+            book = bookStore.getBook(124L);
+            System.out.println("Get the book with id 124. " + book); 
+        } catch (Exception exception) {
+            System.out.println("Get the exception " + exception);
+        }
+        
+        // JAXRSClient invocation
+        JAXRSClient jaxrsClient = new JAXRSClient();
+        bookStore =  jaxrsClient.getBookStore();
+        
+        bookStore.addBook(new Book("Camel User Guide", 124L));
+        book = bookStore.getBook(124L);
+        System.out.println("Get the book with id 124. " + book);
+        
+        try {
+            book = bookStore.getBook(126L);
+            System.out.println("Get the book with id 126. " + book); 
+        } catch (Exception exception) {
+            System.out.println("Get the exception " + exception.getCause());
+        }
+        
+        Thread.sleep(1000);
+        context.stop();
+        System.exit(0);
+    }
+
+    public void configure() {
+        errorHandler(noErrorHandler());
+        
+        // populate the message queue with some messages
+        from(SOAP_ENDPOINT_URI)
+            .process(new MappingProcessor(BookStoreImpl.class))
+            .bean(new BookStoreImpl(false));
+
+        from(REST_ENDPOINT_URI)
+             .process(new MappingProcessor(BookStoreImpl.class))
+             .bean(new BookStoreImpl(true));
+      
+    }
+    
+    // Mapping the request to bean's invocation
+    private class MappingProcessor implements Processor {
+        
+        private Class beanClass;
+        
+        public MappingProcessor(Class clazz) {
+            beanClass = clazz;
+        }
+         
+        public void process(Exchange exchange) throws Exception {
+            String operationName = 
exchange.getIn().getHeader(CxfConstants.OPERATION_NAME, String.class);
+            Method method = findMethod(operationName, 
exchange.getIn().getBody(Object[].class));
+            BeanInvocation invocation = new BeanInvocation();
+            invocation.setMethod(method);
+            invocation.setArgs(exchange.getIn().getBody(Object[].class));
+            exchange.getOut().setBody(invocation);
+        }
+        
+        private Method findMethod(String operationName, Object[] parameters) 
throws SecurityException, NoSuchMethodException {            
+            return beanClass.getMethod(operationName, 
getParameterTypes(parameters));
+        }
+        
+        private Class[] getParameterTypes(Object[] parameters) {
+            if (parameters == null) {
+                return new Class[0];
+            }
+            Class[] answer = new Class[parameters.length];
+            int i = 0;
+            for (Object object : parameters) {
+                answer[i] = object.getClass();
+                i++;
+            }
+            return answer;
+        }
+        
+    }
+
+
+}

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/CamelRouterBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/CamelRouterBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXRSClient.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXRSClient.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXRSClient.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXRSClient.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,63 @@
+/**
+ * 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.camel.example.cxf.jaxrs;
+
+import java.util.Collections;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+import org.apache.camel.example.cxf.jaxrs.resources.BookNotFoundFault;
+import org.apache.camel.example.cxf.jaxrs.resources.BookStore;
+import org.apache.camel.example.cxf.jaxrs.resources.BookStoreImpl;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+
+public final class JAXRSClient {
+    
+    private BookStore bookStore;
+    
+    public JAXRSClient() {       
+        bookStore = (BookStore) JAXRSClientFactory.create(
+            "http://localhost:9002/rest";,
+            BookStore.class,
+            Collections.singletonList(new TestResponseExceptionMapper()));     
   
+    }
+    
+    public BookStore getBookStore() {
+        return bookStore;
+    }
+    
+    public static class TestResponseExceptionMapper implements 
ResponseExceptionMapper<BookNotFoundFault> {
+        
+        public TestResponseExceptionMapper() {
+        }
+        
+        public BookNotFoundFault fromResponse(Response r) {
+            Object value = r.getMetadata().getFirst("BOOK-HEADER");
+            if (value != null) {
+                return new BookNotFoundFault(value.toString());
+            }
+            throw new WebApplicationException();
+        }
+        
+    }
+
+}

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXRSClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXRSClient.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXWSClient.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXWSClient.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXWSClient.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXWSClient.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,38 @@
+/**
+ * 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.camel.example.cxf.jaxrs;
+
+import org.apache.camel.example.cxf.jaxrs.resources.BookStore;
+import org.apache.cxf.jaxws.JaxWsClientFactoryBean;
+import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
+
+public final class JAXWSClient {
+    private BookStore bookStore;
+    
+    public JAXWSClient() {
+        JaxWsProxyFactoryBean cfb = new JaxWsProxyFactoryBean();
+        cfb.setServiceClass(BookStore.class);
+        cfb.setAddress("http://localhost:9000/soap";);
+        bookStore = (BookStore) cfb.create();        
+    }
+    
+    public BookStore getBookStore() {
+        return bookStore;
+    }
+
+}

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXWSClient.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/JAXWSClient.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/Book.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/Book.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/Book.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/Book.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,62 @@
+/**
+ * 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.camel.example.cxf.jaxrs.resources;
+
+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.ws.rs.Produces;
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+...@xmlrootelement(name = "Book")
+public class Book {
+    private String name;
+    private long id;
+    
+    public Book() {
+    }
+    
+    public Book(String name, long id) {
+        this.name = name;
+        this.id = id;
+    }
+    
+    public void setName(String n) {
+        name = n;
+    }
+
+    public String getName() {
+        return name;
+    }
+    
+    public void setId(long i) {
+        id = i;
+    }
+    public long getId() {
+        return id;
+    }
+    
+    public String toString() {
+        return "[Book id=" + id + ", name=" + name + "]";
+    }
+   
+}

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/Book.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/Book.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundDetails.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundDetails.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundDetails.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundDetails.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,34 @@
+/**
+ * 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.camel.example.cxf.jaxrs.resources;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+...@xmlrootelement
+public class BookNotFoundDetails {
+    private long id;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+}

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundDetails.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundDetails.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundFault.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundFault.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundFault.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundFault.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,40 @@
+/**
+ * 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.camel.example.cxf.jaxrs.resources;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.ws.WebFault;
+
+...@webfault
+public class BookNotFoundFault extends Exception {
+    @XmlElement
+    private BookNotFoundDetails details;
+
+    public BookNotFoundFault(String errorMessage) {
+        super(errorMessage);
+    }
+    
+    public BookNotFoundFault(String errorMessage, BookNotFoundDetails details) 
{
+        super(errorMessage);
+        this.details = details;
+    }
+
+    public BookNotFoundDetails getFaultInfo() {
+        return details;
+    }
+}

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundFault.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookNotFoundFault.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStore.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStore.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStore.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStore.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,48 @@
+/**
+ * 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.camel.example.cxf.jaxrs.resources;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebService;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+
+...@webservice
+...@path("/bookstore")
+...@consumes("application/xml")
+...@produces("application/xml")
+public interface BookStore {
+    
+    @WebMethod
+    @GET
+    @Path("/{id}")
+    @Consumes("*/*")
+    Book getBook(@PathParam("id") @WebParam(name = "id") Long id) throws 
BookNotFoundFault;
+
+    @WebMethod
+    @POST
+    @Path("/books")
+    Book addBook(@WebParam(name = "book") Book book);
+   
+}
+

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStore.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStore.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStoreImpl.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStoreImpl.java?rev=781899&view=auto
==============================================================================
--- 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStoreImpl.java
 (added)
+++ 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStoreImpl.java
 Fri Jun  5 03:07:51 2009
@@ -0,0 +1,68 @@
+/**
+ * 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.camel.example.cxf.jaxrs.resources;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Response;
+
+public class BookStoreImpl implements BookStore {
+    
+    private Map<Long, Book> books = new HashMap<Long, Book>();
+    private boolean isRest;
+    
+    public BookStoreImpl(boolean restFlag) {
+        isRest = restFlag;
+        init();        
+    }
+    
+    public BookStoreImpl() {        
+        init();        
+    }
+    
+    public Book getBook(Long id) throws BookNotFoundFault {
+        
+        if (books.get(id) == null) {
+            BookNotFoundDetails details = new BookNotFoundDetails();
+            details.setId(id);
+            if (!isRest) {
+                throw new BookNotFoundFault("Can't find the Book with id " + 
id, details);
+            } else {                
+                Response r = Response.status(404).header("BOOK-HEADER",
+                    "No Book with id " + id + " is 
available").entity(details).build();
+                throw new WebApplicationException(r);
+            }
+        }
+        
+        return books.get(id);
+    }
+    
+    public Book addBook(Book book) {        
+        books.put(book.getId(), book);
+        return books.get(book.getId());
+    }
+    
+    private void init() {
+        Book book = new Book();
+        book.setId(new Long(123));
+        book.setName("CXF in Action");
+        books.put(book.getId(), book);
+    }    
+
+}

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStoreImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/java/org/apache/camel/example/cxf/jaxrs/resources/BookStoreImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties?rev=781899&view=auto
==============================================================================
--- camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties 
(added)
+++ camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties 
Fri Jun  5 03:07:51 2009
@@ -0,0 +1,30 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+
+#
+# The logging properties used for eclipse testing, We want to see INFO output 
on the console.
+#
+log4j.rootLogger=INFO, out
+
+#
+# uncomment the following line to enable debugging of Camel
+#
+#log4j.logger.org.apache.camel=DEBUG
+
+log4j.appender.out=org.apache.log4j.ConsoleAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=[%30.30t] %-30.30c{1} %-5p %m%n

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: 
camel/trunk/examples/camel-example-cxf/src/main/resources/log4j.properties
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to