Search in sources :

Example 1 with BookStore

use of org.apache.camel.example.cxf.jaxrs.resources.BookStore in project camel by apache.

the class Client method invoke.

void invoke() throws BookNotFoundFault {
    // JAXWSClient invocation
    JAXWSClient jaxwsClient = new JAXWSClient();
    BookStore bookStore = jaxwsClient.getBookStore();
    bookStore.addBook(new Book("Camel User Guide", 123L));
    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("Expected exception received: " + exception);
    }
    // JAXRSClient invocation
    JAXRSClient jaxrsClient = new JAXRSClient();
    bookStore = jaxrsClient.getBookStore();
    bookStore.addBook(new Book("Karaf 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("Expected exception received: " + exception);
    }
}
Also used : BookStore(org.apache.camel.example.cxf.jaxrs.resources.BookStore) Book(org.apache.camel.example.cxf.jaxrs.resources.Book)

Example 2 with BookStore

use of org.apache.camel.example.cxf.jaxrs.resources.BookStore in project camel by apache.

the class JAXRSClientServerTest method testJAXWSClient.

@Test
public void testJAXWSClient() throws BookNotFoundFault {
    JAXWSClient jaxwsClient = new JAXWSClient();
    BookStore bookStore = jaxwsClient.getBookStore();
    bookStore.addBook(new Book("Camel User Guide", 123L));
    Book book = bookStore.getBook(123L);
    assertNotNull("We should find the book here", book);
    try {
        book = bookStore.getBook(124L);
        fail("We should not have this book");
    } catch (Exception exception) {
        assertTrue("The exception should be BookNotFoundFault", exception instanceof BookNotFoundFault);
    }
}
Also used : BookStore(org.apache.camel.example.cxf.jaxrs.resources.BookStore) BookNotFoundFault(org.apache.camel.example.cxf.jaxrs.resources.BookNotFoundFault) Book(org.apache.camel.example.cxf.jaxrs.resources.Book) Test(org.junit.Test)

Example 3 with BookStore

use of org.apache.camel.example.cxf.jaxrs.resources.BookStore in project camel by apache.

the class JAXRSClientServerTest method testJAXRSClient.

@Test
public void testJAXRSClient() throws BookNotFoundFault {
    // JAXRSClient invocation
    JAXRSClient jaxrsClient = new JAXRSClient();
    BookStore bookStore = jaxrsClient.getBookStore();
    bookStore.addBook(new Book("Camel User Guide", 124L));
    Book book = bookStore.getBook(124L);
    assertNotNull("We should find the book here", book);
    try {
        book = bookStore.getBook(126L);
        fail("We should not have this book");
    } catch (Exception exception) {
        assertTrue("The exception should be BookNotFoundFault", exception instanceof BookNotFoundFault);
    }
}
Also used : BookStore(org.apache.camel.example.cxf.jaxrs.resources.BookStore) BookNotFoundFault(org.apache.camel.example.cxf.jaxrs.resources.BookNotFoundFault) Book(org.apache.camel.example.cxf.jaxrs.resources.Book) Test(org.junit.Test)

Example 4 with BookStore

use of org.apache.camel.example.cxf.jaxrs.resources.BookStore in project camel by apache.

the class CamelRouterBuilder method main.

/**
     * Allow this route to be run as an application
     */
public static void main(String[] args) throws Exception {
    System.setProperty("soapEndpointPort", "9006");
    System.setProperty("restEndpointPort", "9002");
    CamelContext context = new DefaultCamelContext();
    PropertiesComponent pc = new PropertiesComponent();
    context.addComponent("properties", pc);
    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", 123L));
    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("Expected exception received: " + exception);
    }
    // JAXRSClient invocation
    JAXRSClient jaxrsClient = new JAXRSClient();
    bookStore = jaxrsClient.getBookStore();
    bookStore.addBook(new Book("Karaf 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("Expected exception received: " + exception);
    }
    Thread.sleep(1000);
    context.stop();
    System.exit(0);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) BookStore(org.apache.camel.example.cxf.jaxrs.resources.BookStore) Book(org.apache.camel.example.cxf.jaxrs.resources.Book) PropertiesComponent(org.apache.camel.component.properties.PropertiesComponent) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Book (org.apache.camel.example.cxf.jaxrs.resources.Book)4 BookStore (org.apache.camel.example.cxf.jaxrs.resources.BookStore)4 BookNotFoundFault (org.apache.camel.example.cxf.jaxrs.resources.BookNotFoundFault)2 Test (org.junit.Test)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CamelContext (org.apache.camel.CamelContext)1 PropertiesComponent (org.apache.camel.component.properties.PropertiesComponent)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1