Search in sources :

Example 1 with XsltTransformerFactory

use of com.adaptris.util.text.xml.XsltTransformerFactory in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testXSLT_RecoverableError_NoFail.

@Test
public void testXSLT_RecoverableError_NoFail() throws Exception {
    MultiPayloadAdaptrisMessage m1 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    String oldName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    MultiPayloadXmlTransformService service = createBaseExample();
    XsltTransformerFactory fac = new XsltTransformerFactory();
    fac.setFailOnRecoverableError(false);
    service.setXmlTransformerFactory(fac);
    service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_INVALID_TRANSFORM_URL));
    try {
        execute(service, m1);
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 2 with XsltTransformerFactory

use of com.adaptris.util.text.xml.XsltTransformerFactory in project interlok by adaptris.

the class XmlTransformServiceTest method testXSLT_XslMessageTerminate.

@Test
public void testXSLT_XslMessageTerminate() throws Exception {
    AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    XmlTransformService service = new XmlTransformService();
    XsltTransformerFactory fac = new XsltTransformerFactory();
    fac.getTransformerFactoryAttributes().add(new KeyValuePair("http://saxon.sf.net/feature/messageEmitterClass", MessageWarner.class.getCanonicalName()));
    fac.getTransformerFactoryFeatures().add(new KeyValuePair(XMLConstants.FEATURE_SECURE_PROCESSING, "true"));
    service.setXmlTransformerFactory(fac);
    service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL_XSL_MESSAGE));
    try {
        execute(service, m1);
        fail();
    } catch (ServiceException expected) {
        assertExceptionCause(expected, TransformerException.class, UncheckedXPathException.class);
    }
}
Also used : UncheckedXPathException(net.sf.saxon.trans.UncheckedXPathException) KeyValuePair(com.adaptris.util.KeyValuePair) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) TransformerException(javax.xml.transform.TransformerException) Test(org.junit.Test)

Example 3 with XsltTransformerFactory

use of com.adaptris.util.text.xml.XsltTransformerFactory in project interlok by adaptris.

the class XmlTransformServiceTest method testXSLTOutput_NamedXsltTransformFactory.

@Test
public void testXSLTOutput_NamedXsltTransformFactory() throws Exception {
    AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    XmlTransformService service = new XmlTransformService();
    XsltTransformerFactory fac = new XsltTransformerFactory(net.sf.saxon.TransformerFactoryImpl.class.getCanonicalName());
    service.setXmlTransformerFactory(fac);
    service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL));
    execute(service, m1);
    assertEquals("payload " + m1.getContent(), PROPERTIES.getProperty(KEY_XML_TEST_OUTPUT), m1.getContent());
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) Test(org.junit.Test)

Example 4 with XsltTransformerFactory

use of com.adaptris.util.text.xml.XsltTransformerFactory in project interlok by adaptris.

the class XmlTransformServiceTest method testXSLT_RecoverableError_NoFail.

@Test
public void testXSLT_RecoverableError_NoFail() throws Exception {
    AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    String oldName = Thread.currentThread().getName();
    Thread.currentThread().setName(getName());
    XmlTransformService service = new XmlTransformService();
    XsltTransformerFactory fac = new XsltTransformerFactory();
    fac.setFailOnRecoverableError(false);
    service.setXmlTransformerFactory(fac);
    service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_INVALID_TRANSFORM_URL));
    try {
        execute(service, m1);
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) Test(org.junit.Test)

Example 5 with XsltTransformerFactory

use of com.adaptris.util.text.xml.XsltTransformerFactory in project interlok by adaptris.

the class XmlTransformerTest method testTransform_InputStreamOutputStream.

@Test
public void testTransform_InputStreamOutputStream() throws Exception {
    XmlTransformerFactory factory = new XsltTransformerFactory();
    XmlTransformer transform = factory.configure(new XmlTransformer());
    String xsl = backslashToSlash(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL));
    AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    try (InputStream in = m1.getInputStream();
        OutputStream out = m1.getOutputStream()) {
        transform.transform(factory.createTransformer(xsl), in, out, xsl);
    }
}
Also used : XmlTransformer(com.adaptris.util.text.xml.XmlTransformer) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) XmlTransformerFactory(com.adaptris.util.text.xml.XmlTransformerFactory) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) Test(org.junit.Test)

Aggregations

XsltTransformerFactory (com.adaptris.util.text.xml.XsltTransformerFactory)9 Test (org.junit.Test)9 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)6 MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)3 XmlTransformer (com.adaptris.util.text.xml.XmlTransformer)3 XmlTransformerFactory (com.adaptris.util.text.xml.XmlTransformerFactory)3 ServiceException (com.adaptris.core.ServiceException)2 KeyValuePair (com.adaptris.util.KeyValuePair)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 TransformerException (javax.xml.transform.TransformerException)2 UncheckedXPathException (net.sf.saxon.trans.UncheckedXPathException)2 Reader (java.io.Reader)1 Writer (java.io.Writer)1 StreamResult (javax.xml.transform.stream.StreamResult)1 StreamSource (javax.xml.transform.stream.StreamSource)1