java.lang.Object
google.registry.monitoring.blackbox.message.EppMessage
Direct Known Subclasses:
EppRequestMessage, EppResponseMessage

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

    • DOMAIN_KEY

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

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

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

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

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

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

      public static final 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 Document message
      Document that represents the actual XML document sent inbound or outbound through channel pipeline.
  • Constructor Details

    • EppMessage

      public EppMessage()
  • Method Details

    • eppValidate

      public static void eppValidate(Document xml) throws SAXException, 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:
      SAXException - if the document is not valid
      IOException
    • verifyEppResponse

      protected static void verifyEppResponse(Document xml, List<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 String getElementValue(Document xml, 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 String xmlDocToString(@Nullable 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(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 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 Document getEppDocFromTemplate(String template, Map<String,String> replacements) throws 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:
      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
      IllegalArgumentException - if the xpath expression query yields anything other than an Element node type
    • getElementValue

      @Nullable public String getElementValue(String expression)
    • toString

      public String toString()
      Overrides:
      toString in class Object