java获取web.xml,从Java Web服务客户端获取原始XML响应

I am trying to get the raw XML response from a web service, instead of the usual set of POJOs.

I am using a webservice client that I generated (so I have access to the client's code) from a WSDL and some schemas. The client is generated in RAD 7.5, I think using JAX-WS. I've been looking at the client code itself, but I'm not even sure if the client code ever handles raw XML or if it passes it off to other libraries.

解决方案

You can do it using

javax.xml.ws.handler.soap.SOAPHandler

you can simply get message using SOAPMessageContext#getMessage() and convert message to String using method

public static String getXmlMessage(SOAPMessage message) throws Exception

{

ByteArrayOutputStream os = new ByteArrayOutputStream();

message.writeTo(os);

final String encoding = (String) message.getProperty(SOAPMessage.CHARACTER_SET_ENCODING);

if (encoding == null)

{

return new String(os.toByteArray());

}

else

{

return new String(os.toByteArray(), encoding);

}

}

Also you can read here about SOAP handler on client side

Article

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值