mirror of
https://github.com/google/nomulus.git
synced 2025-05-14 00:17:20 +02:00
Add the ability to generate RDE deposits in lenient mode
We will not want to run this under normal circumstances, but in cases (such as PDT testing in sandbox) where it's desirable to generate an escrow deposit even if it isn't technically valid XML, this gives us that option. Manual-mode RDE generation is also changed so that, if no watermark date is specified, it defaults to the previous midnight, to better support running of RDE in sandbox to catch data problems. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=156108295
This commit is contained in:
parent
e1f4df86bd
commit
74a0defef3
9 changed files with 101 additions and 33 deletions
|
@ -35,6 +35,7 @@ import google.registry.xjc.rdeidn.XjcRdeIdn;
|
|||
import google.registry.xjc.rdeidn.XjcRdeIdnElement;
|
||||
import google.registry.xjc.rdepolicy.XjcRdePolicy;
|
||||
import google.registry.xjc.rdepolicy.XjcRdePolicyElement;
|
||||
import google.registry.xml.ValidationMode;
|
||||
import google.registry.xml.XmlException;
|
||||
import google.registry.xml.XmlFragmentMarshaller;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -50,11 +51,15 @@ import org.joda.time.DateTime;
|
|||
public final class RdeMarshaller implements Serializable {
|
||||
|
||||
private static final FormattingLogger logger = FormattingLogger.getLoggerForCallerClass();
|
||||
|
||||
private static final long serialVersionUID = 202890386611768455L;
|
||||
|
||||
private final ValidationMode validationMode;
|
||||
private transient XmlFragmentMarshaller memoizedMarshaller;
|
||||
|
||||
public RdeMarshaller(ValidationMode validationMode) {
|
||||
this.validationMode = validationMode;
|
||||
}
|
||||
|
||||
/** Returns top-portion of XML document. */
|
||||
public String makeHeader(
|
||||
String depositId, DateTime watermark, Collection<String> uris, int revision) {
|
||||
|
@ -79,7 +84,7 @@ public final class RdeMarshaller implements Serializable {
|
|||
deposit.setContents(contents);
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
try {
|
||||
XjcXmlTransformer.marshalStrict(deposit, os, UTF_8);
|
||||
XjcXmlTransformer.marshal(deposit, os, UTF_8, validationMode);
|
||||
} catch (XmlException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -95,10 +100,18 @@ public final class RdeMarshaller implements Serializable {
|
|||
return "\n</rde:contents>\n</rde:deposit>\n";
|
||||
}
|
||||
|
||||
/** Turns XJC element into XML fragment, with schema validation. */
|
||||
public String marshalStrictlyOrDie(JAXBElement<?> element) {
|
||||
/** Turns XJC element into XML fragment, with schema validation unless in lenient mode. */
|
||||
public String marshal(JAXBElement<?> element) throws MarshalException {
|
||||
return getMarshaller().marshal(element, validationMode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns XJC element into XML fragment, converting {@link MarshalException}s to {@link
|
||||
* RuntimeException}s.
|
||||
*/
|
||||
public String marshalOrDie(JAXBElement<?> element) {
|
||||
try {
|
||||
return getMarshaller().marshal(element);
|
||||
return marshal(element);
|
||||
} catch (MarshalException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -141,7 +154,7 @@ public final class RdeMarshaller implements Serializable {
|
|||
bean.setId(idn.getName());
|
||||
bean.setUrl(idn.getUrl().toString());
|
||||
bean.setUrlPolicy(idn.getPolicy().toString());
|
||||
return marshalStrictlyOrDie(new XjcRdeIdnElement(bean));
|
||||
return marshalOrDie(new XjcRdeIdnElement(bean));
|
||||
}
|
||||
|
||||
private DepositFragment marshalResource(
|
||||
|
@ -149,7 +162,7 @@ public final class RdeMarshaller implements Serializable {
|
|||
String xml = "";
|
||||
String error = "";
|
||||
try {
|
||||
xml = getMarshaller().marshal(element);
|
||||
xml = marshal(element);
|
||||
} catch (MarshalException e) {
|
||||
error = String.format("RDE XML schema validation failed: %s\n%s%s\n",
|
||||
Key.create(resource),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue