Class EppMessage
- Direct Known Subclasses:
EppRequestMessage
,EppResponseMessage
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
Modifier and TypeFieldDescriptionstatic final String
Key that allows for substitution of epp user id to xml template.static final String
Key that allows for substitution of epp password to xml template.static final String
Key that allows for substitution ofclTrid
to xml template.static final String
Key that allows for substitution ofdomainName
to xml template.protected static int
Standard EPP header number of bytes (size of int).protected Document
Document
that represents the actual XML document sent inbound or outbound through channel pipeline.static final String
Key that allows for substitution ofsvTrid
to xml template.static final String
Expression that expresses a result code in theEppResponseMessage
that means failure.static final String
Expression that expresses a result code in theEppResponseMessage
that means success. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Document
byteArrayToXmlDoc
(byte[] responseBuffer) A helper method to transform an byte array to an XMLDocument
usingdocBuilderFactory
static void
eppValidate
(Document xml) Validate an EPP XML document against the set of XSD files that make up the EPP XML Schema.getElementValue
(String expression) static String
getElementValue
(Document xml, String expression) A helper method to extract a value from an element in an XML document.static Document
getEppDocFromTemplate
(String template, Map<String, 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.toString()
protected static void
verifyEppResponse
(Document xml, List<String> expressions, boolean validate) Verify an XML Document as an EPP Response using the provided XPath expressions.static byte[]
A helper method to transform an XML Document to a byte array using the XML Encoding when converting from a String (see xmlDocToString).static String
xmlDocToString
(Document xml) A helper method to transform an XML Document to a string.
-
Field Details
-
DOMAIN_KEY
Key that allows for substitution ofdomainName
to xml template.- See Also:
-
CLIENT_ID_KEY
Key that allows for substitution of epp user id to xml template.- See Also:
-
CLIENT_PASSWORD_KEY
Key that allows for substitution of epp password to xml template.- See Also:
-
CLIENT_TRID_KEY
Key that allows for substitution ofclTrid
to xml template.- See Also:
-
SERVER_TRID_KEY
Key that allows for substitution ofsvTrid
to xml template.- See Also:
-
XPASS_EXPRESSION
Expression that expresses a result code in theEppResponseMessage
that means success. -
XFAIL_EXPRESSION
Expression that expresses a result code in theEppResponseMessage
that means failure. -
HEADER_LENGTH
protected static int HEADER_LENGTHStandard EPP header number of bytes (size of int). -
message
Document
that represents the actual XML document sent inbound or outbound through channel pipeline.
-
-
Constructor Details
-
EppMessage
public EppMessage()
-
-
Method Details
-
eppValidate
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 validIOException
-
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 verifyexpressions
- 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
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
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
ifxml
isnull
. - Throws:
EppClientException
- if the transform fails
-
xmlDocToByteArray
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
A helper method to transform an byte array to an XMLDocument
usingdocBuilderFactory
- 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, EppClientExceptionReads 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 usereplacements
- 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 readEppClientException
- if there are issues parsing the template or evaluating the xpath expression, or if the resulting document is not valid EPPIllegalArgumentException
- if the xpath expression query yields anything other than an Element node type
-
getElementValue
-
toString
-