问题
I have generated java clients uisng wsdl2java using axis2. My client programs can sucessfully connect to webservice. I want to log outgoing soap request to read soap message.
Can someone direct me to an article expaining how can I log soap messages in Axis2.
回答1:
I realize this is an old question, but in case it helps anyone you can turn on logging by putting this tag into both the <requestFlow>
and <responseFlow>
sections of your globalConfig in your server-config.wsdd file:
<handler type="java:org.apache.axis.handlers.LogHandler"/>
回答2:
you can additionally consider writing a custom axis module for logging - check http://axis.apache.org/axis2/java/core/docs/modules.html for more information
回答3:
If you're using Axis2 Data Binding, then the automatically-generated classes for your web services will all be subclasses of ADBBean. You can use something like the following to convert an ADBBean to a string, then log the string.
public static String
writeADBBean(ADBBean aBean) throws XMLStreamException {
if (null == aBean)
return "null";
OMElement omElement;
try
{
// The preferred way of serializing objects generated by Axis2's
// WSDL2JAVA involves methods that are named the same on every
// class but that aren't inherited from any base class. So, use
// reflection to find them.
QName qname;
try {
Field qnameField = aBean.getClass().getField("MY_QNAME");
qname = (QName)qnameField.get(aBean);
} catch (Exception e) {
// Some Axis2-generated objects don't have QNames. Supply
// one based on the object's class.
qname = new QName(aBean.getClass().getCanonicalName());
}
Method getOMElement = aBean.getClass().getMethod("getOMElement", QName.class, OMFactory.class);
omElement = (OMElement)getOMElement.invoke(aBean, qname, OMAbstractFactory.getOMFactory());
} catch (Exception e) {
log.warn("Reflection failed for " + aBean.toString() + ": " + e.toString());
throw new XMLStreamException("Cannot serialize " + aBean.toString(), e);
} catch (NoClassDefFoundError e) {
log.error("NoClassDefFoundError while serializing " + aBean.toString() + ": " + e.toString());
throw new XMLStreamException("Cannot serialize " + aBean.toString(), e);
}
String serialized = omElement.toStringWithConsume();
return serialized;
}
回答4:
Please see Step 6 here: Axis2 Hello world. Besides that, you may check SoapUI
来源:https://stackoverflow.com/questions/4548334/axis2-soap-logging