Class EppMessage

  • Direct Known Subclasses:
    EppRequestMessage, EppResponseMessage

    public class EppMessage
    extends java.lang.Object
    Superclass of EppRequestMessage and EppResponseMessage that represents skeleton of any kind of EPP message, whether inbound or outbound.

    NOTE: Most static methods are copied over from //java/com/google/domain/registry/monitoring/blackbox/EppHelper.java

    Houses number of static methods for use of conversion between String and bytes to Document type, which represents an XML Document, the type of which is used for EPP messages.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CLIENT_ID_KEY
      Key that allows for substitution of epp user id to xml template.
      static java.lang.String CLIENT_PASSWORD_KEY
      Key that allows for substitution of epp password to xml template.
      static java.lang.String CLIENT_TRID_KEY
      Key that allows for substitution ofclTrid to xml template.
      static java.lang.String DOMAIN_KEY
      Key that allows for substitution of domainName to xml template.
      protected static int HEADER_LENGTH
      Standard EPP header number of bytes (size of int).
      protected org.w3c.dom.Document message
      Document that represents the actual XML document sent inbound or outbound through channel pipeline.
      static java.lang.String SERVER_TRID_KEY
      Key that allows for substitution ofsvTrid to xml template.
      static java.lang.String XFAIL_EXPRESSION
      Expression that expresses a result code in the EppResponseMessage that means failure.
      static java.lang.String XPASS_EXPRESSION
      Expression that expresses a result code in the EppResponseMessage that means success.
    • Constructor Summary

      Constructors 
      Constructor Description
      EppMessage()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static org.w3c.dom.Document byteArrayToXmlDoc​(byte[] responseBuffer)
      A helper method to transform an byte array to an XML Document using docBuilderFactory
      static void eppValidate​(org.w3c.dom.Document xml)
      Validate an EPP XML document against the set of XSD files that make up the EPP XML Schema.
      java.lang.String getElementValue​(java.lang.String expression)  
      static java.lang.String getElementValue​(org.w3c.dom.Document xml, java.lang.String expression)
      A helper method to extract a value from an element in an XML document.
      static org.w3c.dom.Document getEppDocFromTemplate​(java.lang.String template, java.util.Map<java.lang.String,​java.lang.String> replacements)
      Reads one of a set of EPP templates (included as resources in our jar) and finds nodes using an xpath expression, then replaces the node value of the first child, returning the transformed XML as a Document.
      java.lang.String toString()  
      protected static void verifyEppResponse​(org.w3c.dom.Document xml, java.util.List<java.lang.String> expressions, boolean validate)
      Verify an XML Document as an EPP Response using the provided XPath expressions.
      static byte[] xmlDocToByteArray​(org.w3c.dom.Document xml)
      A helper method to transform an XML Document to a byte array using the XML Encoding when converting from a String (see xmlDocToString).
      static java.lang.String xmlDocToString​(org.w3c.dom.Document xml)
      A helper method to transform an XML Document to a string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DOMAIN_KEY

        public static final java.lang.String DOMAIN_KEY
        Key that allows for substitution of domainName to xml template.
        See Also:
        Constant Field Values
      • CLIENT_ID_KEY

        public static final java.lang.String CLIENT_ID_KEY
        Key that allows for substitution of epp user id to xml template.
        See Also:
        Constant Field Values
      • CLIENT_PASSWORD_KEY

        public static final java.lang.String CLIENT_PASSWORD_KEY
        Key that allows for substitution of epp password to xml template.
        See Also:
        Constant Field Values
      • CLIENT_TRID_KEY

        public static final java.lang.String CLIENT_TRID_KEY
        Key that allows for substitution ofclTrid to xml template.
        See Also:
        Constant Field Values
      • SERVER_TRID_KEY

        public static final java.lang.String SERVER_TRID_KEY
        Key that allows for substitution ofsvTrid to xml template.
        See Also:
        Constant Field Values
      • XPASS_EXPRESSION

        public static final java.lang.String XPASS_EXPRESSION
        Expression that expresses a result code in the EppResponseMessage that means success.
      • XFAIL_EXPRESSION

        public static final java.lang.String XFAIL_EXPRESSION
        Expression that expresses a result code in the EppResponseMessage that means failure.
      • HEADER_LENGTH

        protected static int HEADER_LENGTH
        Standard EPP header number of bytes (size of int).
      • message

        protected org.w3c.dom.Document message
        Document that represents the actual XML document sent inbound or outbound through channel pipeline.
    • Constructor Detail

      • EppMessage

        public EppMessage()
    • Method Detail

      • eppValidate

        public static void eppValidate​(org.w3c.dom.Document xml)
                                throws org.xml.sax.SAXException,
                                       java.io.IOException
        Validate an EPP XML document against the set of XSD files that make up the EPP XML Schema.

        Note that the document must have the namespace attributes set where expected (i.e. must be built using a DocumentBuilder with namespace awareness set if using a DocumentBuilder).

        Parameters:
        xml - an XML Document to validate
        Throws:
        org.xml.sax.SAXException - if the document is not valid
        java.io.IOException
      • verifyEppResponse

        protected static void verifyEppResponse​(org.w3c.dom.Document xml,
                                                java.util.List<java.lang.String> expressions,
                                                boolean validate)
                                         throws FailureException
        Verify an XML Document as an EPP Response using the provided XPath expressions.

        This will first validate the document against the EPP schema, then run through the list of xpath expressions -- so those need only look for specific EPP elements + values.

        Parameters:
        xml - the XML Document containing the EPP reponse to verify
        expressions - a list of XPath expressions to query the document with.
        validate - a boolean flag to control if schema validation occurs (useful for testing)
        Throws:
        FailureException - if the EPP response cannot be read, parsed, or doesn't containing matching data specified in expressions
      • getElementValue

        public static java.lang.String getElementValue​(org.w3c.dom.Document xml,
                                                       java.lang.String expression)
        A helper method to extract a value from an element in an XML document.
        Returns:
        the text value for the element, or null is the element is not found
      • xmlDocToString

        @Nullable
        public static java.lang.String xmlDocToString​(@Nullable
                                                      org.w3c.dom.Document xml)
                                               throws EppClientException
        A helper method to transform an XML Document to a string. - e.g. a returned string might look like the following for a Document with a root element of "foo" that has a child element of "bar" which has text of "baz":
        '<foo><bar>baz</bar></foo>'
        Parameters:
        xml - the Document to transform
        Returns:
        the resulting string or null if xml is null.
        Throws:
        EppClientException - if the transform fails
      • xmlDocToByteArray

        public static byte[] xmlDocToByteArray​(org.w3c.dom.Document xml)
                                        throws EppClientException
        A helper method to transform an XML Document to a byte array using the XML Encoding when converting from a String (see xmlDocToString).
        Parameters:
        xml - the Document to transform
        Returns:
        the resulting byte array.
        Throws:
        EppClientException - if the transform fails
      • byteArrayToXmlDoc

        public static org.w3c.dom.Document byteArrayToXmlDoc​(byte[] responseBuffer)
                                                      throws FailureException
        A helper method to transform an byte array to an XML Document using docBuilderFactory
        Parameters:
        responseBuffer - the byte array to transform
        Returns:
        the resulting Document
        Throws:
        FailureException - if the transform fails
      • getEppDocFromTemplate

        public static org.w3c.dom.Document getEppDocFromTemplate​(java.lang.String template,
                                                                 java.util.Map<java.lang.String,​java.lang.String> replacements)
                                                          throws java.io.IOException,
                                                                 EppClientException
        Reads one of a set of EPP templates (included as resources in our jar) and finds nodes using an xpath expression, then replaces the node value of the first child, returning the transformed XML as a Document.

        E.g. to replace the value "@@CLTRID@@" in the <clTRID> node with a client transaction ID, use the mapping <"//domainns:clTRID", "AAA-123-BBBB"> (or whatever the ID is).

        Parameters:
        template - the relative (unqualified) name of the template file to use
        replacements - a map of strings to replace in the template keyed by the xpath expression to use to find the nodes to operate on with the value being the text to use as the replacement
        Returns:
        the transformed EPP document
        Throws:
        java.io.IOException - if the template cannot be read
        EppClientException - if there are issues parsing the template or evaluating the xpath expression, or if the resulting document is not valid EPP
        java.lang.IllegalArgumentException - if the xpath expression query yields anything other than an Element node type
      • getElementValue

        @Nullable
        public java.lang.String getElementValue​(java.lang.String expression)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object