use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class LoadDistributorTest method testSingleAltAddress.
@Test
public void testSingleAltAddress() throws Exception {
LoadDistributorFeature feature = new LoadDistributorFeature();
List<String> alternateAddresses = new ArrayList<>();
alternateAddresses.add(Server.ADDRESS2);
SequentialStrategy strategy = new SequentialStrategy();
strategy.setAlternateAddresses(alternateAddresses);
feature.setStrategy(strategy);
BookStore bookStore = getBookStore(Server.ADDRESS1, feature);
Book book = bookStore.getBook("123");
assertEquals("unexpected id", 123L, book.getId());
book = bookStore.getBook("123");
assertEquals("unexpected id", 123L, book.getId());
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class JAXRSJmsTest method testGetBookFromWebClient.
@Test
public void testGetBookFromWebClient() throws Exception {
// setup the the client
String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?replyToName=dynamicQueues/test.jmstransport.response" + "&jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&jndiURL=tcp://localhost:" + JMS_PORT;
WebClient client = WebClient.create(endpointAddressUrlEncoded);
WebClient.getConfig(client).getInInterceptors().add(new LoggingInInterceptor());
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books/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());
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class JAXRSJmsTest method postBook.
private void postBook(Session session, Destination destination, Destination replyTo) throws Exception {
MessageProducer producer = session.createProducer(destination);
byte[] payload = writeBook(new Book("JMS", 3L));
BytesMessage message = session.createBytesMessage();
message.writeBytes(payload);
message.setJMSReplyTo(replyTo);
// or, if oneway,
// message.setStringProperty("OnewayRequest", "true");
// we could've set this header in JMSDestination if no replyTo were set
// but in CXF one could also provide the replyTo in the configuration
// so it is just simpler to set this header if needed to avoid some
// complex logic on the server side
// all these properties are optional
// CXF JAXRS and JMS Transport will default to
// Content-Type : text/xml
// Accept : */*
// POST
// Message.REQUEST_URI : "/"
message.setStringProperty("Content-Type", "application/xml");
message.setStringProperty("Accept", "text/xml");
message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/books");
message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "POST");
message.setStringProperty("custom.protocol.header", "custom.value");
producer.send(message);
producer.close();
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class JAXRSJmsTest method testPutBookOneWayWithWebClient.
@Test
public void testPutBookOneWayWithWebClient() throws Exception {
// setup the the client
String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?replyToName=dynamicQueues/test.jmstransport.response" + "&jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&jndiURL=tcp://localhost:" + JMS_PORT;
WebClient client = WebClient.create(endpointAddressUrlEncoded);
WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/oneway");
client.header("OnewayRequest", "true");
Response r = client.type("application/xml").put(new Book("OneWay From WebClient", 129L));
assertEquals(202, r.getStatus());
assertFalse(r.hasEntity());
Context ctx = getContext();
ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
Destination replyToDestination = (Destination) ctx.lookup("dynamicQueues/test.jmstransport.response");
Connection connection = null;
try {
connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
checkBookInResponse(session, replyToDestination, 129L, "OneWay From WebClient");
session.close();
} finally {
close(connection);
}
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class JAXRSJmsTest method postOneWayBook.
private void postOneWayBook(Session session, Destination destination) throws Exception {
MessageProducer producer = session.createProducer(destination);
byte[] payload = writeBook(new Book("JMS OneWay", 125L));
BytesMessage message = session.createBytesMessage();
message.writeBytes(payload);
message.setStringProperty("Content-Type", "application/xml");
message.setStringProperty(org.apache.cxf.message.Message.REQUEST_URI, "/bookstore/oneway");
message.setStringProperty(org.apache.cxf.message.Message.HTTP_REQUEST_METHOD, "PUT");
producer.send(message);
producer.close();
}
Aggregations