axis2 soap logging

2019-08-27 03:23发布

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.

标签: logging axis2
4条回答
可以哭但决不认输i
2楼-- · 2019-08-27 03:37

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;
}
查看更多
乱世女痞
3楼-- · 2019-08-27 03:38

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"/>
查看更多
Rolldiameter
4楼-- · 2019-08-27 03:51

Please see Step 6 here: Axis2 Hello world. Besides that, you may check SoapUI

查看更多
淡お忘
5楼-- · 2019-08-27 03:56

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

查看更多
登录 后发表回答