コード例 #1
0
 @Override
 protected Object splitMessage(Message<?> message) {
   try {
     Object payload = message.getPayload();
     Object result = null;
     if (payload instanceof Node) {
       result = splitNodePayload((Node) payload, message);
     } else if (payload instanceof String) {
       payload = xmlPayloadConverter.convertToDocument(payload);
       result = splitStringPayload(message);
     } else {
       throw new IllegalArgumentException(
           "Unsupported payload type ["
               + payload.getClass().getName()
               + "]. The XPathMessageSplitter only accepts ["
               + Node.class.getName()
               + "] or [java.lang.String] typed payloads.");
     }
     return result;
   } catch (ParserConfigurationException e) {
     throw new MessagingException(message, "failed to create DocumentBuilder", e);
   } catch (Exception e) {
     throw new MessagingException(message, "failed to split Message payload", e);
   }
 }
コード例 #2
0
 private Object splitStringPayload(Message<?> message)
     throws ParserConfigurationException, TransformerFactoryConfigurationError,
         TransformerException {
   Node node = xmlPayloadConverter.convertToDocument(message.getPayload());
   List<Node> nodes = splitNodePayload(node, message);
   Transformer transformer = TransformerFactory.newInstance().newTransformer();
   List<String> splitStrings = new ArrayList<String>(nodes.size());
   for (Node nodeFromList : nodes) {
     StringResult result = new StringResult();
     transformer.transform(new DOMSource(nodeFromList), result);
     splitStrings.add(result.toString());
   }
   return splitStrings;
 }