Search in sources :

Example 1 with CustomerService

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");
    }
}
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 CustomerService

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");
    }
}
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 CustomerService

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);
}
Also used : Bus(org.apache.cxf.Bus) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) CustomerService(org.example.customers.CustomerService) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList)

Aggregations

CustomerService (org.example.customers.CustomerService)3 ArrayList (java.util.ArrayList)2 JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)2 Customer (org.example.customers.Customer)2 NoSuchCustomerException (org.example.customers.NoSuchCustomerException)2 Response (javax.ws.rs.core.Response)1 Service (javax.xml.ws.Service)1 Bus (org.apache.cxf.Bus)1 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)1 CustomerServiceService (org.example.customers.CustomerServiceService)1