web services - Spring ws logging issue with SLF4j -


hi using spring ws + slf4j logging. while logging soap request & response using below propertiesin application.properties

logging.level.org.springframework.ws.client.messagetracing.sent=debug logging.level.org.springframework.ws.server.messagetracing.sent=debug logging.level.org.springframework.ws.client.messagetracing.received=trace logging.level.org.springframework.ws.server.messagetracing.received=trace 

instead of logging request & response prints following object,

13:13:06.155 [main] debug o.s.ws.client.messagetracing.sent - sent request  [saajsoapmessage {http://ws.sample.customer.com/}getcustomerdetails] 13:13:06.411 [main] debug o.s.w.client.messagetracing.received - received   response [saajsoapmessage  {http://ws.sample.customer.com/}getcustomerdetailsresponse] request [saajsoapmessage {http://ws.sample.customer.com/}getcustomerdetails] 

i calling webservice using following way :

 return (jaxbelement) getwebservicetemplate().marshalsendandreceive(uri, request, webservicemessage -> {             soapmessage soapmessage = (soapmessage) webservicemessage;             marshaller marshaller = getmarshaller();             marshaller.marshal(jaxbelement, soapmessage.getsoapheader().getresult());         }); 

i don't know why not printing request & response. tried intercept request & response using "soapenvelopelogginginterceptor" or "clientinterceptor" nothing triggered got response object.

public class logbackinterceptor implements clientinterceptor {  private static final logger logger = loggerfactory.getlogger(logbackinterceptor.class);   public boolean handlerequest(messagecontext messagecontext) throws webserviceclientexception {        logger.debug("sent request sample [" + messagecontext.getrequest() + "]");        return true;  }   public boolean handleresponse(messagecontext messagecontext) throws webserviceclientexception {        logger.debug("received response sample [" + messagecontext.getresponse() + "] request [" +                             messagecontext.getrequest() + "]");        return true;  }  @override public boolean handlefault(messagecontext messagecontext) throws webserviceclientexception {     // todo auto-generated method stub     return false; }  @override public void aftercompletion(messagecontext messagecontext, exception ex) throws webserviceclientexception {     // todo auto-generated method stub  } 

}

@component public class logginginterceptor  extends soapenvelopelogginginterceptor{  private static final logger logger = loggerfactory.getlogger(logginginterceptor.class);  @override protected void logmessage(string message) {     system.out.println("entered log message");     logger.debug("logginginterceptor::logmessage");     logger.debug(message); /* example, here logging db or whatever want */ } } 

it great if helped me resolve issue

finally found solution hope should others,

we should register "clientinterceptor" in webservicetemplate otherwise spring won't trigger "clientinterceptor".the below code works charm , able intercept request & response.

webservicetemplate webservicetemplate = getwebservicetemplate(); clientinterceptor[] interceptors = new clientinterceptor[1]; interceptors[0] = new logbackinterceptor(); webservicetemplate.setinterceptors(interceptors); 

Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -