| Commit in servicemix/base/src/main on MAIN | |||
| java/org/servicemix/components/util/StreamWriterComponent.java | +86 | added 1.1 | |
| release/examples/rss-binding/servicemix.xml | +23 | -1 | 1.1 -> 1.2 |
| +109 | -1 | ||
Add capability to pretty print messages to a stream
servicemix/base/src/main/java/org/servicemix/components/util
StreamWriterComponent.java added at 1.1
diff -N StreamWriterComponent.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ StreamWriterComponent.java 13 Aug 2005 10:33:55 -0000 1.1 @@ -0,0 +1,86 @@
+/**
+ *
+ * Copyright 2005 RAJD Consultancy LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **/
+
+package org.servicemix.components.util;
+import java.io.OutputStream;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.servicemix.jbi.binding.OutBinding;
+import org.servicemix.jbi.jaxp.SourceTransformer;
+import org.w3c.dom.Node;
+
+/**
+ * A Component that dumps a message to a stream
+ *
+ * @version $Revision: 1.1 $
+ */
+public class StreamWriterComponent extends OutBinding {
+ private static final Log log = LogFactory.getLog(StreamWriterComponent.class);
+ private OutputStream out = System.out;
+
+ /**
+ * @return Returns the out.
+ */
+ public OutputStream getOut() {
+ return out;
+ }
+
+ /**
+ * @param out The out to set.
+ */
+ public void setOut(OutputStream out) {
+ this.out = out;
+ }
+
+
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+
+
+ protected void process(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
+ try {
+ TransformerFactory tFactory = TransformerFactory.newInstance();
+ Transformer transformer = tFactory.newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ Source content = null;
+ Node document = (Node) message.getProperty(SourceTransformer.CONTENT_DOCUMENT_PROPERTY);
+ if (document != null) {
+ content = new DOMSource(document);
+ }
+ else {
+ content = message.getContent();
+ }
+ transformer.transform(content, new StreamResult(out));
+ }
+ catch (TransformerException e) {
+ log.error("Could not transform message", e);
+ throw new MessagingException(e);
+ }
+ }
+}
servicemix/base/src/main/release/examples/rss-binding
diff -u -r1.1 -r1.2 --- servicemix.xml 11 Aug 2005 16:39:26 -0000 1.1 +++ servicemix.xml 13 Aug 2005 10:33:55 -0000 1.2 @@ -11,6 +11,7 @@
<component id="rss" service="my:rss" class="org.servicemix.components.rss.RssPollingComponent" destinationService="my:trace"> <property name="outputType" value = "rss_2.0" /> <property name="monitorInterval" value = "10"/>
+ <property name="lastPolledDate"><value>2005/aug/10</value></property>
<property name="urlStrings">
@@ -22,11 +23,32 @@
</component>
<!-- Route the event to a trace component that just outputs the event to the console -->
- <component id="trace" service="my:trace" class="org.servicemix.components.util.TraceComponent"/>
+ <component id="trace" service="my:trace" class="org.servicemix.components.util.StreamWriterComponent"/>
</components> </container>
+ + <!-- Custom editor for the Date variable lastPolledDate so we can see immediate output --> + <bean id="customEditorConfigurer" + class="org.springframework.beans.factory.config.CustomEditorConfigurer"> + <property name="customEditors"> + <map> + + <entry key="java.util.Date"> + <bean class="org.springframework.beans.propertyeditors.CustomDateEditor"> + <constructor-arg index="0"> + <bean class="java.text.SimpleDateFormat"> + <constructor-arg><value>yyyy/MMM/dd</value></constructor-arg> + </bean> + </constructor-arg> + <constructor-arg index="1"><value>true</value></constructor-arg> + </bean> + </entry> + + </map> + </property> + </bean>
</beans>
