use of org.example.customers.CustomerService in project tesb-rt-se by Talend.
the class CustomerServiceClient method useCustomerServiceSoap.
public void useCustomerServiceSoap(String[] args) throws Exception {
final String address = "http://localhost:" + port + "/services/jaxws";
System.out.println("Using SOAP CustomerService");
Service service = Service.create(CustomerServiceService.SERVICE);
service.addPort(CustomerServiceService.CustomerServicePort, SOAPBinding.SOAP11HTTP_BINDING, address);
CustomerService customerService = service.getPort(CustomerService.class);
Customer customer = createCustomer("Barry");
customerService.updateCustomer(customer);
customer = customerService.getCustomerByName("Barry");
printCustomerDetails(customer);
try {
customerService.getCustomerByName("Smith");
throw new RuntimeException("Exception is expected");
} catch (NoSuchCustomerException ex) {
System.out.println("NoSuchCustomerException : Smith");
}
}
use of org.example.customers.CustomerService in project tesb-rt-se by Talend.
the class CustomerServiceClient method useCustomerServiceRest.
public void useCustomerServiceRest(String[] args) throws Exception {
JAXBElementProvider provider = new JAXBElementProvider();
provider.setUnmarshallAsJaxbElement(true);
provider.setMarshallAsJaxbElement(true);
List<Object> providers = new ArrayList<Object>();
providers.add(provider);
providers.add(new ResponseExceptionMapper<NoSuchCustomerException>() {
@Override
public NoSuchCustomerException fromResponse(Response r) {
return new NoSuchCustomerException();
}
});
CustomerService customerService = JAXRSClientFactory.createFromModel("http://localhost:" + port + "/services/jaxrs", CustomerService.class, "classpath:/data/model/CustomerService-jaxrs.xml", providers, null);
System.out.println("Using RESTful CustomerService");
Customer customer = createCustomer("Smith");
customerService.updateCustomer(customer);
customer = customerService.getCustomerByName("Smith");
printCustomerDetails(customer);
customer = customerService.getCustomerByName("Barry");
if (customer != null) {
throw new RuntimeException("Barry should not be found");
}
System.out.println("Status : " + WebClient.client(customerService).getResponse().getStatus());
try {
customerService.getCustomerByName("John");
throw new RuntimeException("Exception is expected");
} catch (NoSuchCustomerException ex) {
System.out.println("NoSuchCustomerException : John");
}
}
use of org.example.customers.CustomerService in project tesb-rt-se by Talend.
the class CustomerServiceServer method main.
public static void main(String[] args) throws Exception {
Bus bus = BusFactory.getDefaultBus();
System.out.println("Starting Server");
CustomerService implementor = new CustomerServiceImpl();
Endpoint.publish("http://localhost:8080/services/jaxws", implementor);
JAXRSServerFactoryBean jaxrsFactory = new JAXRSServerFactoryBean();
jaxrsFactory.setBus(bus);
jaxrsFactory.setAddress("http://localhost:8080/services/jaxrs");
jaxrsFactory.setModelRef("classpath:/data/model/CustomerService-jaxrs.xml");
jaxrsFactory.setServiceBean(implementor);
List<Object> providers = new ArrayList<Object>();
JAXBElementProvider jaxbProvider = new JAXBElementProvider();
jaxbProvider.setMarshallAsJaxbElement(true);
jaxbProvider.setUnmarshallAsJaxbElement(true);
providers.add(jaxbProvider);
providers.add(new NoCustomerExceptionMapper());
jaxrsFactory.setProviders(providers);
jaxrsFactory.create();
System.out.println("Server ready...");
Thread.sleep(5 * 60 * 1000);
System.out.println("Server exiting");
System.exit(0);
}
Aggregations