目录
4、axis2中发送http请求时,如何设置http请求头?
1、如何将JDK中JAX-WS引擎切换成axis2?
JDK中JAX-WS引擎的选择和加载,主要是在以下几个类中完成的:
javax.xml.ws.spi.Provider
javax.xml.ws.spi.FactoryFinder
JDK中默认的JAX-WS引擎是metro,它对javax.xml.ws.spi.Provider接口的实现为:
com.sun.xml.internal.ws.spi.ProviderImpl
如果要切换成axis2,则需要加载axis2对javax.xml.ws.spi.Provider接口的实现:
org.apache.axis2.jaxws.spi.Provider
2、如何查看axis2发送和请求报文?
JDK中默认的JAX-WS引擎是metro,它查看发送和请求报文的方式为:
-Dcom.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump=true
axis2 是在org.apache.axis2.transport.http.HTTPSender中调用HttpClient的真正向socket中写入是在org.apache.commons.httpclient.HttpMethodBase中完成的。
由于axis2使用commons-httpClient发送http soap请求,可在log4j中配置:
log4j.logger.httpclient.wire.header=DEBUG, A2
log4j.additivity.httpclient.wire.header=false
log4j.logger.httpclient.wire.content=DEBUG, A2
log4j.additivity.httpclient.wire.content=false
若没有使用log4j而是使用commons-logging,也可使用如下配置:
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire.header", "debug");
System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient", "debug");
或在commons-logging.properties中写入:
org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
并创建simplelog.properties,写入以下内容:
# org.apache.commons.logging.simplelog.defaultlog=all
org.apache.commons.logging.simplelog.showdatetime=true
org.apache.commons.logging.simplelog.log.com.sock=debug
3、如何设置axis2中的字符编码?
先通过如下方式设置字符编码:
org.apache.axis2.jaxws.core.MessageContext mc = org.apache.axis2.jaxws.core.new MessageContext();
mc.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING, "GBK");
axis2会在如下代码中将字符编码设置到 OMOutputFormat format = new OMOutputFormat()中:
org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(MessageContext msgContext)
4、axis2中发送http请求时,如何设置http请求头?
给org.apache.axis2.context.MessageContext添加属性,其中
key是org.apache.axis2.transport.http.HTTPConstants.HTTP_HEADERS
value设置成Map<请求头名称,请求头值>
并最终通过如下方法添加的:
org.apache.axis2.transport.http.AbstractHTTPSender.addCustomHeaders