Search in sources :

Example 1 with PrintWriterEventSender

use of org.apache.cxf.ext.logging.event.PrintWriterEventSender in project cxf by apache.

the class OldLoggingFactoryBeanListener method createEventSender.

private LogEventSender createEventSender(String location) {
    if (StringUtils.isEmpty(location)) {
        return null;
    }
    if ("<stdout>".equals(location)) {
        return new PrintWriterEventSender(System.out);
    } else if ("<stderr>".equals(location)) {
        return new PrintWriterEventSender(System.err);
    } else if (location.startsWith("file:")) {
        try {
            URI uri = new URI(location);
            File file = new File(uri);
            PrintWriter writer = new PrintWriter(new FileWriter(file, true), true);
            return new PrintWriterEventSender(writer);
        } catch (Exception ex) {
        // stick with default
        }
    }
    return null;
}
Also used : PrintWriterEventSender(org.apache.cxf.ext.logging.event.PrintWriterEventSender) FileWriter(java.io.FileWriter) URI(java.net.URI) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 2 with PrintWriterEventSender

use of org.apache.cxf.ext.logging.event.PrintWriterEventSender in project cxf by apache.

the class InterceptorFaultTest method testRobustFailWithoutAddressingInUserLogicalPhase.

@Test
public void testRobustFailWithoutAddressingInUserLogicalPhase() throws Exception {
    setupGreeter("org/apache/cxf/systest/interceptor/no-addr.xml", false);
    control.setRobustInOnlyMode(true);
    // behaviour is identicial for all phases
    FaultLocation location = new org.apache.cxf.greeter_control.types.ObjectFactory().createFaultLocation();
    location.setPhase("user-logical");
    control.setFaultLocation(location);
    try {
        // writer to grab the content of soap fault.
        // robust is not yet used at client's side, but I think it should
        StringWriter writer = new StringWriter();
        ((Client) greeter).getInInterceptors().add(new LoggingInInterceptor(new PrintWriterEventSender(new PrintWriter(writer))));
        // it should tell CXF to convert one-way robust out faults into real SoapFaultException
        ((Client) greeter).getEndpoint().put(Message.ROBUST_ONEWAY, true);
        greeter.greetMeOneWay("oneway");
        fail("Oneway operation unexpectedly succeded for phase " + location.getPhase());
    } catch (SOAPFaultException ex) {
    // expected
    }
}
Also used : StringWriter(java.io.StringWriter) PrintWriterEventSender(org.apache.cxf.ext.logging.event.PrintWriterEventSender) FaultLocation(org.apache.cxf.greeter_control.types.FaultLocation) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 3 with PrintWriterEventSender

use of org.apache.cxf.ext.logging.event.PrintWriterEventSender in project cxf by apache.

the class MtomFeatureClientServerTest method setupOutLogging.

private ByteArrayOutputStream setupOutLogging() {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(bos, true);
    LoggingOutInterceptor out = new LoggingOutInterceptor(new PrintWriterEventSender(writer));
    this.bus.getOutInterceptors().add(out);
    return bos;
}
Also used : PrintWriterEventSender(org.apache.cxf.ext.logging.event.PrintWriterEventSender) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter)

Example 4 with PrintWriterEventSender

use of org.apache.cxf.ext.logging.event.PrintWriterEventSender in project cxf by apache.

the class StringArrayTest method testStringArrayList.

@Test
public void testStringArrayList() throws Exception {
    SpringBusFactory factory = new SpringBusFactory();
    Bus bus = factory.createBus();
    BusFactory.setDefaultBus(bus);
    setBus(bus);
    StringWriter swin = new java.io.StringWriter();
    java.io.PrintWriter pwin = new java.io.PrintWriter(swin);
    LoggingInInterceptor logIn = new LoggingInInterceptor(new PrintWriterEventSender(pwin));
    StringWriter swout = new java.io.StringWriter();
    java.io.PrintWriter pwout = new java.io.PrintWriter(swout);
    LoggingOutInterceptor logOut = new LoggingOutInterceptor(new PrintWriterEventSender(pwout));
    getBus().getInInterceptors().add(logIn);
    getBus().getOutInterceptors().add(logOut);
    SOAPServiceRPCLit service = new SOAPServiceRPCLit();
    StringListTest port = service.getSoapPortRPCLit();
    updateAddressPort(port, PORT);
    String[] strs = new String[] { "org", "apache", "cxf" };
    String[] res = port.stringListTest(strs);
    assertArrayEquals(strs, res);
    assertTrue("Request message is not marshalled correctly and @XmlList does not take effect:\n" + swout.toString(), swout.toString().indexOf("<in>org apache cxf</in>") > -1);
    assertTrue("Response message is not marshalled correctly and @XmlList does not take effect\n" + swin.toString(), swin.toString().indexOf("<out>org apache cxf</out>") > -1);
}
Also used : Bus(org.apache.cxf.Bus) PrintWriterEventSender(org.apache.cxf.ext.logging.event.PrintWriterEventSender) SOAPServiceRPCLit(org.apache.stringarray.SOAPServiceRPCLit) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) StringWriter(java.io.StringWriter) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) StringListTest(org.apache.stringarray.StringListTest) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Test(org.junit.Test) StringListTest(org.apache.stringarray.StringListTest)

Aggregations

PrintWriterEventSender (org.apache.cxf.ext.logging.event.PrintWriterEventSender)4 PrintWriter (java.io.PrintWriter)3 StringWriter (java.io.StringWriter)2 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)2 Test (org.junit.Test)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 URI (java.net.URI)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 FaultLocation (org.apache.cxf.greeter_control.types.FaultLocation)1 SOAPServiceRPCLit (org.apache.stringarray.SOAPServiceRPCLit)1 StringListTest (org.apache.stringarray.StringListTest)1