@Test(expected = ConfigException.class) public void marshalMaskedConfigThrowsIOException() throws Exception { Config config = mock(Config.class); OutputStream outputStream = mock( OutputStream.class, (iom) -> { throw new IOException(""); }); JaxbUtil.marshalMasked(config, outputStream); }
public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute( () -> { Marshaller marshaller = MarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); }
JaxbUtil { public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute( () -> { Marshaller marshaller = MarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); } }
JaxbUtil { public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute( () -> { Marshaller marshaller = MarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); } private  JaxbUtil(); }
JaxbUtil { public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute( () -> { Marshaller marshaller = MarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); } private  JaxbUtil(); static T unmarshal(InputStream inputStream, Class<T> type); static void marshal(Object object, OutputStream outputStream); static void marshalWithNoValidation(Object object, OutputStream outputStream); static String marshalToString(Object object); static String marshalToStringNoValidation(Object object); static void marshalMasked(Config object, OutputStream outputStream); }
JaxbUtil { public static void marshalMasked(Config object, OutputStream outputStream) { XmlProcessingCallback.execute( () -> { Marshaller marshaller = MarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); String xmlData; try (StringWriter writer = new StringWriter()) { marshaller.marshal(object, writer); xmlData = writer.toString(); } StreamSource xmlSource = new StreamSource(new StringReader(xmlData)); try (StringWriter writer = new StringWriter()) { StreamResult xmlResult = new StreamResult(writer); createMaskingXslTransformer().transform(xmlSource, xmlResult); writer.flush(); Unmarshaller unmarshaller = UnmarshallerBuilder.create().withXmlMediaType().withoutBeanValidation().build(); Config masked = (Config) unmarshaller.unmarshal(new StringReader(writer.toString())); marshalWithNoValidation(masked, outputStream); return null; } }); } private  JaxbUtil(); static T unmarshal(InputStream inputStream, Class<T> type); static void marshal(Object object, OutputStream outputStream); static void marshalWithNoValidation(Object object, OutputStream outputStream); static String marshalToString(Object object); static String marshalToStringNoValidation(Object object); static void marshalMasked(Config object, OutputStream outputStream); static final Class[] JAXB_CLASSES; }