use of javax.ws.rs.core.GenericType in project cxf by apache.
the class JAXRSRxJava2FlowableTest method doTestGetHelloWorldJsonList.
private void doTestGetHelloWorldJsonList(String address) throws Exception {
WebClient wc = WebClient.create(address, Collections.singletonList(new JacksonJsonProvider()));
WebClient.getConfig(wc).getHttpConduit().getClient().setReceiveTimeout(10000000);
GenericType<List<HelloWorldBean>> genericResponseType = new GenericType<List<HelloWorldBean>>() {
};
List<HelloWorldBean> beans = wc.accept("application/json").get(genericResponseType);
assertEquals(2, beans.size());
assertEquals("Hello", beans.get(0).getGreeting());
assertEquals("World", beans.get(0).getAudience());
assertEquals("Ciao", beans.get(1).getGreeting());
assertEquals("World", beans.get(1).getAudience());
}
use of javax.ws.rs.core.GenericType in project quickstart by wildfly.
the class ContactsRestClient method requestResponseFiltersTest.
// Shows how to use Request and Response filters
public void requestResponseFiltersTest() {
log.info("### Testing Request and Response Filters ###");
// 1 - Drop all contacts
log.info("dropping all contacts");
Response response = ClientBuilder.newClient().target(REST_TARGET_URL).request().delete();
Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
// 2 - Create a new Contact Invocation
log.info("Invoking create new contact using a ClientRequestFilter");
Contact c = new Contact();
c.setName(CONTACT_NAME);
c.setPhoneNumber(CONTACT_PHONE);
Contact persistedContact = ClientBuilder.newClient().register(SavedByClientRequestFilter.class).target(REST_TARGET_URL).request().post(Entity.entity(c, MediaType.APPLICATION_JSON), Contact.class);
Assert.assertEquals("A contact should be persisted with savedBy", SavedByClientRequestFilter.USERNAME, persistedContact.getSavedBy());
// 3 - Fetch all Contacts
log.info("Invoking list all contacts using a ClientResponseFilter");
GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
};
List<Contact> allContacts = ClientBuilder.newClient().register(LogResponseFilter.class).target(REST_TARGET_URL).request().get(contactsListType);
Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
use of javax.ws.rs.core.GenericType in project quickstart by wildfly.
the class ContactsRestClient method delayedInvocationTest.
// Shows how to use a delayed REST invocation
public void delayedInvocationTest() throws Exception {
log.info("### Testing Delayed invocaton ###");
// 1 - Drop all contacts
log.info("dropping all contacts");
Response response = ClientBuilder.newClient().target(REST_TARGET_URL).request().delete();
Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
// 2 - Create a new Contact Invocation
log.info("Creating a new contact invocation");
Contact c = new Contact();
c.setName(CONTACT_NAME);
c.setPhoneNumber(CONTACT_PHONE);
Invocation saveContactInvocation = ClientBuilder.newClient().target(REST_TARGET_URL).request().buildPost(Entity.entity(c, MediaType.APPLICATION_JSON));
// 3 - Create a new list Contacts Invocation
log.info("Creating list all contacts invocation");
Invocation listContactsInvocation = ClientBuilder.newClient().target(REST_TARGET_URL).request().buildGet();
// 4 - Synch Save contact
log.info("invoking the new contact");
Contact persistedContact = saveContactInvocation.invoke(Contact.class);
Assert.assertEquals("A contacts should be persisted with Id=1!", (Long) 1L, (Long) persistedContact.getId());
// 5 - Async List contacts
log.info("invoking list all contacts ASYNC");
GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
};
Future<List<Contact>> futureAllContacts = listContactsInvocation.submit(contactsListType);
List<Contact> allContacts = futureAllContacts.get();
Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
use of javax.ws.rs.core.GenericType in project quickstart by wildfly.
the class ContactsRestClientIT method requestResponseFiltersTest.
// Shows how to use Request and Response filters
@Test
public void requestResponseFiltersTest() {
log.info("### Testing Request and Response Filters ###");
// 1 - Drop all contacts
log.info("dropping all contacts");
Response response = ClientBuilder.newClient().target(getRequestUrl()).request().delete();
Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
// 2 - Create a new Contact Invocation
log.info("Invoking create new contact using a ClientRequestFilter");
Contact c = new Contact();
c.setName(CONTACT_NAME);
c.setPhoneNumber(CONTACT_PHONE);
Contact persistedContact = ClientBuilder.newClient().register(SavedByClientRequestFilter.class).target(getRequestUrl()).request().post(Entity.entity(c, MediaType.APPLICATION_JSON), Contact.class);
Assert.assertEquals("A contact should be persisted with savedBy", SavedByClientRequestFilter.USERNAME, persistedContact.getSavedBy());
// 3 - Fetch all Contacts
log.info("Invoking list all contacts using a ClientResponseFilter");
GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
};
List<Contact> allContacts = ClientBuilder.newClient().register(LogResponseFilter.class).target(getRequestUrl()).request().get(contactsListType);
Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
use of javax.ws.rs.core.GenericType in project quickstart by wildfly.
the class ContactsRestClientIT method delayedInvocationTest.
// Shows how to use a delayed REST invocation
@Test
public void delayedInvocationTest() throws Exception {
log.info("### Testing Delayed invocaton ###");
// 1 - Drop all contacts
log.info("dropping all contacts");
Response response = ClientBuilder.newClient().target(getRequestUrl()).request().delete();
Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
// 2 - Create a new Contact Invocation
log.info("Creating a new contact invocation");
Contact c = new Contact();
c.setName(CONTACT_NAME);
c.setPhoneNumber(CONTACT_PHONE);
Invocation saveContactInvocation = ClientBuilder.newClient().target(getRequestUrl()).request().buildPost(Entity.entity(c, MediaType.APPLICATION_JSON));
// 3 - Create a new list Contacts Invocation
log.info("Creating list all contacts invocation");
Invocation listContactsInvocation = ClientBuilder.newClient().target(getRequestUrl()).request().buildGet();
// 4 - Synch Save contact
log.info("invoking the new contact");
Contact persistedContact = saveContactInvocation.invoke(Contact.class);
Assert.assertEquals("A contacts should be persisted with Id=1!", (Long) 1L, (Long) persistedContact.getId());
// 5 - Async List contacts
log.info("invoking list all contacts ASYNC");
GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
};
Future<List<Contact>> futureAllContacts = listContactsInvocation.submit(contactsListType);
List<Contact> allContacts = futureAllContacts.get();
Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
Aggregations