Search in sources :

Example 6 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method readBook.

private Book readBook(InputStream is) throws Exception {
    JAXBContext c = JAXBContext.newInstance(new Class[] { Book.class });
    Unmarshaller u = c.createUnmarshaller();
    return (Book) u.unmarshal(is);
}
Also used : Book(org.apache.cxf.systest.jaxrs.Book) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 7 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method testGetBookFromWebClientWithPath.

@Test
public void testGetBookFromWebClientWithPath() throws Exception {
    // setup the the client
    String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory";
    WebClient client = WebClient.create(endpointAddressUrlEncoded);
    client.path("bookstore").path("books").path("123");
    Book book = client.get(Book.class);
    assertEquals("Get a wrong response code.", 200, client.getResponse().getStatus());
    assertEquals("Get a wrong book id.", 123, book.getId());
}
Also used : Book(org.apache.cxf.systest.jaxrs.Book) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 8 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method testGetBookFromProxyClientWithQuery.

@Test
public void testGetBookFromProxyClientWithQuery() throws Exception {
    // setup the the client
    String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory";
    JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class);
    Book book = client.getBookByURLQuery(new String[] { "1", "2", "3" });
    assertEquals("Get a wrong response code.", 200, WebClient.client(client).getResponse().getStatus());
    assertEquals("Get a wrong book id.", 123, book.getId());
}
Also used : JMSBookStore(org.apache.cxf.systest.jaxrs.JMSBookStore) Book(org.apache.cxf.systest.jaxrs.Book) Test(org.junit.Test)

Example 9 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method checkBookInResponse.

private void checkBookInResponse(Session session, Destination replyToDestination, long bookId, String bookName) throws Exception {
    MessageConsumer consumer = session.createConsumer(replyToDestination);
    BytesMessage jmsMessage = (BytesMessage) consumer.receive(5000);
    if (jmsMessage == null) {
        throw new RuntimeException("No response recieved on " + replyToDestination);
    }
    byte[] bytes = new byte[(int) jmsMessage.getBodyLength()];
    jmsMessage.readBytes(bytes);
    InputStream is = new ByteArrayInputStream(bytes);
    Book b = readBook(is);
    assertEquals(bookId, b.getId());
    assertEquals(bookName, b.getName());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Book(org.apache.cxf.systest.jaxrs.Book) BytesMessage(javax.jms.BytesMessage)

Example 10 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method testGetBookFromSubresourceProxyClientWithTextJMSMessage.

@Test
public void testGetBookFromSubresourceProxyClientWithTextJMSMessage() throws Exception {
    // setup the the client
    String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory" + "&messageType=text";
    JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class);
    Book bookProxy = client.getBookSubResource("123");
    Book book = bookProxy.retrieveState();
    assertEquals("Get a wrong response code.", 200, WebClient.client(bookProxy).getResponse().getStatus());
    assertEquals("Get a wrong book id.", 123, book.getId());
}
Also used : JMSBookStore(org.apache.cxf.systest.jaxrs.JMSBookStore) Book(org.apache.cxf.systest.jaxrs.Book) Test(org.junit.Test)

Aggregations

Book (org.apache.cxf.systest.jaxrs.Book)46 Test (org.junit.Test)31 WebClient (org.apache.cxf.jaxrs.client.WebClient)22 BookStore (org.apache.cxf.systest.jaxrs.BookStore)8 JMSBookStore (org.apache.cxf.systest.jaxrs.JMSBookStore)6 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)5 Response (javax.ws.rs.core.Response)4 ArrayList (java.util.ArrayList)3 BytesMessage (javax.jms.BytesMessage)3 JAXBContext (javax.xml.bind.JAXBContext)3 InputStream (java.io.InputStream)2 ExecutionException (java.util.concurrent.ExecutionException)2 MessageProducer (javax.jms.MessageProducer)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2 ProcessingException (javax.ws.rs.ProcessingException)2 Client (javax.ws.rs.client.Client)2 ClientBuilder (javax.ws.rs.client.ClientBuilder)2 WebTarget (javax.ws.rs.client.WebTarget)2 Form (javax.ws.rs.core.Form)2