Search in sources :

Example 1 with CustomerService

use of com.example.customerservice.CustomerService in project tesb-rt-se by Talend.

the class JaxWsClient method run.

private void run() {
    JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean();
    factoryBean.setAddress(address);
    factoryBean.setServiceClass(CustomerService.class);
    CustomerService customerService = factoryBean.create(CustomerService.class);
    // Anonymous should not be able to read customers
    try {
        List<Customer> customersByName = customerService.getCustomersByName("Fred");
        customersByName.get(0);
        Assert.fail("Anonymous should not be allowed to read customers");
    } catch (Exception e) {
        logger.info("Anonymous request was correctly denied. " + getMessage(e));
    }
    // Alex should not be able to read customers
    CredentialsInjector.inject(customerService, "alex", "alexspassword");
    try {
        customerService.getCustomersByName("Test");
        Assert.fail("Alex should not be allowed to read customers");
    } catch (Exception e) {
        logger.info("Alex's request was correctly denied. " + getMessage(e));
    }
    // Bob should be able to read customers but not to update
    CredentialsInjector.inject(customerService, "bob", "bobspassword");
    try {
        List<Customer> customersByName = customerService.getCustomersByName("Fred");
        Customer customer = customersByName.get(0);
        logger.info("Bob was able to load the customer " + customer.getName());
    } catch (Exception e) {
        Assert.fail("Bob should be allowed to read customers");
    }
    CredentialsInjector.inject(customerService, "bob", "bobspassword");
    try {
        Customer customer = new Customer();
        customer.setName("Fred");
        customerService.updateCustomer(customer);
        Assert.fail("Bob should not be allowed to update a customer");
    } catch (Exception e) {
        logger.info("Bob's request was correctly denied. " + getMessage(e));
    }
    // Jim should be able to read and update customers
    CredentialsInjector.inject(customerService, "jim", "jimspassword");
    try {
        List<Customer> customersByName = customerService.getCustomersByName("Fred");
        Customer customer = customersByName.get(0);
        logger.info("Jim was able to load the customer " + customer.getName());
    } catch (Exception e) {
        Assert.fail("Jim should be allowed to read customers");
    }
    CredentialsInjector.inject(customerService, "jim", "jimspassword");
    try {
        Customer customer = new Customer();
        customer.setName("Fred");
        customerService.updateCustomer(customer);
        logger.info("Jim was able to update the customer");
    } catch (Exception e) {
        Assert.fail("Jim should be allowed to update a customer");
    }
    logger.info("All request were processed as expected");
}
Also used : CustomerService(com.example.customerservice.CustomerService) Customer(com.example.customerservice.Customer) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) NoSuchCustomerException(com.example.customerservice.NoSuchCustomerException)

Example 2 with CustomerService

use of com.example.customerservice.CustomerService in project cxf by apache.

the class CustomerServiceClient method main.

public static void main(String[] args) throws Exception {
    CustomerServiceService customerServiceService;
    if (args.length != 0 && args[0].length() != 0) {
        File wsdlFile = new File(args[0]);
        URL wsdlURL;
        if (wsdlFile.exists()) {
            wsdlURL = wsdlFile.toURI().toURL();
        } else {
            wsdlURL = new URL(args[0]);
        }
        // Create the service client with specified wsdlurl
        customerServiceService = new CustomerServiceService(wsdlURL);
    } else {
        // Create the service client with its default wsdlurl
        customerServiceService = new CustomerServiceService();
    }
    CustomerService customerService = customerServiceService.getCustomerServicePort();
    // Initialize the test class and call the tests
    CustomerServiceTester client = new CustomerServiceTester();
    client.setCustomerService(customerService);
    client.testCustomerService();
    System.exit(0);
}
Also used : CustomerServiceService(com.example.customerservice.CustomerServiceService) CustomerService(com.example.customerservice.CustomerService) File(java.io.File) URL(java.net.URL)

Aggregations

CustomerService (com.example.customerservice.CustomerService)2 Customer (com.example.customerservice.Customer)1 CustomerServiceService (com.example.customerservice.CustomerServiceService)1 NoSuchCustomerException (com.example.customerservice.NoSuchCustomerException)1 File (java.io.File)1 URL (java.net.URL)1 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)1