Search in sources :

Example 11 with LoggingFeature

use of org.apache.cxf.ext.logging.LoggingFeature in project cxf by apache.

the class RESTLoggingTest method testEvents.

@Test
public void testEvents() throws MalformedURLException {
    LoggingFeature loggingFeature = new LoggingFeature();
    loggingFeature.setLogBinary(true);
    TestEventSender sender = new TestEventSender();
    loggingFeature.setSender(sender);
    Server server = createService(SERVICE_URI, new TestServiceRest(), loggingFeature);
    server.start();
    WebClient client = createClient(SERVICE_URI, loggingFeature);
    String result = client.get(String.class);
    Assert.assertEquals("test1", result);
    server.destroy();
    List<LogEvent> events = sender.getEvents();
    Assert.assertEquals(4, events.size());
    checkRequestOut(events.get(0));
    checkRequestIn(events.get(1));
    checkResponseOut(events.get(2));
    checkResponseIn(events.get(3));
}
Also used : Server(org.apache.cxf.endpoint.Server) LogEvent(org.apache.cxf.ext.logging.event.LogEvent) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 12 with LoggingFeature

use of org.apache.cxf.ext.logging.LoggingFeature in project cxf by apache.

the class JMSClientServerTest method testQueueDecoupledOneWaysConnection.

@Test
public void testQueueDecoupledOneWaysConnection() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldQueueDecoupledOneWaysService");
    QName portName = new QName("http://cxf.apache.org/hello_world_jms", "HelloWorldQueueDecoupledOneWaysPort");
    URL wsdl = getWSDLURL("/wsdl/jms_test.wsdl");
    String wsdl2 = "testutils/jms_test.wsdl".intern();
    wsdlStrings.add(wsdl2);
    broker.updateWsdl(getBus(), wsdl2);
    HelloWorldQueueDecoupledOneWaysService service = new HelloWorldQueueDecoupledOneWaysService(wsdl, serviceName);
    Endpoint requestEndpoint = null;
    Endpoint replyEndpoint = null;
    HelloWorldOneWayPort greeter = service.getPort(portName, HelloWorldOneWayPort.class);
    try {
        GreeterImplQueueDecoupledOneWays requestServant = new GreeterImplQueueDecoupledOneWays();
        requestEndpoint = Endpoint.publish(null, requestServant, new LoggingFeature());
        GreeterImplQueueDecoupledOneWaysDeferredReply replyServant = new GreeterImplQueueDecoupledOneWaysDeferredReply();
        replyEndpoint = Endpoint.publish(null, replyServant, new LoggingFeature());
        BindingProvider bp = (BindingProvider) greeter;
        Map<String, Object> requestContext = bp.getRequestContext();
        JMSMessageHeadersType requestHeader = new JMSMessageHeadersType();
        requestHeader.setJMSReplyTo("dynamicQueues/test.jmstransport.oneway.with.set.replyto.reply");
        requestContext.put(JMSConstants.JMS_CLIENT_REQUEST_HEADERS, requestHeader);
        String expectedRequest = "JMS:Queue:Request";
        greeter.greetMeOneWay(expectedRequest);
        String request = requestServant.ackRequestReceived(5000);
        if (request == null) {
            if (requestServant.getException() != null) {
                fail(requestServant.getException().getMessage());
            } else {
                fail("The oneway call didn't reach its intended endpoint");
            }
        }
        assertEquals(expectedRequest, request);
        requestServant.proceedWithReply();
        String expectedReply = requestServant.ackReplySent(5000);
        if (expectedReply == null) {
            if (requestServant.getException() != null) {
                fail(requestServant.getException().getMessage());
            } else {
                fail("The decoupled one-way reply was not sent");
            }
        }
        String reply = replyServant.ackRequest(5000);
        if (reply == null) {
            if (replyServant.getException() != null) {
                fail(replyServant.getException().getMessage());
            } else {
                fail("The decoupled one-way reply didn't reach its intended endpoint");
            }
        }
        assertEquals(expectedReply, reply);
    } catch (Exception ex) {
        throw ex;
    } finally {
        if (requestEndpoint != null) {
            requestEndpoint.stop();
        }
        if (replyEndpoint != null) {
            replyEndpoint.stop();
        }
        ((java.io.Closeable) greeter).close();
    }
}
Also used : HelloWorldOneWayPort(org.apache.cxf.hello_world_jms.HelloWorldOneWayPort) QName(javax.xml.namespace.QName) Closeable(java.io.Closeable) JMSMessageHeadersType(org.apache.cxf.transport.jms.JMSMessageHeadersType) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) ExecutionException(java.util.concurrent.ExecutionException) Endpoint(javax.xml.ws.Endpoint) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) HelloWorldQueueDecoupledOneWaysService(org.apache.cxf.hello_world_jms.HelloWorldQueueDecoupledOneWaysService) Test(org.junit.Test)

