java.lang.Object
org.miaixz.bus.http.plugin.soap.SoapBuilder
A builder for creating and sending SOAP messages.
This class is used to construct a SOAP message and send it via an HTTP interface. The SOAP message is essentially an
XML text, which can be retrieved by calling the getString(boolean) method.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Constructor Summary
ConstructorsConstructorDescriptionSoapBuilder(String url) Constructs a newSoapBuilderwith the default SOAP 1.2 protocol.SoapBuilder(String url, org.miaixz.bus.core.net.Protocol protocol) Constructs a newSoapBuilderwith a specified protocol version.SoapBuilder(String url, org.miaixz.bus.core.net.Protocol protocol, String namespaceURI) Constructs a newSoapBuilderwith a specified protocol version and namespace URI. -
Method Summary
Modifier and TypeMethodDescriptionjakarta.xml.soap.SOAPHeaderElementaddSOAPHeader(String localName) Adds a SOAP header.jakarta.xml.soap.SOAPHeaderElementaddSOAPHeader(String localName, String value) Adds a SOAP header with a value.jakarta.xml.soap.SOAPHeaderElementaddSOAPHeader(QName name) Adds a SOAP header.jakarta.xml.soap.SOAPHeaderElementAdds a SOAP header.Sets the character encoding.Clears all headers, including global headers.jakarta.xml.soap.SOAPMessageGets the SOAP message object.jakarta.xml.soap.SOAPBodyElementGets the method element, which can be used to create child nodes.getString(boolean pretty) Gets the SOAP request message as a string.Sets a header.headers()Gets the headers.init(org.miaixz.bus.core.net.Protocol protocol) Initializes the SOAP client.static SoapBuilderCreates a new SOAP client with the default SOAP 1.2 protocol.static SoapBuilderCreates a new SOAP client with a specified protocol.static SoapBuilderCreates a new SOAP client with a specified protocol and namespace URI.reset()Resets the SOAP client for reuse.send()Executes the web service request by sending the SOAP content.send(boolean pretty) Executes the web service request by sending the SOAP content.jakarta.xml.soap.SOAPMessageExecutes the web service request by sending the SOAP content.Sends the request and gets an asynchronous response.Sets the request method.Sets the request method.Sets the request method.Sets the request method.Sets the request method.Sets a method parameter, using the method's prefix.Sets a method parameter.Sets multiple parameters, using the method's prefix.Sets multiple parameters.Sets the web service request URL.write(OutputStream out) Writes the XML content of the SOAP message to an output stream.
-
Constructor Details
-
SoapBuilder
Constructs a newSoapBuilderwith the default SOAP 1.2 protocol.- Parameters:
url- The URL of the web service.
-
SoapBuilder
Constructs a newSoapBuilderwith a specified protocol version.- Parameters:
url- The URL of the web service.protocol- The protocol version, seeProtocol.
-
SoapBuilder
Constructs a newSoapBuilderwith a specified protocol version and namespace URI.- Parameters:
url- The URL of the web service.protocol- The protocol version, seeProtocol.namespaceURI- The namespace URI for the method.
-
-
Method Details
-
of
Creates a new SOAP client with the default SOAP 1.2 protocol.- Parameters:
url- The URL of the web service.- Returns:
- A new
SoapBuilderinstance.
-
of
Creates a new SOAP client with a specified protocol.- Parameters:
url- The URL of the web service.protocol- The protocol version, seeProtocol.- Returns:
- A new
SoapBuilderinstance.
-
of
public static SoapBuilder of(String url, org.miaixz.bus.core.net.Protocol protocol, String namespaceURI) Creates a new SOAP client with a specified protocol and namespace URI.- Parameters:
url- The URL of the web service.protocol- The protocol version, seeProtocol.namespaceURI- The namespace URI for the method.- Returns:
- A new
SoapBuilderinstance.
-
init
Initializes the SOAP client.- Parameters:
protocol- The protocol version enum, seeProtocol.- Returns:
- This
SoapBuilderinstance.
-
reset
Resets the SOAP client for reuse. After resetting, you must callsetMethodto specify a new request method andsetParamto redefine the parameters.- Returns:
- This
SoapBuilderinstance.
-
charset
Sets the character encoding.- Parameters:
charset- The character encoding.- Returns:
- This
SoapBuilderinstance.
-
setUrl
Sets the web service request URL.- Parameters:
url- The web service request URL.- Returns:
- This
SoapBuilderinstance.
-
header
Sets a header. If in override mode, it replaces the previous value; otherwise, it adds to the list of values.- Parameters:
name- The header name.value- The header value.isOverride- Whether to override an existing value.- Returns:
- This
SoapBuilderinstance.
-
headers
Gets the headers.- Returns:
- The header map.
-
clearHeaders
Clears all headers, including global headers.- Returns:
- This
SoapBuilderinstance.
-
addSOAPHeader
public jakarta.xml.soap.SOAPHeaderElement addSOAPHeader(QName name, String actorURI, String roleUri, Boolean mustUnderstand, Boolean relay) Adds a SOAP header. The method returns aSOAPHeaderElementthat can be used to set attributes and child nodes.- Parameters:
name- The name of the header element.actorURI- The URI of the intermediary actor.roleUri- The URI of the role.mustUnderstand- Whether the header is mandatory for the recipient.relay- The relay attribute.- Returns:
- The
SOAPHeaderElement.
-
addSOAPHeader
Adds a SOAP header. The method returns aSOAPHeaderElementthat can be used to set attributes and child nodes.- Parameters:
localName- The local name of the header element.- Returns:
- The
SOAPHeaderElement.
-
addSOAPHeader
Adds a SOAP header with a value. The method returns aSOAPHeaderElementthat can be used to set attributes and child nodes.- Parameters:
localName- The local name of the header element.value- The value of the header element.- Returns:
- The
SOAPHeaderElement.
-
addSOAPHeader
Adds a SOAP header. The method returns aSOAPHeaderElementthat can be used to set attributes and child nodes.- Parameters:
name- The qualified name of the header element.- Returns:
- The
SOAPHeaderElement.
-
setMethod
public SoapBuilder setMethod(jakarta.xml.soap.Name name, Map<String, Object> params, boolean useMethodPrefix) Sets the request method.- Parameters:
name- The name and namespace of the method.params- The parameters.useMethodPrefix- Whether to use the method's namespace prefix.- Returns:
- This
SoapBuilderinstance.
-
setMethod
Sets the request method.- Parameters:
name- The name and namespace of the method.params- The parameters.useMethodPrefix- Whether to use the method's namespace prefix.- Returns:
- This
SoapBuilderinstance.
-
setMethod
Sets the request method. The method name automatically recognizes a prefix, separated by a colon. When a prefix is recognized, an xmlns attribute is automatically added, associated with the default namespace URI.- Parameters:
methodName- The method name.- Returns:
- This
SoapBuilderinstance.
-
setMethod
Sets the request method. The method name automatically recognizes a prefix, separated by a colon. When a prefix is recognized, an xmlns attribute is automatically added, associated with the given namespace URI.- Parameters:
methodName- The method name (with or without a prefix).namespaceURI- The namespace URI.- Returns:
- This
SoapBuilderinstance.
-
setMethod
Sets the request method.- Parameters:
name- The name and namespace of the method.- Returns:
- This
SoapBuilderinstance.
-
setParam
Sets a method parameter, using the method's prefix.- Parameters:
name- The parameter name.value- The parameter value, which can be a string, map, orSOAPElement.- Returns:
- This
SoapBuilderinstance.
-
setParam
Sets a method parameter.- Parameters:
name- The parameter name.value- The parameter value, which can be a string, map, orSOAPElement.useMethodPrefix- Whether to use the method's namespace prefix.- Returns:
- This
SoapBuilderinstance.
-
setParams
Sets multiple parameters, using the method's prefix.- Parameters:
params- The list of parameters.- Returns:
- This
SoapBuilderinstance.
-
setParams
Sets multiple parameters.- Parameters:
params- The list of parameters.useMethodPrefix- Whether to use the method's namespace prefix.- Returns:
- This
SoapBuilderinstance.
-
getMethodEle
public jakarta.xml.soap.SOAPBodyElement getMethodEle()Gets the method element, which can be used to create child nodes.- Returns:
- The
SOAPBodyElement.
-
getMessage
public jakarta.xml.soap.SOAPMessage getMessage()Gets the SOAP message object.- Returns:
- The
SOAPMessage.
-
getString
Gets the SOAP request message as a string.- Parameters:
pretty- Whether to format the XML.- Returns:
- The message string.
-
write
Writes the XML content of the SOAP message to an output stream.- Parameters:
out- The output stream.- Returns:
- This
SoapBuilderinstance.
-
sendForMessage
public jakarta.xml.soap.SOAPMessage sendForMessage()Executes the web service request by sending the SOAP content.- Returns:
- The resulting
SOAPMessage.
-
send
Executes the web service request by sending the SOAP content.- Returns:
- The result as a string.
-
send
Executes the web service request by sending the SOAP content.- Parameters:
pretty- Whether to format the result.- Returns:
- The result as a string.
-
sendForResponse
Sends the request and gets an asynchronous response.- Returns:
- The response object.
-