Search in sources :

Example 21 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class WSRM12ServerCycleTest method runTest.

public void runTest(String cfg, boolean faultOnRestart) throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    ControlService cs = new ControlService();
    Control control = cs.getControlPort();
    ConnectionHelper.setKeepAliveConnection(control, false, true);
    updateAddressPort(control, PORT);
    Assert.assertTrue("Failed to start greeter", control.startGreeter(cfg));
    System.setProperty("db.name", getPrefix() + "-recovery");
    Bus greeterBus = new SpringBusFactory().createBus();
    System.clearProperty("db.name");
    BusFactory.setDefaultBus(greeterBus);
    // avoid early client resends
    greeterBus.getExtension(RMManager.class).getConfiguration().setBaseRetransmissionInterval(new Long(60000));
    GreeterService gs = new GreeterService();
    Greeter greeter = gs.getGreeterPort(new LoggingFeature(), new AddressingFeature(), wsrm());
    updateAddressPort(greeter, PORT);
    greeter.greetMe("one");
    greeter.greetMe("two");
    greeter.greetMe("three");
    control.stopGreeter(cfg);
    // make sure greeter is down
    Thread.sleep(1000);
    control.startGreeter(cfg);
    // CXF-7392
    if (faultOnRestart) {
        try {
            greeter.greetMe("four");
        } catch (SOAPFaultException ex) {
            assertTrue(ex.getMessage().contains("wsrm:Identifier"));
        // expected, sequence identifier doesn't exist on other side
        }
    } else {
        // this should work as the sequence should be recovered on the server side
        greeter.greetMe("four");
    }
    ((Closeable) greeter).close();
    greeterBus.shutdown(true);
    control.stopGreeter(cfg);
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) Control(org.apache.cxf.greeter_control.Control) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) AddressingFeature(javax.xml.ws.soap.AddressingFeature) ControlService(org.apache.cxf.greeter_control.ControlService) Greeter(org.apache.cxf.greeter_control.Greeter) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) Closeable(java.io.Closeable) GreeterService(org.apache.cxf.greeter_control.GreeterService) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Example 22 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class ClientServerSessionTest method doSessionsTest.

private void doSessionsTest(String url) {
    GreeterService service = new GreeterService();
    assertNotNull(service);
    Greeter greeter = service.getGreeterPort();
    Greeter greeter2 = service.getGreeterPort();
    BindingProvider bp = (BindingProvider) greeter;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    bp = (BindingProvider) greeter2;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
    bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    String result = greeter.greetMe("World");
    assertEquals("Hello World", result);
    assertEquals("Bonjour World", greeter.sayHi());
    result = greeter2.greetMe("Universe");
    assertEquals("Hello Universe", result);
    assertEquals("Bonjour Universe", greeter2.sayHi());
    // make sure session 1 was maintained
    assertEquals("Bonjour World", greeter.sayHi());
}
Also used : Greeter(org.apache.cxf.greeter_control.Greeter) GreeterService(org.apache.cxf.greeter_control.GreeterService) BindingProvider(javax.xml.ws.BindingProvider)

Example 23 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class ClientServerSessionTest method testInvocationWithSpringBeanAnnotation.

@Test
public void testInvocationWithSpringBeanAnnotation() throws Exception {
    GreeterService service = new GreeterService();
    assertNotNull(service);
    Greeter greeter = service.getGreeterPort();
    BindingProvider bp = (BindingProvider) greeter;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + PORT + "/SpringBean");
    bp.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    String result = greeter.greetMe("World");
    assertEquals("Hello World", result);
    assertEquals("Bonjour World", greeter.sayHi());
}
Also used : Greeter(org.apache.cxf.greeter_control.Greeter) GreeterService(org.apache.cxf.greeter_control.GreeterService) BindingProvider(javax.xml.ws.BindingProvider) Test(org.junit.Test)

Example 24 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class ClientServerSessionTest method testInvocationWithoutSession.

