Search in sources :

Example 56 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testXSLT_RecoverableError.

@Test
public void testXSLT_RecoverableError() 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();
    try {
        execute(service, m1);
    // INTERLOK-1850 - Saxon 9.7 won't report exceptions, so even if we throw, it'll just eat it.
    // fail("Exception expected but none thrown");
    } catch (ServiceException e) {
        assertTrue(e.getCause() instanceof TransformerException);
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) TransformerException(javax.xml.transform.TransformerException) Test(org.junit.Test)

Example 57 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class MultiPayloadXmlTransformServiceTest method testObjectMetadataParameter_NoRegexp.

@Test
public void testObjectMetadataParameter_NoRegexp() throws Exception {
    MultiPayloadAdaptrisMessage msg = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    msg.addObjectHeader("myDocumentObject", XmlHelper.createDocument("<data>World</data>"));
    msg.addObjectHeader("anotherDocument", XmlHelper.createDocument("<data>GoodBye</data>"));
    MultiPayloadXmlTransformService service = createBaseExample();
    service.setUrl(PROPERTIES.getProperty(KEY_XML_NODE_TRANSFORM_URL));
    service.setTransformParameter(new ObjectMetadataParameter());
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    // expected
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 58 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class CommonsSystemCommandExecutorServiceTest method testDoService_ExceedsTimeout.

@Test
public void testDoService_ExceedsTimeout() throws Exception {
    Thread.currentThread().setName(getName());
    SystemCommandExecutorService service = new SystemCommandExecutorService(createTimeoutCommand(), new OverwritePayload());
    service.setTimeout(new TimeInterval(2L, TimeUnit.SECONDS));
    AdaptrisMessage msg = createMessage();
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
        System.err.println(getName() + "=" + msg.getContent());
        expected.printStackTrace(System.err);
    }
}
Also used : TimeInterval(com.adaptris.util.TimeInterval) ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 59 with ServiceException

use of com.adaptris.core.ServiceException in project interlok by adaptris.

the class XmlTransformServiceTest method testObjectMetadataParameter_NoRegexp.

@Test
public void testObjectMetadataParameter_NoRegexp() throws Exception {
    AdaptrisMessage msg = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    msg.addObjectHeader("myDocumentObject", XmlHelper.createDocument("<data>World</data>"));
    msg.addObjectHeader("anotherDocument", XmlHelper.createDocument("<data>GoodBye</data>"));
    XmlTransformService service = new XmlTransformService();
    service.setUrl(PROPERTIES.getProperty(KEY_XML_NODE_TRANSFORM_URL));
    service.setTransformParameter(new ObjectMetadataParameter());
    try {
        execute(service, msg);
        fail();
    } catch (ServiceException expected) {
    }
}
Also used : ServiceException(com.adaptris.core.ServiceException) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) Test(org.junit.Test)

Example 60 with ServiceException

use of com.adaptris.core.ServiceException 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)

Aggregations

ServiceException (com.adaptris.core.ServiceException)236 Test (org.junit.Test)172 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)161 CoreException (com.adaptris.core.CoreException)45 DefaultMessageFactory (com.adaptris.core.DefaultMessageFactory)26 StandaloneProducer (com.adaptris.core.StandaloneProducer)18 MetadataElement (com.adaptris.core.MetadataElement)17 ValidationStage (com.adaptris.transform.validate.ValidationStage)16 Cache (com.adaptris.core.cache.Cache)15 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)13 TimeInterval (com.adaptris.util.TimeInterval)13 MockMessageProducer (com.adaptris.core.stubs.MockMessageProducer)11 Connection (java.sql.Connection)10 File (java.io.File)9 IOException (java.io.IOException)9 OutputStream (java.io.OutputStream)9 SQLException (java.sql.SQLException)9 InputStream (java.io.InputStream)8 Document (org.w3c.dom.Document)8 Channel (com.adaptris.core.Channel)7