Search in sources :

Example 1 with NoSuchCustomerException

use of org.example.customers.NoSuchCustomerException 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 NoSuchCustomerException

use of org.example.customers.NoSuchCustomerException 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 NoSuchCustomerException

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

the class CustomerServiceImpl method getCustomerByName.

public Customer getCustomerByName(String name) throws NoSuchCustomerException {
    if (name.equals("John")) {
        throw new RuntimeException("John is not available");
    }
    if (!name.equals(customer.getName())) {
        NoSuchCustomer noSuchCustomer = new NoSuchCustomer();
        noSuchCustomer.setCustomerName(name);
        throw new NoSuchCustomerException("Did not find any matching customer for name=" + name, noSuchCustomer);
    }
    return customer;
}
Also used : NoSuchCustomer(org.example.customers.NoSuchCustomer) NoSuchCustomerException(org.example.customers.NoSuchCustomerException)

Aggregations

NoSuchCustomerException (org.example.customers.NoSuchCustomerException)3 Customer (org.example.customers.Customer)2 CustomerService (org.example.customers.CustomerService)2 ArrayList (java.util.ArrayList)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