@Test
public void testInvocationWithoutSession() throws Exception {
    GreeterService service = new GreeterService();
    assertNotNull(service);
    try {
        Greeter greeter = service.getGreeterPort();
        updateAddressPort(greeter, PORT);
        String greeting = greeter.greetMe("Bonjour");
        assertNotNull("no response received from service", greeting);
        assertEquals("Hello Bonjour", greeting);
        greeting = greeter.greetMe("Hello");
        assertNotNull("no response received from service", greeting);
        assertEquals("Hello Hello", greeting);
        greeting = greeter.greetMe("NiHao");
        assertNotNull("no response received from service", greeting);
        assertEquals("Hello NiHao", greeting);
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : Greeter(org.apache.cxf.greeter_control.Greeter) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) GreeterService(org.apache.cxf.greeter_control.GreeterService) Test(org.junit.Test)

Example 25 with GreeterService

use of org.apache.cxf.greeter_control.GreeterService in project cxf by apache.

the class StaxTransformFeatureTest method testTransformWithLogging.

@Test
public void testTransformWithLogging() throws Exception {
    SpringBusFactory bf = new SpringBusFactory();
    Bus bus = bf.createBus();
    BusFactory.setDefaultBus(bus);
    TestLoggingEventSender logIn = new TestLoggingEventSender();
    bus.getInInterceptors().add(new LoggingInInterceptor(logIn));
    bus.getInFaultInterceptors().add(new LoggingInInterceptor(logIn));
    TestLoggingEventSender logOut = new TestLoggingEventSender();
    bus.getOutInterceptors().add(new LoggingOutInterceptor(logOut));
    bus.getOutFaultInterceptors().add(new LoggingOutInterceptor(logOut));
    TransformInInterceptor transIn = new TransformInInterceptor();
    Map<String, String> inElements = new HashMap<>();
    inElements.put("{http://cxf.apache.org/greeter_control/types}noFaultDetail", "{http://cxf.apache.org/greeter_control/types}faultDetail");
    bus.getInInterceptors().add(transIn);
    TransformOutInterceptor transOut = new TransformOutInterceptor();
    Map<String, String> outElements = new HashMap<>();
    outElements.put("{http://cxf.apache.org/greeter_control/types}pingMe", "{http://cxf.apache.org/greeter_control/types}dontPingMe");
    transOut.setOutTransformElements(outElements);
    bus.getOutInterceptors().add(transOut);
    bus.getOutFaultInterceptors().add(transOut);
    GreeterService gs = new GreeterService();
    greeter = gs.getGreeterPort();
    updateAddressPort(greeter, PORT);
    LOG.fine("Created greeter client.");
    // ping 1: request-response transformation
    greeter.pingMe();
    verifyPayload(logOut.getMessage(), "dontPingMe");
    verifyPayload(logIn.getMessage(), "pingMeResponse");
    verifyPayload(serverlogIn.getMessage(), "dontPingMe");
    verifyPayload(serverlogOut.getMessage(), "pingMeResponse");
    serverlogOut.cleaerMessage();
    serverlogIn.cleaerMessage();
    logOut.cleaerMessage();
    logIn.cleaerMessage();
    // ping 2: request-fault transformation
    try {
        greeter.pingMe();
        fail("Ping should have failed");
    } catch (Exception e) {
        assertEquals("Pings succeed only every other time.", e.getMessage());
    }
    verifyPayload(logOut.getMessage(), "dontPingMe");
    verifyPayload(logIn.getMessage(), "noFaultDetail");
    verifyPayload(serverlogIn.getMessage(), "dontPingMe");
    verifyPayload(serverlogOut.getMessage(), "noFaultDetail");
    // ping 3: idle
    greeter.pingMe();
    serverlogOut.cleaerMessage();
    serverlogIn.cleaerMessage();
    logOut.cleaerMessage();
    logIn.cleaerMessage();
    // ping 4: request-fault transformation with skipOnFault
    transOut.setSkipOnFault(true);
    servertransOut.setSkipOnFault(true);
    try {
        greeter.pingMe();
        fail("Ping should have failed");
    } catch (Exception e) {
        assertEquals("Pings succeed only every other time.", e.getMessage());
    }
    verifyPayload(logOut.getMessage(), "dontPingMe");
    verifyPayload(logIn.getMessage(), "faultDetail");
    verifyPayload(serverlogIn.getMessage(), "dontPingMe");
    verifyPayload(serverlogOut.getMessage(), "faultDetail");
    bus.shutdown(true);
}
Also used : Bus(org.apache.cxf.Bus) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) HashMap(java.util.HashMap) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) GreeterService(org.apache.cxf.greeter_control.GreeterService) TransformOutInterceptor(org.apache.cxf.interceptor.transform.TransformOutInterceptor) TransformInInterceptor(org.apache.cxf.interceptor.transform.TransformInInterceptor) Test(org.junit.Test)

Aggregations

GreeterService (org.apache.cxf.greeter_control.GreeterService)42 Greeter (org.apache.cxf.greeter_control.Greeter)28 Test (org.junit.Test)28 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)15 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)10 BindingProvider (javax.xml.ws.BindingProvider)10 RMManager (org.apache.cxf.ws.rm.RMManager)10 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)7 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)7 ControlService (org.apache.cxf.greeter_control.ControlService)4 MBeanServer (javax.management.MBeanServer)3 ObjectName (javax.management.ObjectName)3 InstrumentationManager (org.apache.cxf.management.InstrumentationManager)3 IOException (java.io.IOException)2 List (java.util.List)2 TransformerException (javax.xml.transform.TransformerException)2 DOMSource (javax.xml.transform.dom.DOMSource)2 WebServiceException (javax.xml.ws.WebServiceException)2 Bus (org.apache.cxf.Bus)2 Client (org.apache.cxf.endpoint.Client)2