Example 13 with LoggingFeature

use of org.apache.cxf.ext.logging.LoggingFeature in project cxf by apache.

the class ClientServerTest method testDynamicClientFactory.

@Test
public void testDynamicClientFactory() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);
    String wsdlUrl = null;
    wsdlUrl = wsdl.toURI().toString();
    DynamicClientFactory dcf = DynamicClientFactory.newInstance();
    Client client = dcf.createClient(wsdlUrl, serviceName, portName);
    updateAddressPort(client, PORT);
    client.invoke("greetMe", "test");
    Object[] result = client.invoke("sayHi");
    assertNotNull("no response received from service", result);
    assertEquals("Bonjour", result[0]);
    client = dcf.createClient(wsdlUrl, serviceName, portName);
    new LoggingFeature().initialize(client, client.getBus());
    updateAddressPort(client, PORT);
    client.invoke("greetMe", "test");
    result = client.invoke("sayHi");
    assertNotNull("no response received from service", result);
    assertEquals("Bonjour", result[0]);
}
Also used : DynamicClientFactory(org.apache.cxf.endpoint.dynamic.DynamicClientFactory) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature) Client(org.apache.cxf.endpoint.Client) URL(java.net.URL) SOAPServiceMultiPortTypeTest(org.apache.hello_world_soap_http.SOAPServiceMultiPortTypeTest) SOAPServiceBogusAddressTest(org.apache.hello_world_soap_http.SOAPServiceBogusAddressTest) Test(org.junit.Test)

Example 14 with LoggingFeature

use of org.apache.cxf.ext.logging.LoggingFeature in project cxf by apache.

the class ControlImpl method startGreeter.

@Override
public boolean startGreeter(String cfgResource) {
    SpringBusFactory bf = new SpringBusFactory();
    System.setProperty("db.name", dbName);
    if (StringUtils.isEmpty(cfgResource)) {
        greeterBus = bf.createBus();
    } else {
        greeterBus = bf.createBus(cfgResource);
    }
    System.clearProperty("db.name");
    BusFactory.setDefaultBus(greeterBus);
    LOG.info("Initialised bus " + greeterBus + " with cfg file resource: " + cfgResource);
    LOG.fine("greeterBus inInterceptors: " + greeterBus.getInInterceptors());
    LoggingFeature lf = new LoggingFeature();
    lf.setPrettyLogging(true);
    lf.initialize(greeterBus);
    if (cfgResource.indexOf("provider") == -1) {
        endpoint = Endpoint.publish(address, implementor);
        LOG.info("Published greeter endpoint.");
    } else {
        endpoint = Endpoint.publish(address, new GreeterProvider());
        LOG.info("Published greeter provider.");
    }
    return true;
}
Also used : SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) LoggingFeature(org.apache.cxf.ext.logging.LoggingFeature)

Example 15 with LoggingFeature

use of org.apache.cxf.ext.logging.LoggingFeature 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)

Aggregations

LoggingFeature (org.apache.cxf.ext.logging.LoggingFeature)21 Test (org.junit.Test)13 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)4 WebClient (org.apache.cxf.jaxrs.client.WebClient)4 URL (java.net.URL)3 Endpoint (javax.xml.ws.Endpoint)3 Client (org.apache.cxf.endpoint.Client)3 Server (org.apache.cxf.endpoint.Server)3 LogEvent (org.apache.cxf.ext.logging.event.LogEvent)3 BeforeClass (org.junit.BeforeClass)3 Closeable (java.io.Closeable)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 BindingProvider (javax.xml.ws.BindingProvider)2 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)2 AbstractJaxWsTest (org.apache.cxf.jaxws.AbstractJaxWsTest)2 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)2 AddNumberImpl (org.apache.cxf.systest.ws.addr_fromjava.client.AddNumberImpl)2 AddNumbersException_Exception (org.apache.cxf.systest.ws.addr_fromjava.client.AddNumbersException_Exception)2