use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class FailoverWebClientTest method testFailover.
@Test
public void testFailover() throws Exception {
String address = "http://localhost:" + PORT1 + "/bookstore";
FailoverFeature failoverFeature = new FailoverFeature();
SequentialStrategy strategy = new SequentialStrategy();
List<String> addresses = new ArrayList<>();
addresses.add("http://localhost:" + PORT2 + "/bookstore");
addresses.add("http://localhost:" + PORT3 + "/bookstore");
strategy.setAlternateAddresses(addresses);
failoverFeature.setStrategy(strategy);
WebClient webClient = WebClient.create(address, null, Collections.singletonList(failoverFeature), null).accept("application/xml");
// Should hit PORT1
Book b = webClient.get(Book.class);
assertEquals(124L, b.getId());
assertEquals("root", b.getName());
assertEquals("http://localhost:" + PORT1 + "/bookstore", webClient.getBaseURI().toString());
// Should failover to PORT2
webClient.get(Book.class);
assertEquals(124L, b.getId());
assertEquals("root", b.getName());
assertEquals("http://localhost:" + PORT2 + "/bookstore", webClient.getBaseURI().toString());
// Should failover to PORT3
webClient.get(Book.class);
assertEquals(124L, b.getId());
assertEquals("root", b.getName());
assertEquals("http://localhost:" + PORT3 + "/bookstore", webClient.getBaseURI().toString());
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class BookServerWebSocket method run.
protected void run() {
Bus bus = BusFactory.getDefaultBus();
setBus(bus);
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setBus(bus);
sf.setResourceClasses(BookStoreWebSocket.class, BookStorePerRequest.class);
sf.setProvider(new StreamingResponseProvider<Book>());
sf.setResourceProvider(BookStoreWebSocket.class, new SingletonResourceProvider(new BookStoreWebSocket(), true));
sf.setAddress("ws://localhost:" + port + "/websocket");
server = sf.create();
BusFactory.setDefaultBus(null);
BusFactory.setThreadDefaultBus(null);
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class BookStoreWebSocket method getBookStream.
@GET
@Path("/bookstream")
@Produces("application/json")
public StreamingResponse<Book> getBookStream() {
return new StreamingResponse<Book>() {
public void writeTo(final StreamingResponse.Writer<Book> out) throws IOException {
out.write(new Book("WebSocket1", 1));
executor.execute(new Runnable() {
public void run() {
try {
for (int i = 2; i <= 5; i++) {
Thread.sleep(500);
out.write(new Book("WebSocket" + i, i));
out.getEntityStream().flush();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
};
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class JAXRSClientConduitWebSocketTest method testBookWithWebSocket.
@Test
public void testBookWithWebSocket() throws Exception {
String address = "ws://localhost:" + getPort() + "/websocket";
BookStoreWebSocket resource = JAXRSClientFactory.create(address, BookStoreWebSocket.class);
Client client = WebClient.client(resource);
client.header(HttpHeaders.USER_AGENT, JAXRSClientConduitWebSocketTest.class.getName());
// call the GET service
assertEquals("CXF in Action", new String(resource.getBookName()));
// call the GET service in text mode
// TODO add some way to control the client to switch between the bytes and text modes
assertEquals("CXF in Action", new String(resource.getBookName()));
// call another GET service
Book book = resource.getBook(123);
assertEquals("CXF in Action", book.getName());
// call the POST service
assertEquals(Long.valueOf(123), resource.echoBookId(123));
// call the same POST service in the text mode
// TODO add some way to control the client to switch between the bytes and text modes
assertEquals(Long.valueOf(123), resource.echoBookId(123));
// call the GET service returning a continous stream output
// TODO there is no way to get the continuous stream at the moment
// resource.getBookBought();
}
use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.
the class JAXRSClientServerWebSocketSpringWebAppTest method testGetBookHTTP.
@Test
public void testGetBookHTTP() throws Exception {
String address = "http://localhost:" + getPort() + getContext() + "/http/web/bookstore/books/1";
WebClient wc = WebClient.create(address);
wc.accept("application/xml");
Book book = wc.get(Book.class);
assertEquals(1L, book.getId());
}
Aggregations