Search in sources :

Example 6 with InsertNode

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

the class ExceptionReportServiceTest method testBug2356.

@Test
public void testBug2356() throws Exception {
    ServiceImp failingService = new ThrowExceptionService(new ConfiguredException("Fail"));
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new InsertNode(XPATH_ROOT)));
    MockMessageProducer mockProducer = new MockMessageProducer();
    StandardProcessingExceptionHandler speh = new StandardProcessingExceptionHandler(new ServiceList(new Service[] { service, new StandaloneProducer(mockProducer) }));
    MockChannel channel = new MockChannel();
    MockMessageConsumer consumer = new MockMessageConsumer();
    StandardWorkflow wf = new StandardWorkflow();
    wf.getServiceCollection().add(failingService);
    wf.setConsumer(consumer);
    channel.setMessageErrorHandler(speh);
    channel.getWorkflowList().add(wf);
    try {
        channel.prepare();
        channel.requestStart();
        consumer.submitMessage(msg);
        assertEquals(1, mockProducer.getMessages().size());
        AdaptrisMessage failedMessage = mockProducer.getMessages().get(0);
        assertNotSame(XML_PAYLOAD, failedMessage.getContent());
        XmlUtils xml = XmlHelper.createXmlUtils(failedMessage);
        assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
        assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
        String xmlElement = xml.getSingleTextItem(XPATH_ROOT + "/Exception");
        assertTrue(xmlElement.contains("com.adaptris.core.services.exception.ThrowExceptionService.doService"));
    } finally {
        channel.requestClose();
    }
}
Also used : MockChannel(com.adaptris.core.stubs.MockChannel) StandardWorkflow(com.adaptris.core.StandardWorkflow) MockMessageProducer(com.adaptris.core.stubs.MockMessageProducer) XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceList(com.adaptris.core.ServiceList) Service(com.adaptris.core.Service) ServiceImp(com.adaptris.core.ServiceImp) StandardProcessingExceptionHandler(com.adaptris.core.StandardProcessingExceptionHandler) MockMessageConsumer(com.adaptris.core.stubs.MockMessageConsumer) InsertNode(com.adaptris.util.text.xml.InsertNode) StandaloneProducer(com.adaptris.core.StandaloneProducer) Test(org.junit.Test)

Example 7 with InsertNode

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

the class ExceptionReportServiceTest method testBug2220.

@Test
public void testBug2220() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD, "UTF-8");
    msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("I had problems parsing <ABCDE>"));
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport("Exception")).withDocumentMerge(new InsertNode(XPATH_ROOT)));
    execute(service, msg);
    assertNotSame(XML_PAYLOAD, msg.getContent());
    XmlUtils xml = XmlHelper.createXmlUtils(msg);
    assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
    assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
    assertEquals("UTF-8", msg.getContentEncoding());
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 8 with InsertNode

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

the class MergeResultSetIntoPayloadTest method createTranslatorForConfig.

@Override
protected MergeResultSetIntoXmlPayload createTranslatorForConfig() {
    MergeResultSetIntoXmlPayload t = new MergeResultSetIntoXmlPayload(new InsertNode("/root"));
    t.setStripIllegalXmlChars(true);
    t.setXmlColumnRegexp("Data_in_columns_that_match_this_regular_expression_will_be_turned_into_a_Document_Object_Before_Processing");
    return t;
}
Also used : InsertNode(com.adaptris.util.text.xml.InsertNode)

Example 9 with InsertNode

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

the class ExceptionReportServiceTest method testInsertNode.

@Test
public void testInsertNode() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage(XML_PAYLOAD);
    msg.addObjectHeader(CoreConstants.OBJ_METADATA_EXCEPTION, new Exception("This is the exception"));
    ExceptionReportService service = new ExceptionReportService(new ExceptionAsXml().withExceptionGenerator(new SimpleExceptionReport()).withDocumentMerge(new InsertNode(XPATH_ROOT)).withXmlEncoding("UTF-8"));
    execute(service, msg);
    assertNotSame(XML_PAYLOAD, msg.getContent());
    XmlUtils xml = XmlHelper.createXmlUtils(msg);
    assertEquals(RAW_DATA, xml.getSingleTextItem(XPATH_ORIGINAL_NODE));
    assertNotNull(xml.getSingleNode(XPATH_ROOT + "/Exception"));
    assertEquals("UTF-8", msg.getContentEncoding());
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ServiceException(com.adaptris.core.ServiceException) CoreException(com.adaptris.core.CoreException) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Example 10 with InsertNode

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

the class MergeResultSetIntoPayloadTest method testXpathStatementParam_NodeDoesNotExist.

@Test
public void testXpathStatementParam_NodeDoesNotExist() throws Exception {
    createDatabase();
    List<AdapterTypeVersion> dbItems = generate(10);
    AdapterTypeVersion entry = dbItems.get(0);
    populateDatabase(dbItems, false);
    JdbcDataQueryService s = createXmlService();
    // /root/NonExistentNode, doesn't actually exist at this point.
    s.setResultSetTranslator(new MergeResultSetIntoXmlPayload(new InsertNode("/root/NonExistentNode")));
    AdaptrisMessage msg = createMessage(entry);
    execute(s, msg);
    assertTrue(ADAPTER_ID_KEY + " exists", msg.containsKey(ADAPTER_ID_KEY));
    assertNotSame(XML_PAYLOAD_PREFIX + entry.getUniqueId() + XML_PAYLOAD_SUFFIX, msg.getContent());
    assertFalse(msg.containsKey(JdbcDataQueryService.class.getCanonicalName()));
    XmlUtils xu = XmlHelper.createXmlUtils(msg);
    assertNotNull("/root/document doesn't exist", xu.getSingleNode("/root/document"));
    assertNotNull("/root/NonExistentNode/Results/Row doesn't exist", xu.getSingleNode("/root/NonExistentNode/Results/Row"));
}
Also used : XmlUtils(com.adaptris.util.XmlUtils) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) InsertNode(com.adaptris.util.text.xml.InsertNode) Test(org.junit.Test)

Aggregations

InsertNode (com.adaptris.util.text.xml.InsertNode)20 Test (org.junit.Test)19 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)18 XmlUtils (com.adaptris.util.XmlUtils)8 XPath (com.adaptris.util.text.xml.XPath)6 CoreException (com.adaptris.core.CoreException)5 NullService (com.adaptris.core.NullService)5 PooledSplitJoinService (com.adaptris.core.services.splitter.PooledSplitJoinService)5 XpathMessageSplitter (com.adaptris.core.services.splitter.XpathMessageSplitter)5 TimeInterval (com.adaptris.util.TimeInterval)5 ServiceException (com.adaptris.core.ServiceException)2 EvenOddCondition (com.adaptris.core.services.aggregator.MessageAggregatorTest.EvenOddCondition)2 DefectiveMessageFactory (com.adaptris.core.stubs.DefectiveMessageFactory)2 AdaptrisMessageFactory (com.adaptris.core.AdaptrisMessageFactory)1 Service (com.adaptris.core.Service)1 ServiceImp (com.adaptris.core.ServiceImp)1 ServiceList (com.adaptris.core.ServiceList)1 StandaloneProducer (com.adaptris.core.StandaloneProducer)1 StandardProcessingExceptionHandler (com.adaptris.core.StandardProcessingExceptionHandler)1 StandardWorkflow (com.adaptris.core.StandardWorkflow)1