Class SOAPCommunicator


  • public class SOAPCommunicator
    extends Object
    The SOAPCommunicator is a utility package to assist in SAML2 communication over SOAP.
    • Method Detail

      • getInstance

        public static SOAPCommunicator getInstance()
        Gets the singleton instance of the SOAPCommunicator.
        Returns:
        the SOAPCommunicator instance.
      • openSOAPConnection

        public jakarta.xml.soap.SOAPConnection openSOAPConnection()
                                                           throws jakarta.xml.soap.SOAPException
        Opens a SOAP Connection.
        Returns:
        a new SOAPConnection
        Throws:
        jakarta.xml.soap.SOAPException
      • createSOAPMessage

        public jakarta.xml.soap.SOAPMessage createSOAPMessage​(String xmlString,
                                                              boolean isClientMessage)
                                                       throws jakarta.xml.soap.SOAPException,
                                                              SAML2Exception
        Creates SOAPMessage with the input XML String as message body.
        Parameters:
        xmlString - XML string to be put into SOAPMessage body.
        isClientMessage - true if the message is sent from SOAP client to server.
        Returns:
        newly created SOAPMessage.
        Throws:
        jakarta.xml.soap.SOAPException - if it cannot create the SOAPMessage.
        SAML2Exception
      • createSOAPMessage

        public jakarta.xml.soap.SOAPMessage createSOAPMessage​(String header,
                                                              String body,
                                                              boolean isClientMessage)
                                                       throws jakarta.xml.soap.SOAPException,
                                                              SAML2Exception
        Creates SOAPMessage with the input XML String as message header and body.
        Parameters:
        header - XML string to be put into SOAPMessage header.
        body - XML string to be put into SOAPMessage body.
        isClientMessage - true if the message is sent from SOAP client to server.
        Returns:
        newly created SOAPMessage.
        Throws:
        jakarta.xml.soap.SOAPException - if it cannot create the SOAPMessage.
        SAML2Exception
      • getSOAPBody

        public Element getSOAPBody​(jakarta.xml.soap.SOAPMessage message)
                            throws SAML2Exception
        Returns SOAP body as DOM Element from SOAPMessage.
        Parameters:
        message - SOAPMessage object.
        Returns:
        SOAP body, return null if unable to get the SOAP body element.
        Throws:
        SAML2Exception
      • createSOAPFault

        public jakarta.xml.soap.SOAPMessage createSOAPFault​(String faultCode,
                                                            String faultString,
                                                            String detail)
        Forms a SOAP Fault and puts it in the SOAP Message Body.
        Parameters:
        faultCode - Fault code.
        faultString - Fault string.
        detail - Fault details.
        Returns:
        SOAP Fault in the SOAP Message Body or null if unable to generate the message.
      • getSOAPMessage

        public jakarta.xml.soap.SOAPMessage getSOAPMessage​(jakarta.servlet.http.HttpServletRequest request)
                                                    throws IOException,
                                                           jakarta.xml.soap.SOAPException
        Returns SOAP Message from HttpServletRequest.
        Parameters:
        request - HttpServletRequest includes SOAP Message.
        Returns:
        SOAPMessage if request include any soap message in the header.
        Throws:
        IOException - if error in creating input stream.
        jakarta.xml.soap.SOAPException - if error in creating soap message.
      • sendSOAPMessage

        public jakarta.xml.soap.SOAPMessage sendSOAPMessage​(String xmlMessage,
                                                            String soapUrl,
                                                            boolean isClientMessage)
                                                     throws jakarta.xml.soap.SOAPException,
                                                            SAML2Exception
        Send SOAP Message to specified url and returns message from peer.
        Parameters:
        xmlMessage - String will be sent.
        soapUrl - URL the mesaage send to.
        isClientMessage - true if the message is sent from SOAP client to server.
        Returns:
        SOAPMessage if the peer send back any reply.
        Throws:
        jakarta.xml.soap.SOAPException - if error in creating soap message.
        SAML2Exception - if error in creating soap message.
      • soapMessageToString

        public String soapMessageToString​(jakarta.xml.soap.SOAPMessage message)
        Converts a SOAPMessage to a String.
        Parameters:
        message - SOAPMessage object.
        Returns:
        the String converted from the SOAPMessage or null if an error ocurred.
      • getSamlpElement

        public Element getSamlpElement​(jakarta.xml.soap.SOAPMessage message,
                                       String localName)
                                throws SAML2Exception
        Returns first Element with given local name in samlp name space inside SOAP message.
        Parameters:
        message - SOAP message.
        localName - local name of the Element to be returned.
        Returns:
        first Element matching the local name.
        Throws:
        SAML2Exception - if the Element could not be found or there is SOAP Fault present.
      • getHeaders

        public jakarta.xml.soap.MimeHeaders getHeaders​(jakarta.servlet.http.HttpServletRequest req)
        Returns mime headers in HTTP servlet request.
        Parameters:
        req - HTTP servlet request.
        Returns:
        mime headers in HTTP servlet request.