Search in sources :

Example 1 with Customer

use of org.example.customers.Customer 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");
    }
}
Also used : CustomerService(org.example.customers.CustomerService) Customer(org.example.customers.Customer) Service(javax.xml.ws.Service) CustomerService(org.example.customers.CustomerService) CustomerServiceService(org.example.customers.CustomerServiceService) NoSuchCustomerException(org.example.customers.NoSuchCustomerException)

Example 2 with Customer

use of org.example.customers.Customer 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");
    }
}
Also used : Response(javax.ws.rs.core.Response) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) CustomerService(org.example.customers.CustomerService) Customer(org.example.customers.Customer) ArrayList(java.util.ArrayList) NoSuchCustomerException(org.example.customers.NoSuchCustomerException)

Example 3 with Customer

use of org.example.customers.Customer in project tesb-rt-se by Talend.

the class CustomerServiceImpl method getCustomersByName.

public List<Customer> getCustomersByName(String name) throws NoSuchCustomerException {
    Customer customer = getCustomerByName(name);
    List<Customer> customers = new ArrayList<Customer>();
    customers.add(customer);
    return customers;
}
Also used : NoSuchCustomer(org.example.customers.NoSuchCustomer) Customer(org.example.customers.Customer) ArrayList(java.util.ArrayList)

Example 4 with Customer

use of org.example.customers.Customer in project tesb-rt-se by Talend.

the class CustomerServiceClient method createCustomer.

private Customer createCustomer(String name) {
    Customer cust = new Customer();
    cust.setName(name);
    cust.getAddress().add("Pine Street 200");
    Date bDate = new GregorianCalendar(2009, 01, 01).getTime();
    cust.setBirthDate(bDate);
    cust.setNumOrders(1);
    cust.setRevenue(10000);
    cust.setShares(new BigDecimal(1.5));
    cust.setType(CustomerType.BUSINESS);
    return cust;
}
Also used : Customer(org.example.customers.Customer) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Aggregations

Customer (org.example.customers.Customer)4 ArrayList (java.util.ArrayList)2 CustomerService (org.example.customers.CustomerService)2 NoSuchCustomerException (org.example.customers.NoSuchCustomerException)2 BigDecimal (java.math.BigDecimal)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 Response (javax.ws.rs.core.Response)1 Service (javax.xml.ws.Service)1 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)1 CustomerServiceService (org.example.customers.CustomerServiceService)1 NoSuchCustomer (org.example.customers.NoSuchCustomer)1