You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Stephane Eybert <mi...@yahoo.se> on 2012/04/03 17:14:51 UTC
Client inbound interceptor registered callback not fired up
Hello,
I have an inbound interceptor on the client side, that is correctly
contributed, added and invoked:
2012-04-03 16:58:07,453 DEBUG [ClientImpl] Interceptors contributed by
client: [no.nki.stas.ws.client.interceptor.XmlInInterceptor@1fc3828,
org.apache.cxf.interceptor.LoggingInInterceptor@1cb048e]
2012-04-03 16:58:07,454 DEBUG [PhaseInterceptorChain] Adding interceptor
no.nki.stas.ws.client.interceptor.XmlInInterceptor@1fc3828 to phase receive
2012-04-03 16:58:07,457 DEBUG [PhaseInterceptorChain] Invoking
handleMessage on interceptor
no.nki.stas.ws.client.interceptor.XmlInInterceptor@1fc3828
2012-04-03 16:58:07,457 DEBUG [XmlInInterceptor] ============>> In client
handleMessage
But its registered callback is not fired up.
The logger "============>> In LoggingCallback constructor" is not displayed
in the console log, nor is the logger "============>> In onClose".
Here is my interceptor class:
@NoJSR250Annotations
public class XmlInInterceptor extends AbstractSoapInterceptor {
private Logger logger = LoggerFactory.getLogger(XmlInInterceptor.class);
public XmlInInterceptor() {
super(Phase.RECEIVE);
}
public void handleMessage(SoapMessage soapMessage) throws Fault {
logger.debug("============>> In handleMessage");
final OutputStream os = soapMessage.getContent(OutputStream.class);
if (os == null) {
return;
}
final CacheAndWriteOutputStream newOut = new
CacheAndWriteOutputStream(os);
soapMessage.setContent(OutputStream.class, newOut);
newOut.registerCallback(new LoggingCallback(soapMessage, os));
}
private class LoggingCallback implements CachedOutputStreamCallback {
private final Message message;
private final OutputStream origStream;
public LoggingCallback(final Message msg, final OutputStream os) {
this.message = msg;
logger.debug("============>> In LoggingCallback constructor");
this.origStream = os;
}
public void onFlush(CachedOutputStream cos) {
}
public void onClose(CachedOutputStream cos) {
logger.debug("============>> In onClose");
String encoding = (String) message.get(Message.ENCODING);
String ct = (String) message.get(Message.CONTENT_TYPE);
StringBuilder builder = new StringBuilder();
try {
writePayload(builder, cos, encoding, ct);
} catch (IOException ex) {
throw new RuntimeException("Cannot generate audit log for soap
response", ex);
}
String msg = builder.toString();
logger.debug("CLIENT IN MESSAGE {}", msg);
message.setContent(OutputStream.class, origStream);
}
protected void writePayload(StringBuilder builder, CachedOutputStream cos,
String encoding, String contentType) throws IOException {
if (StringUtils.isEmpty(encoding)) {
cos.writeCacheTo(builder);
} else {
cos.writeCacheTo(builder, encoding);
}
}
}
}
Kind Regards,
Stephane
--
View this message in context: http://cxf.547215.n5.nabble.com/Client-inbound-interceptor-registered-callback-not-fired-up-tp5615483p5615483.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Client inbound interceptor registered callback not fired up
Posted by Stephane Eybert <mi...@yahoo.se>.
You know what, I wondered if that output stream had any meaning related to
the chaining direction, and reckoned it did not and was just a helper to
output content. So I was wrong. There must be then something to the tune of
an input stream maybe ? I'll wake up Google. Thanks for the pointing.
Stephane
--
View this message in context: http://cxf.547215.n5.nabble.com/Client-inbound-interceptor-registered-callback-not-fired-up-tp5615483p5616418.html
Sent from the cxf-user mailing list archive at Nabble.com.
Re: Client inbound interceptor registered callback not fired up
Posted by Daniel Kulp <dk...@apache.org>.
You are on the INBOUND chain but looking for an OUTPUT stream?
I think something is a bit mixed up there....
Dan
On Tuesday, April 03, 2012 08:14:51 AM Stephane Eybert wrote:
> Hello,
>
> I have an inbound interceptor on the client side, that is correctly
> contributed, added and invoked:
>
> 2012-04-03 16:58:07,453 DEBUG [ClientImpl] Interceptors contributed by
> client: [no.nki.stas.ws.client.interceptor.XmlInInterceptor@1fc3828,
> org.apache.cxf.interceptor.LoggingInInterceptor@1cb048e]
>
> 2012-04-03 16:58:07,454 DEBUG [PhaseInterceptorChain] Adding interceptor
> no.nki.stas.ws.client.interceptor.XmlInInterceptor@1fc3828 to phase
> receive
>
> 2012-04-03 16:58:07,457 DEBUG [PhaseInterceptorChain] Invoking
> handleMessage on interceptor
> no.nki.stas.ws.client.interceptor.XmlInInterceptor@1fc3828
> 2012-04-03 16:58:07,457 DEBUG [XmlInInterceptor] ============>> In client
> handleMessage
>
> But its registered callback is not fired up.
>
> The logger "============>> In LoggingCallback constructor" is not
> displayed in the console log, nor is the logger "============>> In
> onClose".
>
> Here is my interceptor class:
>
> @NoJSR250Annotations
> public class XmlInInterceptor extends AbstractSoapInterceptor {
>
> private Logger logger =
LoggerFactory.getLogger(XmlInInterceptor.class);
>
> public XmlInInterceptor() {
> super(Phase.RECEIVE);
> }
>
> public void handleMessage(SoapMessage soapMessage) throws Fault {
> logger.debug("============>> In handleMessage");
> final OutputStream os =
soapMessage.getContent(OutputStream.class);
> if (os == null) {
> return;
> }
> final CacheAndWriteOutputStream newOut = new
> CacheAndWriteOutputStream(os);
> soapMessage.setContent(OutputStream.class, newOut);
>
> newOut.registerCallback(new LoggingCallback(soapMessage, os));
> }
>
> private class LoggingCallback implements CachedOutputStreamCallback {
>
> private final Message message;
> private final OutputStream origStream;
>
> public LoggingCallback(final Message msg, final OutputStream os) {
> this.message = msg;
> logger.debug("============>> In LoggingCallback
constructor");
> this.origStream = os;
> }
>
> public void onFlush(CachedOutputStream cos) {
> }
>
> public void onClose(CachedOutputStream cos) {
> logger.debug("============>> In onClose");
> String encoding = (String) message.get(Message.ENCODING);
> String ct = (String) message.get(Message.CONTENT_TYPE);
> StringBuilder builder = new StringBuilder();
> try {
> writePayload(builder, cos, encoding, ct);
> } catch (IOException ex) {
> throw new RuntimeException("Cannot generate audit log
for soap
> response", ex);
> }
>
> String msg = builder.toString();
> logger.debug("CLIENT IN MESSAGE {}", msg);
> message.setContent(OutputStream.class, origStream);
> }
>
> protected void writePayload(StringBuilder builder,
CachedOutputStream
> cos, String encoding, String contentType) throws IOException {
> if (StringUtils.isEmpty(encoding)) {
> cos.writeCacheTo(builder);
> } else {
> cos.writeCacheTo(builder, encoding);
> }
> }
>
> }
>
> }
>
> Kind Regards,
>
> Stephane
>
>
> --
> View this message in context:
> http://cxf.547215.n5.nabble.com/Client-inbound-interceptor-registered-cal
> lback-not-fired-up-tp5615483p5615483.html Sent from the cxf-user mailing
> list archive at Nabble.com.
--
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com