Search in sources :

Example 41 with MultiPayloadAdaptrisMessage

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

the class MultiPayloadXmlTransformServiceTest method testXSLT_XslMessageTerminate.

@Test
public void testXSLT_XslMessageTerminate() throws Exception {
    MultiPayloadAdaptrisMessage m1 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT));
    MultiPayloadXmlTransformService service = createBaseExample();
    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) XsltTransformerFactory(com.adaptris.util.text.xml.XsltTransformerFactory) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) TransformerException(javax.xml.transform.TransformerException) Test(org.junit.Test)

Example 42 with MultiPayloadAdaptrisMessage

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

the class MessageHelper method createMultiPayloadMessage.

public static MultiPayloadAdaptrisMessage createMultiPayloadMessage(String payloadId, String filename, String encoding) throws IOException {
    MultiPayloadMessageFactory factory = new MultiPayloadMessageFactory();
    factory.setDefaultPayloadId(payloadId);
    if (encoding != null) {
        factory.setDefaultCharEncoding(encoding);
    }
    MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) factory.newMessage();
    StreamUtil.copyAndClose(new FileInputStream(new File(filename)), message.getOutputStream(payloadId));
    return message;
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 43 with MultiPayloadAdaptrisMessage

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

the class MultiPayloadMessageSplitter method splitMessage.

@Override
public Iterable<AdaptrisMessage> splitMessage(AdaptrisMessage msg) {
    List<AdaptrisMessage> splitMessages = new ArrayList<>();
    if (!(msg instanceof MultiPayloadAdaptrisMessage)) {
        log.warn("Message [{}] is not a multi-payload message!", msg.getUniqueId());
        splitMessages.add(msg);
    } else {
        MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) msg;
        for (String id : message.getPayloadIDs()) {
            message.switchPayload(id);
            try {
                AdaptrisMessage splitMessage = DefaultMessageFactory.getDefaultInstance().newMessage(message, null);
                splitMessage.setPayload(message.getPayload());
                splitMessages.add(splitMessage);
            } catch (CloneNotSupportedException e) {
                log.error("Could not clone message [{}]", id, e);
            }
        }
    }
    log.info("Split multi-payload message into {} standard messages", splitMessages.size());
    return splitMessages;
}
Also used : MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) ArrayList(java.util.ArrayList) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage)

Example 44 with MultiPayloadAdaptrisMessage

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

the class MultiPayloadStreamOutputParameterTest method testInsertSetId.

@Test
public void testInsertSetId() throws Exception {
    MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) new MultiPayloadMessageFactory().newMessage();
    try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) {
        InputStreamWithEncoding stream = new InputStreamWithEncoding(in, ENCODING);
        MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter();
        parameter.setPayloadId(ID);
        parameter.insert(stream, message);
    }
    assertEquals(PAYLOAD, message.getContent(ID));
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Example 45 with MultiPayloadAdaptrisMessage

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

the class MultiPayloadStreamOutputParameterTest method testInsertNoEncoding.

@Test
public void testInsertNoEncoding() throws Exception {
    MultiPayloadMessageFactory messageFactory = new MultiPayloadMessageFactory();
    MultiPayloadAdaptrisMessage message = (MultiPayloadAdaptrisMessage) messageFactory.newMessage();
    try (InputStream in = new ByteArrayInputStream(PAYLOAD.getBytes())) {
        InputStreamWithEncoding stream = new InputStreamWithEncoding(in, null);
        MultiPayloadStreamOutputParameter parameter = new MultiPayloadStreamOutputParameter();
        parameter.setContentEncoding(null);
        parameter.insert(stream, ID, message);
    }
    assertEquals(PAYLOAD, message.getContent(ID));
}
Also used : MultiPayloadMessageFactory(com.adaptris.core.MultiPayloadMessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MultiPayloadAdaptrisMessage(com.adaptris.core.MultiPayloadAdaptrisMessage) Test(org.junit.Test)

Aggregations

MultiPayloadAdaptrisMessage (com.adaptris.core.MultiPayloadAdaptrisMessage)48 Test (org.junit.Test)44 MultiPayloadMessageFactory (com.adaptris.core.MultiPayloadMessageFactory)24 ServiceException (com.adaptris.core.ServiceException)5 InputStream (java.io.InputStream)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 StxTransformerFactory (com.adaptris.util.text.xml.StxTransformerFactory)3 XsltTransformerFactory (com.adaptris.util.text.xml.XsltTransformerFactory)3 TransformerException (javax.xml.transform.TransformerException)3 KeyValuePair (com.adaptris.util.KeyValuePair)2 XPath (com.adaptris.util.text.xml.XPath)2 UncheckedXPathException (net.sf.saxon.trans.UncheckedXPathException)2 Document (org.w3c.dom.Document)2 CoreException (com.adaptris.core.CoreException)1 KeyValuePairList (com.adaptris.util.KeyValuePairList)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 ArrayList (java.util.ArrayList)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1