I have been fiddling around with server side interceptors on CXF. But is seems that it is not a trivial task to implement simple incoming and outgoing interceptors that give me a plain string containing the SOAP XML.
I need to have the plain XML in the interceptor so that I can use them for specific logging tasks. The standard LogIn & LogOut interceptors are not up to the task. Is anyone willing to share some example on how I could implement a simple incoming interceptor that is able to get the incoming SOAP XML and a outgoing interceptor to again get the SOAP XML?
Make sure the “do not disturb” option is deactivated on your phone. Note: Depending on your phone model and operating system, the "do not disturb" option may completely reject calls, or it may mute ringtones and other audible alerts. Make sure you test your phone to find out how it handles “do not disturb”.
Android 9.0Find and tap Phone. Tap the menu button (three vertical dots), then tap Settings. Tap Calls > Additional settings. Tap the switch beside Call waiting to enable the function.
Found the code for an incoming interceptor here: Logging request/response with Apache CXF as XML
My outgoing interceptor:
import java.io.OutputStream;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.io.CacheAndWriteOutputStream;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.io.CachedOutputStreamCallback;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.Phase;
public class MyLogInterceptor extends LoggingOutInterceptor {
public MyLogInterceptor() {
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage(Message message) throws Fault {
OutputStream out = message.getContent(OutputStream.class);
final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(out);
message.setContent(OutputStream.class, newOut);
newOut.registerCallback(new LoggingCallback());
}
public class LoggingCallback implements CachedOutputStreamCallback {
public void onFlush(CachedOutputStream cos) {
}
public void onClose(CachedOutputStream cos) {
try {
StringBuilder builder = new StringBuilder();
cos.writeCacheTo(builder, limit);
// here comes my xml:
String soapXml = builder.toString();
} catch (Exception e) {
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With