Aby uzyskać odpowiedź xml z komunikatu mydła, można użyć "CacheAndWriteOutputStream" i "CachedOutputStreamCallback". W klasie wywołania zwrotnego można uzyskać komunikat przed zamknięciem strumienia. Powiedzmy, nasz odchodzący LoggingInterceptor jest „wsLoggingOutInterceptor”, które mogą być skonfigurowane w pliku kontekstowego następująco:
<bean id="loggingInInterceptor" class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
<bean id="logOutInterceptor" class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
<bean id="wsLoggingOutInterceptor" class="org.jinouts.webservice.logging.WSLoggingOutInterceptor"></bean>
<cxf:bus>
<cxf:inInterceptors>
<ref bean="loggingInInterceptor"/>
</cxf:inInterceptors>
<cxf:outInterceptors>
<ref bean="logOutInterceptor"/>
<ref bean="wsLoggingOutInterceptor"/>
</cxf:outInterceptors>
</cxf:bus>
zauważyć, że mamy tu również pewne domyślne przechwytywania, który jest dostępny z słoików CXF. Teraz w naszym własnym kolektora możemy zapisać w następujący sposób, aby zalogować się komunikat odpowiedzi wyjście lub można również edytować tutaj:
/**
* @author asraf
* [email protected]
*/
public class WSLoggingOutInterceptor extends AbstractLoggingInterceptor
{
public WSLoggingOutInterceptor()
{
super(Phase.PRE_STREAM);
}
@Override
public void handleMessage (Message message) throws Fault
{
// TODO Auto-generated method stub
OutputStream os = message.getContent (OutputStream.class);
CacheAndWriteOutputStream cwos = new CacheAndWriteOutputStream (os);
message.setContent (OutputStream.class, cwos);
cwos.registerCallback (new LoggingOutCallBack ());
}
@Override
protected Logger getLogger ()
{
// TODO Auto-generated method stub
return null;
}
}
class LoggingOutCallBack implements CachedOutputStreamCallback
{
@Override
public void onClose (CachedOutputStream cos)
{
try
{
if (cos != null)
{
System.out.println ("Response XML in out Interceptor : " + IOUtils.toString (cos.getInputStream ()));
}
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onFlush (CachedOutputStream arg0)
{
}
}
Wystarczy popatrzeć na tej stronie więcej szczegółów: http://cxf.apache.org/docs/interceptors.html
może mi dać jakieś sugestie? Dzięki! – user809965
Szukasz treści SOAP jako ciąg lub jako obiekt? – ThomasRS