Module bus.http

Class SoapBuilder

java.lang.Object
org.miaixz.bus.http.plugin.soap.SoapBuilder

public class SoapBuilder extends Object
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 Details

    • SoapBuilder

      public SoapBuilder(String url)
      Constructs a new SoapBuilder with the default SOAP 1.2 protocol.
      Parameters:
      url - The URL of the web service.
    • SoapBuilder

      public SoapBuilder(String url, org.miaixz.bus.core.net.Protocol protocol)
      Constructs a new SoapBuilder with a specified protocol version.
      Parameters:
      url - The URL of the web service.
      protocol - The protocol version, see Protocol.
    • SoapBuilder

      public SoapBuilder(String url, org.miaixz.bus.core.net.Protocol protocol, String namespaceURI)
      Constructs a new SoapBuilder with a specified protocol version and namespace URI.
      Parameters:
      url - The URL of the web service.
      protocol - The protocol version, see Protocol.
      namespaceURI - The namespace URI for the method.
  • Method Details

    • of

      public static SoapBuilder of(String url)
      Creates a new SOAP client with the default SOAP 1.2 protocol.
      Parameters:
      url - The URL of the web service.
      Returns:
      A new SoapBuilder instance.
    • of

      public static SoapBuilder of(String url, org.miaixz.bus.core.net.Protocol protocol)
      Creates a new SOAP client with a specified protocol.
      Parameters:
      url - The URL of the web service.
      protocol - The protocol version, see Protocol.
      Returns:
      A new SoapBuilder instance.
    • 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, see Protocol.
      namespaceURI - The namespace URI for the method.
      Returns:
      A new SoapBuilder instance.
    • init

      public SoapBuilder init(org.miaixz.bus.core.net.Protocol protocol)
      Initializes the SOAP client.
      Parameters:
      protocol - The protocol version enum, see Protocol.
      Returns:
      This SoapBuilder instance.
    • reset

      public SoapBuilder reset()
      Resets the SOAP client for reuse. After resetting, you must call setMethod to specify a new request method and setParam to redefine the parameters.
      Returns:
      This SoapBuilder instance.
    • charset

      public SoapBuilder charset(Charset charset)
      Sets the character encoding.
      Parameters:
      charset - The character encoding.
      Returns:
      This SoapBuilder instance.
    • setUrl

      public SoapBuilder setUrl(String url)
      Sets the web service request URL.
      Parameters:
      url - The web service request URL.
      Returns:
      This SoapBuilder instance.
    • header

      public SoapBuilder header(String name, String value, boolean isOverride)
      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 SoapBuilder instance.
    • headers

      public Map<String,String> headers()
      Gets the headers.
      Returns:
      The header map.
    • clearHeaders

      public SoapBuilder clearHeaders()
      Clears all headers, including global headers.
      Returns:
      This SoapBuilder instance.
    • addSOAPHeader

      public jakarta.xml.soap.SOAPHeaderElement addSOAPHeader(QName name, String actorURI, String roleUri, Boolean mustUnderstand, Boolean relay)
      Adds a SOAP header. The method returns a SOAPHeaderElement that 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

      public jakarta.xml.soap.SOAPHeaderElement addSOAPHeader(String localName)
      Adds a SOAP header. The method returns a SOAPHeaderElement that can be used to set attributes and child nodes.
      Parameters:
      localName - The local name of the header element.
      Returns:
      The SOAPHeaderElement.
    • addSOAPHeader

      public jakarta.xml.soap.SOAPHeaderElement addSOAPHeader(String localName, String value)
      Adds a SOAP header with a value. The method returns a SOAPHeaderElement that 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

      public jakarta.xml.soap.SOAPHeaderElement addSOAPHeader(QName name)
      Adds a SOAP header. The method returns a SOAPHeaderElement that 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 SoapBuilder instance.
    • setMethod

      public SoapBuilder setMethod(QName 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 SoapBuilder instance.
    • setMethod

      public SoapBuilder setMethod(String methodName)
      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 SoapBuilder instance.
    • setMethod

      public SoapBuilder setMethod(String methodName, String namespaceURI)
      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 SoapBuilder instance.
    • setMethod

      public SoapBuilder setMethod(QName name)
      Sets the request method.
      Parameters:
      name - The name and namespace of the method.
      Returns:
      This SoapBuilder instance.
    • setParam

      public SoapBuilder setParam(String name, Object value)
      Sets a method parameter, using the method's prefix.
      Parameters:
      name - The parameter name.
      value - The parameter value, which can be a string, map, or SOAPElement.
      Returns:
      This SoapBuilder instance.
    • setParam

      public SoapBuilder setParam(String name, Object value, boolean useMethodPrefix)
      Sets a method parameter.
      Parameters:
      name - The parameter name.
      value - The parameter value, which can be a string, map, or SOAPElement.
      useMethodPrefix - Whether to use the method's namespace prefix.
      Returns:
      This SoapBuilder instance.
    • setParams

      public SoapBuilder setParams(Map<String,Object> params)
      Sets multiple parameters, using the method's prefix.
      Parameters:
      params - The list of parameters.
      Returns:
      This SoapBuilder instance.
    • setParams

      public SoapBuilder setParams(Map<String,Object> params, boolean useMethodPrefix)
      Sets multiple parameters.
      Parameters:
      params - The list of parameters.
      useMethodPrefix - Whether to use the method's namespace prefix.
      Returns:
      This SoapBuilder instance.
    • 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

      public String getString(boolean pretty)
      Gets the SOAP request message as a string.
      Parameters:
      pretty - Whether to format the XML.
      Returns:
      The message string.
    • write

      public SoapBuilder write(OutputStream out)
      Writes the XML content of the SOAP message to an output stream.
      Parameters:
      out - The output stream.
      Returns:
      This SoapBuilder instance.
    • sendForMessage

      public jakarta.xml.soap.SOAPMessage sendForMessage()
      Executes the web service request by sending the SOAP content.
      Returns:
      The resulting SOAPMessage.
    • send

      public String send()
      Executes the web service request by sending the SOAP content.
      Returns:
      The result as a string.
    • send

      public String send(boolean pretty)
      Executes the web service request by sending the SOAP content.
      Parameters:
      pretty - Whether to format the result.
      Returns:
      The result as a string.
    • sendForResponse

      public Response sendForResponse()
      Sends the request and gets an asynchronous response.
      Returns:
      The response object.