Java Reference
In-Depth Information
The previous approach works well if you are issuing a single request; on the other
hand, if you have lots of URIs to consume, you can use the ClientRequestFact-
ory class to encapsulate your URIs. This approach has two main benefits:
• It allows the initial request to be reused by just changing the query para-
meter or a Path element
• It allows the REST interceptor to be registered so that any future cli-
ent.get calls or client.createRequest will use that interceptor
So, let's see the full test method using the ClientRequestFactory class:
@Test
public void testREST() {
System.out.println("Testing Ticket REST
Service");
ClientRequestFactory crf = new
ClientRequestFactory(UriBuilder.fromUri("http://localhost:8080/
ticket-agency-ws/rest/seat").build());
ClientRequest bookRequest =
crf.createRelativeRequest("/4");
String entity=null;
try {
entity =
bookRequest.post(String.class).getEntity();
assertTrue(entity.equals("Ticket
booked"));
System.out.println("Ticket Booked with
REST Service");
ClientRequest request =
crf.createRelativeRequest("/");
String seatList=null;
seatList =
Search WWH ::




Custom Search