public class SoapClient extends HttpBase<SoapClient>
此对象用于构建一个SOAP消息,并通过HTTP接口发出消息内容。
SOAP消息本质上是一个XML文本,可以通过调用getMsgStr(boolean)
方法获取消息体
使用方法:
SoapClient client = SoapClient.create(url) .setMethod(methodName, namespaceURI) .setCharset(CharsetUtil.CHARSET_GBK) .setParam(param1, "XXX"); String response = client.send(true);
body, charset, DEFAULT_CHARSET, headers, HTTP_1_0, HTTP_1_1, httpVersion
Constructor and Description |
---|
SoapClient(String url)
构造,默认使用soap1.1版本协议
|
SoapClient(String url,
SoapProtocol protocol)
构造
|
SoapClient(String url,
SoapProtocol protocol,
String namespaceURI)
构造
|
Modifier and Type | Method and Description |
---|---|
SOAPHeaderElement |
addSOAPHeader(QName name)
增加SOAP头信息,方法返回
SOAPHeaderElement 可以设置具体属性和子节点 |
SOAPHeaderElement |
addSOAPHeader(QName name,
String actorURI,
String roleUri,
Boolean mustUnderstand,
Boolean relay)
增加SOAP头信息,方法返回
SOAPHeaderElement 可以设置具体属性和子节点 |
SOAPHeaderElement |
addSOAPHeader(String localName)
增加SOAP头信息,方法返回
SOAPHeaderElement 可以设置具体属性和子节点 |
SOAPHeaderElement |
addSOAPHeader(String localName,
String value)
增加SOAP头信息,方法返回
SOAPHeaderElement 可以设置具体属性和子节点 |
SoapClient |
charset(Charset charset)
设置字符集
|
static SoapClient |
create(String url)
创建SOAP客户端,默认使用soap1.1版本协议
|
static SoapClient |
create(String url,
SoapProtocol protocol)
创建SOAP客户端
|
static SoapClient |
create(String url,
SoapProtocol protocol,
String namespaceURI)
创建SOAP客户端
|
SOAPMessage |
getMessage()
获取SOAP消息对象
SOAPMessage |
SOAPBodyElement |
getMethodEle()
获取方法节点
用于创建子节点等操作 |
String |
getMsgStr(boolean pretty)
获取SOAP请求消息
|
SoapClient |
init(SoapProtocol protocol)
初始化
|
SoapClient |
reset()
重置SOAP客户端,用于客户端复用
重置后需调用serMethod方法重新指定请求方法,并调用setParam方法重新定义参数
|
String |
send()
执行Webservice请求,即发送SOAP内容
|
String |
send(boolean pretty)
执行Webservice请求,即发送SOAP内容
|
SOAPMessage |
sendForMessage()
执行Webservice请求,即发送SOAP内容
|
HttpResponse |
sendForResponse()
发送请求,获取异步响应
|
SoapClient |
setCharset(Charset charset)
设置编码
|
SoapClient |
setConnectionTimeout(int milliseconds)
设置连接超时,单位:毫秒
|
SoapClient |
setMethod(Name name,
Map<String,Object> params,
boolean useMethodPrefix)
设置请求方法
|
SoapClient |
setMethod(QName name)
设置请求方法
|
SoapClient |
setMethod(QName name,
Map<String,Object> params,
boolean useMethodPrefix)
设置请求方法
|
SoapClient |
setMethod(String methodName)
设置请求方法
方法名自动识别前缀,前缀和方法名使用“:”分隔 当识别到前缀后,自动添加xmlns属性,关联到默认的namespaceURI |
SoapClient |
setMethod(String methodName,
String namespaceURI)
设置请求方法
方法名自动识别前缀,前缀和方法名使用“:”分隔 当识别到前缀后,自动添加xmlns属性,关联到传入的namespaceURI |
SoapClient |
setParam(String name,
Object value)
设置方法参数,使用方法的前缀
|
SoapClient |
setParam(String name,
Object value,
boolean useMethodPrefix)
设置方法参数
|
SoapClient |
setParams(Map<String,Object> params)
批量设置参数,使用方法的前缀
|
SoapClient |
setParams(Map<String,Object> params,
boolean useMethodPrefix)
批量设置参数
|
SoapClient |
setReadTimeout(int milliseconds)
设置连接超时,单位:毫秒
|
SoapClient |
setUrl(String url)
设置Webservice请求地址
|
SoapClient |
timeout(int milliseconds)
设置超时,单位:毫秒
超时包括: 1. |
SoapClient |
write(OutputStream out)
将SOAP消息的XML内容输出到流
|
addHeaders, bodyBytes, charset, charset, clearHeaders, header, header, header, header, header, header, header, header, headerList, headerMap, headers, httpVersion, httpVersion, removeHeader, removeHeader, toString
public SoapClient(String url)
url
- WS的URL地址public SoapClient(String url, SoapProtocol protocol)
url
- WS的URL地址protocol
- 协议版本,见SoapProtocol
public SoapClient(String url, SoapProtocol protocol, String namespaceURI)
url
- WS的URL地址protocol
- 协议版本,见SoapProtocol
namespaceURI
- 方法上的命名空间URIpublic static SoapClient create(String url)
url
- WS的URL地址public static SoapClient create(String url, SoapProtocol protocol)
url
- WS的URL地址protocol
- 协议,见SoapProtocol
public static SoapClient create(String url, SoapProtocol protocol, String namespaceURI)
url
- WS的URL地址protocol
- 协议,见SoapProtocol
namespaceURI
- 方法上的命名空间URIpublic SoapClient init(SoapProtocol protocol)
protocol
- 协议版本枚举,见SoapProtocol
public SoapClient reset()
重置后需调用serMethod方法重新指定请求方法,并调用setParam方法重新定义参数
public SoapClient setCharset(Charset charset)
charset
- 编码charset(Charset)
public SoapClient charset(Charset charset)
HttpBase
charset
in class HttpBase<SoapClient>
charset
- 字符集CharsetUtil
public SoapClient setUrl(String url)
url
- Webservice请求地址public SOAPHeaderElement addSOAPHeader(QName name, String actorURI, String roleUri, Boolean mustUnderstand, Boolean relay)
SOAPHeaderElement
可以设置具体属性和子节点name
- 头信息标签名actorURI
- 中间的消息接收者roleUri
- Role的URImustUnderstand
- 标题项对于要对其进行处理的接收者来说是强制的还是可选的relay
- relay属性SOAPHeaderElement
public SOAPHeaderElement addSOAPHeader(String localName)
SOAPHeaderElement
可以设置具体属性和子节点localName
- 头节点名称SOAPHeaderElement
public SOAPHeaderElement addSOAPHeader(String localName, String value)
SOAPHeaderElement
可以设置具体属性和子节点localName
- 头节点名称value
- 头节点的值SOAPHeaderElement
public SOAPHeaderElement addSOAPHeader(QName name)
SOAPHeaderElement
可以设置具体属性和子节点name
- 头节点名称SOAPHeaderElement
public SoapClient setMethod(Name name, Map<String,Object> params, boolean useMethodPrefix)
name
- 方法名及其命名空间params
- 参数useMethodPrefix
- 是否使用方法的命名空间前缀public SoapClient setMethod(QName name, Map<String,Object> params, boolean useMethodPrefix)
name
- 方法名及其命名空间params
- 参数useMethodPrefix
- 是否使用方法的命名空间前缀public SoapClient setMethod(String methodName)
methodName
- 方法名public SoapClient setMethod(String methodName, String namespaceURI)
methodName
- 方法名(可有前缀也可无)namespaceURI
- 命名空间URIpublic SoapClient setMethod(QName name)
name
- 方法名及其命名空间public SoapClient setParam(String name, Object value)
name
- 参数名value
- 参数值,可以是字符串或Map或SOAPElement
public SoapClient setParam(String name, Object value, boolean useMethodPrefix)
name
- 参数名value
- 参数值,可以是字符串或Map或SOAPElement
useMethodPrefix
- 是否使用方法的命名空间前缀public SoapClient setParams(Map<String,Object> params)
params
- 参数列表public SoapClient setParams(Map<String,Object> params, boolean useMethodPrefix)
params
- 参数列表useMethodPrefix
- 是否使用方法的命名空间前缀public SOAPBodyElement getMethodEle()
SOAPBodyElement
public SOAPMessage getMessage()
SOAPMessage
SOAPMessage
public String getMsgStr(boolean pretty)
pretty
- 是否格式化public SoapClient write(OutputStream out)
out
- 输出流public SoapClient timeout(int milliseconds)
1. 连接超时 2. 读取响应超时
milliseconds
- 超时毫秒数setConnectionTimeout(int)
,
setReadTimeout(int)
public SoapClient setConnectionTimeout(int milliseconds)
milliseconds
- 超时毫秒数public SoapClient setReadTimeout(int milliseconds)
milliseconds
- 超时毫秒数public SOAPMessage sendForMessage()
public String send()
public String send(boolean pretty)
pretty
- 是否格式化public HttpResponse sendForResponse()
Copyright © 2024. All rights reserved.