Search in sources :

Example 1 with AddNumbers

use of org.apache.handlers.AddNumbers in project cxf by apache.

the class Client method main.

public static void main(String[] args) throws Exception {
    if (args.length == 0) {
        System.err.println("please provide wsdl");
        System.exit(0);
    }
    File wsdl = new File(args[0]);
    AddNumbersService service = new AddNumbersService(wsdl.toURI().toURL(), serviceName);
    AddNumbers port = (AddNumbers) service.getPort(portName, AddNumbers.class);
    // Add client side handlers programmatically
    SmallNumberHandler sh = new SmallNumberHandler();
    List<Handler> newHandlerChain = new ArrayList<>();
    newHandlerChain.add(sh);
    ((BindingProvider) port).getBinding().setHandlerChain(newHandlerChain);
    try {
        int number1 = 10;
        int number2 = 20;
        System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
        int result = port.addNumbers(number1, number2);
        System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
        number1 = 3;
        number2 = 5;
        System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
        result = port.addNumbers(number1, number2);
        System.out.printf("The result of adding %d and %d is %d.\n\n", number1, number2, result);
        number1 = -10;
        System.out.printf("Invoking addNumbers(%d, %d)\n", number1, number2);
        result = port.addNumbers(number1, number2);
        System.out.printf("The result of adding %d and %d is %d.\n", number1, number2, result);
    } catch (AddNumbersFault ex) {
        System.out.printf("Caught AddNumbersFault: %s\n", ex.getFaultInfo().getMessage());
    }
    System.exit(0);
}
Also used : SmallNumberHandler(demo.handlers.common.SmallNumberHandler) AddNumbersService(org.apache.handlers.AddNumbersService) AddNumbers(org.apache.handlers.AddNumbers) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) SmallNumberHandler(demo.handlers.common.SmallNumberHandler) File(java.io.File) AddNumbersFault(org.apache.handlers.AddNumbersFault)

Example 2 with AddNumbers

use of org.apache.handlers.AddNumbers in project cxf by apache.

the class HandlerInvocationUsingAddNumbersTest method testHandlerPostConstruct.

@Test
public void testHandlerPostConstruct() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    AddNumbersServiceWithAnnotation service = new AddNumbersServiceWithAnnotation(wsdl, serviceName);
    AddNumbers port = service.getPort(portName, AddNumbers.class);
    setAddress(port, addNumbersAddress);
    @SuppressWarnings("rawtypes") List<Handler> handlerChain = ((BindingProvider) port).getBinding().getHandlerChain();
    SmallNumberHandler h = (SmallNumberHandler) handlerChain.get(0);
    assertTrue(h.isPostConstructInvoked());
}
Also used : AddNumbers(org.apache.handlers.AddNumbers) Handler(javax.xml.ws.handler.Handler) URL(java.net.URL) Test(org.junit.Test)

Example 3 with AddNumbers

use of org.apache.handlers.AddNumbers in project cxf by apache.

the class HandlerInvocationUsingAddNumbersTest method testAddHandlerProgrammaticallyClientSide.

@Test
public void testAddHandlerProgrammaticallyClientSide() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    AddNumbers port = service.getPort(portName, AddNumbers.class);
    setAddress(port, addNumbersAddress);
    SmallNumberHandler sh = new SmallNumberHandler();
    addHandlersProgrammatically((BindingProvider) port, sh);
    int result = port.addNumbers(10, 20);
    assertEquals(200, result);
    int result1 = port.addNumbers(5, 6);
    assertEquals(11, result1);
}
Also used : AddNumbersService(org.apache.handlers.AddNumbersService) AddNumbers(org.apache.handlers.AddNumbers) URL(java.net.URL) Test(org.junit.Test)

Example 4 with AddNumbers

use of org.apache.handlers.AddNumbers in project cxf by apache.

the class SpringConfiguredHandlerTest method testSpringConfiguresHandlers.

@Test
public void testSpringConfiguresHandlers() throws Exception {
    AddNumbers addNumbers = getApplicationContext().getBean("cxfHandlerTestClientEndpoint", AddNumbers.class);
    int r = addNumbers.addNumbers(10, 15);
    assertEquals(1015, r);
    addNumbers = getApplicationContext().getBean("cxfHandlerTestClientEndpointNoHandler", AddNumbers.class);
    r = addNumbers.addNumbers(10, 15);
    assertEquals(115, r);
    addNumbers = getApplicationContext().getBean("cxfHandlerTestClientServer", AddNumbers.class);
    r = addNumbers.addNumbers(10, 15);
    assertEquals(1015, r);
}
Also used : AddNumbers(org.apache.handlers.AddNumbers) AbstractCXFSpringTest(org.apache.cxf.test.AbstractCXFSpringTest) Test(org.junit.Test)

Example 5 with AddNumbers

use of org.apache.handlers.AddNumbers in project cxf by apache.

the class SpringConfiguredNoAutoRewriteSoapAddressTest method testWsdlAddress.

@Test
public void testWsdlAddress() throws Exception {
    AddNumbers addNumbers = getApplicationContext().getBean("cxfHandlerTestClientEndpoint", AddNumbers.class);
    int r = addNumbers.addNumbers(10, 15);
    assertEquals(1015, r);
    List<String> serviceUrls = findAllServiceUrlsFromWsdl("localhost", port);
    assertEquals(1, serviceUrls.size());
    assertEquals("http://localhost:" + port + "/SpringEndpoint", serviceUrls.get(0));
    String version = System.getProperty("java.version");
    if (version.startsWith("1.8")) {
        // Just skip the test as "127.0.0.1" doesn't work in JDK8
        return;
    }
    serviceUrls = findAllServiceUrlsFromWsdl("127.0.0.1", port);
    assertEquals(1, serviceUrls.size());
    assertEquals("http://localhost:" + port + "/SpringEndpoint", serviceUrls.get(0));
}
Also used : AddNumbers(org.apache.handlers.AddNumbers) Test(org.junit.Test)

Aggregations

AddNumbers (org.apache.handlers.AddNumbers)8 Test (org.junit.Test)7 URL (java.net.URL)4 Handler (javax.xml.ws.handler.Handler)3 AddNumbersService (org.apache.handlers.AddNumbersService)2 SmallNumberHandler (demo.handlers.common.SmallNumberHandler)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Bus (org.apache.cxf.Bus)1 ResourceManager (org.apache.cxf.resource.ResourceManager)1 AbstractCXFSpringTest (org.apache.cxf.test.AbstractCXFSpringTest)1 AddNumbersFault (org.apache.handlers.AddNumbersFault)1