[SM-2066] Reinclude servicemix-components required by lwcontainer.
git-svn-id: https://svn.apache.org/repos/asf/servicemix/smx3/trunk@1088548 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/common/pom.xml b/common/pom.xml
new file mode 100644
index 0000000..db87d0b
--- /dev/null
+++ b/common/pom.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix</artifactId>
+ <version>3.4-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>common</artifactId>
+ <version>3.4-SNAPSHOT</version>
+ <name>ServiceMix :: Common</name>
+ <packaging>pom</packaging>
+
+ <modules>
+ <module>servicemix-components</module>
+ </modules>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-build</artifactId>
+ <version>1.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>copy</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-build</artifactId>
+ <version>1.0</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/common/servicemix-components/pom.xml b/common/servicemix-components/pom.xml
new file mode 100644
index 0000000..b2c4e70
--- /dev/null
+++ b/common/servicemix-components/pom.xml
@@ -0,0 +1,329 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>common</artifactId>
+ <version>3.4-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>servicemix-components</artifactId>
+ <packaging>jar</packaging>
+ <name>ServiceMix :: Components</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-core</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-httpclient</groupId>
+ <artifactId>commons-httpclient</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-vfs</groupId>
+ <artifactId>commons-vfs</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-net</groupId>
+ <artifactId>commons-net</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-pool</groupId>
+ <artifactId>commons-pool</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.xfire</groupId>
+ <artifactId>xfire-aegis</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.xfire</groupId>
+ <artifactId>xfire-spring</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.xfire</groupId>
+ <artifactId>xfire-core</artifactId>
+ <optional>true</optional>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws</groupId>
+ <artifactId>wsif</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.ws</groupId>
+ <artifactId>wsif-j2c</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-servlet_2.4_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-javamail_1.3.1_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-saaj_1.1_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-jaxrpc_1.1_spec</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <!-- Drools dependencies -->
+ <dependency>
+ <groupId>drools</groupId>
+ <artifactId>drools-all-jdk1.4</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>janino</groupId>
+ <artifactId>janino</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>antlr</groupId>
+ <artifactId>antlr</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>groovy-all-1.0-jsr</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>quartz</groupId>
+ <artifactId>quartz</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>rome</groupId>
+ <artifactId>rome</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smack</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>jivesoftware</groupId>
+ <artifactId>smackx</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>activesoap</groupId>
+ <artifactId>activesoap</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>groovy</groupId>
+ <artifactId>groovy-all-1.0-jsr</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.livetribe</groupId>
+ <artifactId>livetribe-jsr223</artifactId>
+ <version>2.0.5</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>com.sun.script</groupId>
+ <artifactId>groovy-engine</artifactId>
+ <version>20080611</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+
+ <dependency>
+ <groupId>axis</groupId>
+ <artifactId>axis-jaxrpc</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>axis</groupId>
+ <artifactId>axis</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!--
+ <dependency>
+ <groupId>net.java.dev.saaj</groupId>
+ <artifactId>saaj-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+ -->
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-ra</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-aop</artifactId>
+ <version>${spring-version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ <version>${spring-version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring-version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jms</artifactId>
+ <version>${spring-version}</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>codehaus-snapshots</id>
+ <url>http://repository.codehaus.org</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <workingDirectory>${basedir}</workingDirectory>
+ <includes>
+ <include>**/*Test.*</include>
+ </includes>
+ <excludes>
+ <!-- exclude abstract tests -->
+ <exclude>**/Abstract*.*</exclude>
+ <exclude>**/*$*</exclude>
+
+ <!-- Need external resources -->
+ <exclude>**/Jabber*.*</exclude>
+ <exclude>**/FTP*.*</exclude>
+
+ <!-- These ones can not work, need rewrite -->
+ <exclude>**/JmsOverJcaWithFullXATest.*</exclude>
+
+ <!-- exclude until amq4 stable -->
+ <exclude>**/JmsOverJca*.*</exclude>
+
+ <!-- enable when GERONIMO-1419 is solved -->
+ <exclude>**/HttpSoapAttachmentsTest.*</exclude>
+
+ <!-- The following tests fails with m2 -->
+ <exclude>**/HttpTest.*</exclude>
+ <exclude>**/ValidationTest.*</exclude>
+ <exclude>**/HttpSoapTest.*</exclude>
+ <exclude>**/SaajMarshalerTest.*</exclude>
+ <exclude>**/SaajTest.*</exclude>
+ <exclude>**/XsltPublisherTest.*</exclude>
+ <exclude>**/BinaryFileTest.*</exclude>
+ <exclude>**/FileTest.*</exclude>
+ <exclude>**/CounterMonitorComponentTest.*</exclude>
+ <exclude>**/OptionalAxisQueriesTest.*</exclude>
+ <exclude>**/JmsBindingTest.*</exclude>
+ <exclude>**/WsifTest.*</exclude>
+ <exclude>**/HttpSoapAndSaajTest.*</exclude>
+ <exclude>**/JmsBindingClusterTest.*</exclude>
+ <exclude>**/JmsBindingUsingEndpointSubscriptionTest.*</exclude>
+ <exclude>**/GroovyTransformTest.*</exclude>
+ <exclude>**/TransformComponentTest.*</exclude>
+
+ <!-- Hangs -->
+ <exclude>**/SaajSoapActionTest.*</exclude>
+
+ <!-- https://issues.apache.org/activemq/browse/SM-529 -->
+ <exclude>**/MPSSettingTest.*</exclude>
+
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASInOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASInOutBinding.java
new file mode 100644
index 0000000..be436d8
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASInOutBinding.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.activesoap;
+
+import java.io.StringWriter;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.codehaus.activesoap.RestService;
+
+/**
+ * Converts an inbound JBI message into an <a href="http://activesoap.codehaus.org/">ActiveSOAP</a>
+ * request-response and outputs the response back into JBI
+ *
+ * @version $Revision: 429277 $
+ */
+public class ASInOutBinding extends OutBinding {
+
+ private RestService service;
+ private ASMarshaler marshaler = new ASMarshaler();
+
+ public ASInOutBinding(RestService service) {
+ this.service = service;
+ }
+
+ /**
+ * @deprecated use getMarshaler instead
+ */
+ public ASMarshaler getMarshaller() {
+ return marshaler;
+ }
+
+ /**
+ * @deprecated use setMarshaler instead
+ */
+ public void setMarshaller(ASMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return the marshaler
+ */
+ public ASMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ /**
+ * @param marshaler the marshaler to set
+ */
+ public void setMarshaler(ASMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange messageExchange, NormalizedMessage inMessage) throws Exception {
+ XMLStreamReader in = marshaler.createStreamReader(inMessage);
+
+ StringWriter buffer = new StringWriter();
+ XMLStreamWriter out = marshaler.createStreamWriter(buffer);
+
+ org.codehaus.activesoap.MessageExchange asExchange = service.createMessageExchange(in, out);
+ marshaler.fromNMS(asExchange, inMessage);
+
+ service.invoke(asExchange);
+
+ NormalizedMessage outMessage = messageExchange.createMessage();
+
+ marshaler.setContent(outMessage, buffer.toString());
+ marshaler.toNMS(outMessage, asExchange);
+
+ answer(messageExchange, outMessage);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASInvocation.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASInvocation.java
new file mode 100644
index 0000000..0597990
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASInvocation.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.activesoap;
+
+import org.codehaus.activesoap.transport.Invocation;
+import org.codehaus.activesoap.util.XMLStreamFactory;
+
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * An <a href="http://activesoap.codehaus.org/">ActiveSOAP</a> {@link Invocation} which uses JBI.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ASInvocation extends Invocation {
+ private ASTransport asTransport;
+
+ public ASInvocation(ASTransport transport, XMLStreamFactory streamFactory) {
+ super(transport, streamFactory);
+ this.asTransport = transport;
+ }
+
+ public void invokeOneWay() throws Exception {
+ String xml = getRequestText();
+ asTransport.invokeOneWay(this, xml);
+ }
+
+ public XMLStreamReader invokeRequest() throws Exception {
+ String xml = getRequestText();
+ return asTransport.invokeRequest(this, xml);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASMarshaler.java
new file mode 100644
index 0000000..844afcb
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASMarshaler.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.activesoap;
+
+import java.io.Writer;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.codehaus.activesoap.MessageExchange;
+import org.codehaus.activesoap.util.XMLStreamFactory;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class ASMarshaler {
+
+ private XMLStreamFactory streamFactory = new XMLStreamFactory();
+
+ public void setContent(NormalizedMessage message, String xml) throws MessagingException {
+ message.setContent(new StringSource(xml));
+ }
+
+ public XMLStreamReader createStreamReader(NormalizedMessage message) throws XMLStreamException {
+ Source content = message.getContent();
+ return streamFactory.getInputFactory().createXMLStreamReader(content);
+ }
+
+
+ public XMLStreamWriter createStreamWriter(Writer writer) throws XMLStreamException {
+ return streamFactory.getOutputFactory().createXMLStreamWriter(writer);
+ }
+
+ /**
+ * Converts from an NMS message to an ActiveSOAP message exchange
+ */
+ public void fromNMS(MessageExchange asExchange, NormalizedMessage normalizedMessage) {
+ }
+
+ /**
+ * Converts from an ActiveSOAP message exchange to an NMS message
+ */
+ public void toNMS(NormalizedMessage normalizedMessage, MessageExchange asExchange) {
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public XMLStreamFactory getStreamFactory() {
+ return streamFactory;
+ }
+
+ public void setStreamFactory(XMLStreamFactory streamFactory) {
+ this.streamFactory = streamFactory;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASOutBinding.java
new file mode 100644
index 0000000..cb067ad
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASOutBinding.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.activesoap;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.codehaus.activesoap.RestService;
+
+/**
+ * Converts an inbound JBI message into an <a href="http://activesoap.codehaus.org/">ActiveSOAP</a>
+ * one way invocation.
+ *
+ * @version $Revision: 429277 $
+ */
+public class ASOutBinding extends OutBinding {
+
+ private RestService service;
+ private ASMarshaler marshaler = new ASMarshaler();
+
+ public ASOutBinding(RestService service) {
+ this.service = service;
+ }
+
+ /**
+ * @deprecated use getMarshaler instead
+ */
+ public ASMarshaler getMarshaller() {
+ return marshaler;
+ }
+
+ /**
+ * @deprecated use setMarshaler instead
+ */
+ public void setMarshaller(ASMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return the marshaler
+ */
+ public ASMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ /**
+ * @param marshaler the marshaler to set
+ */
+ public void setMarshaler(ASMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange messageExchange, NormalizedMessage inMessage) throws Exception {
+ XMLStreamReader in = marshaler.createStreamReader(inMessage);
+
+ org.codehaus.activesoap.MessageExchange asExchange = service.createMessageExchange(in, null);
+ marshaler.fromNMS(asExchange, inMessage);
+ service.invoke(asExchange);
+
+ done(messageExchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASTransport.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASTransport.java
new file mode 100644
index 0000000..10a37b2
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/ASTransport.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.activesoap;
+
+import org.codehaus.activesoap.transport.Invocation;
+import org.codehaus.activesoap.transport.TransportClient;
+import org.codehaus.activesoap.util.XMLStreamFactory;
+
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLStreamReader;
+import java.io.Reader;
+
+/**
+ * An <a href="http://activesoap.codehaus.org/">ActiveSOAP</a> transport which uses JBI.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ASTransport implements TransportClient {
+
+ private ASMarshaler marshaler = new ASMarshaler();
+
+
+ private DeliveryChannel channel;
+ private XMLStreamFactory streamFactory;
+
+ public ASTransport(DeliveryChannel channel) {
+ this(channel, new XMLStreamFactory());
+ }
+
+ public ASTransport(DeliveryChannel channel, XMLStreamFactory streamFactory) {
+ this.channel = channel;
+ this.streamFactory = streamFactory;
+ }
+
+ public Invocation createInvocation() {
+ return new ASInvocation(this, streamFactory);
+ }
+
+ public void invokeOneWay(Invocation invocation, Reader request) throws Exception {
+ throw new UnsupportedOperationException("Should never be invoked directly");
+ }
+
+ public Reader invokeRequest(Invocation invocation, Reader request) throws Exception {
+ throw new UnsupportedOperationException("Should never be invoked directly");
+ }
+
+ public void close() throws Exception {
+ channel.close();
+ }
+
+ public void invokeOneWay(ASInvocation invocation, String xml) throws Exception {
+ MessageExchangeFactory fac = channel.createExchangeFactory();
+ InOnly exchange = fac.createInOnlyExchange();
+ NormalizedMessage inMessage = exchange.createMessage();
+ marshaler.setContent(inMessage, xml);
+ exchange.setInMessage(inMessage);
+ channel.send(exchange);
+ }
+
+ public XMLStreamReader invokeRequest(ASInvocation invocation, String xml) throws Exception {
+ MessageExchangeFactory fac = channel.createExchangeFactory();
+ InOut exchange = fac.createInOutExchange();
+ NormalizedMessage inMessage = exchange.createMessage();
+ marshaler.setContent(inMessage, xml);
+ exchange.setInMessage(inMessage);
+ boolean answer = channel.sendSync(exchange);
+ if (answer) {
+ NormalizedMessage outMessage = exchange.getOutMessage();
+ return marshaler.createStreamReader(outMessage);
+ }
+ else {
+ Fault fault = exchange.getFault();
+ return marshaler.createStreamReader(fault);
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/package.html
new file mode 100644
index 0000000..08b7021
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/activesoap/package.html
@@ -0,0 +1,28 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for integrating <a href="http://activesoap.codehaus.org/">ActiveSOAP</a> services and for ActiveSOAP to use
+JBI as its transport bindings.
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/CacheComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/CacheComponent.java
new file mode 100644
index 0000000..31defb1
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/CacheComponent.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.cache;
+
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.servicemix.expression.Expression;
+import org.apache.servicemix.expression.PropertyExpression;
+import org.apache.servicemix.jbi.NoOutMessageAvailableException;
+
+/**
+ * Implements a caching layer on top of a service invocation to avoid calling an expensive remote service too often.
+ * The cache can be a simple Map based cache or a full <a href="http://www.jcp.org/en/jsr/detail?id=107">JCache</a> instance.
+ *
+ * @version $Revision: 426415 $
+ */
+public class CacheComponent extends TransformComponentSupport {
+
+ public static final PropertyExpression KEY_PROPERTY_EXPRESSION = new PropertyExpression("org.apache.servicemix.key");
+
+ private Map cache;
+ private Expression keyExpression = KEY_PROPERTY_EXPRESSION;
+
+ public Map getCache() {
+ return cache;
+ }
+
+ public void setCache(Map cache) {
+ this.cache = cache;
+ }
+
+ public Expression getKeyExpression() {
+ return keyExpression;
+ }
+
+ public void setKeyExpression(Expression keyExpression) {
+ this.keyExpression = keyExpression;
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ super.init();
+ if (cache == null) {
+ throw new JBIException("You must specify a cache property");
+ }
+ }
+
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ Object key = keyExpression.evaluate(exchange, in);
+ if (key != null) {
+ NormalizedMessage message = (NormalizedMessage) cache.get(key);
+ if (message != null) {
+ getMessageTransformer().transform(exchange, message, out);
+ return true;
+ }
+ }
+
+ InOut inOut = getExchangeFactory().createInOutExchange();
+ NormalizedMessage request = inOut.createMessage();
+ getMessageTransformer().transform(exchange, in, request);
+ inOut.setInMessage(request);
+ getDeliveryChannel().sendSync(inOut);
+
+ NormalizedMessage response = inOut.getOutMessage();
+ Fault fault = inOut.getFault();
+ Exception error = inOut.getError();
+ if (fault != null) {
+ fail(exchange, fault);
+ }
+ else if (error != null) {
+ fail(exchange, error);
+ }
+ else if (response != null) {
+ getMessageTransformer().transform(exchange, response, out);
+
+ if (key != null) {
+ cache.put(key, response);
+ }
+ }
+ else {
+ throw new NoOutMessageAvailableException(exchange);
+ }
+ return true;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/LRUCache.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/LRUCache.java
new file mode 100644
index 0000000..52acd8d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/LRUCache.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.cache;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * Represnts an LRUCache of a fixed maximum size which by default will
+ * remove items based on access order but can be used to use insertion order
+ *
+ * @version $Revision: 426415 $
+ */
+public class LRUCache extends LinkedHashMap {
+ private static final long serialVersionUID = -5754338187296859149L;
+
+ protected static final int DEFAULT_INITIAL_CAPACITY = 1000;
+ protected static final float DEFAULT_LOAD_FACTOR = (float) 0.75;
+
+ private int maxSize;
+
+ public LRUCache(int initialCapacity, float loadFactor, boolean accessOrder, int maxSize) {
+ super(initialCapacity, loadFactor, accessOrder);
+ this.maxSize = maxSize;
+ }
+
+ public LRUCache(int maxSize) {
+ this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, true, maxSize);
+ }
+
+ public LRUCache(int maxSize, boolean accessOrder) {
+ this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, accessOrder, maxSize);
+ }
+
+ protected boolean removeEldestEntry(Map.Entry eldest) {
+ return size() > maxSize;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/package.html
new file mode 100644
index 0000000..3a9b0f2
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/cache/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A component which peforms caching using the <a href="http://servicemix.org/JCache">JCache API</a>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/DroolsComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/DroolsComponent.java
new file mode 100644
index 0000000..32bc7aa
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/DroolsComponent.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools;
+
+import java.net.URL;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.JbiConstants;
+import org.apache.servicemix.components.util.OutBinding;
+import org.drools.FactException;
+import org.drools.RuleBase;
+import org.drools.WorkingMemory;
+import org.drools.io.RuleBaseLoader;
+import org.springframework.core.io.Resource;
+
+/**
+ * A component which implements a rules based routing using <a href="http://drools.org/">Drools</a> to decide
+ * where to route the message.
+ *
+ * @version $Revision: 478818 $
+ */
+public class DroolsComponent extends OutBinding {
+
+ private RuleBase ruleBase;
+ private Resource ruleBaseResource;
+ private URL ruleBaseURL;
+ private ThreadLocal routed = new ThreadLocal();
+
+ public RuleBase getRuleBase() {
+ return ruleBase;
+ }
+
+ public void setRuleBase(RuleBase ruleBase) {
+ this.ruleBase = ruleBase;
+ }
+
+ public Resource getRuleBaseResource() {
+ return ruleBaseResource;
+ }
+
+ public void setRuleBaseResource(Resource ruleBaseResource) {
+ this.ruleBaseResource = ruleBaseResource;
+ }
+
+ public URL getRuleBaseURL() {
+ return ruleBaseURL;
+ }
+
+ public void setRuleBaseURL(URL ruleBaseURL) {
+ this.ruleBaseURL = ruleBaseURL;
+ }
+
+ // Helper methods for the rule base
+ //-------------------------------------------------------------------------
+ public void forwardToService(MessageExchange exchange, NormalizedMessage in, QName name) throws MessagingException {
+ DeliveryChannel channel = getDeliveryChannel();
+ MessageExchangeFactory factory = channel.createExchangeFactoryForService(name);
+ InOnly outExchange = factory.createInOnlyExchange();
+ String processCorrelationId = (String)exchange.getProperty(JbiConstants.CORRELATION_ID);
+ if (processCorrelationId != null) {
+ outExchange.setProperty(JbiConstants.CORRELATION_ID, processCorrelationId);
+ }
+ forwardToExchange(exchange, outExchange, in);
+ }
+
+
+ public void forwardToInterface(QName name, MessageExchange exchange, NormalizedMessage in) throws MessagingException {
+ DeliveryChannel channel = getDeliveryChannel();
+ MessageExchangeFactory factory = channel.createExchangeFactory(name);
+ InOnly outExchange = factory.createInOnlyExchange();
+ String processCorrelationId = (String)exchange.getProperty(JbiConstants.CORRELATION_ID);
+ if (processCorrelationId != null) {
+ outExchange.setProperty(JbiConstants.CORRELATION_ID, processCorrelationId);
+ }
+ forwardToExchange(exchange, outExchange, in);
+ }
+
+ public void route(MessageExchange exchange, NormalizedMessage in, QName service, QName interfaceName, QName operation) throws MessagingException {
+ if (routed.get() != null) {
+ throw new IllegalStateException("Drools component has already routed this exchange");
+ }
+ routed.set(Boolean.TRUE);
+ DeliveryChannel channel = getDeliveryChannel();
+ MessageExchangeFactory factory = channel.createExchangeFactory();
+ MessageExchange me = factory.createExchange(exchange.getPattern());
+ me.setInterfaceName(interfaceName);
+ me.setService(service);
+ me.setOperation(operation);
+ NormalizedMessage nm = me.createMessage();
+ me.setMessage(nm, "in");
+ getMessageTransformer().transform(exchange, in, nm);
+ channel.sendSync(me);
+ if (me.getStatus() == ExchangeStatus.ERROR) {
+ fail(exchange, me.getError());
+ } else if (me.getStatus() == ExchangeStatus.DONE) {
+ done(exchange);
+ } else {
+ NormalizedMessage out = me.getMessage("out");
+ if (out != null) {
+ nm = exchange.createMessage();
+ exchange.setMessage(nm, "out");
+ getMessageTransformer().transform(exchange, out, nm);
+ } else {
+ Fault f = me.getFault();
+ Fault of = exchange.createFault();
+ exchange.setFault(of);
+ getMessageTransformer().transform(exchange, f, of);
+ }
+ channel.send(exchange);
+ done(me);
+ }
+
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ super.init();
+ try {
+ if (ruleBase == null) {
+ if (ruleBaseResource != null) {
+ ruleBase = RuleBaseLoader.loadFromInputStream(ruleBaseResource.getInputStream());
+ }
+ else if (ruleBaseURL != null) {
+ ruleBase = RuleBaseLoader.loadFromUrl(ruleBaseURL);
+ }
+ else {
+ throw new IllegalArgumentException("You must specify a ruleBase, ruleBaseResource or ruleBaseURL property");
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ throw new JBIException(e);
+ }
+ }
+
+ protected void process(MessageExchange exchange, NormalizedMessage in) throws Exception {
+ WorkingMemory memory = ruleBase.newWorkingMemory();
+ populateWorkingMemory(memory, exchange, in);
+ routed.set(null);
+ memory.fireAllRules();
+ if (routed.get() == null) {
+ if (exchange instanceof InOut) {
+ fail(exchange, new Exception("Drools component has not routed the exchange"));
+ } else {
+ done(exchange);
+ }
+ }
+ }
+
+ protected void populateWorkingMemory(WorkingMemory memory, MessageExchange exchange, NormalizedMessage in) throws MessagingException, FactException {
+ memory.setApplicationData("context", getContext());
+ memory.setApplicationData("deliveryChannel", getDeliveryChannel());
+ memory.setApplicationData("jbi", new JbiHelper(this, exchange, in, memory));
+ memory.assertObject(in);
+ memory.assertObject(exchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/FactMessagingException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/FactMessagingException.java
new file mode 100644
index 0000000..50aa1d0
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/FactMessagingException.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools;
+
+import org.drools.FactException;
+
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class FactMessagingException extends MessagingException {
+ public FactMessagingException(FactException e) {
+ super(e.getMessage(), e);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/JbiHelper.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/JbiHelper.java
new file mode 100644
index 0000000..e35174d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/JbiHelper.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools;
+
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.drools.WorkingMemory;
+
+/**
+ * A helper class for use inside a rule to forward a message to an endpoint
+ *
+ * @version $Revision: 426415 $
+ */
+public class JbiHelper {
+ private DroolsComponent component;
+ private MessageExchange exchange;
+ private NormalizedMessage in;
+ private WorkingMemory memory;
+
+ public JbiHelper(DroolsComponent component,
+ MessageExchange exchange,
+ NormalizedMessage in,
+ WorkingMemory memory) {
+ this.component = component;
+ this.exchange = exchange;
+ this.in = in;
+ this.memory = memory;
+ }
+
+ /**
+ * Forwards the inbound message to the given
+ *
+ * @param uri
+ * @param localPart
+ */
+ public void forwardToService(String uri, String localPart) throws MessagingException {
+ QName service = new QName(uri, localPart);
+ component.forwardToService(exchange, in, service);
+ }
+
+ public void forwardToService(QName name, QName operation, QName interfaceName) throws MessagingException {
+ component.forwardToService(exchange, in, name);
+ }
+
+ public void invoke(QName service, QName operation, QName interfaceName) throws MessagingException {
+ component.invoke(exchange, in, service, interfaceName, operation);
+ }
+
+ public void route(QName service, QName operation, QName interfaceName) throws MessagingException {
+ component.route(exchange, in, service, interfaceName, operation);
+ }
+
+ public DeliveryChannel getDeliveryChannel() throws MessagingException {
+ return getComponent().getContext().getDeliveryChannel();
+ }
+
+ public DroolsComponent getComponent() {
+ return component;
+ }
+
+ public MessageExchange getExchange() {
+ return exchange;
+ }
+
+ public NormalizedMessage getIn() {
+ return in;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/ForwardConsequenceFactory.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/ForwardConsequenceFactory.java
new file mode 100644
index 0000000..fd9a77f
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/ForwardConsequenceFactory.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools.dsl;
+
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.drools.JbiHelper;
+import org.drools.rule.Rule;
+import org.drools.smf.Configuration;
+import org.drools.smf.ConsequenceFactory;
+import org.drools.smf.FactoryException;
+import org.drools.spi.Consequence;
+import org.drools.spi.RuleBaseContext;
+import org.drools.spi.Tuple;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class ForwardConsequenceFactory implements ConsequenceFactory {
+ private static transient Log log = LogFactory.getLog(ForwardConsequenceFactory.class);
+
+ public Consequence newConsequence(Rule rule, RuleBaseContext ruleBaseContext, final Configuration configuration) throws FactoryException {
+ final String[] services = configuration.getAttribute("service").split(",");
+ return new JbiConsequence() {
+ protected void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException {
+ for (int i = 0; i < services.length; i++) {
+ QName service = toQName(configuration, services[i]);
+ helper.forwardToService(service, null, null);
+ }
+ }
+ };
+ }
+
+ /**
+ * Converts the String into a QName
+ */
+ protected QName toQName(Configuration configuration, String text) {
+ if (text == null) {
+ return null;
+ }
+ String[] names = configuration.getAttributeNames();
+ String localPart = text;
+ String prefix = null;
+ int idx = text.indexOf(':');
+ if (idx >= 0) {
+ prefix = "xmlns:" + text.substring(0, idx);
+ localPart = text.substring(idx + 1);
+ }
+ String uri = "";
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ if (prefix == null) {
+ if ("xmlns".equals(name)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ else {
+ if (name.equals(prefix)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ }
+ log.debug("Creating QName with uri: " + uri + " name: " + localPart);
+ return new QName(uri, localPart);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/InvokeConsequenceFactory.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/InvokeConsequenceFactory.java
new file mode 100644
index 0000000..448d8fb
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/InvokeConsequenceFactory.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools.dsl;
+
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.drools.JbiHelper;
+import org.drools.rule.Rule;
+import org.drools.smf.Configuration;
+import org.drools.smf.ConsequenceFactory;
+import org.drools.smf.FactoryException;
+import org.drools.spi.Consequence;
+import org.drools.spi.RuleBaseContext;
+import org.drools.spi.Tuple;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class InvokeConsequenceFactory implements ConsequenceFactory {
+
+ private static transient Log log = LogFactory.getLog(InvokeConsequenceFactory.class);
+
+ public Consequence newConsequence(Rule rule, RuleBaseContext ruleBaseContext, Configuration configuration) throws FactoryException {
+ final QName operation = toQName(configuration, configuration.getAttribute("operation"));
+ final QName service = toQName(configuration, configuration.getAttribute("service"));
+ final QName interfaceName = toQName(configuration, configuration.getAttribute("interface"));
+ return new JbiConsequence() {
+ protected void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException {
+ helper.invoke(service, operation, interfaceName);
+ }
+ };
+ }
+
+ /**
+ * Converts the String into a QName
+ */
+ protected QName toQName(Configuration configuration, String text) {
+ if (text == null) {
+ return null;
+ }
+ String[] names = configuration.getAttributeNames();
+ String localPart = text;
+ String prefix = null;
+ int idx = text.indexOf(':');
+ if (idx >= 0) {
+ prefix = "xmlns:" + text.substring(0, idx);
+ localPart = text.substring(idx + 1);
+ }
+ String uri = "";
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ if (prefix == null) {
+ if ("xmlns".equals(name)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ else {
+ if (name.equals(prefix)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ }
+ log.debug("Creating QName with uri: " + uri + " name: " + localPart);
+ return new QName(uri, localPart);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JaxenCondition.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JaxenCondition.java
new file mode 100644
index 0000000..8ea0743
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JaxenCondition.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools.dsl;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.expression.JaxenVariableContext;
+import org.apache.servicemix.expression.JaxenXPathExpression;
+import org.drools.WorkingMemory;
+import org.drools.rule.Declaration;
+import org.drools.rule.Rule;
+import org.drools.spi.Condition;
+import org.drools.spi.Tuple;
+
+/**
+ * Represents a Jaxen based condition using the W3C DOM.
+ *
+ * @version $Revision: 426415 $
+ */
+public class JaxenCondition implements Condition {
+ private Rule rule;
+ private JaxenXPathExpression expression;
+
+ public JaxenCondition(Rule rule, JaxenXPathExpression expression) {
+ this.rule = rule;
+ this.expression = expression;
+ }
+
+ public Declaration[] getRequiredTupleMembers() {
+ Collection list = rule.getParameterDeclarations();
+ Declaration[] answer = new Declaration[list.size()];
+ list.toArray(answer);
+ return answer;
+ }
+
+ public boolean isAllowed(Tuple tuple) {
+ List list = (List) rule.getParameterDeclarations();
+ WorkingMemory memory = tuple.getWorkingMemory();
+ JaxenVariableContext variableContext = expression.getVariableContext();
+ variableContext.setVariables(null);
+
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ Declaration declaration = (Declaration) iter.next();
+ String name = declaration.getIdentifier();
+ Object value = tuple.get(declaration);
+ variableContext.setVariableValue(name, value);
+ }
+ NormalizedMessage message = (NormalizedMessage) findFirst(memory, NormalizedMessage.class);
+ MessageExchange exchange = (MessageExchange) findFirst(memory, MessageExchange.class);
+
+ try {
+ return expression.matches(exchange, message);
+ }
+ catch (MessagingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected Object findFirst(WorkingMemory memory, Class type) {
+ List objects = memory.getObjects(type);
+ Object answer = null;
+ if (objects.size() > 0) {
+ answer = objects.get(0);
+ }
+ return answer;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JaxenConditionFactory.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JaxenConditionFactory.java
new file mode 100644
index 0000000..64fa9e9
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JaxenConditionFactory.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools.dsl;
+
+import org.apache.servicemix.expression.JaxenXPathExpression;
+import org.drools.rule.Rule;
+import org.drools.smf.ConditionFactory;
+import org.drools.smf.Configuration;
+import org.drools.smf.FactoryException;
+import org.drools.spi.Condition;
+import org.drools.spi.RuleBaseContext;
+import org.jaxen.NamespaceContext;
+import org.jaxen.SimpleNamespaceContext;
+
+/**
+ * A condition which uses Jaxen based XPath expressions
+ *
+ * @version $Revision: 449611 $
+ */
+public class JaxenConditionFactory implements ConditionFactory {
+
+ public Condition[] newCondition(Rule rule, RuleBaseContext ruleBaseContext, Configuration configuration) throws FactoryException {
+ String text = configuration.getText();
+ if (text == null) {
+ throw new FactoryException("No XPath provided!");
+ }
+ try {
+ JaxenXPathExpression expression = new JaxenXPathExpression();
+ expression.setXpath(text);
+ expression.setNamespaceContext(createNamespaceContext(configuration));
+ expression.afterPropertiesSet();
+ return new Condition[]{ new JaxenCondition(rule, expression) };
+ }
+ catch (Exception e) {
+ throw new FactoryException(e);
+ }
+ }
+
+ protected NamespaceContext createNamespaceContext(Configuration configuration) {
+ SimpleNamespaceContext answer = new SimpleNamespaceContext();
+ String[] names = configuration.getAttributeNames();
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ if (name.equals("xmlns")) {
+ answer.addNamespace("", configuration.getAttribute(name));
+ }
+ else {
+ if (name.startsWith("xmlns:")) {
+ String prefix = name.substring(6);
+ String uri = configuration.getAttribute(name);
+ answer.addNamespace(prefix, uri);
+ }
+ }
+ }
+ return answer;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JbiConsequence.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JbiConsequence.java
new file mode 100644
index 0000000..28bdd0d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/JbiConsequence.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools.dsl;
+
+import org.apache.servicemix.components.drools.JbiHelper;
+import org.drools.spi.Consequence;
+import org.drools.spi.ConsequenceException;
+import org.drools.spi.Tuple;
+
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public abstract class JbiConsequence implements Consequence {
+
+ public void invoke(Tuple tuple) throws ConsequenceException {
+ JbiHelper helper = (JbiHelper) tuple.getWorkingMemory().getApplicationData("jbi");
+ if (helper == null) {
+ throw new ConsequenceException("No 'jbi' application data available");
+ }
+ try {
+ invokeJbiOperation(helper, tuple);
+ }
+ catch (MessagingException e) {
+ throw new ConsequenceException(e);
+ }
+ }
+
+ protected abstract void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException;
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/RouteConsequenceFactory.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/RouteConsequenceFactory.java
new file mode 100644
index 0000000..c45a1de
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/dsl/RouteConsequenceFactory.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools.dsl;
+
+import javax.jbi.messaging.MessagingException;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.drools.JbiHelper;
+import org.drools.rule.Rule;
+import org.drools.smf.Configuration;
+import org.drools.smf.ConsequenceFactory;
+import org.drools.smf.FactoryException;
+import org.drools.spi.Consequence;
+import org.drools.spi.RuleBaseContext;
+import org.drools.spi.Tuple;
+
+/**
+ * @version $Revision: 359186 $
+ */
+public class RouteConsequenceFactory implements ConsequenceFactory {
+ private static transient Log log = LogFactory.getLog(RouteConsequenceFactory.class);
+
+ public Consequence newConsequence(Rule rule, RuleBaseContext ruleBaseContext, Configuration configuration) throws FactoryException {
+ final QName operation = toQName(configuration, configuration.getAttribute("operation"));
+ final QName service = toQName(configuration, configuration.getAttribute("service"));
+ final QName interfaceName = toQName(configuration, configuration.getAttribute("interface"));
+ return new JbiConsequence() {
+ protected void invokeJbiOperation(JbiHelper helper, Tuple tuple) throws MessagingException {
+ helper.route(service, operation, interfaceName);
+ }
+ };
+ }
+
+ /**
+ * Converts the String into a QName
+ */
+ protected QName toQName(Configuration configuration, String text) {
+ if (text == null) {
+ return null;
+ }
+ String[] names = configuration.getAttributeNames();
+ String localPart = text;
+ String prefix = null;
+ int idx = text.indexOf(':');
+ if (idx >= 0) {
+ prefix = "xmlns:" + text.substring(0, idx);
+ localPart = text.substring(idx + 1);
+ }
+ String uri = "";
+ for (int i = 0; i < names.length; i++) {
+ String name = names[i];
+ if (prefix == null) {
+ if ("xmlns".equals(name)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ else {
+ if (name.equals(prefix)) {
+ uri = configuration.getAttribute(name);
+ break;
+ }
+ }
+ }
+ log.debug("Creating QName with uri: " + uri + " name: " + localPart);
+ return new QName(uri, localPart);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/package.html
new file mode 100644
index 0000000..9d31d62
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/drools/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A component which peforms rules based routing using <a href="http://drools.org/">Drools</a> to decide where to route the message.
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
new file mode 100644
index 0000000..9d6b538
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MailMarshalerSupport.java
@@ -0,0 +1,247 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.mail.Address;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+import org.apache.servicemix.components.util.MarshalerSupport;
+import org.apache.servicemix.expression.Expression;
+import org.apache.servicemix.expression.PropertyExpression;
+
+/**
+ * A useful base class for mail marshalers.
+ *
+ * @version $Revision: 472747 $
+ */
+public abstract class MailMarshalerSupport extends MarshalerSupport {
+ private DateFormat dateFormat = DateFormat.getInstance();
+
+ private Expression to = new PropertyExpression("org.apache.servicemix.email.to");
+ private Expression cc = new PropertyExpression("org.apache.servicemix.email.cc");
+ private Expression bcc = new PropertyExpression("org.apache.servicemix.email.bcc");
+ private Expression from = new PropertyExpression("org.apache.servicemix.email.from", "noone@servicemix.org");
+ private Expression text = new PropertyExpression("org.apache.servicemix.email.text");
+ private Expression html = new PropertyExpression("org.apache.servicemix.email.html");
+ private Expression subject = new PropertyExpression("org.apache.servicemix.email.subject", "Message from ServiceMix");
+ private Expression replyTo = new PropertyExpression("org.apache.servicemix.email.replyTo");
+ private Expression sentDate = new PropertyExpression("org.apache.servicemix.email.sentDate");
+ private Expression attachments = new PropertyExpression("org.apache.servicemix.email.attachments");
+
+ public Expression getTo() {
+ return to;
+ }
+
+ public void setTo(Expression to) {
+ this.to = to;
+ }
+
+ public Expression getCc() {
+ return cc;
+ }
+
+ public void setCc(Expression cc) {
+ this.cc = cc;
+ }
+
+ public Expression getBcc() {
+ return bcc;
+ }
+
+ public void setBcc(Expression bcc) {
+ this.bcc = bcc;
+ }
+
+ public Expression getFrom() {
+ return from;
+ }
+
+ public void setFrom(Expression from) {
+ this.from = from;
+ }
+
+ public Expression getText() {
+ return text;
+ }
+
+ public void setText(Expression text) {
+ this.text = text;
+ }
+
+ public Expression getHtml() {
+ return html;
+ }
+
+ public void setHtml(Expression html) {
+ this.html = html;
+ }
+
+ public Expression getSubject() {
+ return subject;
+ }
+
+ public void setSubject(Expression subject) {
+ this.subject = subject;
+ }
+
+ public Expression getReplyTo() {
+ return replyTo;
+ }
+
+ public void setReplyTo(Expression replyTo) {
+ this.replyTo = replyTo;
+ }
+
+ public Expression getSentDate() {
+ return sentDate;
+ }
+
+ public void setSentDate(Expression sentDate) {
+ this.sentDate = sentDate;
+ }
+
+ public DateFormat getDateFormat() {
+ return dateFormat;
+ }
+
+ public void setDateFormat(DateFormat dateFormat) {
+ this.dateFormat = dateFormat;
+ }
+
+ public Expression getAttachments() {
+ return attachments;
+ }
+
+ public void setAttachments(Expression attachments) {
+ this.attachments = attachments;
+ }
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected Date getSentDate(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException {
+ return asDate(sentDate.evaluate(exchange, normalizedMessage));
+ }
+
+ protected String getSubject(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException {
+ return asString(subject.evaluate(exchange, normalizedMessage));
+ }
+
+ protected String getText(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, TransformerException {
+ String text = asString(this.text.evaluate(exchange, normalizedMessage));
+ if (text == null) {
+ // lets just turn the XML body to text
+ Source content = normalizedMessage.getContent();
+ if (content != null) {
+ text = getTransformer().toString(content);
+ }
+ }
+ return text;
+ }
+
+ protected String getHtml(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, TransformerException {
+ return (this.html != null) ? asString(this.html.evaluate(exchange, normalizedMessage)) : null;
+ }
+
+ protected Address asAddress(Object value) throws AddressException {
+ if (value instanceof Address) {
+ return (Address) value;
+ }
+ if (value instanceof String) {
+ return new InternetAddress((String) value);
+ }
+ if (value != null) {
+ throw new IllegalArgumentException("Expression does not evaluate to an Address. Is of type: " + value.getClass().getName() + " with value: " + value);
+ }
+ return null;
+ }
+
+ protected Date asDate(Object value) {
+ if (value instanceof Date) {
+ return (Date) value;
+ }
+ if (value instanceof String) {
+ String text = (String) value;
+ try {
+ return dateFormat.parse(text);
+ }
+ catch (ParseException e) {
+ throw new IllegalArgumentException("Invalid date format for: " + text + ". Reason: " + e);
+ }
+ }
+ if (value != null) {
+ throw new IllegalArgumentException("Expression does not evaluate to a Date. Is of type: " + value.getClass().getName() + " with value: " + value);
+
+ }
+ return null;
+ }
+
+ protected Address[] asAddressArray(Object value) throws AddressException {
+ if (value instanceof String) {
+ Address[] addresses = InternetAddress.parse((String)value);
+ return addresses;
+ }
+ if (value instanceof Address[]) {
+ return (Address[]) value;
+ }
+ if (value instanceof Collection) {
+ Collection collection = (Collection) value;
+ Address[] answer = new Address[collection.size()];
+ int i = 0;
+ for (Iterator iter = collection.iterator(); iter.hasNext();) {
+ answer[i++] = asAddress(iter.next());
+ }
+ return answer;
+ }
+ if (value != null) {
+ throw new IllegalArgumentException("Expression does not evaluate to an Address[]. Is of type: " + value.getClass().getName() + " with value: " + value);
+ }
+ return null;
+ }
+
+ protected Object asStringOrStringArray(Object value) {
+ if (value instanceof String) {
+ return value;
+ }
+ if (value instanceof String[]) {
+ return value;
+ }
+ if (value instanceof Collection) {
+ Collection collection = (Collection) value;
+ String[] answer = new String[collection.size()];
+ int i = 0;
+ for (Iterator iter = collection.iterator(); iter.hasNext();) {
+ answer[i++] = asString(iter.next());
+ }
+ return answer;
+ }
+ if (value != null) {
+ throw new IllegalArgumentException("Expression does not evaluate to a String[]. Is of type: " + value.getClass().getName() + " with value: " + value);
+ }
+ return null;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
new file mode 100644
index 0000000..e5b16f2
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailMarshaler.java
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.activation.DataHandler;
+import javax.activation.DataSource;
+import javax.activation.FileDataSource;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.mail.Address;
+import javax.mail.BodyPart;
+import javax.mail.Message;
+import javax.mail.Multipart;
+import javax.mail.Part;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeBodyPart;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.xml.transform.TransformerException;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * The default marshaler from the {@link NormalizedMessage} to a Mime email using
+ * expressions for each field required on the email.
+ *
+ * @version $Revision: 472747 $
+ */
+public class MimeMailMarshaler extends MailMarshalerSupport {
+ private static Log log = LogFactory.getLog(MimeMailPoller.class);
+
+ /**
+ * Populates the MessageExchange with values extracted from the mail message using expressions.
+ *
+ * @param exchange the JBI message exchange
+ * @param normalizedMessage the normalized message from JBI
+ * @param mimeMessage the mime email
+ * @throws javax.mail.MessagingException if the message could not be constructed or there was an error creating an address
+ */
+ public void prepareExchange(MessageExchange exchange, NormalizedMessage normalizedMessage, MimeMessage mimeMessage) throws javax.mail.MessagingException {
+ String from = InternetAddress.toString(mimeMessage.getFrom());
+ String to = InternetAddress.toString(mimeMessage.getRecipients(Message.RecipientType.TO));
+ String cc = InternetAddress.toString(mimeMessage.getRecipients(Message.RecipientType.CC));
+ String replyTo = InternetAddress.toString(mimeMessage.getReplyTo());
+ String sentDate = getDateFormat().format(mimeMessage.getSentDate());
+ String text = null;
+ String html = null;
+ MimeMultipart mp = null;
+ Object content = null;
+ Object subContent = null;
+ MimeMultipart subMP = null;
+
+ try {
+ content = mimeMessage.getContent();
+ if (content instanceof String)
+ // simple mail
+ text = asString(content);
+ else if (content instanceof MimeMultipart) {
+ // mail with attachment
+ mp = (MimeMultipart)content;
+ int nbMP = mp.getCount();
+ for (int i=0; i < nbMP; i++) {
+ Part part = mp.getBodyPart(i);
+ String disposition = part.getDisposition();
+ if ((disposition != null) &&
+ ((disposition.equals(Part.ATTACHMENT) ||
+ (disposition.equals(Part.INLINE))))) {
+ //Parts marked with a disposition of Part.ATTACHMENT from part.getDisposition() are clearly attachments
+ DataHandler att = part.getDataHandler();
+ normalizedMessage.addAttachment(att.getName(), att);
+ } else {
+ MimeBodyPart mbp = (MimeBodyPart)part;
+ if (mbp.isMimeType("text/plain")) {
+ // Handle plain
+ text = (String)mbp.getContent();
+ } else if (mbp.isMimeType("text/html")) {
+ // Handle html contents
+ html = (String)mbp.getContent();
+ } else if (mbp.isMimeType("multipart/related")){
+ // Special case for multipart/related message type
+ subContent = mbp.getContent();
+ if (subContent instanceof MimeMultipart) {
+ subMP = (MimeMultipart)subContent;
+ int nbsubMP = subMP.getCount();
+ for (int j=0; j < nbsubMP; j++) {
+ MimeBodyPart subMBP = (MimeBodyPart)part;
+ // add a property into the normalize message
+ normalizedMessage.setProperty("org.apache.servicemix.email.alternativeContent" + j, subMBP.getContent());
+ }
+ }
+ } else // strange mail...log a warning
+ log.warn("Some mail contents can not be traited and is not include into message");
+ }
+ }
+ } else { // strange mail...log a warning
+ log.warn("Some mail contents can not be traited and is not include into message");
+ }
+ } catch (MessagingException e) {
+ throw new javax.mail.MessagingException("Error while setting content on normalized message",e);
+ } catch (IOException e) {
+ throw new javax.mail.MessagingException("Error while fetching content",e);
+ }
+
+ normalizedMessage.setProperty("org.apache.servicemix.email.from", from);
+ normalizedMessage.setProperty("org.apache.servicemix.email.to", to);
+ normalizedMessage.setProperty("org.apache.servicemix.email.cc", cc);
+ normalizedMessage.setProperty("org.apache.servicemix.email.text", text);
+ normalizedMessage.setProperty("org.apache.servicemix.email.replyTo", replyTo);
+ normalizedMessage.setProperty("org.apache.servicemix.email.sentDate", sentDate);
+ normalizedMessage.setProperty("org.apache.servicemix.email.html", html);
+
+ try {
+ normalizedMessage.setContent(new StringSource(text));
+ } catch (MessagingException e) {
+ throw new javax.mail.MessagingException("Error while setting content on normalized message",e);
+ }
+ }
+
+ /**
+ * Populates the mime email message with values extracted from the message exchange using expressions.
+ *
+ * @param mimeMessage the mime email
+ * @param exchange the JBI message exchange
+ * @param normalizedMessage the normalized message from JBI
+ * @throws javax.mail.MessagingException if the message could not be constructed or there was an error creating an address
+ */
+ public void prepareMessage(MimeMessage mimeMessage, MessageExchange exchange, NormalizedMessage normalizedMessage) throws javax.mail.MessagingException {
+ try {
+ Address[] to = getTo(exchange, normalizedMessage);
+ if (to != null) {
+ mimeMessage.setRecipients(Message.RecipientType.TO, to);
+ }
+ Address[] cc = getCc(exchange, normalizedMessage);
+ if (cc != null) {
+ mimeMessage.setRecipients(Message.RecipientType.CC, cc);
+ }
+ Address[] bcc = getBcc(exchange, normalizedMessage);
+ if (bcc != null) {
+ mimeMessage.setRecipients(Message.RecipientType.BCC, bcc);
+ }
+ Address from = getFrom(exchange, normalizedMessage);
+ if (from != null) {
+ mimeMessage.setFrom(from);
+ }
+ String text = getText(exchange, normalizedMessage);
+ String html = getHtml(exchange, normalizedMessage);
+ if ((text != null) && (html == null)) {
+ mimeMessage.setText(text);
+ }
+ else if ((text != null) && (html != null)) {
+ MimeMultipart content = new MimeMultipart("alternative");
+ MimeBodyPart textBodyPart = new MimeBodyPart();
+ MimeBodyPart htmlBodyPart = new MimeBodyPart();
+ textBodyPart.setText(text);
+ htmlBodyPart.setContent(html, "text/html");
+ content.addBodyPart(textBodyPart);
+ content.addBodyPart(htmlBodyPart);
+
+ mimeMessage.setContent(content);
+ }
+ String subject = getSubject(exchange, normalizedMessage);
+ if (subject != null) {
+ mimeMessage.setSubject(subject);
+ }
+ Date sentDate = getSentDate(exchange, normalizedMessage);
+ if (sentDate != null) {
+ mimeMessage.setSentDate(sentDate);
+ }
+ Address[] replyTo = getReplyTo(exchange, normalizedMessage);
+ if (replyTo != null) {
+ mimeMessage.setReplyTo(replyTo);
+ }
+
+ // add attachment from message and properties
+ HashMap attachments = this.getAttachments(exchange, normalizedMessage);
+ if (attachments != null) {
+ Set attNames = attachments.keySet();
+ Iterator itAttNames = attNames.iterator();
+ if (itAttNames.hasNext()) { // there is at least one attachment
+ // Create the message part
+ BodyPart messageBodyPart = new MimeBodyPart();
+ // Fill the message
+ messageBodyPart.setText(text);
+ // Create a Multipart
+ Multipart multipart = new MimeMultipart();
+ // Add part one
+ multipart.addBodyPart(messageBodyPart);
+ while (itAttNames.hasNext()) {
+ String oneAttachmentName = (String)itAttNames.next();
+ // Create another body part
+ messageBodyPart = new MimeBodyPart();
+ // Set the data handler to the attachment
+ messageBodyPart.setDataHandler(new DataHandler((DataSource)attachments.get(oneAttachmentName)));
+ // Set the filename
+ messageBodyPart.setFileName(oneAttachmentName);
+ // Set Disposition
+ messageBodyPart.setDisposition(Part.ATTACHMENT);
+ // Add part to multipart
+ multipart.addBodyPart(messageBodyPart);
+ }
+ // Put parts in message
+ mimeMessage.setContent(multipart);
+ }
+ }
+ }
+ catch (MessagingException e) {
+ throw new javax.mail.MessagingException(e.getMessage(), e);
+ }
+ catch (TransformerException e) {
+ throw new javax.mail.MessagingException(e.getMessage(), e);
+ }
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected Address getFrom(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asAddress(getFrom().evaluate(exchange, normalizedMessage));
+ }
+
+ protected Address[] getTo(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asAddressArray(getTo().evaluate(exchange, normalizedMessage));
+ }
+
+ protected Address[] getCc(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asAddressArray(getCc().evaluate(exchange, normalizedMessage));
+ }
+
+ protected Address[] getBcc(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asAddressArray(getBcc().evaluate(exchange, normalizedMessage));
+ }
+
+ protected Address[] getReplyTo(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asAddressArray(getReplyTo().evaluate(exchange, normalizedMessage));
+ }
+
+ protected HashMap getAttachments(MessageExchange exchange, NormalizedMessage normalizedMessage) {
+ HashMap attachments = new HashMap();
+ String filePath = "";
+ String oneAttachmentName = "";
+ try {
+ // get attachment from property org.apache.servicemix.email.attachment
+ String listAttachment = (String)getAttachments().evaluate(exchange, normalizedMessage);
+ if (StringUtils.isNotBlank(listAttachment)) {
+ StringTokenizer st = new StringTokenizer(listAttachment, ",");
+ if (st != null) {
+ while (st.hasMoreTokens()) {
+ filePath = st.nextToken();
+ File file = new File(filePath);
+ attachments.put(file.getName(), new FileDataSource(file));
+ }
+ }
+ }
+ } catch (MessagingException e) {
+ log.warn("file not found for attachment : " + e.getMessage() + " : " + filePath);
+ }
+ // get attachment from Normalize Message
+ Set attNames = normalizedMessage.getAttachmentNames();
+ Iterator itAttNames = attNames.iterator();
+ while (itAttNames.hasNext()) {
+ oneAttachmentName = (String)itAttNames.next();
+ DataSource oneAttchmentInputString = normalizedMessage.getAttachment(oneAttachmentName).getDataSource();
+ attachments.put(oneAttachmentName, oneAttchmentInputString);
+ }
+
+ return attachments;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailPoller.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailPoller.java
new file mode 100644
index 0000000..6e61120
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailPoller.java
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.mail.Flags;
+import javax.mail.Folder;
+import javax.mail.Session;
+import javax.mail.Store;
+import javax.mail.internet.MimeMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.PollingComponentSupport;
+
+/**
+ * A polling component which looks for emails in a mail server and sends them
+ * into the JBI bus as messages, deleting the messages by default when they
+ * are processed.
+ *
+ * @version $Revision: 426415 $
+ */
+public class MimeMailPoller extends PollingComponentSupport {
+
+ private static Log log = LogFactory.getLog(MimeMailPoller.class);
+
+ private Session session;
+ private String hostName;
+ private String userName;
+ private String password;
+ private String mailBox;
+ private boolean debug;
+ private int maxFetchSize = 5;
+ private MimeMailMarshaler marshaler = new MimeMailMarshaler();
+
+ protected void init() throws JBIException {
+ super.init();
+ if (session == null) {
+ log.debug("No Session informed. Using default instance");
+ this.session = Session.getDefaultInstance(System.getProperties());
+ }
+ if (mailBox == null) {
+ log.debug("No mailbox informed. Using INBOX");
+ mailBox = "INBOX";
+ }
+ if (hostName == null) {
+ throw new JBIException("HostName not informed");
+ }
+ if (userName == null) {
+ throw new JBIException("UserName not informed");
+ }
+ if (password == null) {
+ throw new JBIException("Password not informed");
+ }
+ if (maxFetchSize < 1) {
+ throw new JBIException("Fetch Size must be at least 1");
+ }
+
+ }
+
+ /**
+ * @return Returns the hostName.
+ */
+ public String getHostName() {
+ return hostName;
+ }
+
+ /**
+ * @param hostName The hostName to set.
+ */
+ public void setHostName(String hostName) {
+ this.hostName = hostName;
+ }
+
+ /**
+ * @return Returns the marshaler.
+ */
+ public MimeMailMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ /**
+ * @param marshaler The marshaler to set.
+ */
+ public void setMarshaler(MimeMailMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public void poll() throws Exception {
+ Store store = null;
+ Folder folder = null;
+ try {
+ session.setDebug(isDebug());
+ store = session.getStore((mailBox.equals("INBOX")) ? "pop3"
+ : "imap");
+ store.connect(hostName, userName, password);
+ folder = store.getFolder(mailBox);
+ if (folder == null || !folder.exists()) {
+ throw new Exception("Folder not found or invalid: " + mailBox);
+ }
+ folder.open(Folder.READ_WRITE);
+ int msgCount = Math.min(folder.getMessageCount(),maxFetchSize);
+ DeliveryChannel channel = getDeliveryChannel();
+ MessageExchangeFactory mef = getExchangeFactory();
+ for(int i=1; i <= msgCount;i++) {
+ MimeMessage mailMsg = (MimeMessage) folder.getMessage(i);
+ InOnly io = mef.createInOnlyExchange();
+ NormalizedMessage normalizedMessage = io.createMessage();
+ this.marshaler.prepareExchange(io,normalizedMessage,mailMsg);
+ io.setInMessage(normalizedMessage);
+ channel.send(io);
+ mailMsg.setFlag(Flags.Flag.DELETED,true);
+ }
+ } finally {
+ try {
+ if (folder != null) {
+ folder.close(true);
+ }
+ if (store != null) {
+ store.close();
+ }
+ } catch (Exception ignored) {}
+ }
+ }
+
+ /**
+ * @return Returns the debug.
+ */
+ public boolean isDebug() {
+ return debug;
+ }
+
+ /**
+ * @param debug
+ * The debug to set.
+ */
+ public void setDebug(boolean debug) {
+ this.debug = debug;
+ }
+
+ /**
+ * @return Returns the mailBox.
+ */
+ public String getMailBox() {
+ return mailBox;
+ }
+
+ /**
+ * @param mailBox
+ * The mailBox to set.
+ */
+ public void setMailBox(String mailBox) {
+ this.mailBox = mailBox;
+ }
+
+ /**
+ * @return Returns the password.
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * @param password
+ * The password to set.
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * @return Returns the userName.
+ */
+ public String getUserName() {
+ return userName;
+ }
+
+ /**
+ * @param userName
+ * The userName to set.
+ */
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ /**
+ * @return Returns the session.
+ */
+ public Session getSession() {
+ return session;
+ }
+
+ /**
+ * @param session
+ * The session to set.
+ */
+ public void setSession(Session session) {
+ this.session = session;
+ }
+
+ /**
+ * @return Returns the maxFetchSize.
+ */
+ public int getMaxFetchSize() {
+ return maxFetchSize;
+ }
+
+ /**
+ * @param maxFetchSize The maxFetchSize to set.
+ */
+ public void setMaxFetchSize(int maxFetchSize) {
+ this.maxFetchSize = maxFetchSize;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailSender.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailSender.java
new file mode 100644
index 0000000..166d585
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/MimeMailSender.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMessagePreparator;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+/**
+ * An outbound component capable of sending MIME email via
+ * <a href="http://java.sun.com/products/javamail/">JavaMail</a>
+ *
+ * @version $Revision: 426415 $
+ */
+public class MimeMailSender extends OutBinding {
+ private JavaMailSender sender;
+ private MimeMailMarshaler marshaler = new MimeMailMarshaler();
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public JavaMailSender getSender() {
+ return sender;
+ }
+
+ public void setSender(JavaMailSender sender) {
+ this.sender = sender;
+ }
+
+ public MimeMailMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(MimeMailMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ super.init();
+ if (sender == null) {
+ throw new JBIException("You must configure the sender property");
+ }
+ }
+
+ protected void process(final MessageExchange exchange, final NormalizedMessage message) throws Exception {
+ MimeMessagePreparator preparator = new MimeMessagePreparator() {
+ public void prepare(MimeMessage mimeMessage) throws MessagingException {
+ marshaler.prepareMessage(mimeMessage, exchange, message);
+ }
+ };
+ sender.send(preparator);
+ done(exchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/SimpleMailMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/SimpleMailMarshaler.java
new file mode 100644
index 0000000..3909f99
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/SimpleMailMarshaler.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import java.util.Date;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.mail.internet.AddressException;
+import javax.xml.transform.TransformerException;
+
+import org.springframework.mail.SimpleMailMessage;
+
+/**
+ * The default marshaler from the {@link NormalizedMessage} to a {@link SimpleMailMessage} using
+ * expressions for each field required on the email.
+ *
+ * @version $Revision: 429277 $
+ */
+public class SimpleMailMarshaler extends MailMarshalerSupport{
+
+ /**
+ * Populates the mime email message with values extracted from the message exchange using expressions.
+ *
+ * @param mailMessage the mime email
+ * @param exchange the JBI message exchange
+ * @param normalizedMessage the normalized message from JBI
+ * @throws javax.mail.MessagingException if the message could not be constructed or there was an error creating an address
+ */
+ public void prepareMessage(SimpleMailMessage mailMessage, MessageExchange exchange, NormalizedMessage normalizedMessage) throws javax.mail.MessagingException {
+ try {
+ Object to = getTo(exchange, normalizedMessage);
+ if (to != null) {
+ if (to instanceof String) {
+ mailMessage.setTo((String) to);
+ }
+ else {
+ mailMessage.setTo((String[]) to);
+ }
+ }
+ Object cc = getCc(exchange, normalizedMessage);
+ if (cc != null) {
+ if (cc instanceof String) {
+ mailMessage.setCc((String) cc);
+ }
+ else {
+ mailMessage.setCc((String[]) cc);
+ }
+ }
+ Object bcc = getBcc(exchange, normalizedMessage);
+ if (bcc != null) {
+ if (bcc instanceof String) {
+ mailMessage.setBcc((String) bcc);
+ }
+ else {
+ mailMessage.setBcc((String[]) bcc);
+ }
+ }
+ String from = getFrom(exchange, normalizedMessage);
+ if (from != null) {
+ mailMessage.setFrom(from);
+ }
+ String replyTo = getReplyTo(exchange, normalizedMessage);
+ if (replyTo != null) {
+ mailMessage.setReplyTo(replyTo);
+ }
+
+ String text = getText(exchange, normalizedMessage);
+ if (text != null) {
+ mailMessage.setText(text);
+ }
+ String subject = getSubject(exchange, normalizedMessage);
+ if (subject != null) {
+ mailMessage.setSubject(subject);
+ }
+ Date sentDate = getSentDate(exchange, normalizedMessage);
+ if (sentDate != null) {
+ mailMessage.setSentDate(sentDate);
+ }
+ }
+ catch (MessagingException e) {
+ throw new javax.mail.MessagingException(e.getMessage(), e);
+ }
+ catch (TransformerException e) {
+ throw new javax.mail.MessagingException(e.getMessage(), e);
+ }
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected String getFrom(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asString(getFrom().evaluate(exchange, normalizedMessage));
+ }
+
+ protected String getReplyTo(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException {
+ return asString(getReplyTo().evaluate(exchange, normalizedMessage));
+ }
+
+ protected Object getTo(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asStringOrStringArray(getTo().evaluate(exchange, normalizedMessage));
+ }
+
+ protected Object getCc(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asStringOrStringArray(getCc().evaluate(exchange, normalizedMessage));
+ }
+
+ protected Object getBcc(MessageExchange exchange, NormalizedMessage normalizedMessage) throws MessagingException, AddressException {
+ return asStringOrStringArray(getBcc().evaluate(exchange, normalizedMessage));
+ }
+
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/SimpleMailSender.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/SimpleMailSender.java
new file mode 100644
index 0000000..3c4e6ad
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/SimpleMailSender.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.springframework.mail.MailSender;
+import org.springframework.mail.SimpleMailMessage;
+
+/**
+ * An outbound component capable of sending simple email using Spring
+ *
+ * @version $Revision: 426415 $
+ */
+public class SimpleMailSender extends OutBinding {
+ private MailSender sender;
+ private SimpleMailMarshaler marshaler = new SimpleMailMarshaler();
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public MailSender getSender() {
+ return sender;
+ }
+
+ public void setSender(MailSender sender) {
+ this.sender = sender;
+ }
+
+ public SimpleMailMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(SimpleMailMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ super.init();
+ if (sender == null) {
+ throw new JBIException("You must configure the sender property");
+ }
+ }
+
+ protected void process(final MessageExchange exchange, final NormalizedMessage message) throws Exception {
+ SimpleMailMessage email = new SimpleMailMessage();
+ marshaler.prepareMessage(email, exchange, message);
+ sender.send(email);
+ done(exchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/package.html
new file mode 100644
index 0000000..f2697cb
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/email/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+An outbound component capable of sending email via <a href="http://java.sun.com/products/javamail/">JavaMail</a>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/FilePoller.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/FilePoller.java
new file mode 100644
index 0000000..8eda967
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/FilePoller.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.file;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.components.util.FileMarshaler;
+import org.apache.servicemix.components.util.PollingComponentSupport;
+import org.apache.servicemix.jbi.util.FileUtil;
+
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import javax.jbi.JBIException;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+
+/**
+ * A polling component which looks for a file or files in a directory
+ * and sends the files into the JBI bus as messages, deleting the files
+ * by default when they are processed.
+ *
+ * @version $Revision: 666120 $
+ */
+public class FilePoller extends PollingComponentSupport {
+ private static final Log log = LogFactory.getLog(FilePoller.class);
+
+ private File archive;
+ private File file;
+ private FileFilter filter;
+ private boolean deleteFile = true;
+ private boolean recursive = true;
+ private boolean autoCreateDirectory = true;
+ private FileMarshaler marshaler = new DefaultFileMarshaler();
+ private Set workingSet = new CopyOnWriteArraySet();
+
+ public void poll() throws Exception {
+ pollFileOrDirectory(file);
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * Sets the file to poll, which can be a directory or a file.
+ *
+ * @param file
+ */
+ public void setFile(File file) {
+ this.file = file;
+ }
+
+ public FileFilter getFilter() {
+ return filter;
+ }
+
+ /**
+ * Sets the optional filter to choose which files to process
+ */
+ public void setFilter(FileFilter filter) {
+ this.filter = filter;
+ }
+
+ /**
+ * Returns whether or not we should delete the file when its processed
+ */
+ public boolean isDeleteFile() {
+ return deleteFile;
+ }
+
+ public void setDeleteFile(boolean deleteFile) {
+ this.deleteFile = deleteFile;
+ }
+
+ public boolean isRecursive() {
+ return recursive;
+ }
+
+ public void setRecursive(boolean recursive) {
+ this.recursive = recursive;
+ }
+
+ public boolean isAutoCreateDirectory() {
+ return autoCreateDirectory;
+ }
+
+ public void setAutoCreateDirectory(boolean autoCreateDirectory) {
+ this.autoCreateDirectory = autoCreateDirectory;
+ }
+
+ public FileMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(FileMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public File getArchive() {
+ return archive;
+ }
+
+ /**
+ * Configure a directory to archive files before deleting them.
+ *
+ * @param archive the archive directory
+ */
+ public void setArchive(File archive) {
+ this.archive = archive;
+ }
+
+ /**
+ * The set of FTPFiles that this component is currently working on
+ *
+ * @return
+ */
+ public Set getWorkingSet() {
+ return workingSet;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ if (file == null) {
+ throw new IllegalArgumentException("You must specify a file property");
+ }
+ if (isAutoCreateDirectory() && !file.exists()) {
+ file.mkdirs();
+ }
+ if (archive != null) {
+ if (!deleteFile) {
+ throw new DeploymentException("Archive shouldn't be specified unless deleteFile='true'");
+ }
+ if (isAutoCreateDirectory() && !archive.exists()) {
+ archive.mkdirs();
+ }
+ if (!archive.isDirectory()) {
+ throw new DeploymentException("Archive should refer to a directory");
+ }
+ }
+ super.init();
+ }
+
+ protected void pollFileOrDirectory(File fileOrDirectory) {
+ pollFileOrDirectory(fileOrDirectory, true);
+ }
+
+ protected void pollFileOrDirectory(File fileOrDirectory, boolean processDir) {
+ if (!fileOrDirectory.isDirectory()) {
+ pollFile(fileOrDirectory); // process the file
+ } else if (processDir) {
+ log.debug("Polling directory " + fileOrDirectory);
+ File[] files = fileOrDirectory.listFiles(getFilter());
+ for (int i = 0; i < files.length; i++) {
+ pollFileOrDirectory(files[i], isRecursive()); // self-recursion
+ }
+ } else {
+ log.debug("Skipping directory " + fileOrDirectory);
+ }
+ }
+
+ protected void pollFile(final File aFile) {
+ if (workingSet.add(aFile)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scheduling file " + aFile + " for processing");
+ }
+ getExecutor().execute(new Runnable() {
+ public void run() {
+ try {
+ processFileAndDelete(aFile);
+ } finally {
+ workingSet.remove(aFile);
+ }
+ }
+ });
+ }
+ }
+
+ protected void processFileAndDelete(File aFile) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Processing file " + aFile);
+ }
+ if (aFile.exists()) {
+ processFile(aFile);
+ if (isDeleteFile()) {
+ if (archive != null) {
+ FileUtil.moveFile(aFile, archive);
+ } else {
+ if (!aFile.delete()) {
+ throw new IOException("Could not delete file " + aFile);
+ }
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ log.error("Failed to process file: " + aFile + ". Reason: " + e, e);
+ }
+ }
+
+ protected void processFile(File aFile) throws Exception {
+ InputStream in = null;
+ try {
+ String name = aFile.getCanonicalPath();
+ in = new BufferedInputStream(new FileInputStream(aFile));
+ InOnly exchange = getExchangeFactory().createInOnlyExchange();
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setInMessage(message);
+ marshaler.readMessage(exchange, message, in, name);
+ getDeliveryChannel().sendSync(exchange);
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/FileWriter.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/FileWriter.java
new file mode 100644
index 0000000..bbeefe9
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/FileWriter.java
@@ -0,0 +1,135 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.file;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.components.util.FileMarshaler;
+import org.apache.servicemix.components.util.OutBinding;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A component which receives a message and writes the content to a file using the
+ * <a href="http://jakarta.apache.org/commons/vfs.html">Jakarta Commons VFS</a> library
+ * for handling various file systems like files, Samba, WebDAV, FTP, SFTP and temporary files.
+ *
+ * @version $Revision: 426415 $
+ */
+public class FileWriter extends OutBinding {
+ private static final Log log = LogFactory.getLog(FileWriter.class);
+
+ private File directory;
+ private FileMarshaler marshaler = new DefaultFileMarshaler();
+ private String tempFilePrefix = "servicemix-";
+ private String tempFileSuffix = ".xml";
+ private boolean autoCreateDirectory = true;
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public File getDirectory() {
+ return directory;
+ }
+
+ public void setDirectory(File directory) {
+ this.directory = directory;
+ }
+
+ public FileMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(FileMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public String getTempFilePrefix() {
+ return tempFilePrefix;
+ }
+
+ public void setTempFilePrefix(String tempFilePrefix) {
+ this.tempFilePrefix = tempFilePrefix;
+ }
+
+ public String getTempFileSuffix() {
+ return tempFileSuffix;
+ }
+
+ public void setTempFileSuffix(String tempFileSuffix) {
+ this.tempFileSuffix = tempFileSuffix;
+ }
+
+ public boolean isAutoCreateDirectory() {
+ return autoCreateDirectory;
+ }
+
+ public void setAutoCreateDirectory(boolean autoCreateDirectory) {
+ this.autoCreateDirectory = autoCreateDirectory;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ if (directory == null) {
+ throw new IllegalArgumentException("You must specify the directory property");
+ }
+ if (isAutoCreateDirectory()) {
+ directory.mkdirs();
+ }
+ if (!directory.isDirectory()) {
+ throw new IllegalArgumentException("The directory property must be a directory but was: " + directory);
+ }
+
+ super.init();
+ }
+
+ protected void process(MessageExchange exchange, NormalizedMessage message) throws Exception {
+ OutputStream out = null;
+ try {
+ String name = marshaler.getOutputName(exchange, message);
+ File newFile = null;
+ if (name == null) {
+ newFile = File.createTempFile(tempFilePrefix, tempFileSuffix, directory);
+ }
+ else {
+ newFile = new File(directory, name);
+ }
+ out = new BufferedOutputStream(new FileOutputStream(newFile));
+ marshaler.writeMessage(exchange, message, out, name);
+ done(exchange);
+ }
+ finally {
+ if (out != null) {
+ try {
+ out.close();
+ }
+ catch (IOException e) {
+ log.error("Caught exception while closing stream on error: " + e, e);
+ }
+ }
+ }
+ }
+}
+
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/package.html
new file mode 100644
index 0000000..350f261
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/file/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A collection of file system components capable of polling for files in a directory or writing messages to files.
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/GroovyComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/GroovyComponent.java
new file mode 100644
index 0000000..e4c0116
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/GroovyComponent.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.groovy;
+
+import groovy.xml.DOMBuilder;
+
+import org.apache.servicemix.components.script.ScriptComponent;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.script.Bindings;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+/**
+ * A component which is capable of invoking a <a href="http://groovy.codehaus.org/">Groovy</a> script to process
+ * or transform a message.
+ *
+ * @version $Revision: 495362 $
+ */
+public class GroovyComponent extends ScriptComponent {
+
+ private DocumentBuilderFactory documentBuilderFactory;
+ private DocumentBuilder documentBuilder;
+
+ public GroovyComponent() {
+ setScriptEngineName("groovy");
+ }
+
+ public GroovyComponent(QName service, String endpoint) {
+ super(service, endpoint);
+ setScriptEngineName("groovy");
+ }
+
+ public DocumentBuilder getDocumentBuilder() throws ParserConfigurationException {
+ if (documentBuilder == null) {
+ documentBuilder = getDocumentBuilderFactory().newDocumentBuilder();
+ }
+ return documentBuilder;
+ }
+
+ public void setDocumentBuilder(DocumentBuilder documentBuilder) {
+ this.documentBuilder = documentBuilder;
+ }
+
+ public DocumentBuilderFactory getDocumentBuilderFactory() {
+ if (documentBuilderFactory == null) {
+ documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ }
+ return documentBuilderFactory;
+ }
+
+ public void setDocumentBuilderFactory(DocumentBuilderFactory documentBuilderFactory) {
+ this.documentBuilderFactory = documentBuilderFactory;
+ }
+
+ protected void populateBindings(Bindings bindings, MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ try {
+ super.populateBindings(bindings, exchange, in, out);
+
+ // lets output a builder
+ DocumentBuilder documentBuilder = getDocumentBuilder();
+ bindings.put("builder", new DOMBuilder(documentBuilder));
+ }
+ catch (ParserConfigurationException e) {
+ throw new MessagingException("Failed to create DOM DocumentBuilder: " + e, e);
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/GroovyMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/GroovyMarshaler.java
new file mode 100644
index 0000000..e72374d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/GroovyMarshaler.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.groovy;
+
+import org.apache.servicemix.jbi.messaging.DefaultMarshaler;
+import org.apache.servicemix.jbi.messaging.PojoMarshaler;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.MessagingException;
+
+import groovy.lang.GString;
+
+/**
+ * A {@link PojoMarshaler} capable of handling <a href="http://groovy.codehaus.org/">Groovy</a>
+ * specific types.
+ *
+ * @version $Revision: 426415 $
+ */
+public class GroovyMarshaler extends DefaultMarshaler {
+
+ public void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException {
+ if (body instanceof GString) {
+ body = body.toString();
+ }
+
+ // TODO handle Node
+ super.marshal(exchange, message, body);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/JBIModule.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/JBIModule.java
new file mode 100644
index 0000000..d3f3d2e
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/JBIModule.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.groovy;
+
+/**
+ * A Groovy module of helper methods to make JBI more groovy.
+ *
+ * @version $Revision: 426415 $
+ */
+public class JBIModule {
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/package.html
new file mode 100644
index 0000000..c578c78
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/groovy/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A component and support classes for the <a href="http://groovy.codehaus.org/">Groovy</a> scripting language.
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/BindingServlet.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/BindingServlet.java
new file mode 100644
index 0000000..bcf9ab8
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/BindingServlet.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.jbi.JBIException;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
+
+/**
+ * A Servlet which dispatches requests into the JBI container and returns the result.
+ *
+ * @version $Revision: 426415 $
+ */
+public class BindingServlet extends HttpServlet {
+
+ private HttpBinding binding;
+
+ /**
+ * get da binding
+ *
+ * @return the binding
+ */
+ public HttpBinding getBinding() {
+ return binding;
+ }
+
+ public void setBinding(HttpBinding binding) {
+ this.binding = binding;
+ }
+
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ if (binding == null) {
+ binding = (HttpBinding) getServletContext().getAttribute("binding");
+ if (binding == null) {
+ binding = createHttpBinding(config);
+ }
+ if (binding == null) {
+ throw new ServletException("No binding property available on the servlet context");
+ }
+ }
+ }
+
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ try {
+ getBinding().process(request, response);
+ }
+ catch (JBIException e) {
+ throw new ServletException("Failed to process JBI request: " + e, e);
+ }
+ }
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ try {
+ getBinding().process(request, response);
+ }
+ catch (JBIException e) {
+ throw new ServletException("Failed to process JBI request: " + e, e);
+ }
+ }
+
+ protected HttpBinding createHttpBinding(ServletConfig config) throws ServletException {
+ // lets default to in/out
+ return new HttpInOutBinding();
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpBinding.java
new file mode 100644
index 0000000..8debfe5
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpBinding.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.jbi.JBIException;
+import java.io.IOException;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public interface HttpBinding {
+
+ /**
+ * Invokes the HTTP request from a servlet
+ *
+ * @param request
+ * @param response
+ * @throws ServletException
+ * @throws IOException
+ * @throws JBIException
+ */
+ void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+ JBIException;
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpBindingSupport.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpBindingSupport.java
new file mode 100644
index 0000000..9ae25a3
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpBindingSupport.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import org.apache.servicemix.components.util.ComponentSupport;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletException;
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintWriter;
+
+/**
+ * @version $Revision: 449651 $
+ */
+public abstract class HttpBindingSupport extends ComponentSupport implements HttpBinding {
+ protected static final int BAD_REQUEST_STATUS_CODE = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
+ private HttpMarshaler marshaler;
+
+ public HttpMarshaler getMarshaler() {
+ if (marshaler == null) {
+ marshaler = createMarshaler();
+ }
+ return marshaler;
+ }
+
+ public void setMarshaler(HttpMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public abstract void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+ JBIException;
+
+ /**
+ * A factory method used to create the default {@link HttpMarshaler} to be used to turn the request into a
+ * {@link NormalizedMessage} and to turn a normalized message into a response.
+ *
+ * @return the newly created marshaler
+ */
+ protected HttpMarshaler createMarshaler() {
+ return new HttpMarshaler();
+ }
+
+ protected void outputException(HttpServletResponse response, Exception e) throws IOException {
+ response.setStatus(BAD_REQUEST_STATUS_CODE);
+ PrintWriter writer = null;
+ try {
+ writer = response.getWriter();
+ } catch (IllegalStateException ise) {
+ OutputStream os = response.getOutputStream();
+ writer = new PrintWriter (os);
+ }
+ writer.println("Request failed with error: " + e);
+ e.printStackTrace(writer);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java
new file mode 100644
index 0000000..9ed72a4
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpClientMarshaler.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamSource;
+
+import java.util.Iterator;
+
+/**
+ * A class which marshalls a client HTTP request to a NMS message
+ *
+ * @version $Revision: 426415 $
+ */
+public class HttpClientMarshaler {
+
+ protected SourceTransformer sourceTransformer;
+ private boolean streaming;
+ private String contentType = "text/xml";
+
+ public HttpClientMarshaler() {
+ this(false);
+ }
+
+ public HttpClientMarshaler(boolean streaming) {
+ this.sourceTransformer = new SourceTransformer();
+ this.streaming = streaming;
+ }
+
+ /**
+ * @return the streaming
+ */
+ public boolean isStreaming() {
+ return streaming;
+ }
+
+ /**
+ * @param streaming the streaming to set
+ */
+ public void setStreaming(boolean streaming) {
+ this.streaming = streaming;
+ }
+
+ /**
+ * @return the contentType
+ */
+ public String getContentType() {
+ return contentType;
+ }
+
+ /**
+ * @param contentType the contentType to set
+ */
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public void toNMS(NormalizedMessage normalizedMessage, HttpMethod method) throws Exception {
+ addNmsProperties(normalizedMessage, method);
+ if (streaming) {
+ normalizedMessage.setContent(new StreamSource(method.getResponseBodyAsStream()));
+ } else {
+ normalizedMessage.setContent(new StringSource(method.getResponseBodyAsString()));
+ }
+ }
+
+ public void fromNMS(PostMethod method, MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception, TransformerException {
+ addHttpHeaders(method, normalizedMessage);
+ if (streaming) {
+ method.setContentChunked(true);
+ Source src = normalizedMessage.getContent();
+ if (src instanceof StreamSource && ((StreamSource) src).getInputStream() != null) {
+ method.setRequestEntity(new InputStreamRequestEntity(
+ ((StreamSource) src).getInputStream(), -1));
+ } else {
+ String text = sourceTransformer.toString(normalizedMessage.getContent());
+ method.setRequestEntity(new StringRequestEntity(text));
+
+ }
+ } else {
+ String text = sourceTransformer.toString(normalizedMessage.getContent());
+ method.setRequestEntity(new StringRequestEntity(text));
+ }
+ }
+
+ protected void addHttpHeaders(HttpMethod method, NormalizedMessage message) {
+ for (Iterator iter = message.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = message.getProperty(name);
+ if (shouldIncludeHeader(message, name, value)) {
+ method.addRequestHeader(name, value.toString());
+ }
+ }
+ if (method.getRequestHeader("Content-Type") == null) {
+ method.setRequestHeader("Content-Type", contentType);
+ }
+ }
+
+ protected void addNmsProperties(NormalizedMessage message, HttpMethod method) {
+ Header[] headers = method.getResponseHeaders();
+ for (int i = 0; i < headers.length; i++) {
+ Header header = headers[i];
+ String name = header.getName();
+ String value = header.getValue();
+ message.setProperty(name, value);
+ }
+ }
+
+ /**
+ * Decides whether or not the given header should be included in the JMS message.
+ * By default this includes all suitable typed values
+ */
+ protected boolean shouldIncludeHeader(NormalizedMessage normalizedMessage, String name, Object value) {
+ return value instanceof String &&
+ !"Content-Length".equalsIgnoreCase(name) &&
+ !"Content-Type".equalsIgnoreCase(name);
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpConnector.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpConnector.java
new file mode 100644
index 0000000..14d96c9
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpConnector.java
@@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.thread.BoundedThreadPool;
+
+/**
+ * An embedded Servlet engine to implement a HTTP connector
+ *
+ * @version $Revision: 426415 $
+ */
+public class HttpConnector extends HttpInOutBinding {
+ private Connector listener = new SocketConnector();
+
+ /**
+ * The maximum number of threads for the Jetty SocketListener. It's set
+ * to 256 by default to match the default value in Jetty.
+ */
+ private int maxThreads = 256;
+
+ private Server server;
+ private String host;
+ private int port;
+
+ /**
+ * Constructor
+ *
+ * @param host
+ * @param port
+ */
+ public HttpConnector(String host, int port) {
+ this.host = host;
+ this.port = port;
+ }
+
+ public HttpConnector() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param listener
+ */
+ public HttpConnector(Connector listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Called when the Component is initialized
+ *
+ * @param cc
+ * @throws JBIException
+ */
+ public void init(ComponentContext cc) throws JBIException {
+ super.init(cc);
+ //should set all ports etc here - from the naming context I guess ?
+ if (listener == null) {
+ listener = new SocketConnector();
+ }
+ listener.setHost(host);
+ listener.setPort(port);
+ server = new Server();
+ BoundedThreadPool btp = new BoundedThreadPool();
+ btp.setMaxThreads(getMaxThreads());
+ server.setThreadPool(btp);
+ }
+
+ /**
+ * start the Component
+ *
+ * @throws JBIException
+ */
+ public void start() throws JBIException {
+ server.setConnectors(new Connector[] { listener });
+ ContextHandler context = new ContextHandler();
+ context.setContextPath("/");
+ ServletHolder holder = new ServletHolder();
+ holder.setName("jbiServlet");
+ holder.setClassName(BindingServlet.class.getName());
+ ServletHandler handler = new ServletHandler();
+ handler.setServlets(new ServletHolder[] { holder });
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName("jbiServlet");
+ mapping.setPathSpec("/*");
+ handler.setServletMappings(new ServletMapping[] { mapping });
+ context.setHandler(handler);
+ server.setHandler(context);
+ context.setAttribute("binding", this);
+ try {
+ server.start();
+ }
+ catch (Exception e) {
+ throw new JBIException("Start failed: " + e, e);
+ }
+ }
+
+ /**
+ * stop
+ */
+ public void stop() throws JBIException {
+ try {
+ if (server != null) {
+ server.stop();
+ }
+ }
+ catch (Exception e) {
+ throw new JBIException("Stop failed: " + e, e);
+ }
+ }
+
+ /**
+ * shutdown
+ */
+ public void shutDown() throws JBIException {
+ super.shutDown();
+ server = null;
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public void setServer(Server server) {
+ this.server = server;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getMaxThreads() {
+ return maxThreads;
+ }
+
+ public void setMaxThreads(int maxThreads) {
+ this.maxThreads = maxThreads;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInOnlyBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInOnlyBinding.java
new file mode 100644
index 0000000..dc4b29b
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInOnlyBinding.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.jbi.messaging.InOnly;
+
+/**
+ * A HTTP Binding Component which performs an {@link InOnly} exchange with JBI and returns the response.
+ *
+ * @version $Revision: 426415 $
+ */
+public class HttpInOnlyBinding extends HttpInOutBinding {
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public boolean isDefaultInOut() {
+ return false;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInOutBinding.java
new file mode 100644
index 0000000..ebc7cd9
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInOutBinding.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.TransformerException;
+import java.io.IOException;
+
+/**
+ * A HTTP Binding Component which performs an {@link InOut} exchange with JBI and returns the response
+ * by default but is configurable to be an {@link InOnly} exchange.
+ *
+ * @version $Revision: 426415 $
+ */
+public class HttpInOutBinding extends HttpBindingSupport {
+
+ private boolean defaultInOut = true;
+
+ public void process(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+ JBIException {
+ //response.setContentType("application/soap+xml");
+ if (isInOutRequest(request, response)) {
+ processInOut(request, response);
+ }
+ else {
+ processInOnly(request, response);
+ }
+ }
+
+ public void processInOut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+ JBIException {
+ MessageExchangeFactory factory = getExchangeFactory();
+ InOut exchange = factory.createInOutExchange();
+ NormalizedMessage inMessage = exchange.createMessage();
+ try {
+ getMarshaler().toNMS(exchange, inMessage, request);
+ exchange.setInMessage(inMessage);
+ boolean result = getDeliveryChannel().sendSync(exchange);
+ if (result) {
+ if (exchange.getStatus() == ExchangeStatus.ERROR) {
+ if (exchange.getError() != null) {
+ throw new ServletException(exchange.getError());
+ } else {
+ throw new ServletException("Exchange status is ERROR");
+ }
+ }
+ getMarshaler().toResponse(exchange, exchange.getOutMessage(), response);
+ }
+ done(exchange);
+ response.setStatus(HttpServletResponse.SC_OK);
+ }
+ catch (IOException e) {
+ fail(exchange, e);
+ outputException(response, e);
+ }
+ catch (TransformerException e) {
+ fail(exchange, e);
+ outputException(response, e);
+ }
+ }
+
+ public void processInOnly(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException,
+ JBIException {
+ MessageExchangeFactory factory = getExchangeFactory();
+ InOnly exchange = factory.createInOnlyExchange();
+ NormalizedMessage inMessage = exchange.createMessage();
+ try {
+ HttpMarshaler marshaler = getMarshaler();
+ marshaler.toNMS(exchange, inMessage, request);
+ exchange.setInMessage(inMessage);
+ // Do a sendSync so that the stream is not closed
+ getDeliveryChannel().sendSync(exchange);
+ response.setStatus(HttpServletResponse.SC_OK);
+ }
+ catch (IOException e) {
+ fail(exchange, e);
+ outputException(response, e);
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public boolean isDefaultInOut() {
+ return defaultInOut;
+ }
+
+ /**
+ * Sets whether an InOut (the default) or an InOnly message exchange will be used by default.
+ */
+ public void setDefaultInOut(boolean defaultInOut) {
+ this.defaultInOut = defaultInOut;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ /**
+ * Return true if this request is an {@link InOut} request otherwise it will be assumed to be an {@link InOnly}
+ */
+ protected boolean isInOutRequest(HttpServletRequest request, HttpServletResponse response) {
+ return isDefaultInOut();
+ }
+
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java
new file mode 100644
index 0000000..eeb6db8
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpInvoker.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.URI;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * Performs HTTP client invocations on a remote HTTP site.
+ *
+ * @version $Revision: 426415 $
+ */
+public class HttpInvoker extends TransformComponentSupport implements MessageExchangeListener {
+
+ protected HttpClientMarshaler marshaler = new HttpClientMarshaler();
+ protected MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+ protected HttpClient httpClient = new HttpClient(connectionManager);
+ protected HostConfiguration hostConfiguration = new HostConfiguration();
+ protected String url;
+ protected boolean defaultInOut = true;
+
+ public void stop() throws JBIException {
+ super.stop();
+ connectionManager.shutdown();
+ }
+
+ public HttpInvoker() {
+ // By default, do not forward anything
+ setCopyAttachments(false);
+ setCopyProperties(false);
+ }
+
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ PostMethod method = new PostMethod(url);
+ try {
+ marshaler.fromNMS(method, exchange, in);
+ if (url != null) {
+ hostConfiguration.setHost(new URI(url, false));
+ }
+ int response = httpClient.executeMethod(hostConfiguration, method);
+
+ if (response != HttpStatus.SC_OK && response != HttpStatus.SC_ACCEPTED) {
+ throw new InvalidStatusResponseException(response);
+ }
+
+ // now lets grab the output and set it on the out message
+ if (defaultInOut) {
+ marshaler.toNMS(out, method);
+ }
+ return defaultInOut;
+ }
+ catch (Exception e) {
+ throw new MessagingException("Error executing http request", e);
+ }
+ finally {
+ method.releaseConnection();
+ }
+ }
+
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public void setHttpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public boolean isDefaultInOut() {
+ return defaultInOut;
+ }
+
+ public void setDefaultInOut(boolean defaultInOut) {
+ this.defaultInOut = defaultInOut;
+ }
+
+ public HttpClientMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(HttpClientMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java
new file mode 100644
index 0000000..cc17279
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpMarshaler.java
@@ -0,0 +1,178 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.servicemix.components.util.MarshalerSupport;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * A class which marshalls a HTTP request to a NMS message
+ *
+ * @version $Revision: 426415 $
+ */
+public class HttpMarshaler extends MarshalerSupport {
+
+ public static final String CGI_HEADERS = "cgi.headers";
+
+ public static final String AUTH_TYPE = "AUTH_TYPE";
+ public static final String CONTENT_LENGTH = "CONTENT_LENGTH";
+ public static final String CONTENT_TYPE = "CONTENT_TYPE";
+ public static final String DOCUMENT_ROOT = "DOCUMENT_ROOT";
+ public static final String PATH_INFO = "PATH_INFO";
+ public static final String PATH_TRANSLATED = "PATH_TRANSLATED";
+ public static final String QUERY_STRING = "QUERY_STRING";
+ public static final String REMOTE_ADDRESS = "REMOTE_ADDR";
+ public static final String REMOTE_HOST = "REMOTE_HOST";
+ public static final String REMOTE_USER = "REMOTE_USER";
+ public static final String REQUEST_METHOD = "REQUEST_METHOD";
+ public static final String REQUEST_URI = "REQUEST_URI";
+ public static final String SCRIPT_NAME = "SCRIPT_NAME";
+ public static final String SERVER_NAME = "SERVER_NAME";
+ public static final String SERVER_PORT = "SERVER_PORT";
+ public static final String SERVER_PROTOCOL = "SERVER_PROTOCOL";
+
+ protected static final Source EMPTY_CONTENT = new StringSource("<payload/>");
+
+ private String contentType = "text/xml";
+
+ public void toNMS(MessageExchange exchange, NormalizedMessage inMessage, HttpServletRequest request) throws IOException, MessagingException {
+ addNmsProperties(inMessage, request);
+ String method = request.getMethod();
+ if (method != null && method.equalsIgnoreCase("POST")) {
+ /*
+ Source src = null;
+ try {
+ if (request.getContentType() != null) {
+ String charset = new MimeType(request.getContentType()).getParameter("charset");
+ if (charset != null) {
+ XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(request.getInputStream(), charset);
+ src = new StaxSource(xr);
+ }
+ }
+ if (src == null) {
+ XMLStreamReader xr = XMLInputFactory.newInstance().createXMLStreamReader(request.getInputStream());
+ src = new StaxSource(xr);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ try {
+ src = getTransformer().toDOMSource(src);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ inMessage.setContent(src);
+ */
+ inMessage.setContent(new StreamSource(request.getInputStream()));
+ }
+ else {
+ Enumeration enumeration = request.getParameterNames();
+ while (enumeration.hasMoreElements()) {
+ String name = (String) enumeration.nextElement();
+ String value = request.getParameter(name);
+ inMessage.setProperty(name, value);
+ }
+ inMessage.setContent(EMPTY_CONTENT);
+ }
+ }
+
+ public void toResponse(InOut exchange, NormalizedMessage message, HttpServletResponse response) throws IOException, TransformerException {
+ if (message != null) {
+ addHttpHeaders(response, message);
+ }
+
+ response.setContentType(contentType);
+ getTransformer().toResult(message.getContent(), new StreamResult(response.getOutputStream()));
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ protected void addNmsProperties(NormalizedMessage message, HttpServletRequest request) {
+ Enumeration enumeration = request.getHeaderNames();
+ while (enumeration.hasMoreElements()) {
+ String name = (String) enumeration.nextElement();
+ String value = request.getHeader(name);
+ message.setProperty(name, value);
+ }
+ Map cgi = new HashMap();
+ cgi.put(AUTH_TYPE, request.getAuthType());
+ cgi.put(CONTENT_LENGTH, String.valueOf(request.getContentLength()));
+ cgi.put(CONTENT_TYPE, request.getContentType());
+ cgi.put(DOCUMENT_ROOT, request.getRealPath("/"));
+ cgi.put(PATH_INFO, request.getPathInfo());
+ cgi.put(PATH_TRANSLATED, request.getPathTranslated());
+ cgi.put(QUERY_STRING, request.getQueryString());
+ cgi.put(REMOTE_ADDRESS, request.getRemoteAddr());
+ cgi.put(REMOTE_HOST, request.getRemoteHost());
+ cgi.put(REMOTE_USER, request.getRemoteUser());
+ cgi.put(REQUEST_METHOD, request.getMethod());
+ cgi.put(REQUEST_URI, request.getRequestURL());
+ cgi.put(SCRIPT_NAME, request.getServletPath());
+ cgi.put(SERVER_NAME, request.getServerName());
+ cgi.put(SERVER_PORT, String.valueOf(request.getServerPort()));
+ cgi.put(SERVER_PROTOCOL, request.getProtocol());
+ message.setProperty(CGI_HEADERS, cgi);
+ }
+
+ protected void addHttpHeaders(HttpServletResponse response, NormalizedMessage normalizedMessage) {
+ for (Iterator iter = normalizedMessage.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = normalizedMessage.getProperty(name);
+ if (shouldIncludeHeader(normalizedMessage, name, value)) {
+ response.setHeader(name, value.toString());
+ }
+ }
+ }
+
+ /**
+ * Decides whether or not the given header should be included in the JMS
+ * message. By default this includes all suitable typed values
+ */
+ protected boolean shouldIncludeHeader(NormalizedMessage normalizedMessage, String name, Object value) {
+ return value instanceof String &&
+ !"Content-Length".equalsIgnoreCase(name) &&
+ !"Content-Type".equalsIgnoreCase(name);
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java
new file mode 100644
index 0000000..53467b5
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapClientMarshaler.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.xpath.CachedXPathAPI;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+
+/**
+ * A class which marshalls a client HTTP request to a NMS message
+ *
+ * @version $Revision: 431309 $
+ */
+public class HttpSoapClientMarshaler extends HttpClientMarshaler {
+
+ public HttpSoapClientMarshaler() {
+ super();
+ }
+
+ public HttpSoapClientMarshaler(boolean streaming) {
+ super(streaming);
+ }
+
+ public void toNMS(NormalizedMessage normalizedMessage, HttpMethod method)
+ throws Exception {
+ addNmsProperties(normalizedMessage, method);
+ String response = method.getResponseBodyAsString();
+ Node node = sourceTransformer.toDOMNode(new StringSource(response));
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "/*/*[local-name()='Body']/*");
+ Node root = iterator.nextNode();
+ if (root instanceof Element == false) {
+ throw new IllegalStateException("Could not find body content");
+ }
+ Element element = (Element) root;
+
+ // Copy embedded namespaces from the envelope into the body root
+ for (Node parent = element.getParentNode(); parent != null; parent = parent.getParentNode()) {
+ NamedNodeMap attributes = parent.getAttributes();
+ if (attributes != null) {
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Attr att = (Attr) attributes.item(i);
+ if (att.getName().startsWith("xmlns:")
+ && element.getAttributes().getNamedItemNS(att.getNamespaceURI(),
+ att.getLocalName()) == null) {
+ element.setAttributeNS(att.getNamespaceURI(),
+ att.getName(),
+ att.getValue());
+ }
+ }
+ }
+ }
+
+ normalizedMessage.setContent(new DOMSource(element));
+ }
+
+ public void fromNMS(PostMethod method, MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception {
+ addHttpHeaders(method, normalizedMessage);
+ Element elem = sourceTransformer.toDOMElement(normalizedMessage.getContent());
+ Document document = sourceTransformer.createDocument();
+ Element env = document.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "env:Envelope");
+ document.appendChild(env);
+ env.setAttribute("xmlns:env", "http://schemas.xmlsoap.org/soap/envelope/");
+ Element body = document.createElementNS("http://schemas.xmlsoap.org/soap/envelope/", "env:Body");
+ env.appendChild(body);
+ body.appendChild(document.importNode(elem, true));
+ String text = sourceTransformer.toString(document);
+ method.setRequestEntity(new StringRequestEntity(text));
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapConnector.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapConnector.java
new file mode 100644
index 0000000..c1d128d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapConnector.java
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.bio.SocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.thread.BoundedThreadPool;
+
+public class HttpSoapConnector extends HttpSoapInOutBinding {
+ private Connector listener = new SocketConnector();
+
+ /**
+ * The maximum number of threads for the Jetty SocketListener. It's set
+ * to 256 by default to match the default value in Jetty.
+ */
+ private int maxThreads = 256;
+
+ private Server server;
+
+ private String host;
+
+ private int port;
+
+ /**
+ * Constructor
+ *
+ * @param host
+ * @param port
+ */
+ public HttpSoapConnector(String host, int port, boolean defaultInOut) {
+ this.host = host;
+ this.port = port;
+ this.defaultInOut = defaultInOut;
+ }
+
+ public HttpSoapConnector() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param listener
+ */
+ public HttpSoapConnector(Connector listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Called when the Component is initialized
+ *
+ * @param cc
+ * @throws JBIException
+ */
+ public void init(ComponentContext cc) throws JBIException {
+ super.init(cc);
+ //should set all ports etc here - from the naming context I guess ?
+ if (listener == null) {
+ listener = new SocketConnector();
+ }
+ listener.setHost(host);
+ listener.setPort(port);
+ server = new Server();
+ BoundedThreadPool btp = new BoundedThreadPool();
+ btp.setMaxThreads(getMaxThreads());
+ server.setThreadPool(btp);
+ }
+
+ /**
+ * start the Component
+ *
+ * @throws JBIException
+ */
+ public void start() throws JBIException {
+ server.setConnectors(new Connector[] { listener });
+ ContextHandler context = new ContextHandler();
+ context.setContextPath("/");
+ ServletHolder holder = new ServletHolder();
+ holder.setName("jbiServlet");
+ holder.setClassName(BindingServlet.class.getName());
+ ServletHandler handler = new ServletHandler();
+ handler.setServlets(new ServletHolder[] { holder });
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName("jbiServlet");
+ mapping.setPathSpec("/*");
+ handler.setServletMappings(new ServletMapping[] { mapping });
+ context.setHandler(handler);
+ server.setHandler(context);
+ context.setAttribute("binding", this);
+ try {
+ server.start();
+ }
+ catch (Exception e) {
+ throw new JBIException("Start failed: " + e, e);
+ }
+ }
+
+ /**
+ * stop
+ */
+ public void stop() throws JBIException {
+ try {
+ if (server != null) {
+ server.stop();
+ }
+ } catch (Exception e) {
+ throw new JBIException("Stop failed: " + e, e);
+ }
+ }
+
+ /**
+ * shutdown
+ */
+ public void shutDown() throws JBIException {
+ server = null;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public void setServer(Server server) {
+ this.server = server;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getMaxThreads() {
+ return maxThreads;
+ }
+
+ public void setMaxThreads(int maxThreads) {
+ this.maxThreads = maxThreads;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOnlyBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOnlyBinding.java
new file mode 100644
index 0000000..ea68314
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOnlyBinding.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+public class HttpSoapInOnlyBinding extends HttpSoapInOutBinding {
+
+ public HttpSoapInOnlyBinding() {
+ defaultInOut = false;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java
new file mode 100644
index 0000000..bc0f5e9
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInOutBinding.java
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.xml.XMLConstants;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.codehaus.xfire.DefaultXFire;
+import org.codehaus.xfire.MessageContext;
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.aegis.AegisBindingProvider;
+import org.codehaus.xfire.attachments.Attachment;
+import org.codehaus.xfire.attachments.Attachments;
+import org.codehaus.xfire.fault.XFireFault;
+import org.codehaus.xfire.service.Service;
+import org.codehaus.xfire.service.invoker.BeanInvoker;
+import org.codehaus.xfire.service.binding.ObjectServiceFactory;
+import org.codehaus.xfire.soap.SoapConstants;
+import org.codehaus.xfire.soap.handler.ReadHeadersHandler;
+import org.codehaus.xfire.transport.http.XFireServletController;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+public class HttpSoapInOutBinding extends ComponentSupport implements
+ HttpBinding {
+
+ protected XFire xfire;
+ protected XFireServletController controller;
+ protected Service service;
+ protected boolean defaultInOut = true;
+ protected String soapAction = "\"\"";
+ protected SourceTransformer transformer;
+
+ public HttpSoapInOutBinding() {
+ }
+
+ public void init(ComponentContext context) throws JBIException {
+ super.init(context);
+ xfire = new DefaultXFire();
+ ObjectServiceFactory factory = new ObjectServiceFactory(xfire.getTransportManager(),
+ new AegisBindingProvider());
+ factory.setVoidOneWay(true);
+ factory.setStyle(SoapConstants.STYLE_DOCUMENT);
+ if (isDefaultInOut()) {
+ service = factory.create(InOutService.class);
+ service.setInvoker(new BeanInvoker(new InOutService(this)));
+ } else {
+ service = factory.create(InOnlyService.class);
+ service.setInvoker(new BeanInvoker(new InOnlyService(this)));
+ }
+ xfire.getServiceRegistry().register(service);
+ controller = new Controller(xfire);
+ transformer = new SourceTransformer();
+ }
+
+ public void process(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ controller.doService(request, response);
+ }
+
+ public void invokeInOnly(Source source, MessageContext context) throws XFireFault {
+ if (source == null) {
+ throw new XFireFault("Invalid source.", XFireFault.SENDER);
+ }
+ try {
+ if (soapAction != null) {
+ XFireServletController.getResponse().setHeader("SOAPAction", soapAction);
+ }
+ DeliveryChannel channel = getDeliveryChannel();
+ MessageExchangeFactory factory = channel.createExchangeFactory();
+ InOnly exchange = factory.createInOnlyExchange();
+ populateExchange(exchange, source, context);
+ boolean result = channel.sendSync(exchange);
+ if (!result) {
+ throw new XFireFault("Error sending exchange", XFireFault.SENDER);
+ }
+ } catch (XFireFault e) {
+ throw e;
+ } catch (Exception e) {
+ throw new XFireFault(e);
+ }
+ }
+
+ public Source invokeInOut(Source source, MessageContext context) throws XFireFault {
+ if (source == null) {
+ throw new XFireFault("Invalid source.", XFireFault.SENDER);
+ }
+ try {
+ if (soapAction != null) {
+ XFireServletController.getResponse().setHeader("SOAPAction", soapAction);
+ }
+ DeliveryChannel channel = getDeliveryChannel();
+ MessageExchangeFactory factory = channel.createExchangeFactory();
+ InOut exchange = factory.createInOutExchange();
+ populateExchange(exchange, source, context);
+ boolean result = channel.sendSync(exchange);
+ if (!result) {
+ throw new XFireFault("Error sending exchange", XFireFault.SENDER);
+ }
+ if (exchange.getStatus() == ExchangeStatus.ERROR) {
+ Exception e = exchange.getError();
+ if (e == null) {
+ throw new XFireFault("Received error", XFireFault.SENDER);
+ } else {
+ throw new XFireFault(e, XFireFault.SENDER);
+ }
+ }
+ NormalizedMessage outMessage = exchange.getOutMessage();
+ if (outMessage == null) {
+ exchange.setError(new Exception("Expected an out message"));
+ channel.sendSync(exchange);
+ throw new XFireFault("No response", XFireFault.SENDER);
+ }
+ Source src = exchange.getOutMessage().getContent();
+ exchange.setStatus(ExchangeStatus.DONE);
+ channel.send(exchange);
+ src = transformer.toDOMSource(src);
+ return src;
+ } catch (XFireFault e) {
+ throw e;
+ } catch (Exception e) {
+ throw new XFireFault(e);
+ }
+ }
+
+ protected void populateExchange(MessageExchange exchange, Source src, MessageContext ctx) throws Exception {
+ // TODO: Retrieve properties
+ NormalizedMessage inMessage = exchange.createMessage();
+ // Add removed namespace declarations from the parents
+ Map namespaces = (Map) ctx.getProperty(ReadHeadersHandler.DECLARED_NAMESPACES);
+ Node node = transformer.toDOMNode(src);
+ Element element;
+ if (node instanceof Element) {
+ element = (Element) node;
+ } else if (node instanceof Document) {
+ element = ((Document) node).getDocumentElement();
+ } else {
+ throw new UnsupportedOperationException("Unable to handle nodes of type " + node.getNodeType());
+ }
+ // Copy embedded namespaces from the envelope into the body root
+ for (Iterator it = namespaces.entrySet().iterator(); it.hasNext();) {
+ Entry entry = (Entry) it.next();
+ if (element.getAttributes().getNamedItemNS(
+ XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
+ (String) entry.getKey()) == null) {
+ element.setAttributeNS(
+ XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
+ XMLConstants.XMLNS_ATTRIBUTE + ":" + (String) entry.getKey(),
+ (String) entry.getValue());
+ }
+ }
+ // Set the source
+ inMessage.setContent(new DOMSource(element));
+ // Retrieve attachments
+ Attachments attachments = (Attachments) ctx.getInMessage().getAttachments();
+ if (attachments != null) {
+ for (Iterator it = attachments.getParts(); it.hasNext();) {
+ Attachment part = (Attachment) it.next();
+ inMessage.addAttachment(part.getId(), part.getDataHandler());
+ }
+ }
+ exchange.setMessage(inMessage, "in");
+ }
+
+ public static class InOnlyService {
+ private HttpSoapInOutBinding component;
+ public InOnlyService() {}
+ public InOnlyService(HttpSoapInOutBinding component) {
+ this.component = component;
+ }
+ public void invokeInOnly(Source source, MessageContext context) throws XFireFault {
+ this.component.invokeInOnly(source, context);
+ }
+ }
+
+ public static class InOutService {
+ private HttpSoapInOutBinding component;
+ public InOutService() {}
+ public InOutService(HttpSoapInOutBinding component) {
+ this.component = component;
+ }
+ public Source invokeInOut(Source source, MessageContext context) throws XFireFault {
+ return this.component.invokeInOut(source, context);
+ }
+ }
+
+
+ public class Controller extends XFireServletController {
+ public Controller(XFire xfire) {
+ super(xfire);
+ }
+ protected String getService(HttpServletRequest request) {
+ return service.getSimpleName();
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public boolean isDefaultInOut() {
+ return defaultInOut;
+ }
+
+ /**
+ * Sets whether an InOut (the default) or an InOnly message exchange will be used by default.
+ */
+ public void setDefaultInOut(boolean defaultInOut) {
+ this.defaultInOut = defaultInOut;
+ }
+
+ public String getSoapAction() {
+ return soapAction;
+ }
+
+ public void setSoapAction(String soapAction) {
+ this.soapAction = soapAction;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInvoker.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInvoker.java
new file mode 100644
index 0000000..d39f707
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpSoapInvoker.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+public class HttpSoapInvoker extends HttpInvoker {
+
+ public HttpSoapInvoker() {
+ marshaler = new HttpSoapClientMarshaler();
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java
new file mode 100644
index 0000000..336ef1f
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsConnector.java
@@ -0,0 +1,362 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.Security;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.thread.BoundedThreadPool;
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ * An embedded Servlet engine to implement a HTTP connector
+ *
+ * @version $Revision: 373823 $
+ */
+public class HttpsConnector extends HttpInOutBinding {
+ private SslSocketConnector listener = new SslSocketConnector();
+
+ /**
+ * The maximum number of threads for the Jetty SocketListener. It's set
+ * to 256 by default to match the default value in Jetty.
+ */
+ private int maxThreads = 256;
+ private static final Log log = LogFactory.getLog(HttpsConnector.class);
+ private Server server;
+ private String host;
+ private int port;
+ private String keyPassword;
+ private String keyStore;
+ private String keyStorePassword;
+ private String keyStoreType = "JKS"; // type of the key store
+ private String protocol = "TLS";
+ // cert algorithm
+ private String keyManagerFactoryAlgorithm = Security.getProperty(
+ "ssl.KeyManagerFactory.algorithm") == null
+ ? "SunX509" : Security.getProperty("ssl.KeyManagerFactory.algorithm");
+ // cert algorithm
+ private String trustManagerFactoryAlgorithm = Security.getProperty(
+ "ssl.TrustManagerFactory.algorithm") == null
+ ? "SunX509" : Security.getProperty("ssl.TrustManagerFactory.algorithm");
+ private boolean wantClientAuth = false;
+ private boolean needClientAuth = false;
+
+ /**
+ * Constructor
+ *
+ * @param host
+ * @param port
+ */
+ public HttpsConnector(String host, int port, String keyPassword, String keyStorePassword, String keyStore, boolean needClientAuth, boolean wantClientAuth) {
+ this.host = host;
+ this.port = port;
+ this.keyPassword = keyPassword;
+ this.keyStorePassword = keyStorePassword;
+ this.keyStore = keyStore;
+ this.wantClientAuth = wantClientAuth;
+ this.needClientAuth = needClientAuth;
+ }
+
+ public HttpsConnector() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param listener
+ */
+ public HttpsConnector(SslSocketConnector listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Called when the Component is initialized
+ *
+ * @param cc
+ * @throws JBIException
+ */
+ public void init(ComponentContext cc) throws JBIException {
+ super.init(cc);
+ //should set all ports etc here - from the naming context I guess ?
+ if (keyStore == null) {
+ keyStore = System.getProperty("javax.net.ssl.keyStore", "");
+ if (keyStore == null) {
+ throw new IllegalArgumentException("keyStore or system property javax.net.ssl.keyStore must be set");
+ }
+ }
+ if (keyStore.startsWith("classpath:")) {
+ try {
+ String res = keyStore.substring(10);
+ URL url = new ClassPathResource(res).getURL();
+ keyStore = url.toString();
+ } catch (IOException e) {
+ throw new JBIException("Unable to find keystore " + keyStore, e);
+ }
+ }
+ if (keyStorePassword == null) {
+ keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
+ if (keyStorePassword == null) {
+ throw new IllegalArgumentException("keyStorePassword or system property javax.net.ssl.keyStorePassword must be set");
+ }
+ }
+ if (listener == null) {
+ listener = new SslSocketConnector();
+ }
+ listener.setHost(host);
+ listener.setPort(port);
+ listener.setConfidentialPort(port);
+ listener.setPassword(keyStorePassword);
+ listener.setKeyPassword(keyPassword != null ? keyPassword : keyStorePassword);
+ listener.setKeystore(keyStore);
+ listener.setWantClientAuth(wantClientAuth);
+ listener.setNeedClientAuth(needClientAuth);
+ listener.setProtocol(protocol);
+ listener.setSslKeyManagerFactoryAlgorithm(keyManagerFactoryAlgorithm);
+ listener.setSslTrustManagerFactoryAlgorithm(trustManagerFactoryAlgorithm);
+ listener.setKeystoreType(keyStoreType);
+ server = new Server();
+ BoundedThreadPool btp = new BoundedThreadPool();
+ btp.setMaxThreads(getMaxThreads());
+ server.setThreadPool(btp);
+ }
+
+ /**
+ * start the Component
+ *
+ * @throws JBIException
+ */
+ public void start() throws JBIException {
+ server.setConnectors(new Connector[] { listener });
+ ContextHandler context = new ContextHandler();
+ context.setContextPath("/");
+ ServletHolder holder = new ServletHolder();
+ holder.setName("jbiServlet");
+ holder.setClassName(BindingServlet.class.getName());
+ ServletHandler handler = new ServletHandler();
+ handler.setServlets(new ServletHolder[] { holder });
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName("jbiServlet");
+ mapping.setPathSpec("/*");
+ handler.setServletMappings(new ServletMapping[] { mapping });
+ context.setHandler(handler);
+ server.setHandler(context);
+ context.setAttribute("binding", this);
+ try {
+ server.start();
+ }
+ catch (Exception e) {
+ log.warn(e.toString());
+ throw new JBIException("Start failed: " + e, e);
+ }
+ }
+
+ /**
+ * stop
+ */
+ public void stop() throws JBIException {
+ try {
+ if (server != null) {
+ server.stop();
+ }
+ }
+ catch (Exception e) {
+ log.warn(e.toString());
+ throw new JBIException("Stop failed: " + e, e);
+ }
+ }
+
+ /**
+ * shutdown
+ */
+ public void shutDown() throws JBIException {
+ server = null;
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public void setServer(Server server) {
+ this.server = server;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getMaxThreads() {
+ return maxThreads;
+ }
+
+ public void setMaxThreads(int maxThreads) {
+ this.maxThreads = maxThreads;
+ }
+
+ /**
+ * @return Returns the algorithm.
+ */
+ public String getKeyManagerFactoryAlgorithm() {
+ return keyManagerFactoryAlgorithm;
+ }
+
+ /**
+ * @param algorithm The algorithm to set.
+ */
+ public void setKeyManagerFactoryAlgorithm(String algorithm) {
+ this.keyManagerFactoryAlgorithm = algorithm;
+ }
+
+ /**
+ * @return Returns the algorithm.
+ */
+ public String getTrustManagerFactoryAlgorithm() {
+ return trustManagerFactoryAlgorithm;
+ }
+
+ /**
+ * @param algorithm The algorithm to set.
+ */
+ public void setTrustManagerFactoryAlgorithm(String algorithm) {
+ this.trustManagerFactoryAlgorithm = algorithm;
+ }
+
+ /**
+ * @return Returns the keyPassword.
+ */
+ public String getKeyPassword() {
+ return keyPassword;
+ }
+
+ /**
+ * @param keyPassword The keyPassword to set.
+ */
+ public void setKeyPassword(String keyPassword) {
+ this.keyPassword = keyPassword;
+ }
+
+ /**
+ * @return Returns the keyStore.
+ */
+ public String getKeyStore() {
+ return keyStore;
+ }
+
+ /**
+ * @param keyStore The keyStore to set.
+ */
+ public void setKeyStore(String keyStore) {
+ this.keyStore = keyStore;
+ }
+
+ /**
+ * @return Returns the keyStorePassword.
+ */
+ public String getKeyStorePassword() {
+ return keyStorePassword;
+ }
+
+ /**
+ * @param keyStorePassword The keyStorePassword to set.
+ */
+ public void setKeyStorePassword(String keyStorePassword) {
+ this.keyStorePassword = keyStorePassword;
+ }
+
+ /**
+ * @return Returns the keyStoreType.
+ */
+ public String getKeyStoreType() {
+ return keyStoreType;
+ }
+
+ /**
+ * @param keyStoreType The keyStoreType to set.
+ */
+ public void setKeyStoreType(String keyStoreType) {
+ this.keyStoreType = keyStoreType;
+ }
+
+ /**
+ * @return Returns the needClientAuth.
+ */
+ public boolean isNeedClientAuth() {
+ return needClientAuth;
+ }
+
+ /**
+ * @param needClientAuth The needClientAuth to set.
+ */
+ public void setNeedClientAuth(boolean needClientAuth) {
+ this.needClientAuth = needClientAuth;
+ }
+
+ /**
+ * @return Returns the protocol.
+ */
+ public String getProtocol() {
+ return protocol;
+ }
+
+ /**
+ * @param protocol The protocol to set.
+ */
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+
+ /**
+ * @return Returns the wantClientAuth.
+ */
+ public boolean isWantClientAuth() {
+ return wantClientAuth;
+ }
+
+ /**
+ * @param wantClientAuth The wantClientAuth to set.
+ */
+ public void setWantClientAuth(boolean wantClientAuth) {
+ this.wantClientAuth = wantClientAuth;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java
new file mode 100644
index 0000000..b26f879
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsInvoker.java
@@ -0,0 +1,383 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.URI;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.security.KeyStore;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.commons.httpclient.ConnectTimeoutException;
+import org.apache.commons.httpclient.HostConfiguration;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpHost;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.params.HttpConnectionParams;
+import org.apache.commons.httpclient.protocol.Protocol;
+import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
+import org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.mortbay.resource.Resource;
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ * Performs HTTP client invocations on a remote HTTP site.
+ *
+ * @version $Revision: 373823 $
+ */
+public class HttpsInvoker extends TransformComponentSupport implements MessageExchangeListener {
+
+ protected HttpClientMarshaler marshaler = new HttpClientMarshaler();
+ protected MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
+ protected HttpClient httpClient = new HttpClient(connectionManager);
+ protected HostConfiguration hostConfiguration = new HostConfiguration();
+ protected String url;
+ protected boolean defaultInOut = true;
+
+ private String keyPassword;
+ private String keyStore;
+ private String keyStorePassword;
+ private String keyStoreType = "JKS"; // type of the key store
+ private String trustStore;
+ private String trustStorePassword;
+ private String trustStoreType = "JKS";
+ private String protocol = "TLS";
+ private String algorithm = "SunX509"; // cert algorithm
+
+ private class CommonsHttpSSLSocketFactory implements SecureProtocolSocketFactory {
+
+ private SSLSocketFactory factory;
+
+ public CommonsHttpSSLSocketFactory() throws Exception {
+ SSLContext context = SSLContext.getInstance(protocol);
+ KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(algorithm);
+ if (keyStore == null) {
+ keyStore = System.getProperty("javax.net.ssl.keyStore");
+ if (keyStore == null) {
+ throw new IllegalArgumentException("keyStore or system property javax.net.ssl.keyStore must be set");
+ }
+ }
+ if (keyStore.startsWith("classpath:")) {
+ try {
+ String res = keyStore.substring(10);
+ URL url = new ClassPathResource(res).getURL();
+ keyStore = url.toString();
+ } catch (IOException e) {
+ throw new JBIException("Unable to find keyStore " + keyStore, e);
+ }
+ }
+ if (keyStorePassword == null) {
+ keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
+ if (keyStorePassword == null) {
+ throw new IllegalArgumentException("keyStorePassword or system property javax.net.ssl.keyStorePassword must be set");
+ }
+ }
+ if (trustStore == null) {
+ trustStore = System.getProperty("javax.net.ssl.trustStore");
+ }
+ if (trustStore != null && trustStore.startsWith("classpath:")) {
+ try {
+ String res = trustStore.substring(10);
+ URL url = new ClassPathResource(res).getURL();
+ trustStore = url.toString();
+ } catch (IOException e) {
+ throw new JBIException("Unable to find trustStore " + trustStore, e);
+ }
+ }
+ if (trustStorePassword == null) {
+ trustStorePassword = System.getProperty("javax.net.ssl.trustStorePassword");
+ if (keyStorePassword == null) {
+ throw new IllegalArgumentException("trustStorePassword or system property javax.net.ssl.trustStorePassword must be set");
+ }
+ }
+ KeyStore ks = KeyStore.getInstance(keyStoreType);
+ ks.load(Resource.newResource(keyStore).getInputStream(), keyStorePassword.toCharArray());
+ keyManagerFactory.init(ks, keyPassword != null ? keyPassword.toCharArray() : keyStorePassword.toCharArray());
+ if (trustStore != null) {
+ KeyStore ts = KeyStore.getInstance(trustStoreType);
+ ts.load(Resource.newResource(trustStore).getInputStream(), trustStorePassword.toCharArray());
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(algorithm);
+ trustManagerFactory.init(ts);
+ context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new java.security.SecureRandom());
+ } else {
+ context.init(keyManagerFactory.getKeyManagers(), null, new java.security.SecureRandom());
+ }
+ factory = context.getSocketFactory();
+ }
+
+ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
+ return factory.createSocket(socket, host, port, autoClose);
+ }
+
+ public Socket createSocket(String host, int port, InetAddress localAddress, int localPort) throws IOException, UnknownHostException {
+ return factory.createSocket(host, port, localAddress, localPort);
+ }
+
+ public Socket createSocket(String host, int port, InetAddress localAddress, int localPort, HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
+ if (params == null) {
+ throw new IllegalArgumentException("Parameters may not be null");
+ }
+ int timeout = params.getConnectionTimeout();
+ if (timeout == 0) {
+ return createSocket(host, port, localAddress, localPort);
+ } else {
+ Socket socket = factory.createSocket();
+ SocketAddress localaddr = new InetSocketAddress(localAddress, localPort);
+ SocketAddress remoteaddr = new InetSocketAddress(host, port);
+ socket.bind(localaddr);
+ socket.connect(remoteaddr, timeout);
+ return socket;
+ }
+ }
+
+ public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
+ return factory.createSocket(host, port);
+ }
+
+ }
+
+ protected void init() throws JBIException {
+ super.init();
+ try {
+ URI uri = new URI(url);
+ ProtocolSocketFactory sf = new CommonsHttpSSLSocketFactory();
+ Protocol protocol = new Protocol("https", sf, 443);
+ HttpHost host = new HttpHost(uri.getHost(), uri.getPort(), protocol);
+ hostConfiguration.setHost(host);
+ } catch (Exception e) {
+ throw new JBIException("Unable to initialize HttpsInvoker", e);
+ }
+ }
+
+ public void stop() throws JBIException {
+ super.stop();
+ connectionManager.shutdown();
+ }
+
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ String url;
+ // We need to relativize the method url to the host config
+ // so that the hostConfiguration is not overriden by the executeMethod call
+ try {
+ java.net.URI uri = new URI(this.url);
+ uri = uri.relativize(new URI(hostConfiguration.getHostURL()));
+ url = uri.toString();
+ } catch (Exception e1) {
+ url = this.url;
+ }
+ PostMethod method = new PostMethod(url);
+ try {
+ marshaler.fromNMS(method, exchange, in);
+ if (method.getRequestHeader("Content-Type") == null) {
+ method.setRequestHeader("Content-Type", "text/html; charset=UTF-8");
+ }
+ int response = httpClient.executeMethod(hostConfiguration, method);
+
+ if (response != HttpStatus.SC_OK && response != HttpStatus.SC_ACCEPTED) {
+ throw new InvalidStatusResponseException(response);
+ }
+
+ // now lets grab the output and set it on the out message
+ if (defaultInOut) {
+ marshaler.toNMS(out, method);
+ }
+ return defaultInOut;
+ }
+ catch (Exception e) {
+ throw new MessagingException("Error executing http request", e);
+ }
+ finally {
+ method.releaseConnection();
+ }
+ }
+
+ public HttpClient getHttpClient() {
+ return httpClient;
+ }
+
+ public void setHttpClient(HttpClient httpClient) {
+ this.httpClient = httpClient;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ public boolean isDefaultInOut() {
+ return defaultInOut;
+ }
+
+ public void setDefaultInOut(boolean defaultInOut) {
+ this.defaultInOut = defaultInOut;
+ }
+
+ public HttpClientMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(HttpClientMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return Returns the algorithm.
+ */
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ /**
+ * @param algorithm The algorithm to set.
+ */
+ public void setAlgorithm(String algorithm) {
+ this.algorithm = algorithm;
+ }
+
+ /**
+ * @return Returns the keyPassword.
+ */
+ public String getKeyPassword() {
+ return keyPassword;
+ }
+
+ /**
+ * @param keyPassword The keyPassword to set.
+ */
+ public void setKeyPassword(String keyPassword) {
+ this.keyPassword = keyPassword;
+ }
+
+ /**
+ * @return Returns the keyStore.
+ */
+ public String getKeyStore() {
+ return keyStore;
+ }
+
+ /**
+ * @param keyStore The keyStore to set.
+ */
+ public void setKeyStore(String keyStore) {
+ this.keyStore = keyStore;
+ }
+
+ /**
+ * @return Returns the keyStorePassword.
+ */
+ public String getKeyStorePassword() {
+ return keyStorePassword;
+ }
+
+ /**
+ * @param keyStorePassword The keyStorePassword to set.
+ */
+ public void setKeyStorePassword(String keyStorePassword) {
+ this.keyStorePassword = keyStorePassword;
+ }
+
+ /**
+ * @return Returns the keyStoreType.
+ */
+ public String getKeyStoreType() {
+ return keyStoreType;
+ }
+
+ /**
+ * @param keyStoreType The keyStoreType to set.
+ */
+ public void setKeyStoreType(String keyStoreType) {
+ this.keyStoreType = keyStoreType;
+ }
+
+ /**
+ * @return Returns the protocol.
+ */
+ public String getProtocol() {
+ return protocol;
+ }
+
+ /**
+ * @param protocol The protocol to set.
+ */
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+
+ /**
+ * @return Returns the trustStore.
+ */
+ public String getTrustStore() {
+ return trustStore;
+ }
+
+ /**
+ * @param trustStore The trustStore to set.
+ */
+ public void setTrustStore(String trustStore) {
+ this.trustStore = trustStore;
+ }
+
+ /**
+ * @return Returns the trustStorePassword.
+ */
+ public String getTrustStorePassword() {
+ return trustStorePassword;
+ }
+
+ /**
+ * @param trustStorePassword The trustStorePassword to set.
+ */
+ public void setTrustStorePassword(String trustStorePassword) {
+ this.trustStorePassword = trustStorePassword;
+ }
+
+ /**
+ * @return Returns the trustStoreType.
+ */
+ public String getTrustStoreType() {
+ return trustStoreType;
+ }
+
+ /**
+ * @param trustStoreType The trustStoreType to set.
+ */
+ public void setTrustStoreType(String trustStoreType) {
+ this.trustStoreType = trustStoreType;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java
new file mode 100644
index 0000000..a98124e
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/HttpsSoapConnector.java
@@ -0,0 +1,353 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.IOException;
+import java.net.URL;
+import java.security.Security;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.security.SslSocketConnector;
+import org.mortbay.jetty.handler.ContextHandler;
+import org.mortbay.jetty.servlet.ServletHandler;
+import org.mortbay.jetty.servlet.ServletHolder;
+import org.mortbay.jetty.servlet.ServletMapping;
+import org.mortbay.thread.BoundedThreadPool;
+import org.springframework.core.io.ClassPathResource;
+
+public class HttpsSoapConnector extends HttpSoapInOutBinding {
+ private SslSocketConnector listener = new SslSocketConnector();
+
+ /**
+ * The maximum number of threads for the Jetty SocketListener. It's set
+ * to 256 by default to match the default value in Jetty.
+ */
+ private int maxThreads = 256;
+ private Server server;
+ private static final Log log = LogFactory.getLog(HttpsConnector.class);
+ private String host;
+ private int port;
+ private String keyPassword;
+ private String keyStore;
+ private String keyStorePassword;
+ private String keyStoreType = "JKS"; // type of the key store
+ private String protocol = "TLS";
+ // cert algorithm
+ private String keyManagerFactoryAlgorithm = Security.getProperty(
+ "ssl.KeyManagerFactory.algorithm") == null
+ ? "SunX509" : Security.getProperty("ssl.KeyManagerFactory.algorithm");
+ // cert algorithm
+ private String trustManagerFactoryAlgorithm = Security.getProperty(
+ "ssl.TrustManagerFactory.algorithm") == null
+ ? "SunX509" : Security.getProperty("ssl.TrustManagerFactory.algorithm");
+ private boolean wantClientAuth = false;
+ private boolean needClientAuth = false;
+
+ /**
+ * Constructor
+ *
+ * @param host
+ * @param port
+ */
+ public HttpsSoapConnector(String host, int port, String keyPassword, String keyStorePassword, String keyStore, boolean needClientAuth, boolean wantClientAuth) {
+ this.host = host;
+ this.port = port;
+ this.keyPassword = keyPassword;
+ this.keyStorePassword = keyStorePassword;
+ this.keyStore = keyStore;
+ this.wantClientAuth = wantClientAuth;
+ this.needClientAuth = needClientAuth;
+ }
+
+ public HttpsSoapConnector() {
+ }
+
+ /**
+ * Constructor
+ *
+ * @param listener
+ */
+ public HttpsSoapConnector(SslSocketConnector listener) {
+ this.listener = listener;
+ }
+
+ /**
+ * Called when the Component is initialized
+ *
+ * @param cc
+ * @throws JBIException
+ */
+ public void init(ComponentContext cc) throws JBIException {
+ super.init(cc);
+ //should set all ports etc here - from the naming context I guess ?
+ if (keyStore == null) {
+ keyStore = System.getProperty("javax.net.ssl.keyStore", "");
+ if (keyStore == null) {
+ throw new IllegalArgumentException("keyStore or system property javax.net.ssl.keyStore must be set");
+ }
+ }
+ if (keyStore.startsWith("classpath:")) {
+ try {
+ String res = keyStore.substring(10);
+ URL url = new ClassPathResource(res).getURL();
+ keyStore = url.toString();
+ } catch (IOException e) {
+ throw new JBIException("Unable to find keystore " + keyStore, e);
+ }
+ }
+ if (keyStorePassword == null) {
+ keyStorePassword = System.getProperty("javax.net.ssl.keyStorePassword");
+ if (keyStorePassword == null) {
+ throw new IllegalArgumentException("keyStorePassword or system property javax.net.ssl.keyStorePassword must be set");
+ }
+ }
+ if (listener == null) {
+ listener = new SslSocketConnector();
+ }
+ listener.setHost(host);
+ listener.setPort(port);
+ listener.setConfidentialPort(port);
+ listener.setPassword(keyStorePassword);
+ listener.setKeyPassword(keyPassword != null ? keyPassword : keyStorePassword);
+ listener.setKeystore(keyStore);
+ listener.setWantClientAuth(wantClientAuth);
+ listener.setNeedClientAuth(needClientAuth);
+ listener.setProtocol(protocol);
+ listener.setSslKeyManagerFactoryAlgorithm(keyManagerFactoryAlgorithm);
+ listener.setSslTrustManagerFactoryAlgorithm(trustManagerFactoryAlgorithm);
+ listener.setKeystoreType(keyStoreType);
+ server = new Server();
+ BoundedThreadPool btp = new BoundedThreadPool();
+ btp.setMaxThreads(getMaxThreads());
+ server.setThreadPool(btp);
+ }
+
+ /**
+ * start the Component
+ *
+ * @throws JBIException
+ */
+ public void start() throws JBIException {
+ server.setConnectors(new Connector[] { listener });
+ ContextHandler context = new ContextHandler();
+ context.setContextPath("/");
+ ServletHolder holder = new ServletHolder();
+ holder.setName("jbiServlet");
+ holder.setClassName(BindingServlet.class.getName());
+ ServletHandler handler = new ServletHandler();
+ handler.setServlets(new ServletHolder[] { holder });
+ ServletMapping mapping = new ServletMapping();
+ mapping.setServletName("jbiServlet");
+ mapping.setPathSpec("/*");
+ handler.setServletMappings(new ServletMapping[] { mapping });
+ context.setHandler(handler);
+ server.setHandler(context);
+ context.setAttribute("binding", this);
+ try {
+ server.start();
+ }
+ catch (Exception e) {
+ log.warn(e.toString());
+ throw new JBIException("Start failed: " + e, e);
+ }
+ }
+
+ /**
+ * stop
+ */
+ public void stop() throws JBIException {
+ try {
+ if (server != null) {
+ server.stop();
+ }
+ } catch (Exception e) {
+ throw new JBIException("Stop failed: " + e, e);
+ }
+ }
+
+ /**
+ * shutdown
+ */
+ public void shutDown() throws JBIException {
+ server = null;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public Server getServer() {
+ return server;
+ }
+
+ public void setServer(Server server) {
+ this.server = server;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getMaxThreads() {
+ return maxThreads;
+ }
+
+ public void setMaxThreads(int maxThreads) {
+ this.maxThreads = maxThreads;
+ }
+
+ /**
+ * @return Returns the algorithm.
+ */
+ public String getKeyManagerFactoryAlgorithm() {
+ return keyManagerFactoryAlgorithm;
+ }
+
+ /**
+ * @param algorithm The algorithm to set.
+ */
+ public void setKeyManagerFactoryAlgorithm(String algorithm) {
+ this.keyManagerFactoryAlgorithm = algorithm;
+ }
+
+ /**
+ * @return Returns the algorithm.
+ */
+ public String getTrustManagerFactoryAlgorithm() {
+ return trustManagerFactoryAlgorithm;
+ }
+
+ /**
+ * @param algorithm The algorithm to set.
+ */
+ public void setTrustManagerFactoryAlgorithm(String algorithm) {
+ this.trustManagerFactoryAlgorithm = algorithm;
+ }
+
+ /**
+ * @return Returns the keyPassword.
+ */
+ public String getKeyPassword() {
+ return keyPassword;
+ }
+
+ /**
+ * @param keyPassword The keyPassword to set.
+ */
+ public void setKeyPassword(String keyPassword) {
+ this.keyPassword = keyPassword;
+ }
+
+ /**
+ * @return Returns the keyStore.
+ */
+ public String getKeyStore() {
+ return keyStore;
+ }
+
+ /**
+ * @param keyStore The keyStore to set.
+ */
+ public void setKeyStore(String keyStore) {
+ this.keyStore = keyStore;
+ }
+
+ /**
+ * @return Returns the keyStorePassword.
+ */
+ public String getKeyStorePassword() {
+ return keyStorePassword;
+ }
+
+ /**
+ * @param keyStorePassword The keyStorePassword to set.
+ */
+ public void setKeyStorePassword(String keyStorePassword) {
+ this.keyStorePassword = keyStorePassword;
+ }
+
+ /**
+ * @return Returns the keyStoreType.
+ */
+ public String getKeyStoreType() {
+ return keyStoreType;
+ }
+
+ /**
+ * @param keyStoreType The keyStoreType to set.
+ */
+ public void setKeyStoreType(String keyStoreType) {
+ this.keyStoreType = keyStoreType;
+ }
+
+ /**
+ * @return Returns the needClientAuth.
+ */
+ public boolean isNeedClientAuth() {
+ return needClientAuth;
+ }
+
+ /**
+ * @param needClientAuth The needClientAuth to set.
+ */
+ public void setNeedClientAuth(boolean needClientAuth) {
+ this.needClientAuth = needClientAuth;
+ }
+
+ /**
+ * @return Returns the protocol.
+ */
+ public String getProtocol() {
+ return protocol;
+ }
+
+ /**
+ * @param protocol The protocol to set.
+ */
+ public void setProtocol(String protocol) {
+ this.protocol = protocol;
+ }
+
+ /**
+ * @return Returns the wantClientAuth.
+ */
+ public boolean isWantClientAuth() {
+ return wantClientAuth;
+ }
+
+ /**
+ * @param wantClientAuth The wantClientAuth to set.
+ */
+ public void setWantClientAuth(boolean wantClientAuth) {
+ this.wantClientAuth = wantClientAuth;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/InvalidStatusResponseException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/InvalidStatusResponseException.java
new file mode 100644
index 0000000..56a9791
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/InvalidStatusResponseException.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class InvalidStatusResponseException extends MessagingException {
+ private int statusCode;
+
+ public InvalidStatusResponseException(int statusCode) {
+ super("Invalid status response code: " + statusCode);
+ this.statusCode = statusCode;
+ }
+
+ public int getStatusCode() {
+ return statusCode;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/SpringBindingServlet.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/SpringBindingServlet.java
new file mode 100644
index 0000000..02ff0f6
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/SpringBindingServlet.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.springframework.context.ApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+
+/**
+ * A Spring based HTTP Binding Servlet for ServiceMix which will
+ * lookup the JBI container and the HttpBinding to use from the Spring
+ * {@link ApplicationContext}
+ *
+ * @version $Revision: 426415 $
+ */
+public class SpringBindingServlet extends BindingServlet {
+
+ protected HttpBinding createHttpBinding(ServletConfig config) throws ServletException {
+ ApplicationContext applicationContext = WebApplicationContextUtils.getRequiredWebApplicationContext(getServletContext());
+
+ String jbiName = config.getInitParameter("jbi");
+ if (jbiName == null) {
+ jbiName = "jbi";
+ }
+ String endpointName = config.getInitParameter("endpoint");
+ if (endpointName == null) {
+ throw new ServletException("You must configure a servlet config parameter of endpointRef");
+ }
+
+ SpringJBIContainer jbi = (SpringJBIContainer) applicationContext.getBean(jbiName);
+ if (jbi == null) {
+ throw new ServletException("Could not find the JBIContainer in the Spring application context for name: " + jbiName);
+ }
+
+ Object value = jbi.getBean(endpointName);
+ if (value == null) {
+ throw new ServletException("Could not find bean in the SpringJBIContainer for id: " + endpointName);
+ }
+ if (value instanceof HttpBinding) {
+ return (HttpBinding) value;
+ }
+ else {
+ throw new ServletException("The endpoint is not a HttpBinding: " + value);
+ }
+ }
+
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/package.html
new file mode 100644
index 0000000..f8e66e3
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/http/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for HTTP and <a href="http://java.sun.com/products/servlet/">Servlets</a>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberChatSender.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberChatSender.java
new file mode 100644
index 0000000..745e2e1
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberChatSender.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import org.jivesoftware.smack.Chat;
+import org.jivesoftware.smack.packet.Message;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * Sends one way messages to a private Jabber {@link Chat}
+ *
+ * @version $Revision: 426415 $
+ */
+public class JabberChatSender extends JabberComponentSupport {
+
+ private Chat chat;
+ private String participant;
+
+ public void afterPropertiesSet() throws Exception {
+ super.afterPropertiesSet();
+ if (chat == null) {
+ if (participant == null) {
+ throw new IllegalArgumentException("You must specify the participant property");
+ }
+ }
+ }
+
+ public void start() throws JBIException {
+ super.start();
+ if (chat == null) {
+ chat = getConnection().createChat(participant);
+ }
+ }
+
+ public void stop() throws JBIException {
+ chat = null;
+ super.stop();
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public Chat getChat() {
+ return chat;
+ }
+
+ public void setChat(Chat chat) {
+ this.chat = chat;
+ }
+
+ public String getParticipant() {
+ return participant;
+ }
+
+ public void setParticipant(String participant) {
+ this.participant = participant;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange messageExchange, NormalizedMessage normalizedMessage) throws Exception {
+ Message message = chat.createMessage();
+ getMarshaler().fromNMS(message, normalizedMessage);
+ chat.sendMessage(message);
+ done(messageExchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberComponentSupport.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberComponentSupport.java
new file mode 100644
index 0000000..782968c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberComponentSupport.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.OutBinding;
+import org.jivesoftware.smack.AccountManager;
+import org.jivesoftware.smack.PacketListener;
+import org.jivesoftware.smack.XMPPConnection;
+import org.jivesoftware.smack.XMPPException;
+import org.jivesoftware.smack.packet.Packet;
+import org.jivesoftware.smack.packet.XMPPError;
+import org.springframework.beans.factory.InitializingBean;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * @version $Revision: 517251 $
+ */
+public abstract class JabberComponentSupport extends OutBinding implements InitializingBean, PacketListener {
+ private static final transient Log log = LogFactory.getLog(JabberComponentSupport.class);
+
+ private JabberMarshaler marshaler = new JabberMarshaler();
+ private XMPPConnection connection;
+ private String host;
+ private int port;
+ private String user;
+ private String password;
+ private String resource = "ServiceMix";
+ private boolean login = true;
+
+ public void afterPropertiesSet() throws Exception {
+ if (connection == null) {
+ if (host == null) {
+ throw new IllegalArgumentException("You must specify the connection or the host property");
+ }
+ }
+ }
+
+ public void start() throws JBIException {
+ try {
+ if (connection == null) {
+ if (port > 0) {
+ connection = new XMPPConnection(host, port);
+ }
+ else {
+ connection = new XMPPConnection(host);
+ }
+ }
+ if (login && !connection.isAuthenticated()) {
+ if (user != null) {
+ AccountManager accountManager = new AccountManager(connection);
+ try {
+ log.info("Logging in to Jabber as user: " + user + " on connection: " + connection);
+ connection.login(user, password, resource);
+ } catch (XMPPException e) {
+ final XMPPError error = e.getXMPPError();
+ // 401 == Not Authorized
+ if (error != null && error.getCode() == 401) {
+ // is ist possible to create Accounts?
+ if (accountManager.supportsAccountCreation()) {
+ //try to create the Account (maybe it wasn't there)
+ accountManager.createAccount(user, password);
+ log.info("Logging in to Jabber as user: " + user + " on connection: " + connection);
+ // try to login again (if this fails we are screwed and fail ultimatively)
+ connection.login(user, password, resource);
+ }
+ }
+ }
+ }
+ else {
+ log.info("Logging in anonymously to Jabber on connection: " + connection);
+ connection.loginAnonymously();
+ }
+ }
+ }
+ catch (XMPPException e) {
+ throw new JBIException("Failed to login to Jabber. Reason: " + e, e);
+ }
+ }
+
+ public void stop() throws JBIException {
+ if (connection != null) {
+ connection.close();
+ connection = null;
+ }
+ }
+
+ public void processPacket(Packet packet) {
+ try {
+ InOnly exchange = getExchangeFactory().createInOnlyExchange();
+ NormalizedMessage in = exchange.createMessage();
+ exchange.setInMessage(in);
+ marshaler.toNMS(in, packet);
+ done(exchange);
+ }
+ catch (MessagingException e) {
+ throw new JabberListenerException(e, packet);
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public XMPPConnection getConnection() {
+ return connection;
+ }
+
+ public void setConnection(XMPPConnection connection) {
+ this.connection = connection;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public JabberMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(JabberMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public String getResource() {
+ return resource;
+ }
+
+ public void setResource(String resource) {
+ this.resource = resource;
+ }
+
+ public boolean isLogin() {
+ return login;
+ }
+
+ public void setLogin(boolean login) {
+ this.login = login;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberGroupChatSender.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberGroupChatSender.java
new file mode 100644
index 0000000..745b548
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberGroupChatSender.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.jivesoftware.smack.GroupChat;
+import org.jivesoftware.smack.packet.Message;
+
+/**
+ * Sends one way messages to a Jabber {@link GroupChat} and receives inbound messages
+ * from the chat
+ *
+ * @version $Revision: 426415 $
+ */
+public class JabberGroupChatSender extends JabberComponentSupport {
+
+ private GroupChat chat;
+ private String room;
+
+ public void afterPropertiesSet() throws Exception {
+ super.afterPropertiesSet();
+ if (chat == null) {
+ if (room == null) {
+ throw new IllegalArgumentException("You must specify the room property");
+ }
+ }
+ }
+
+ public void start() throws JBIException {
+ super.start();
+ if (chat == null) {
+ chat = getConnection().createGroupChat(room);
+ }
+ }
+
+ public void stop() throws JBIException {
+ if (chat != null) {
+ chat.leave();
+ chat = null;
+ }
+ super.stop();
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public GroupChat getChat() {
+ return chat;
+ }
+
+ public void setChat(GroupChat chat) {
+ this.chat = chat;
+ }
+
+ public String getRoom() {
+ return room;
+ }
+
+ public void setRoom(String room) {
+ this.room = room;
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange messageExchange, NormalizedMessage normalizedMessage) throws Exception {
+ Message message = chat.createMessage();
+ getMarshaler().fromNMS(message, normalizedMessage);
+ chat.sendMessage(message);
+ done(messageExchange);
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberListenerException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberListenerException.java
new file mode 100644
index 0000000..bc73e19
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberListenerException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import org.jivesoftware.smack.packet.Packet;
+
+/**
+ * A runtime exception thrown when processing inbound Jabber packets.
+ *
+ * @version $Revision: 426415 $
+ */
+public class JabberListenerException extends RuntimeException {
+ private Packet packet;
+
+ public JabberListenerException(Exception cause, Packet packet) {
+ super(cause.getMessage() + ". Was processing packet: " + packet, cause);
+ this.packet = packet;
+ }
+
+ public Packet getPacket() {
+ return packet;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberMarshaler.java
new file mode 100644
index 0000000..1a10016
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberMarshaler.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import org.apache.servicemix.jbi.jaxp.SourceMarshaler;
+import org.jivesoftware.smack.packet.Message;
+import org.jivesoftware.smack.packet.Packet;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import java.util.Date;
+import java.util.Iterator;
+
+/**
+ * Marshals Jabber messages into and out of NMS messages
+ *
+ * @version $Revision: 429277 $
+ */
+public class JabberMarshaler {
+ private SourceMarshaler sourceMarshaler;
+
+ public JabberMarshaler() {
+ this(new SourceMarshaler());
+ }
+
+ public JabberMarshaler(SourceMarshaler sourceMarshaler) {
+ this.sourceMarshaler = sourceMarshaler;
+ }
+
+ /**
+ * Marshals the Jabber message into an NMS message
+ *
+ * @throws MessagingException
+ */
+ public void toNMS(NormalizedMessage normalizedMessage, Packet packet) throws MessagingException {
+ addNmsProperties(normalizedMessage, packet);
+ if (packet instanceof Message) {
+ Message message = (Message) packet;
+ Source source = sourceMarshaler.asSource(message.getBody());
+ normalizedMessage.setContent(source);
+ }
+
+ // lets add the packet to the NMS
+ normalizedMessage.setProperty("org.apache.servicemix.jabber.packet", packet);
+ }
+
+ /**
+ * Marshals from the Jabber message to the normalized message
+ *
+ * @param message
+ * @param normalizedMessage
+ * @throws TransformerException
+ */
+ public void fromNMS(Message message, NormalizedMessage normalizedMessage) throws TransformerException {
+ // lets create a text message
+ String xml = messageAsString(normalizedMessage);
+ message.setBody(xml);
+ addJabberProperties(message, normalizedMessage);
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ /**
+ * @deprecated use getSourceMarshaler instead
+ */
+ public SourceMarshaler getSourceMarshaller() {
+ return sourceMarshaler;
+ }
+
+ /**
+ * @deprecated use setSourceMashaler instead
+ */
+ public void setSourceMarshaller(SourceMarshaler sourceMarshaler) {
+ this.sourceMarshaler = sourceMarshaler;
+ }
+
+ /**
+ * @return the sourceMarshaler
+ */
+ public SourceMarshaler getSourceMarshaler() {
+ return sourceMarshaler;
+ }
+
+ /**
+ * @param sourceMarshaler the sourceMarshaler to set
+ */
+ public void setSourceMarshaler(SourceMarshaler sourceMarshaler) {
+ this.sourceMarshaler = sourceMarshaler;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ /**
+ * Converts the inbound message to a String that can be sent
+ */
+ protected String messageAsString(NormalizedMessage normalizedMessage) throws TransformerException {
+ return sourceMarshaler.asString(normalizedMessage.getContent());
+ }
+
+ /**
+ * Appends properties on the NMS to the JMS Message
+ */
+ protected void addJabberProperties(Message message, NormalizedMessage normalizedMessage) {
+ for (Iterator iter = normalizedMessage.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = normalizedMessage.getProperty(name);
+ if (shouldIncludeHeader(normalizedMessage, name, value)) {
+ message.setProperty(name, value);
+ }
+ }
+ }
+
+ protected void addNmsProperties(NormalizedMessage normalizedMessage, Packet message) {
+ Iterator iter = message.getPropertyNames();
+ while (iter.hasNext()) {
+ String name = (String) iter.next();
+ Object value = message.getProperty(name);
+ normalizedMessage.setProperty(name, value);
+ }
+ }
+
+ /**
+ * Decides whether or not the given header should be included in the JMS message.
+ * By default this includes all suitable typed values
+ */
+ protected boolean shouldIncludeHeader(NormalizedMessage normalizedMessage, String name, Object value) {
+ return value instanceof String || value instanceof Number || value instanceof Date;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberReceiver.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberReceiver.java
new file mode 100644
index 0000000..bf5b8cb
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/JabberReceiver.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.jivesoftware.smack.filter.PacketFilter;
+import org.jivesoftware.smack.filter.PacketTypeFilter;
+import org.jivesoftware.smack.packet.Message;
+
+/**
+ * Receives inbound messages or packets and dispatches them into the NMR
+ *
+ * @version $Revision: 426415 $
+ */
+public class JabberReceiver extends JabberComponentSupport {
+
+ private PacketFilter filter;
+
+ public void afterPropertiesSet() throws Exception {
+ super.afterPropertiesSet();
+
+ if (filter == null) {
+ filter = new PacketTypeFilter(Message.class);
+ }
+ }
+
+ public void start() throws JBIException {
+ super.start();
+ getConnection().addPacketListener(this, filter);
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public PacketFilter getFilter() {
+ return filter;
+ }
+
+ public void setFilter(PacketFilter filter) {
+ this.filter = filter;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange exchange, NormalizedMessage message) throws Exception {
+ throw new MessagingException("This component is not meant to receive inbound messages but received: " + message);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/package.html
new file mode 100644
index 0000000..4093382
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jabber/package.html
@@ -0,0 +1,28 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for <a href="http://jabber.org/">Jabber</a> using the <a href="http://xmlpp.org/">XMPP</a> protocol via the
+<a href="http://www.jivesoftware.org/smack/">Smack</a> Java client
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/JaxRpcInBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/JaxRpcInBinding.java
new file mode 100644
index 0000000..0fe8c99
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/JaxRpcInBinding.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jaxrpc;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.rpc.Call;
+
+import org.apache.servicemix.components.util.OutBinding;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JaxRpcInBinding extends OutBinding {
+ private JaxRpcMarshaler marshaler = new JaxRpcMarshaler();
+
+
+ protected void process(MessageExchange messageExchange, NormalizedMessage inMessage) throws Exception {
+ Call call = marshaler.createCall(inMessage);
+ Object[] params = marshaler.getCallParams(inMessage);
+
+ call.invokeOneWay(params);
+ done(messageExchange);
+ }
+}
\ No newline at end of file
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/JaxRpcMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/JaxRpcMarshaler.java
new file mode 100644
index 0000000..8a68d11
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/JaxRpcMarshaler.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jaxrpc;
+
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.rpc.Call;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JaxRpcMarshaler {
+
+ public Call createCall(NormalizedMessage normalizedMessage) {
+ return null; /** TODO */
+ }
+
+ public Object[] getCallParams(NormalizedMessage normalizedMessage) {
+ return new Object[0]; /** TODO */
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/package.html
new file mode 100644
index 0000000..60afc79
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jaxrpc/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for <a href="http://java.sun.com/xml/jaxrpc/">JAX-RPC</a>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java
new file mode 100644
index 0000000..38b747c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jdbc;
+
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.sql.DataSource;
+import javax.xml.transform.Source;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.xpath.CachedXPathAPI;
+import org.w3c.dom.Node;
+
+public class JdbcComponent extends TransformComponentSupport implements MessageExchangeListener {
+ private static final Log log = LogFactory.getLog(JdbcComponent.class);
+
+ private DataSource dataSource;
+ private boolean responseRequired = false;
+
+ public boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ log.debug("Received a JDBC request. Datasource=" + dataSource + ", ResponseRequired=" + responseRequired);
+ Connection conn = null;
+ Statement stmt = null;
+ ResultSet rs = null;
+
+ try {
+
+ SourceTransformer domTransform = new SourceTransformer();
+ Node domNode = domTransform.toDOMNode(in);
+
+ // Return the exception message
+// if (isExceptionXml(domNode)) {
+// log.debug("Found an exception message: " + domNode);
+// out.setContent(in.getContent());
+// return true;
+// }
+
+ String query = getQuery(domNode);
+ log.debug("Retrieved query: " + query);
+
+ conn = dataSource.getConnection();
+
+ stmt = conn.createStatement();
+
+ Source outMsg = null;
+ if (query != null && query.length() > 0) {
+ if (stmt.execute(query)) {
+ // Result is a ResultSet object
+ rs = stmt.getResultSet();
+
+ log.debug("Formatting ResultSet: " + rs);
+ outMsg = toXmlSource(rs);
+ } else {
+ int updateCount = stmt.getUpdateCount();
+ if (updateCount > -1) {
+ log.debug("Formatting UpdateCount: " + updateCount);
+ // Result is an update count
+ outMsg = toXmlSource(updateCount);
+ } else {
+ log.debug("Formatting NoResult.");
+ // Result is neither a result set nor an update count
+ outMsg = null;
+ }
+ }
+ }
+
+ if (outMsg != null) {
+ // There is a valid response
+ log.debug("Response: " + domTransform.toString(outMsg));
+ out.setContent(outMsg);
+ return true;
+
+ } else if (responseRequired) {
+ // Create an empty <sqlResult> element
+ log.debug("Response: Empty Response");
+ out.setContent(toXmlSource());
+ return true;
+
+ } else {
+ log.debug("Response: No Response");
+ // There is no valid response
+ return false;
+ }
+ } catch (Exception e) {
+ log.error("JDBC Component Exception: ", e);
+// out.setContent(createExceptionXml(e));
+// return true;
+ throw new MessagingException(e);
+ } finally {
+ if (rs != null) {
+ try {
+ rs.close();
+ } catch (SQLException e) {
+ // Ignore
+ }
+ }
+
+ if (stmt != null) {
+ try {
+ stmt.close();
+ } catch (SQLException e) {
+ // Ignore
+ }
+ }
+
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+
+ public String getQuery(Node node) throws Exception {
+ CachedXPathAPI xpath = new CachedXPathAPI();
+
+ node = xpath.selectSingleNode(node, "sql/child::text()");
+
+ // First child should be <sql></sql> element
+ if (node == null) {
+ throw new IllegalStateException("Expecting <sql></sql> node. Found: " + node);
+ }
+
+ return node.getNodeValue();
+ }
+
+ public void setDataSource(DataSource ds) {
+ dataSource = ds;
+ }
+
+ public DataSource getDataSource() {
+ return dataSource;
+ }
+
+ /**
+ * If true, an empty <sqlResult> element is created and send as a response if there is no result
+ * @param val
+ */
+ public void setResponseRequired(boolean val) {
+ responseRequired = val;
+ }
+
+ public boolean getResponseRequired() {
+ return responseRequired;
+ }
+
+ protected Source toXmlSource(ResultSet rs) throws Exception {
+
+ ResultSetMetaData meta = rs.getMetaData();
+ int colCount = meta.getColumnCount();
+
+ String[] colNames = getUniqueColumnNames(meta);
+
+ StringBuffer buff = new StringBuffer("");
+
+ while (rs.next()) {
+ buff.append("<row ");
+ for (int i = 0; i < colCount; i++) {
+ buff.append(colNames[i].toLowerCase() + "='" + rs.getString(i + 1) + "' ");
+ }
+ buff.append("/>");
+ }
+
+ if (buff.length() > 0) {
+ // If non-empty result, insert parent tags
+ buff.insert(0, "<sqlResult><resultSet>");
+ buff.append("</resultSet></sqlResult>");
+ } else {
+ // If empty result, return null source
+ return null;
+ }
+
+ return new StringSource(buff.toString());
+ }
+
+ /**
+ * Returns a String[] containing unique ColNames.
+ */
+ protected String[] getUniqueColumnNames(ResultSetMetaData metaData) throws SQLException {
+
+ List colNames = new LinkedList();
+ Map chanedNames = new HashMap();
+
+ for (int i = 1; i <= metaData.getColumnCount(); i++) {
+ String name = metaData.getColumnName(i);
+
+ if (name.equals("")) {
+ name = "__unknown_column__";
+ }
+
+ if (colNames.contains(name)) {
+
+ int count;
+ if (chanedNames.containsKey(name)) {
+ Integer integer = (Integer) chanedNames.get(name);
+ Integer newInteger = new Integer(integer.intValue() + 1);
+ chanedNames.put(name, newInteger);
+ count = newInteger.intValue();
+ } else {
+ chanedNames.put(name, new Integer(1));
+ count = 1;
+ }
+
+ name = name + "_" + count;
+
+ }
+
+ colNames.add(name);
+
+ }
+
+ return (String[]) colNames.toArray(new String[colNames.size()]);
+ }
+
+ protected Source toXmlSource(int updateCount) throws Exception {
+ return new StringSource("<sqlResult><updateCount value='" + updateCount + "'/></sqlResult>");
+ }
+
+ protected Source toXmlSource() throws Exception {
+ return new StringSource("<sqlResult></sqlResult>");
+ }
+
+
+ // Custom method to create and handle exception
+ /*
+ public boolean isExceptionXml(Node document) {
+ return document.getFirstChild().getNodeName().equalsIgnoreCase("exception");
+ }
+
+ public Source createExceptionXml(Throwable e) {
+ return new StringSource("<exception class='" + e.getClass() + "'>'" + e.getMessage() + "'</exception>");
+ } */
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/DestinationChooser.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/DestinationChooser.java
new file mode 100644
index 0000000..969cccc
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/DestinationChooser.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jms.Destination;
+
+/**
+ * A pluggable strategy used to decide which JMS Destination to use for an outbound JMS message
+ *
+ * @version $Revision: 426415 $
+ */
+public interface DestinationChooser {
+
+ /**
+ * Chooses which JMS destintation to use for the outbound message
+ */
+ Destination chooseDestination(MessageExchange messageExchange);
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JBIJMSException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JBIJMSException.java
new file mode 100644
index 0000000..7812da4
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JBIJMSException.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.JBIException;
+import javax.jms.JMSException;
+
+/**
+ * Thrown when a JMS message is thrown from inside a JMS binding
+ * component for the JBI container
+ *
+ * @version $Revision: 426415 $
+ */
+public class JBIJMSException extends JBIException {
+ public JBIJMSException(JMSException cause) {
+ super(cause);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsInBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsInBinding.java
new file mode 100644
index 0000000..d300c61
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsInBinding.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.RuntimeJBIException;
+
+/**
+ * A JMS {@link MessageListener} which sends the inbound JMS message into the JBI container
+ * for processing
+ *
+ * @version $Revision: 487499 $
+ */
+public class JmsInBinding extends ComponentSupport implements MessageListener, MessageExchangeListener {
+ private static final Log log = LogFactory.getLog(JmsInBinding.class);
+
+ private JmsMarshaler marshaler = new JmsMarshaler();
+ private boolean synchronous = false;
+
+ /**
+ * @return the synchronous
+ */
+ public boolean isSynchronous() {
+ return synchronous;
+ }
+
+ /**
+ * @param synchronous the synchronous to set
+ */
+ public void setSynchronous(boolean synchronous) {
+ this.synchronous = synchronous;
+ }
+
+ public JmsMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(JmsMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public void onMessage(Message jmsMessage) {
+ if (log.isTraceEnabled()) {
+ log.trace("Received: " + jmsMessage);
+ }
+
+ try {
+ InOnly messageExchange = getDeliveryChannel().createExchangeFactory().createInOnlyExchange();
+ NormalizedMessage inMessage = messageExchange.createMessage();
+
+ try {
+ marshaler.toNMS(inMessage, jmsMessage);
+
+ messageExchange.setInMessage(inMessage);
+ if (synchronous) {
+ getDeliveryChannel().sendSync(messageExchange);
+ } else {
+ getDeliveryChannel().send(messageExchange);
+ }
+ }
+ catch (JMSException e) {
+ messageExchange.setError(e);
+ messageExchange.setStatus(ExchangeStatus.ERROR);
+ }
+ }
+ catch (JBIException e) {
+ throw new RuntimeJBIException(e);
+ }
+ }
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ // Do nothing as we only send in-only
+ // but this ensure that messages are not queued in the DeliveryChannel
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsInUsingJCABinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsInUsingJCABinding.java
new file mode 100644
index 0000000..51040b7
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsInUsingJCABinding.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.JBIException;
+import javax.resource.spi.ActivationSpec;
+import javax.transaction.TransactionManager;
+
+import org.jencks.JCAConnector;
+import org.jencks.JCAContainer;
+import org.jencks.SingletonEndpointFactory;
+import org.springframework.beans.factory.BeanNameAware;
+
+/**
+ * Uses the JCA Container for better inbound subscription.
+ *
+ * @version $Revision: 487499 $
+ */
+public class JmsInUsingJCABinding extends JmsInBinding implements BeanNameAware {
+
+ private JCAContainer jcaContainer;
+ private ActivationSpec activationSpec;
+ private TransactionManager transactionManager;
+ private JCAConnector jcaConnector;
+ private String name;
+
+ protected void init() throws JBIException {
+ if (jcaContainer == null) {
+ throw new IllegalArgumentException("Must specify a jcaContainer property");
+ }
+ if (activationSpec == null) {
+ throw new IllegalArgumentException("Must specify an activationSpec property");
+ }
+ jcaConnector = jcaContainer.addConnector();
+ jcaConnector.setActivationSpec(activationSpec);
+ if (transactionManager == null) {
+ transactionManager = (TransactionManager) getContext().getTransactionManager();
+ }
+ if (transactionManager != null) {
+ jcaConnector.setTransactionManager(transactionManager);
+ }
+ SingletonEndpointFactory ef = new SingletonEndpointFactory(this, transactionManager);
+ ef.setName(name);
+ jcaConnector.setEndpointFactory(ef);
+ try {
+ jcaConnector.afterPropertiesSet();
+ } catch (Exception e) {
+ throw new JBIException("Unable to initialize jca connector", e);
+ }
+ super.init();
+ }
+
+ public void start() throws JBIException {
+ try {
+ jcaConnector.start();
+ } catch (Exception e) {
+ throw new JBIException("Unable to start jca connector", e);
+ }
+ super.start();
+ }
+
+ public void stop() throws JBIException {
+ super.stop();
+ try {
+ jcaConnector.destroy();
+ } catch (Exception e) {
+ throw new JBIException("Unable to stop jca connector", e);
+ }
+ }
+
+ public JCAContainer getJcaContainer() {
+ return jcaContainer;
+ }
+
+ public void setJcaContainer(JCAContainer jcaContainer) {
+ this.jcaContainer = jcaContainer;
+ }
+
+ public ActivationSpec getActivationSpec() {
+ return activationSpec;
+ }
+
+ public void setActivationSpec(ActivationSpec activationSpec) {
+ this.activationSpec = activationSpec;
+ }
+
+ public TransactionManager getTransactionManager() {
+ return transactionManager;
+ }
+
+ public void setTransactionManager(TransactionManager transactionManager) {
+ this.transactionManager = transactionManager;
+ }
+
+ public JCAConnector getJcaConnector() {
+ return jcaConnector;
+ }
+
+ public void setBeanName(String name) {
+ this.name = name;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsMarshaler.java
new file mode 100644
index 0000000..be56c2c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsMarshaler.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import org.apache.servicemix.jbi.jaxp.SourceMarshaler;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.Iterator;
+
+/**
+ * Marshalls JMS messages into and out of NMS messages
+ *
+ * @version $Revision: 426415 $
+ */
+public class JmsMarshaler {
+ private SourceMarshaler sourceMarshaler;
+
+ private boolean needJavaIdentifiers;
+
+ public JmsMarshaler() {
+ this(new SourceMarshaler());
+ }
+
+ public JmsMarshaler(SourceMarshaler sourceMarshaler) {
+ this.sourceMarshaler = sourceMarshaler;
+ }
+
+ /**
+ * Marshalls the JMS message into an NMS message
+ *
+ * @throws MessagingException
+ */
+ public void toNMS(NormalizedMessage normalizedMessage, Message message) throws JMSException, MessagingException {
+ addNmsProperties(normalizedMessage, message);
+ if (message instanceof TextMessage) {
+ TextMessage textMessage = (TextMessage) message;
+ Source source = sourceMarshaler.asSource(textMessage.getText());
+ normalizedMessage.setContent(source);
+ }
+
+ // lets add the message to the NMS
+ // Fix SM-178 : the message exchange is not serializable
+ //normalizedMessage.setProperty("org.apache.servicemix.jms.message", message);
+ }
+
+ public Message createMessage(NormalizedMessage normalizedMessage, Session session) throws JMSException, TransformerException {
+ // lets create a text message
+ String xml = messageAsString(normalizedMessage);
+ TextMessage message = session.createTextMessage(xml);
+ addJmsProperties(message, normalizedMessage);
+ return message;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public SourceMarshaler getSourceMarshaller() {
+ return sourceMarshaler;
+ }
+
+ public void setSourceMarshaller(SourceMarshaler sourceMarshaler) {
+ this.sourceMarshaler = sourceMarshaler;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ /**
+ * Converts the inbound message to a String that can be sent
+ */
+ protected String messageAsString(NormalizedMessage normalizedMessage) throws TransformerException {
+ return sourceMarshaler.asString(normalizedMessage.getContent());
+ }
+
+ /**
+ * Appends properties on the NMS to the JMS Message
+ */
+ protected void addJmsProperties(Message message, NormalizedMessage normalizedMessage) throws JMSException {
+ for (Iterator iter = normalizedMessage.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = normalizedMessage.getProperty(name);
+ if (shouldIncludeHeader(normalizedMessage, name, value)) {
+ message.setObjectProperty(name, value);
+ }
+ }
+ }
+
+ protected void addNmsProperties(NormalizedMessage message, Message jmsMessage) throws JMSException {
+ Enumeration enumeration = jmsMessage.getPropertyNames();
+ while (enumeration.hasMoreElements()) {
+ String name = (String) enumeration.nextElement();
+ Object value = jmsMessage.getObjectProperty(name);
+ message.setProperty(name, value);
+ }
+ }
+
+ /**
+ * Decides whether or not the given header should be included in the JMS message.
+ * By default this includes all suitable typed values
+ */
+ protected boolean shouldIncludeHeader(NormalizedMessage normalizedMessage, String name, Object value) {
+ return (value instanceof String || value instanceof Number || value instanceof Date) &&
+ (!isNeedJavaIdentifiers() || isJavaIdentifier(name));
+ }
+
+ private static boolean isJavaIdentifier(String s) {
+ int n = s.length();
+ if (n==0) return false;
+ if (!Character.isJavaIdentifierStart(s.charAt(0)))
+ return false;
+ for (int i = 1; i < n; i++)
+ if (!Character.isJavaIdentifierPart(s.charAt(i)))
+ return false;
+ return true;
+ }
+
+ /**
+ * @return Returns the needJavaIdentifiers.
+ */
+ public boolean isNeedJavaIdentifiers() {
+ return needJavaIdentifiers;
+ }
+
+ /**
+ * @param needJavaIdentifiers The needJavaIdentifiers to set.
+ */
+ public void setNeedJavaIdentifiers(boolean needJavaIdentifiers) {
+ this.needJavaIdentifiers = needJavaIdentifiers;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java
new file mode 100644
index 0000000..64ca77c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsReceiverComponent.java
@@ -0,0 +1,142 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.JBIException;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.MessageConsumer;
+import javax.jms.Session;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.jms.core.JmsTemplate;
+
+/**
+ * A component which uses a {@link JmsTemplate} to consume messages from a
+ * destination.
+ *
+ * @version $Revision: 466982 $
+ */
+public class JmsReceiverComponent extends JmsInBinding implements InitializingBean {
+ private JmsTemplate template;
+ private String selector;
+ private MessageConsumer consumer;
+ private ConnectionFactory connectionFactory;
+ private Connection connection;
+ private Session session;
+
+ public void afterPropertiesSet() throws Exception {
+ if (template == null) {
+ throw new IllegalArgumentException("Must have a template set");
+ }
+ }
+
+ public void start() throws JBIException {
+ // Start receiving messages only when the component has actually been started.
+ super.start();
+ try {
+ connectionFactory = template.getConnectionFactory();
+ /*
+ * Component code did not work for JMS 1.02 compliant provider because uses APIs
+ * that did not exist in JMS 1.02 : ConnectionFactory.createConnection,
+ * Connection.createSession
+ */
+ if (template instanceof org.springframework.jms.core.JmsTemplate102) {
+ //Note1 - would've preferred to call JmsTemplate102 methods but they are protected.
+ if (template.isPubSubDomain()) {
+ javax.jms.TopicConnection tc;
+ connection = tc = ((javax.jms.TopicConnectionFactory)connectionFactory).createTopicConnection();
+ session = tc.createTopicSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+ }
+ else {
+ javax.jms.QueueConnection qc;
+ connection = qc = ((javax.jms.QueueConnectionFactory)connectionFactory).createQueueConnection();
+ session = qc.createQueueSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+ }
+ } else { // JMS 1.1 style
+ connection = connectionFactory.createConnection();
+ session = connection.createSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+ }
+
+ Destination defaultDestination = template.getDefaultDestination();
+ if (defaultDestination == null) {
+ defaultDestination = template.getDestinationResolver().resolveDestinationName(session, template.getDefaultDestinationName(),
+ template.isPubSubDomain());
+ }
+
+ /*
+ * Component code did not work for JMS 1.02 compliant provider because uses APIs
+ * that did not exist in JMS 1.02: Session.createConsumer
+ */
+ if (template instanceof org.springframework.jms.core.JmsTemplate102) {
+ //Note1 - would've preferred to call JmsTemplate102.createConsumer but it is protected. Code below is same.
+ //Note2 - assert that defaultDestination is correct type according to isPubSubDomain()
+ if (template.isPubSubDomain()) {
+ consumer = ((javax.jms.TopicSession)session).createSubscriber((javax.jms.Topic)defaultDestination, selector, template.isPubSubNoLocal());
+ } else {
+ consumer = ((javax.jms.QueueSession)session).createReceiver((javax.jms.Queue)defaultDestination, selector);
+ }
+ } else { // JMS 1.1 style
+ consumer = session.createConsumer(defaultDestination, selector);
+ }
+ connection.start();
+ consumer.setMessageListener(this);
+ } catch (JMSException e) {
+ throw new JBIException("Unable to start jms component", e);
+ }
+ }
+
+ public void stop() throws JBIException {
+ try {
+ if (consumer != null) {
+ consumer.close();
+ }
+ if (session != null) {
+ session.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ } catch (JMSException e) {
+ throw new JBIException("Unable to stop jms component", e);
+ } finally {
+ connection = null;
+ session = null;
+ consumer = null;
+ }
+ }
+
+ public JmsTemplate getTemplate() {
+ return template;
+ }
+
+ public void setTemplate(JmsTemplate template) {
+ this.template = template;
+ }
+
+ public String getSelector() {
+ return selector;
+ }
+
+ public void setSelector(String selector) {
+ this.selector = selector;
+ }
+
+}
+
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsSenderComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsSenderComponent.java
new file mode 100644
index 0000000..af6ccc7
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsSenderComponent.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.xml.transform.TransformerException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.OutBinding;
+import org.springframework.jms.core.JmsTemplate;
+import org.springframework.jms.core.MessageCreator;
+
+/**
+ * Consumers JBI messages and sends them to a JMS destination using the Spring
+ * {@link JmsTemplate}
+ *
+ * @version $Revision: 426415 $
+ */
+public class JmsSenderComponent extends OutBinding {
+
+ private static final Log log = LogFactory.getLog(JmsSenderComponent.class);
+
+ private JmsTemplate template;
+ private JmsMarshaler marshaler = new JmsMarshaler();
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public JmsTemplate getTemplate() {
+ return template;
+ }
+
+ public void setTemplate(JmsTemplate template) {
+ this.template = template;
+ }
+
+ public JmsMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(JmsMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return Returns the needJavaIdentifiers.
+ */
+ public boolean isNeedJavaIdentifiers() {
+ return this.marshaler.isNeedJavaIdentifiers();
+ }
+
+ /**
+ * @param needJavaIdentifiers The needJavaIdentifiers to set.
+ */
+ public void setNeedJavaIdentifiers(boolean needJavaIdentifiers) {
+ this.marshaler.setNeedJavaIdentifiers(needJavaIdentifiers);
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange exchange, final NormalizedMessage inMessage) throws Exception {
+ template.send(new MessageCreator() {
+ public Message createMessage(Session session) throws JMSException {
+ try {
+ Message message = marshaler.createMessage(inMessage, session);
+ if (log.isTraceEnabled()) {
+ log.trace("Sending message to: " + template.getDefaultDestinationName() + " message: " + message);
+ }
+ return message;
+ }
+ catch (TransformerException e) {
+ JMSException jmsEx = new JMSException("Failed to create JMS Message: " + e);
+ jmsEx.setLinkedException(e);
+ throw jmsEx;
+ }
+ }
+ });
+ done(exchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java
new file mode 100644
index 0000000..eb792aa
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/JmsServiceComponent.java
@@ -0,0 +1,312 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.xml.transform.TransformerException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.executors.Executor;
+import org.apache.servicemix.executors.ExecutorFactory;
+import org.apache.servicemix.jbi.framework.ComponentContextImpl;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.jms.JmsException;
+import org.springframework.jms.core.JmsTemplate;
+import org.springframework.jms.core.MessageCreator;
+
+/**
+ * A component which uses a {@link JmsTemplate} to consume messages from a destination, forward then intot the JBI
+ * container for processing, and send back the result to the JMS requestor - used for the TopipcRequestor and
+ * QueueRequestor pattern
+ *
+ * @version $Revision: 466982 $
+ */
+public class JmsServiceComponent extends ComponentSupport implements MessageListener, InitializingBean {
+ private static final Log log = LogFactory.getLog(JmsServiceComponent.class);
+ private DestinationChooser destinationChooser;
+ private JmsMarshaler marshaler = new JmsMarshaler();
+ private JmsTemplate template;
+ private String selector;
+ private MessageConsumer consumer;
+ private ConnectionFactory connectionFactory;
+ private Connection connection;
+ private Session session;
+ private Executor executor;
+
+ /**
+ * called by Spring framework after initialization
+ * @throws Exception
+ */
+ public void afterPropertiesSet() throws Exception {
+ if (template == null) {
+ throw new IllegalArgumentException("Must have a template set");
+ }
+ }
+
+ public void start() throws JBIException {
+ // Start receiving messages only when the component has actually been started.
+ super.start();
+ try {
+ connectionFactory = template.getConnectionFactory();
+ /*
+ * Component code did not work for JMS 1.02 compliant provider because uses APIs
+ * that did not exist in JMS 1.02 : ConnectionFactory.createConnection,
+ * Connection.createSession
+ */
+ if (template instanceof org.springframework.jms.core.JmsTemplate102) {
+ //Note1 - would've preferred to call JmsTemplate102 methods but they are protected.
+ if (template.isPubSubDomain()) {
+ javax.jms.TopicConnection tc;
+ connection = tc = ((javax.jms.TopicConnectionFactory)connectionFactory).createTopicConnection();
+ session = tc.createTopicSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+ }
+ else {
+ javax.jms.QueueConnection qc;
+ connection = qc = ((javax.jms.QueueConnectionFactory)connectionFactory).createQueueConnection();
+ session = qc.createQueueSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+ }
+ } else { // JMS 1.1 style
+ connection = connectionFactory.createConnection();
+ session = connection.createSession(template.isSessionTransacted(), template.getSessionAcknowledgeMode());
+ }
+
+ Destination defaultDestination = template.getDefaultDestination();
+ if (defaultDestination == null) {
+ defaultDestination = template.getDestinationResolver().resolveDestinationName(session, template.getDefaultDestinationName(),
+ template.isPubSubDomain());
+ }
+
+ /*
+ * Component code did not work for JMS 1.02 compliant provider because uses APIs
+ * that did not exist in JMS 1.02: Session.createConsumer
+ */
+ if (template instanceof org.springframework.jms.core.JmsTemplate102) {
+ //Note1 - would've preferred to call JmsTemplate102.createConsumer but it is protected. Code below is same.
+ //Note2 - assert that defaultDestination is correct type according to isPubSubDomain()
+ if (template.isPubSubDomain()) {
+ consumer = ((javax.jms.TopicSession)session).createSubscriber((javax.jms.Topic)defaultDestination, selector, template.isPubSubNoLocal());
+ } else {
+ consumer = ((javax.jms.QueueSession)session).createReceiver((javax.jms.Queue)defaultDestination, selector);
+ }
+ } else { // JMS 1.1 style
+ consumer = session.createConsumer(defaultDestination, selector);
+ }
+ connection.start();
+ consumer.setMessageListener(this);
+ } catch (JMSException e) {
+ throw new JBIException("Unable to start jms component", e);
+ }
+ }
+
+ public void stop() throws JBIException {
+ try {
+ if (consumer != null) {
+ consumer.close();
+ }
+ if (session != null) {
+ session.close();
+ }
+ if (connection != null) {
+ connection.close();
+ }
+ } catch (JMSException e) {
+ throw new JBIException("Unable to stop jms component", e);
+ } finally {
+ connection = null;
+ session = null;
+ consumer = null;
+ }
+ }
+
+ protected void init() throws JBIException {
+ ComponentContextImpl context = (ComponentContextImpl) getContext();
+ ExecutorFactory factory = context.getContainer().getExecutorFactory();
+ executor = factory.createExecutor("component." + context.getComponentName());
+ super.init();
+ }
+
+ /**
+ * @return Return the DestinationChooser
+ */
+ public DestinationChooser getDestinationChooser() {
+ return destinationChooser;
+ }
+
+ /**
+ * Set the DestinationChooser
+ *
+ * @param destinationChooser
+ */
+ public void setDestinationChooser(DestinationChooser destinationChooser) {
+ this.destinationChooser = destinationChooser;
+ }
+
+ /**
+ * Get the JMSMarshaler
+ *
+ * @return the marshaler
+ */
+ public JmsMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ /**
+ * Set the JMSMarshaler
+ *
+ * @param marshaler
+ */
+ public void setMarshaler(JmsMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return the JmsTemplate
+ */
+ public JmsTemplate getTemplate() {
+ return template;
+ }
+
+ /**
+ * Set the JmsTemplate
+ *
+ * @param template
+ */
+ public void setTemplate(JmsTemplate template) {
+ this.template = template;
+ }
+
+ /**
+ * @return Return the selector
+ */
+ public String getSelector() {
+ return selector;
+ }
+
+ /**
+ * Set the Selector
+ *
+ * @param selector
+ */
+ public void setSelector(String selector) {
+ this.selector = selector;
+ }
+
+ /**
+ * MessageListener implementation
+ * @param jmsMessage
+ */
+ public void onMessage(final Message jmsMessage) {
+ executor.execute(new Runnable() {
+ public void run() {
+ handleMessage(jmsMessage);
+ }
+ });
+ }
+
+ protected void handleMessage(final Message jmsMessage) {
+ try {
+ final InOut messageExchange = getDeliveryChannel().createExchangeFactory().createInOutExchange();
+ NormalizedMessage inMessage = messageExchange.createMessage();
+ try {
+ marshaler.toNMS(inMessage, jmsMessage);
+ messageExchange.setInMessage(inMessage);
+ if (getDeliveryChannel().sendSync(messageExchange)) {
+ Destination destination = getReplyToDestination(jmsMessage, messageExchange);
+ try {
+ template.send(destination, new MessageCreator() {
+ public Message createMessage(Session session) throws JMSException {
+ try {
+ Message message = marshaler.createMessage(messageExchange.getOutMessage(), session);
+ message.setJMSCorrelationID(jmsMessage.getJMSCorrelationID());
+ if (log.isTraceEnabled()) {
+ log.trace("Sending message to: " + template.getDefaultDestinationName()
+ + " message: " + message);
+ }
+ return message;
+ }
+ catch (TransformerException e) {
+ JMSException jmsEx = new JMSException("Failed to create a JMS Message: " + e);
+ jmsEx.setLinkedException(e);
+ throw jmsEx;
+ }
+ }
+ });
+ done(messageExchange);
+ }
+ catch (JmsException e) {
+ fail(messageExchange, e);
+ }
+ }
+ }
+ catch (JMSException e) {
+ log.error("Couldn't process " + jmsMessage, e);
+ messageExchange.setError(e);
+ messageExchange.setStatus(ExchangeStatus.ERROR);
+ }
+ }
+ catch (MessagingException e) {
+ log.error("Failed to process inbound JMS Message: " + jmsMessage, e);
+ }
+ }
+
+ protected Destination getReplyToDestination(Message jmsMessage, final InOut messageExchange) throws JMSException {
+ if (destinationChooser == null) {
+ return jmsMessage.getJMSReplyTo();
+ }
+ return destinationChooser.chooseDestination(messageExchange);
+ }
+
+ /**
+ * Choose the out bound destination to send the repsonse from JBI too If a DestinatonChooser is set, this is used,
+ * else the replyTo destination on the inbound message is used
+ *
+ * @param exchange
+ * @param inboundMessage
+ * @return the choosen outbound destination or null
+ * @throws JMSException if no destination can be found
+ */
+ protected Destination chooseOutBoundDestination(MessageExchange exchange, Message inboundMessage)
+ throws JMSException {
+ Destination result = null;
+ if (destinationChooser != null) {
+ result = destinationChooser.chooseDestination(exchange);
+ }
+ else if (inboundMessage != null && inboundMessage.getJMSReplyTo() != null) {
+ result = inboundMessage.getJMSReplyTo();
+ }
+ if (result == null) {
+ log.error("Could not find an outbound destination for " + inboundMessage);
+ throw new JMSException("No outbound JMS Destination can be found");
+ }
+ return result;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/RuntimeJMSException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/RuntimeJMSException.java
new file mode 100644
index 0000000..815b0c7
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/RuntimeJMSException.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jms.JMSException;
+
+/**
+ * A runtime exception caused when a JMS exception is thrown
+ * in a method which cannot throw a checked exception such
+ * as inside a JMS {@link javax.jms.MessageListener#onMessage(javax.jms.Message)} method.
+ *
+ * @version $Revision: 426415 $
+ */
+public class RuntimeJMSException extends RuntimeException {
+
+ public RuntimeJMSException(JMSException cause) {
+ super(cause);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/SimpleDestinationChooser.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/SimpleDestinationChooser.java
new file mode 100644
index 0000000..0a4aea8
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/SimpleDestinationChooser.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jms.Destination;
+
+/**
+ * A simple destination chooser which will use the value of the {@link #OUT_DESTINATION_KEY}
+ * property on the message exchange, or fall back to a default destination
+ *
+ * @version $Revision: 426415 $
+ */
+public class SimpleDestinationChooser implements DestinationChooser {
+ public static final String OUT_DESTINATION_KEY = "org.apache.servicemix.binding.jms.out.destination";
+
+ private Destination defaultDestination;
+
+ public SimpleDestinationChooser() {
+ }
+
+ public SimpleDestinationChooser(Destination defaultDestination) {
+ this.defaultDestination = defaultDestination;
+ }
+
+ public Destination chooseDestination(MessageExchange messageExchange) {
+ Object property = messageExchange.getProperty(OUT_DESTINATION_KEY);
+ if (property instanceof Destination) {
+ return (Destination) property;
+ }
+ return getDefaultDestination();
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public Destination getDefaultDestination() {
+ return defaultDestination;
+ }
+
+ public void setDefaultDestination(Destination defaultDestination) {
+ this.defaultDestination = defaultDestination;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/package.html
new file mode 100644
index 0000000..65924de
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jms/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for <a href="http://java.sun.com/products/jms/">JMS</a>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/jmx/CounterMonitorComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jmx/CounterMonitorComponent.java
new file mode 100644
index 0000000..0438082
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/jmx/CounterMonitorComponent.java
@@ -0,0 +1,281 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jmx;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.management.DeploymentException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.monitor.CounterMonitor;
+import javax.xml.transform.Source;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * A JMX Counter Monitor as a Component to enable firing notifications
+ *
+ * @version $Revision: 426415 $
+ */
+public class CounterMonitorComponent extends ComponentSupport implements NotificationListener, MessageExchangeListener {
+
+ private static final Log log = LogFactory.getLog(ComponentSupport.class);
+ private String name;
+ private ObjectName ourName;
+ private String observedObjectName;
+ private String attributeName;
+ private long granularityPeriod =5000;
+ private Number threshold;
+ private Number offset;
+ private MBeanServer mbeanServer;
+ private CounterMonitor counterMonitor = new CounterMonitor();
+
+ /**
+ * Called when the Component is initialized
+ *
+ * @param cc
+ * @throws JBIException
+ */
+ public void init(ComponentContext cc) throws JBIException {
+ super.init(cc);
+ validate();
+ if (mbeanServer == null) {
+ mbeanServer = cc.getMBeanServer();
+ }
+ try {
+ ObjectName observedName = new ObjectName(observedObjectName);
+ if (name == null) {
+ String type = observedName.getKeyProperty("type");
+ type = type != null ? type : "UNKNOWN";
+ name = mbeanServer.getDefaultDomain() + ":type=CounterMonitor_" + type;
+ }
+ ourName = new ObjectName(name);
+ counterMonitor.setNotify(true);
+ counterMonitor.addObservedObject(observedName);
+ counterMonitor.setObservedAttribute(attributeName);
+ counterMonitor.setGranularityPeriod(granularityPeriod);
+ counterMonitor.setDifferenceMode(false);
+ counterMonitor.setInitThreshold(threshold);
+ counterMonitor.setOffset(offset);
+ mbeanServer.registerMBean(counterMonitor, ourName);
+ mbeanServer.addNotificationListener(ourName, this, null, new Object());
+ } catch (Exception e) {
+ throw new DeploymentException(e);
+ }
+ }
+
+ /**
+ * Start the item.
+ *
+ * @exception javax.jbi.JBIException
+ * if the item fails to start.
+ */
+ public void start() throws javax.jbi.JBIException {
+ super.start();
+ counterMonitor.start();
+ }
+
+ /**
+ * Stop the item. This suspends current messaging activities.
+ *
+ * @exception javax.jbi.JBIException
+ * if the item fails to stop.
+ */
+ public void stop() throws javax.jbi.JBIException {
+ counterMonitor.stop();
+ super.stop();
+ }
+
+ /**
+ * Shut down the item. The releases resources, preparatory to uninstallation.
+ *
+ * @exception javax.jbi.JBIException
+ * if the item fails to shut down.
+ */
+ public void shutDown() throws javax.jbi.JBIException {
+ stop();
+ if (ourName != null && mbeanServer != null) {
+ try{
+ mbeanServer.removeNotificationListener(ourName,this);
+ } catch(Exception e) {
+ throw new JBIException(e);
+ }
+ }
+ super.shutDown();
+ }
+
+
+ /**
+ * @see javax.management.NotificationListener#handleNotification(javax.management.Notification, java.lang.Object)
+ */
+ public void handleNotification(Notification notification,Object arg1) {
+ try {
+ Source source = new StringSource(notification.getMessage());
+ InOnly exchange = getExchangeFactory().createInOnlyExchange();
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(source);
+ exchange.setInMessage(message);
+ send(exchange);
+ }
+ catch (Exception e) {
+ log.error("Failed to send Notification message to the NMR");
+ }
+
+ }
+
+ protected void validate() throws JBIException {
+ if (observedObjectName == null) {
+ throw new DeploymentException("observedObjectName is null");
+ }
+ if (attributeName == null) {
+ throw new DeploymentException("attributeName is null");
+ }
+ if (threshold == null) {
+ throw new DeploymentException("threshold is null");
+ }
+ if (offset == null) {
+ throw new DeploymentException("offset is null");
+ }
+ }
+
+ /**
+ * @return Returns the attributeName.
+ */
+ public String getAttributeName() {
+ return attributeName;
+ }
+
+ /**
+ * @param attributeName
+ * The attributeName to set.
+ */
+ public void setAttributeName(String attributeName) {
+ this.attributeName = attributeName;
+ }
+
+ /**
+ * @return Returns the counterMonitor.
+ */
+ public CounterMonitor getCounterMonitor() {
+ return counterMonitor;
+ }
+
+ /**
+ * @param counterMonitor The counterMonitor to set.
+ */
+ public void setCounterMonitor(CounterMonitor counterMonitor) {
+ this.counterMonitor = counterMonitor;
+ }
+
+ /**
+ * @return Returns the granularityPeriod.
+ */
+ public long getGranularityPeriod() {
+ return granularityPeriod;
+ }
+
+ /**
+ * @param granularityPeriod The granularityPeriod to set.
+ */
+ public void setGranularityPeriod(long granularityPeriod) {
+ this.granularityPeriod = granularityPeriod;
+ }
+
+ /**
+ * @return Returns the mbeanServer.
+ */
+ public MBeanServer getMbeanServer() {
+ return mbeanServer;
+ }
+
+ /**
+ * @param mbeanServer The mbeanServer to set.
+ */
+ public void setMbeanServer(MBeanServer mbeanServer) {
+ this.mbeanServer = mbeanServer;
+ }
+
+ /**
+ * @return Returns the name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return Returns the observedObjectName.
+ */
+ public String getObservedObjectName() {
+ return observedObjectName;
+ }
+
+ /**
+ * @param observedObjectName The observedObjectName to set.
+ */
+ public void setObservedObjectName(String observedObjectName) {
+ this.observedObjectName = observedObjectName;
+ }
+
+ /**
+ * @return Returns the offset.
+ */
+ public Number getOffset() {
+ return offset;
+ }
+
+ /**
+ * @param offset The offset to set.
+ */
+ public void setOffset(Number offset) {
+ this.offset = offset;
+ }
+
+ /**
+ * @return Returns the threshold.
+ */
+ public Number getThreshold() {
+ return threshold;
+ }
+
+ /**
+ * @param threshold The threshold to set.
+ */
+ public void setThreshold(Number threshold) {
+ this.threshold = threshold;
+ }
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ // We can only receive acks, so do nothing
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/ConfigNotSupportedException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/ConfigNotSupportedException.java
new file mode 100644
index 0000000..2d80d7e
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/ConfigNotSupportedException.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+public class ConfigNotSupportedException extends Exception {
+
+ public ConfigNotSupportedException() {
+ super();
+ }
+ public ConfigNotSupportedException(String message) {
+ super(message);
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/ExistingPropertyCopier.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/ExistingPropertyCopier.java
new file mode 100644
index 0000000..10c8330
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/ExistingPropertyCopier.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+
+
+/**
+ * Copy a property value from an existing property (somewhere)
+ * @author rbuckland
+ *
+ */
+public class ExistingPropertyCopier implements PropertyValue {
+
+ public final static String XML_ELEMENT_NAME = "existing-property";
+
+ private String name;
+
+ public ExistingPropertyCopier(String name) {
+ this.name = name;
+ }
+ public String getPropertyValue(NormalizedMessage msg) throws JBIException {
+ if (msg.getProperty(name) != null) {
+ return msg.getProperty(name).toString();
+ } else {
+ return null;
+ }
+
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/MessagePropertySetterXML.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/MessagePropertySetterXML.java
new file mode 100644
index 0000000..ddcaf8e
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/MessagePropertySetterXML.java
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.xpath.CachedXPathAPI;
+import org.apache.xpath.objects.XObject;
+import org.springframework.core.io.Resource;
+import org.springframework.util.Assert;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+
+
+/**
+ * Sets properties on the message, loaded from an XML MPS file
+ * where the properties to set are located in a <property-set ..>
+ * inside the XML config file.
+ *
+ * There can be more than one propertySet to "load".
+ *
+ * The property values are derived from 3 types of config.
+ * The first config that can return a value as a String to
+ * set onto the message, will be the "value" that is set
+ * as the property.
+ *
+ * <static-value>
+ * As it's name suggests, the "value" of this element
+ * will be the value of the JBI property.
+ *
+ * This is helpful as a default value, or as a static value.
+ *
+ * <exisiting-property> and <existint-property name="..."/>
+ * This will obtain the value of an existing property (itself)
+ * or another property on the same message.
+ *
+ * This can be helpful when you want the to "ONLY" change the
+ * the value of the property if there is some "xpath" expression
+ * that could not be derived.
+ *
+ * name=".." form will copy the string value of the other JBI property
+ * onto this one, (duping it). This may be handy when you have a component
+ * which expects a new property, but you have it as a different name at the moment.
+ *
+ * <xpath-expression>
+ * As it's name suggests, will locate a value in the inMessage source
+ * and set the resulting XPath String as the value of the JBI property.
+ *
+ * So given the three types, they can be arranged in any order. and the first
+ * PropertyValue Type that returns a value, will become the "value" of the JBI property.
+ *
+ *
+ * <!--
+ * <mps>
+ * <property-set name="someSetNameForASetOfProperties">
+ * <property name="some.property.name1">
+ * <static-value><![CDATA[value for the property]]></static-value>
+ * </property>
+ * <property name="some.property.name2">
+ * <xpath-expression>
+ * <![CDATA[/someexpath/statement/to/be/applied/to/message/source]]>
+ * </xpath-expression>
+ * <existing-property name="someproperty"/>
+ * <static-value><![CDATA[a value in the raw]]></static-value>
+ * </property>
+ * <property name="prop.xpath.with.static.default">
+ * <xpath-expression>
+ * <![CDATA[/someexpath/statement]]>
+ * </xpath-expression>
+ * <static-value><![CDATA[some default if xpath does not resolve]]></static-value>
+ * </property>
+ * <property name="prop.xpath.or.keep.existing">
+ * <xpath-expression>
+ * <![CDATA[/someexpath/statement]]>
+ * </xpath-expression>
+ * <existing-property/>
+ * </property>
+ * <property name="new.prop.name">
+ * <existing-property name="other.property"/>
+ * </property>
+ * <property name="...">
+ * ...
+ * </property>
+ * </property-set>
+ * <property-set name="...">
+ * ...
+ * </property-set>
+ * </mps>
+ * -->
+ *
+ *
+ * @author rbuckland
+ *
+ */
+public class MessagePropertySetterXML extends TransformComponentSupport {
+
+ /**
+ * Apache commons logger
+ */
+ private final transient Log logger = LogFactory.getLog(getClass());
+
+ /**
+ * The name of our JBI property we may have to interrogate to
+ * use as the "xpath" for the set of config.
+ */
+ public static final String MPS_PROP_NAME_PROPERTYSET = "org.apache.servicemix.components.mps.propertyset";
+
+ /**
+ * The XML Element name "property-set"
+ */
+ public static final String XML_ELEMENT_NAME = "property-set";
+
+ /**
+ * This is our XML file
+ */
+ private Resource xmlConfiguration = null;
+
+ /**
+ * Our XML config MPS.
+ */
+ private Document xmlMPSdom = null;
+
+ /**
+ * Holds the propertyValueResolver objects.
+ * if propertySet is not null, this holds one.
+ * if propertySet is null, this will hold
+ * one for each propertyvalue entry used during the time
+ * we are "active".
+ */
+ private Map propertSets = new HashMap();
+
+ /**
+ * If this is set, it is hardcoded as the fixed value.
+ *
+ * If this is null
+ * we will look for a propery MPS_PROP_NAME_PROPERTYSET
+ * as the "name" of the property set we will work with.
+ * So the message incoming, seeds the set of properties to load, just by
+ * the JBI property itself.
+ */
+ private String propertySet = null;
+
+
+ /**
+ * If the XPath for a propertySet is not null
+ * we will try and locate the propertySet to use by
+ * pulling a String from the inMessage content using this
+ * XPath.
+ */
+ private String xpathForPropertySet = null;
+
+ /**
+ * Here is the transform of the message
+ * We will locate the propertySetName to use
+ * and the load up our propertySet magic wand and apply all the properties
+ * we can to the outgoing NormalizedMessage
+ */
+ protected boolean transform(MessageExchange arg0, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ try {
+ copyPropertiesAndAttachments(arg0,in,out);
+ out.setContent(in.getContent());
+
+ String propertySetName = "";
+ if (xpathForPropertySet != null) {
+ try {
+ CachedXPathAPI xpathApi = new org.apache.xpath.CachedXPathAPI();
+ Document doc = new SourceTransformer().toDOMDocument(in);
+ XObject propSetXO = xpathApi.eval(doc.getDocumentElement(),xpathForPropertySet);
+ propertySetName = propSetXO.str();
+ } catch (Exception e) {
+ throw new MessagingException("Problem getting the propertySet using XPath", e);
+ }
+ } else if (this.propertySet != null) {
+ propertySetName = this.propertySet;
+ } else if (in.getProperty(MPS_PROP_NAME_PROPERTYSET) != null) {
+ propertySetName = in.getProperty(MPS_PROP_NAME_PROPERTYSET).toString();
+ } else {
+ return false;
+ }
+ logger.info("Applying properties from property-set [" + propertySetName + "]");
+ getPropertySetByName(propertySetName).applyProperties(in,out);
+ return true;
+ } catch (JBIException e) {
+ throw new MessagingException("Problem setting properties",e);
+ } catch (PropertySetNotFoundException e) {
+ logger.warn(e.getLocalizedMessage());
+ return false;
+ }
+ }
+
+ /**
+ * Initialise by loading the mps.xml file up into an internal DOM.
+ *
+ * @throws JBIException
+ */
+ private void initConfig() throws JBIException {
+ Assert.notNull(this.xmlConfiguration);
+ DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
+ domFactory.setIgnoringElementContentWhitespace(true);
+ domFactory.setIgnoringComments(true);
+ domFactory.setCoalescing(true); // convert CDATA to test nodes
+ DocumentBuilder domBuilder;
+ try {
+ logger.info("Intialising MessagePropertySetterXML, loading settings from " + this.xmlConfiguration.getFile().getAbsolutePath());
+ domBuilder = domFactory.newDocumentBuilder();
+ xmlMPSdom = domBuilder.parse(this.xmlConfiguration.getInputStream());
+ } catch (ParserConfigurationException e) {
+ throw new JBIException("Problem parsing the XML config file for MPS",e);
+ } catch (SAXException e) {
+ throw new JBIException("Problem loading the XML config file for MPS",e);
+ } catch (IOException e) {
+ throw new JBIException("Problem loading the XML config file for MPS",e);
+ }
+
+ }
+
+ /**
+ * We are only interested in loading the XML onfig, nothing else
+ */
+ public void init(ComponentContext context) throws JBIException {
+ super.init(context);
+ initConfig();
+ }
+
+ /**
+ * Create a propertyset (loading up the Object config based on the XML config)
+ *
+ * @param propertySetName
+ * @return
+ * @throws JBIException
+ * @throws PropertySetNotFoundException
+ */
+ private PropertySet createPropertySet(String propertySetName) throws JBIException , PropertySetNotFoundException{
+ PropertySet ps;
+ CachedXPathAPI xpath = new CachedXPathAPI();
+ StringBuffer xpathSB = new StringBuffer("//")
+ .append(XML_ELEMENT_NAME)
+ .append("[@name='")
+ .append(propertySetName)
+ .append("']");
+ try {
+ Node propertySetNode = xpath.selectSingleNode(xmlMPSdom,xpathSB.toString());
+ if (propertySetNode == null) {
+ throw new PropertySetNotFoundException("Could not find a property-set for [" + propertySetName + "] in " + xmlConfiguration.getFilename());
+ }
+ ps = new PropertySet(propertySetName,(Element) propertySetNode);
+ this.propertSets.put(propertySetName, ps);
+ } catch (TransformerException e) {
+ throw new JBIException("Could not load the PropertySet for " + propertySet,e);
+ } catch (ConfigNotSupportedException e) {
+ throw new JBIException("Could not load the PropertySet for. XMLConfig is not good for " + propertySet,e);
+ }
+ return ps;
+
+ }
+
+ /**
+ * Get a property set from ou
+ * @param name
+ * @return
+ * @throws JBIException
+ */
+ private PropertySet getPropertySetByName(String name) throws JBIException, PropertySetNotFoundException {
+ // find a pre "created" one
+ if (this.propertSets.containsKey(name)) {
+ return (PropertySet)this.propertSets.get(name);
+ } else {
+ return this.createPropertySet(name);
+ }
+
+ }
+
+ /**
+ * @param propertySet The propertySet to set.
+ */
+ public void setPropertySet(String propertySet) {
+ this.propertySet = propertySet;
+ }
+
+ /**
+ * @param xmlConfiguration The xmlConfiguration to set.
+ */
+ public void setXmlConfiguration(Resource xmlConfiguration) {
+ this.xmlConfiguration = xmlConfiguration;
+ }
+
+ /**
+ * @param xpathForPropertySet xpath to apply to a message to derive the name of the property-set we want to load
+ */
+ public void setXpathForPropertySet(String xpathForPropertySet) {
+ this.xpathForPropertySet = xpathForPropertySet;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertySet.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertySet.java
new file mode 100644
index 0000000..ae7d3cc
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertySet.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class PropertySet {
+
+
+ public final static String XML_ELEMENT_NAME = "property-set";
+
+ public final static String XML_ATTR_NAME_NAME = "name";
+
+ /**
+ * Our name
+ */
+ private String propertySetName;
+
+ /**
+ * Our list of property value resolvers
+ */
+ private ArrayList pvrs = new ArrayList();
+
+ /**
+ * Create a propertySet with a particular name
+ * Element self is //property-set
+ *
+ * @param name
+ */
+ public PropertySet(String name, Element self) throws ConfigNotSupportedException{
+ this.propertySetName = name;
+ NodeList properties = self.getElementsByTagName(PropertyValueResolver.XML_ELEMENT_NAME);
+ for (int i=0; i < properties.getLength();i++) {
+ Element property = (Element)properties.item(i);
+ this.pvrs.add((new PropertyValueResolver(property.getAttribute(XML_ATTR_NAME_NAME),property)));
+ }
+ }
+
+ /**
+ * Apply all the property values for this in/out pair
+ *
+ * @param in
+ * @param out
+ */
+ public void applyProperties(NormalizedMessage in, NormalizedMessage out) throws JBIException {
+
+ // for every property, set the value on the message
+ for (Iterator iter = pvrs.iterator(); iter.hasNext();) {
+ ((PropertyValueResolver)iter.next()).setProperty(in,out);
+ }
+ }
+
+ public String getName() {
+ return propertySetName;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertySetNotFoundException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertySetNotFoundException.java
new file mode 100644
index 0000000..f4ce853
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertySetNotFoundException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+public class PropertySetNotFoundException extends Exception {
+
+ public PropertySetNotFoundException() {
+ super();
+ }
+
+ public PropertySetNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public PropertySetNotFoundException(String message) {
+ super(message);
+ }
+
+ public PropertySetNotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertyValue.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertyValue.java
new file mode 100644
index 0000000..f8844fe
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertyValue.java
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+
+public interface PropertyValue {
+
+ public String getPropertyValue(NormalizedMessage msg) throws JBIException;
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertyValueResolver.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertyValueResolver.java
new file mode 100644
index 0000000..67abb4c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/PropertyValueResolver.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Class to hold the list of propertyValues
+ *
+ * @author rbuckland
+ *
+ */
+public class PropertyValueResolver {
+
+ private final transient Log logger = LogFactory.getLog(getClass());
+
+ public static final String XML_ELEMENT_NAME = "property";
+
+ /**
+ * The name of the JBI property that this class will set.
+ */
+ private String name;
+
+ /**
+ * if the set contains a static-string propertyvalue at the top of the
+ * config, we don't need to do anything so the value is stored "here". Null
+ * if the list has to be evald
+ */
+ private String staticValue = null;
+
+ /**
+ * Our list of PropertySetTypes
+ */
+ private List propertySetTypes = new ArrayList();
+
+ /**
+ * Construct this PVR, the Element is the .. //property-set/property element
+ *
+ * @param propertyName
+ * the name of the property that will be set
+ * @param self
+ * Element
+ * @throws JBIException
+ */
+ public PropertyValueResolver(String propertyName, Element self)
+ throws ConfigNotSupportedException {
+ this.name = propertyName;
+ addPropertySetTypes(self);
+ }
+
+ /**
+ * Set the property (this.name) on the out message based on any properties
+ * on the message
+ *
+ * @param msg
+ */
+ public void setProperty(NormalizedMessage in, NormalizedMessage out)
+ throws JBIException {
+
+ if (this.staticValue != null) {
+ out.setProperty(name, staticValue);
+ } else {
+ String value = resolveValue(in);
+ if (value != null) {
+ out.setProperty(name, value);
+ } else {
+ logger.warn("Property " + name
+ + " was not set as the value was unresolved");
+ }
+ }
+ }
+
+ /**
+ * Get the value out of the in, and put it in the out.
+ *
+ * @param in
+ * @param out
+ * @return
+ */
+ private String resolveValue(NormalizedMessage message) throws JBIException {
+ // go through the list
+ // if a value is found on the one, return it, until the list is
+ // exhausted
+ String propValue = null;
+ logger.debug("propvrsize=" + propertySetTypes.size());
+ for (int i = 0; i < propertySetTypes.size(); i++) {
+ PropertyValue pv = (PropertyValue) propertySetTypes.get(i);
+ propValue = pv.getPropertyValue(message);
+ logger.debug("value from" + pv.getClass() + " = " + propValue);
+ if (propValue != null && !"".equals(propValue)) {
+ break;
+ }
+ if (logger.isDebugEnabled()) {
+ logger.debug(this.name + ": " + pv.getClass() + " was empty");
+ }
+ }
+ return propValue;
+ }
+
+ /**
+ * Given the XML below, we will locate the different propertyValueTypes and
+ * set them on us.
+ *
+ * <property name="some.property.name"> <existing-property/>
+ * <existing-property name="someproperty"/> <xpath-expression>
+ * <![CDATA[/someexpath/statement]]> </xpath-expression> <static-value><![CDATA[a
+ * value in the raw]]></static-value> </property>
+ *
+ * @param propertyNode
+ */
+ private void addPropertySetTypes(Element propertyElement)
+ throws ConfigNotSupportedException {
+
+ NodeList propertyValueNodes = propertyElement.getChildNodes();
+ // iterate of all the propertyValue nodes ..
+ // (same as equiv to select='//property[@name='x']/*'
+ for (int i = 0; i < propertyValueNodes.getLength(); i++) {
+ if (propertyValueNodes.item(i).getNodeType() != Element.ELEMENT_NODE) {
+ continue;
+ }
+ Element pvElem = (Element) propertyValueNodes.item(i);
+ PropertyValue pv;
+ if (pvElem.getNodeName().equals(
+ StaticStringPropertyValue.XML_ELEMENT_NAME)) {
+ if (this.propertySetTypes.size() == 0) {
+ this.staticValue = DOMUtil.getElementText(pvElem);
+ }
+ pv = new StaticStringPropertyValue(DOMUtil
+ .getElementText(pvElem));
+ } else if (pvElem.getNodeName().equals(
+ XPathContentMessagePropertyValue.XML_ELEMENT_NAME)) {
+ String xpath = DOMUtil.getElementText(pvElem);
+ pv = new XPathContentMessagePropertyValue(xpath);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Created an XPath VR :" + xpath);
+ }
+ } else if (pvElem.getNodeName().equals(
+ ExistingPropertyCopier.XML_ELEMENT_NAME)) {
+ // default to this parents name (so it acts like a property
+ // copy)
+
+ String propertyName = this.name;
+ if (pvElem.getAttribute("name") != null
+ && !"".equals(pvElem.getAttribute("name"))) {
+ // if there was a <existing-property name="somename"/>
+ // then use that name as the source JBI property
+ // in this mode it acts like a cp src dest and not a dupe.
+ propertyName = pvElem.getAttribute("name");
+ }
+ pv = new ExistingPropertyCopier(propertyName);
+ } else {
+ throw new ConfigNotSupportedException("Property value type "
+ + pvElem.getNodeName()
+ + " is not supported for the MessagePropertySetter");
+ }
+ this.propertySetTypes.add(pv);
+
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/StaticStringPropertyValue.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/StaticStringPropertyValue.java
new file mode 100644
index 0000000..452fae8
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/StaticStringPropertyValue.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+
+
+public class StaticStringPropertyValue implements PropertyValue {
+
+ /**
+ * Our element name
+ */
+ public final static String XML_ELEMENT_NAME = "static-value";
+
+ /**
+ * This is the static value we represent
+ */
+ private String staticValue;
+
+ /**
+ * Ctor
+ * @param staticValue
+ */
+ public StaticStringPropertyValue(String staticValue) {
+ this.staticValue = staticValue;
+ }
+
+ /**
+ *
+ */
+ public String getPropertyValue(NormalizedMessage msg) throws JBIException {
+ return staticValue;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/XPathContentMessagePropertyValue.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/XPathContentMessagePropertyValue.java
new file mode 100644
index 0000000..bbebf8d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/mps/XPathContentMessagePropertyValue.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.w3c.dom.Document;
+
+import org.apache.xpath.CachedXPathAPI;
+import org.apache.xpath.objects.XObject;
+
+/**
+ * Get the Value of a property from the message given the XPath Statement.
+ * @author rbuckland
+ *
+ */
+public class XPathContentMessagePropertyValue implements PropertyValue {
+
+ public final static String XML_ELEMENT_NAME = "xpath-expression";
+
+ private String xpath;
+
+ public XPathContentMessagePropertyValue(String xpath) {
+ this.xpath = xpath;
+ }
+
+ /**
+ * Get a value give the XPath statement preset in our Ctor.
+ * Return null if the value was empty or not there
+ */
+ public String getPropertyValue(NormalizedMessage msg) throws JBIException {
+ String resultValue = null;
+ if (msg.getContent() != null) {
+ CachedXPathAPI xpathApi = new CachedXPathAPI();
+ try {
+ Document doc = new SourceTransformer().toDOMDocument(msg);
+ XObject result = xpathApi.eval(doc,xpath);
+
+ resultValue = result.toString();
+ if ("".equals(resultValue)) {
+ resultValue = null;
+ }
+ } catch (Exception e) {
+ throw new JBIException("Could not get value from message via xpath " + xpath, e);
+ }
+ }
+ return resultValue;
+
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/ConnectionRefusedException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/ConnectionRefusedException.java
new file mode 100644
index 0000000..6835cf3
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/ConnectionRefusedException.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.net;
+
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * Exception thrown if the connection could not be established.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ConnectionRefusedException extends MessagingException {
+ private int code;
+
+ public ConnectionRefusedException(int code) {
+ super("Connection refused with return code: " + code);
+ this.code = code;
+ }
+
+ /**
+ * @return the status code for why the connection was refused
+ */
+ public int getCode() {
+ return code;
+ }
+}
+
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPClientPool.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPClientPool.java
new file mode 100644
index 0000000..6647cd2
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPClientPool.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.net;
+
+import org.apache.commons.net.SocketClient;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPReply;
+import org.apache.commons.net.ftp.FTPClientConfig;
+
+import java.io.IOException;
+
+/**
+ * A pool of FTP clients for
+ * the <a href="http://jakarta.apache.org/commons/net.html">Jakarta Commons Net</a> library
+ *
+ * @version $Revision: 426415 $
+ */
+public class FTPClientPool extends SocketClientPoolSupport {
+
+ private String username;
+ private String password;
+ private boolean binaryMode = true;
+ private boolean passiveMode = false;
+ private FTPClientConfig config;
+
+ public boolean validateObject(Object object) {
+ FTPClient client = (FTPClient) object;
+ try {
+ return client.sendNoOp();
+ }
+ catch (IOException e) {
+ throw new RuntimeException("Failed to validate client: " + e, e);
+ }
+ }
+
+ public void activateObject(Object object) throws Exception {
+ FTPClient client = (FTPClient) object;
+ client.setReaderThread(true);
+ }
+
+ public void passivateObject(Object object) throws Exception {
+ FTPClient client = (FTPClient) object;
+ client.setReaderThread(false);
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public boolean isBinaryMode() {
+ return binaryMode;
+ }
+
+ public void setBinaryMode(boolean binaryMode) {
+ this.binaryMode = binaryMode;
+ }
+
+ /**
+ * @return the passiveMode
+ */
+ public boolean isPassiveMode() {
+ return passiveMode;
+ }
+
+ /**
+ * @param passiveMode the passiveMode to set
+ */
+ public void setPassiveMode(boolean passiveMode) {
+ this.passiveMode = passiveMode;
+ }
+
+ public FTPClientConfig getConfig() {
+ return config;
+ }
+
+ public void setConfig(FTPClientConfig config) {
+ this.config = config;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void connect(SocketClient client) throws Exception {
+ FTPClient ftp = (FTPClient) client;
+
+ if (config != null) {
+ ftp.configure(config);
+ }
+ super.connect(client);
+
+ int code = ftp.getReplyCode();
+ if (!FTPReply.isPositiveCompletion(code)) {
+ ftp.disconnect();
+ throw new ConnectionRefusedException(code);
+ }
+ if (!ftp.login(getUsername(), getPassword())) {
+ ftp.disconnect();
+ throw new ConnectionRefusedException(ftp.getReplyCode());
+ }
+ if (isBinaryMode()) {
+ ftp.setFileType(FTP.BINARY_FILE_TYPE);
+ }
+ if (isPassiveMode()) {
+ ftp.enterLocalPassiveMode();
+ }
+ }
+
+ protected void disconnect(SocketClient client) throws Exception {
+ FTPClient ftp = (FTPClient) client;
+ if (ftp.isConnected()) {
+ ftp.logout();
+ }
+ super.disconnect(client);
+ }
+
+ protected SocketClient createSocketClient() {
+ return new FTPClient();
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPPoller.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPPoller.java
new file mode 100644
index 0000000..2c6ab01
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPPoller.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.net;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.net.SocketClient;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.components.util.FileMarshaler;
+import org.apache.servicemix.components.util.PollingComponentSupport;
+
+import java.util.concurrent.CopyOnWriteArraySet;
+
+/**
+ * A component which polls for files to arrive on an FTP server
+ * using the <a href="http://jakarta.apache.org/commons/net.html">Jakarta Commons Net</a> library
+ * and then sends them into the normalized message service, using a plugable transformer
+ * and removes them.
+ *
+ * @version $Revision: 666120 $
+ */
+public class FTPPoller extends PollingComponentSupport {
+ private static final Log log = LogFactory.getLog(FTPPoller.class);
+
+ private FTPClientPool clientPool;
+ private String path;
+ private FileMarshaler marshaler = new DefaultFileMarshaler();
+ private Set workingSet = new CopyOnWriteArraySet();
+
+ private String getWorkingPath() {
+ return path == null ? "." : path;
+ }
+
+ public void poll() throws Exception {
+ FTPClient ftp = (FTPClient) borrowClient();
+ try {
+ FTPFile[] files = ftp.listFiles(getWorkingPath());
+ for (int i = 0; i < files.length; i++) {
+ pollFile(files[i]);
+ }
+ }
+ finally {
+ returnClient(ftp);
+ }
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public FTPClientPool getClientPool() {
+ return clientPool;
+ }
+
+ public void setClientPool(FTPClientPool clientPool) {
+ this.clientPool = clientPool;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public FileMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(FileMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * The set of FTPFiles that this component is currently working on
+ */
+ public Set getWorkingSet() {
+ return workingSet;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ protected void init() throws JBIException {
+ if (clientPool == null) {
+ throw new IllegalArgumentException("You must initialise the clientPool property");
+ }
+ super.init();
+ }
+
+ protected void pollFile(final FTPFile aFile) {
+ if (workingSet.add(aFile)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scheduling file " + aFile + " for processing");
+ }
+ getExecutor().execute(new Runnable() {
+ public void run() {
+ try {
+ processFile(aFile);
+ } finally {
+ workingSet.remove(aFile);
+ }
+ }
+ });
+ }
+ }
+
+ protected void processFile(FTPFile file) {
+ if (file.getName().equals(".") || file.getName().equals("..")) { // TODO: what about other directories?
+ return;
+ }
+ FTPClient client = null;
+ try {
+ client = (FTPClient) borrowClient();
+ processFile(client, file);
+ if (!client.deleteFile(getWorkingPath() + file.getName())) {
+ throw new IOException("Could not delete file " + file);
+ }
+ }
+ catch (Exception e) {
+ log.error("Failed to process file: " + file + ". Reason: " + e, e);
+ }
+ finally {
+ if (client != null) {
+ returnClient(client);
+ }
+ }
+ }
+
+ protected void processFile(FTPClient client, FTPFile file) throws Exception {
+ String name = file.getName();
+ InputStream in = client.retrieveFileStream(getWorkingPath() + name);
+ InOnly exchange = getExchangeFactory().createInOnlyExchange();
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setInMessage(message);
+ marshaler.readMessage(exchange, message, in, name);
+ getDeliveryChannel().sendSync(exchange);
+ in.close();
+ client.completePendingCommand();
+ }
+
+
+ protected SocketClient borrowClient() throws JBIException {
+ try {
+ return getClientPool().borrowClient();
+ }
+ catch (Exception e) {
+ throw new JBIException(e);
+ }
+ }
+
+ protected void returnClient(SocketClient client) {
+ if (client != null) {
+ try {
+ getClientPool().returnClient(client);
+ }
+ catch (Exception e) {
+ log.error("Failed to return client to pool: " + e, e);
+ }
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPSender.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPSender.java
new file mode 100644
index 0000000..bd81d7d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/FTPSender.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.net;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.net.SocketClient;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.components.util.FileMarshaler;
+import org.apache.servicemix.components.util.OutBinding;
+
+/**
+ * A component which sends a message to a file using FTP via the
+ * <a href="http://jakarta.apache.org/commons/net.html">Jakarta Commons Net</a> library
+ *
+ * @version $Revision: 486715 $
+ */
+public class FTPSender extends OutBinding {
+ private static final Log log = LogFactory.getLog(FTPSender.class);
+
+ private FTPClientPool clientPool;
+ private FileMarshaler marshaler = new DefaultFileMarshaler();
+ private String uniqueFileName = "ServiceMix";
+ private boolean overwrite = false;
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public FTPClientPool getClientPool() {
+ return clientPool;
+ }
+
+ public void setClientPool(FTPClientPool clientPool) {
+ this.clientPool = clientPool;
+ }
+
+ public FileMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(FileMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public String getUniqueFileName() {
+ return uniqueFileName;
+ }
+
+ /**
+ * Sets the name used to make a unique name if no file name is available on the message.
+ *
+ * @param uniqueFileName the new value of the unique name to use for generating unique names
+ */
+ public void setUniqueFileName(String uniqueFileName) {
+ this.uniqueFileName = uniqueFileName;
+ }
+
+ public boolean isOverwrite() {
+ return overwrite;
+ }
+
+ public void setOverwrite(boolean overwrite) {
+ this.overwrite = overwrite;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ if (clientPool == null) {
+ throw new IllegalArgumentException("You must initialise the clientPool property");
+ }
+ super.init();
+ }
+
+ protected void process(MessageExchange exchange, NormalizedMessage message) throws Exception {
+ FTPClient client = null;
+ OutputStream out = null;
+ try {
+ client = (FTPClient) getClientPool().borrowClient();
+
+ String name = marshaler.getOutputName(exchange, message);
+ if (name == null) {
+ if (uniqueFileName != null) {
+ out = client.storeUniqueFileStream(uniqueFileName);
+ }
+ else {
+ out = client.storeUniqueFileStream();
+ }
+ }
+ else {
+ out = client.storeFileStream(name);
+ if (out == null) {
+ // lets try overwrite the previous file?
+ if (overwrite) {
+ client.deleteFile(name);
+ }
+ out = client.storeFileStream(name);
+ }
+ }
+ if (out == null) {
+ throw new IOException("No output stream available for output name: " + name + ". Maybe the file already exists?");
+ }
+ marshaler.writeMessage(exchange, message, out, name);
+ done(exchange);
+ }
+ finally {
+ if (out != null) {
+ try {
+ out.close();
+ }
+ catch (IOException e) {
+ log.error("Caught exception while closing stream on error: " + e, e);
+ }
+ }
+ client.completePendingCommand();
+ returnClient(client);
+ }
+ }
+
+ protected void returnClient(SocketClient client) {
+ if (client != null) {
+ try {
+ getClientPool().returnClient(client);
+ }
+ catch (Exception e) {
+ log.error("Failed to return client to pool: " + e, e);
+ }
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/SocketClientPoolSupport.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/SocketClientPoolSupport.java
new file mode 100644
index 0000000..073d62e
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/SocketClientPoolSupport.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.net;
+
+import org.apache.commons.net.SocketClient;
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.impl.GenericObjectPool;
+import org.springframework.beans.factory.DisposableBean;
+import org.springframework.beans.factory.InitializingBean;
+
+import javax.jbi.JBIException;
+import java.io.IOException;
+import java.net.InetAddress;
+
+/**
+ * A pool of {@link SocketClient} instances from the
+ * <a href="http://jakarta.apache.org/commons/net.html">Jakarta Commons Net</a> library to handle
+ * internet networking connections.
+ *
+ * @version $Revision: 469500 $
+ */
+public abstract class SocketClientPoolSupport implements InitializingBean, DisposableBean, PoolableObjectFactory {
+ private ObjectPool pool;
+ private InetAddress address;
+ private String host;
+ private int port = -1;
+ private InetAddress localAddress;
+ private int localPort;
+
+ public void afterPropertiesSet() throws Exception {
+ if (pool == null) {
+ GenericObjectPool goPool = new GenericObjectPool();
+ goPool.setTestOnBorrow(true);
+ pool = goPool;
+ }
+ pool.setFactory(this);
+ }
+
+ public void destroy() throws Exception {
+ if (pool != null) {
+ pool.close();
+ }
+ }
+
+ public SocketClient borrowClient() throws Exception {
+ return (SocketClient) getPool().borrowObject();
+ }
+
+ public void returnClient(SocketClient client) throws Exception {
+ getPool().returnObject(client);
+ }
+
+ // PoolableObjectFactory interface
+ //-------------------------------------------------------------------------
+ public Object makeObject() throws Exception {
+ SocketClient client = createSocketClient();
+ connect(client);
+ return client;
+ }
+
+ public void destroyObject(Object object) throws Exception {
+ SocketClient client = (SocketClient) object;
+ disconnect(client);
+ }
+
+ public boolean validateObject(Object object) {
+ return true;
+ }
+
+ public void activateObject(Object object) throws Exception {
+ }
+
+ public void passivateObject(Object object) throws Exception {
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public InetAddress getAddress() {
+ return address;
+ }
+
+ public void setAddress(InetAddress address) {
+ this.address = address;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public InetAddress getLocalAddress() {
+ return localAddress;
+ }
+
+ public void setLocalAddress(InetAddress localAddress) {
+ this.localAddress = localAddress;
+ }
+
+ public int getLocalPort() {
+ return localPort;
+ }
+
+ public void setLocalPort(int localPort) {
+ this.localPort = localPort;
+ }
+
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
+ public ObjectPool getPool() {
+ return pool;
+ }
+
+ public void setPool(ObjectPool pool) {
+ if (pool != null) {
+ pool.setFactory(this);
+ }
+ this.pool = pool;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void connect(SocketClient client) throws IOException, JBIException, Exception {
+ if (host != null) {
+ if (localAddress != null) {
+ client.connect(host, port, localAddress, localPort);
+ }
+ else if (port >= 0) {
+ client.connect(host, port);
+ }
+ else {
+ client.connect(host);
+ }
+ }
+ else if (address != null) {
+ if (localAddress != null) {
+ client.connect(address, port, localAddress, localPort);
+ }
+ else if (port >= 0) {
+ client.connect(address, port);
+ }
+ else {
+ client.connect(address);
+ }
+ }
+ else {
+ throw new JBIException("You must configure the address or host property");
+ }
+ }
+
+
+ protected void disconnect(SocketClient client) throws Exception {
+ if (client.isConnected()) {
+ client.disconnect();
+ }
+ }
+
+ protected abstract SocketClient createSocketClient();
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/package.html
new file mode 100644
index 0000000..193e088
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/net/package.html
@@ -0,0 +1,29 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A collection of network components using the
+<a href="http://jakarta.apache.org/commons/net.html">Jakarta Commons Net</a> library
+for handling things like FTP
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/DefaultQuartzMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/DefaultQuartzMarshaler.java
new file mode 100644
index 0000000..149bdd2
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/DefaultQuartzMarshaler.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.quartz;
+
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.servicemix.components.util.MarshalerSupport;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.quartz.JobDataMap;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * The default implementation of the Quartz marshaler
+ *
+ * @version $Revision: 426415 $
+ */
+public class DefaultQuartzMarshaler extends MarshalerSupport implements QuartzMarshaler {
+
+ public void populateNormalizedMessage(NormalizedMessage message, JobExecutionContext context) throws JobExecutionException, MessagingException {
+ JobDetail detail = context.getJobDetail();
+ JobDataMap dataMap = detail.getJobDataMap();
+ for (Iterator iter = dataMap.entrySet().iterator(); iter.hasNext(); ) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String key = (String) entry.getKey();
+ if (!key.equals(QuartzComponent.COMPONENT_KEY)) {
+ Object value = entry.getValue();
+ message.setProperty(key, value);
+ }
+ }
+
+ try {
+ Document document = getTransformer().createDocument();
+ Element root = document.createElement("timer");
+ document.appendChild(root);
+ DOMUtil.addChildElement(root, "name", detail.getName());
+ DOMUtil.addChildElement(root, "group", detail.getGroup());
+ DOMUtil.addChildElement(root, "fullname", detail.getFullName());
+ DOMUtil.addChildElement(root, "description", detail.getDescription());
+ DOMUtil.addChildElement(root, "fireTime", context.getFireTime());
+
+ message.setContent(new DOMSource(document));
+ }
+ catch (ParserConfigurationException e) {
+ throw new MessagingException("Failed to create content: " + e, e);
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/QuartzComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/QuartzComponent.java
new file mode 100644
index 0000000..8be9f17
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/QuartzComponent.java
@@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.quartz;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.quartz.JobDetail;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.SchedulerFactory;
+import org.quartz.Trigger;
+import org.quartz.impl.StdSchedulerFactory;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * A <a href="http://www.opensymphony.com/quartz/">Quartz</a> component for triggering components when timer events fire.
+ *
+ * @version $Revision: 433012 $
+ */
+public class QuartzComponent extends ComponentSupport implements MessageExchangeListener {
+ private static final transient Log log = LogFactory.getLog(QuartzComponent.class);
+
+ public static final String COMPONENT_KEY = "org.apache.servicemix.component";
+
+ private SchedulerFactory factory;
+ private Scheduler scheduler;
+ private Map triggers;
+ private QuartzMarshaler marshaler = new DefaultQuartzMarshaler();
+
+ public void start() throws JBIException {
+ try {
+ scheduler.start();
+ super.start();
+ } catch (SchedulerException e) {
+ throw new JBIException(e);
+ }
+ }
+
+ public void stop() throws JBIException {
+ try {
+ super.stop();
+ scheduler.standby();
+ } catch (SchedulerException e) {
+ throw new JBIException(e);
+ }
+ }
+
+ public void shutDown() throws JBIException {
+ try {
+ scheduler.shutdown();
+ } catch (SchedulerException e) {
+ throw new JBIException(e);
+ } finally {
+ super.shutDown();
+ }
+ }
+
+ public void addTrigger(Trigger trigger, JobDetail detail) throws JBIException {
+ try {
+ // lets default the trigger name to the job name
+ if (trigger.getName() == null) {
+ trigger.setName(detail.getName());
+ }
+ // lets default the trigger group to the job group
+ if (trigger.getGroup() == null) {
+ trigger.setGroup(detail.getGroup());
+ }
+ // default start time to now if not specified
+ if (trigger.getStartTime() == null) {
+ trigger.setStartTime(new Date());
+ }
+ detail.getJobDataMap().put(COMPONENT_KEY, this);
+ Class jobClass = detail.getJobClass();
+ if (jobClass == null) {
+ detail.setJobClass(ServiceMixJob.class);
+ }
+ scheduler.scheduleJob(detail, trigger);
+ }
+ catch (SchedulerException e) {
+ throw new JBIException("Failed to add trigger: " + trigger + " with detail: " + detail + ". Reason: " + e, e);
+ }
+ }
+
+
+ /**
+ * This method is invoked when a Quartz job is fired.
+ *
+ * @param context the Quartz Job context
+ */
+ public void onJobExecute(JobExecutionContext context) throws JobExecutionException {
+ if (log.isDebugEnabled()) {
+ log.debug("Firing Quartz Job with context: " + context);
+ }
+ try {
+ InOnly exchange = getExchangeFactory().createInOnlyExchange();
+ NormalizedMessage message = exchange.createMessage();
+ getMarshaler().populateNormalizedMessage(message, context);
+ exchange.setInMessage(message);
+ send(exchange);
+ }
+ catch (MessagingException e) {
+ throw new JobExecutionException(e);
+ }
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public SchedulerFactory getFactory() {
+ return factory;
+ }
+
+ public void setFactory(SchedulerFactory factory) {
+ this.factory = factory;
+ }
+
+ public Scheduler getScheduler() {
+ return scheduler;
+ }
+
+ public void setScheduler(Scheduler scheduler) {
+ this.scheduler = scheduler;
+ }
+
+ public Map getTriggers() {
+ return triggers;
+ }
+
+ public void setTriggers(Map triggers) {
+ this.triggers = triggers;
+ }
+
+ public QuartzMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(QuartzMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ super.init();
+ try {
+ if (scheduler == null) {
+ if (factory == null) {
+ factory = new StdSchedulerFactory();
+ }
+ scheduler = factory.getScheduler();
+ }
+ }
+ catch (SchedulerException e) {
+ throw new JBIException(e);
+ }
+
+ if (triggers != null) {
+ for (Iterator iter = triggers.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ Object key = entry.getKey();
+ Object value = entry.getValue();
+ if (key == null) {
+ throw new IllegalArgumentException("Key of the map cannot be null");
+ }
+ if (value == null) {
+ throw new IllegalArgumentException("Key of the map cannot be null");
+ }
+ if (!(key instanceof Trigger)) {
+ throw new IllegalArgumentException("Key of the map must be a Trigger but was: " + key.getClass().getName());
+ }
+ if (!(value instanceof JobDetail)) {
+ throw new IllegalArgumentException("Key of the map must be a JobDetail but was: " + value.getClass().getName());
+ }
+ addTrigger((Trigger) key, (JobDetail) value);
+ }
+ }
+ }
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ // As we send in-only MEPS, we will only
+ // receive DONE or ERROR status
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/QuartzMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/QuartzMarshaler.java
new file mode 100644
index 0000000..7c8dab3
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/QuartzMarshaler.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.quartz;
+
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.MessagingException;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public interface QuartzMarshaler {
+
+ /**
+ * Populates the given normalized message from the Quartz context
+ *
+ * @param message the normalized message to populate
+ * @param context the Quartz context
+ * @throws JobExecutionException
+ * @throws MessagingException
+ */
+ void populateNormalizedMessage(NormalizedMessage message, JobExecutionContext context) throws JobExecutionException, MessagingException;
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/ServiceMixJob.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/ServiceMixJob.java
new file mode 100644
index 0000000..199c222
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/ServiceMixJob.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.quartz;
+
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+/**
+ * A Quartz Job which dispatches a message to a component.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ServiceMixJob implements Job {
+ public void execute(JobExecutionContext context) throws JobExecutionException {
+ QuartzComponent component = (QuartzComponent) context.getJobDetail().getJobDataMap().get(QuartzComponent.COMPONENT_KEY);
+ if (component == null) {
+ throw new JobExecutionException("No quartz JBI component available for key: " + QuartzComponent.COMPONENT_KEY + ". Bad job data map");
+ }
+ component.onJobExecute(context);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/package.html
new file mode 100644
index 0000000..bf9de58
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/quartz/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A <a href="http://www.opensymphony.com/quartz/">Quartz</a> component for triggering components when timer events fire.
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ProxyInOnlyBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ProxyInOnlyBinding.java
new file mode 100644
index 0000000..128ea17
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ProxyInOnlyBinding.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.reflection;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.RuntimeJBIException;
+
+/**
+ * A Proxy factory which sends the method invocations into the JBI container
+ * for processing.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ProxyInOnlyBinding extends ComponentSupport implements InvocationHandler {
+
+ private static final Log log = LogFactory.getLog(ProxyInOnlyBinding.class);
+
+ private ClassLoader cl;
+ private Class[] interfaces;
+
+ public void setTarget(Object target) {
+ setTargetType( target.getClass().getClassLoader(), target.getClass().getInterfaces());
+ }
+
+ private void setTargetType(ClassLoader classLoader, Class[] interfaces) {
+ this.cl = classLoader;
+ this.interfaces = interfaces;
+ }
+
+ public Object createProxy() {
+ return Proxy.newProxyInstance(cl, interfaces, this);
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (log.isTraceEnabled()) {
+ log.trace("Invoked: " + method);
+ }
+ try {
+ InOnly messageExchange = getDeliveryChannel().createExchangeFactory().createInOnlyExchange();
+ NormalizedMessage inMessage = messageExchange.createMessage();
+ if( proxy != null )
+ inMessage.setProperty("proxy", proxy);
+ inMessage.setProperty("method", method);
+ if( args!= null )
+ inMessage.setProperty("args", args);
+
+ messageExchange.setInMessage(inMessage);
+ getDeliveryChannel().send(messageExchange);
+ return null;
+ }
+ catch (JBIException e) {
+ throw new RuntimeJBIException(e);
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ProxyInOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ProxyInOutBinding.java
new file mode 100644
index 0000000..cdf6379
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ProxyInOutBinding.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.reflection;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.RuntimeJBIException;
+
+/**
+ * A Proxy factory which sends the method invocations into the JBI container
+ * for processing.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ProxyInOutBinding extends ComponentSupport implements InvocationHandler {
+
+ private static final Log log = LogFactory.getLog(ProxyInOutBinding.class);
+
+ private ClassLoader cl;
+ private final Class[] interfaces;
+
+ public ProxyInOutBinding(Object target) {
+ this( target.getClass().getClassLoader(), target.getClass().getInterfaces());
+ }
+
+ public ProxyInOutBinding(ClassLoader cl, Class [] interfaces) {
+ this.cl = cl;
+ this.interfaces = interfaces;
+ }
+
+ public Object createProxy() {
+ return Proxy.newProxyInstance(cl, interfaces, this);
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (log.isTraceEnabled()) {
+ log.trace("Invoked: " + proxy);
+ }
+ try {
+ InOut messageExchange = getDeliveryChannel().createExchangeFactory().createInOutExchange();
+ NormalizedMessage inMessage = messageExchange.createMessage();
+ inMessage.setProperty("proxy", proxy);
+ inMessage.setProperty("method", method);
+ inMessage.setProperty("args", args);
+
+ messageExchange.setInMessage(inMessage);
+ if (getDeliveryChannel().sendSync(messageExchange)) {
+ NormalizedMessage outMessage = messageExchange.getOutMessage();
+ return getBody(outMessage);
+ } else if ( messageExchange.getStatus() == ExchangeStatus.ERROR ) {
+ throw messageExchange.getError();
+ }
+ return null;
+ }
+ catch (JBIException e) {
+ throw new RuntimeJBIException(e);
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ReflectionOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ReflectionOutBinding.java
new file mode 100644
index 0000000..010f84c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/ReflectionOutBinding.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.reflection;
+
+import java.lang.reflect.Method;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.components.util.OutBinding;
+
+/**
+ * Consumes normalized method invocation from the JBI container.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ReflectionOutBinding extends OutBinding {
+
+ private Object target;
+
+ public Object getTarget() {
+ return target;
+ }
+ public void setTarget(Object target) {
+ this.target = target;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange messageExchange, NormalizedMessage inMessage) throws Exception {
+
+ Method method = (Method) inMessage.getProperty("method");
+ Object []args = (Object[]) inMessage.getProperty("args");
+ method.invoke(target, args);
+ done(messageExchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/package.html
new file mode 100644
index 0000000..f13720f
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/reflection/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A JBI component which uses reflection to invoke methods on POJOs
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/Predicate.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/Predicate.java
new file mode 100644
index 0000000..c02eb81
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/Predicate.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.router;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.component.ComponentContext;
+
+/**
+ * A simple predicate which evaluates to true or false given the current
+ * context and message exchange.
+ *
+ * @version $Revision: 426415 $
+ */
+public interface Predicate {
+ boolean evaluate(ComponentContext context, MessageExchange exchange);
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/RoutingRule.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/RoutingRule.java
new file mode 100644
index 0000000..19d0328
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/RoutingRule.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.router;
+
+import org.apache.servicemix.jbi.resolver.EndpointFilter;
+import org.apache.servicemix.jbi.resolver.EndpointResolver;
+import org.apache.servicemix.jbi.resolver.NullEndpointFilter;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+
+/**
+ * A simple routing rule which if the predicate is matched then the message is forwarded to
+ * the given endpoint.
+ *
+ * @version $Revision: 426415 $
+ */
+public class RoutingRule {
+ private Predicate predicate;
+ private EndpointResolver resolver;
+ private EndpointFilter filter = NullEndpointFilter.getInstance();
+
+ public EndpointFilter getFilter() {
+ return filter;
+ }
+
+ public void setFilter(EndpointFilter filter) {
+ this.filter = filter;
+ }
+
+ public Predicate getPredicate() {
+ return predicate;
+ }
+
+ public void setPredicate(Predicate predicate) {
+ this.predicate = predicate;
+ }
+
+ public EndpointResolver getResolver() {
+ return resolver;
+ }
+
+ public void setResolver(EndpointResolver resolver) {
+ this.resolver = resolver;
+ }
+
+ public void onMessageExchange(ComponentContext context, MessageExchange exchange) throws JBIException {
+ if (predicate.evaluate(context, exchange)) {
+
+ // lets forward the message on to the endpoint
+ ServiceEndpoint endpoint = resolver.resolveEndpoint(context, exchange, filter);
+ exchange.setEndpoint(endpoint);
+ }
+ }
+
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/package.html
new file mode 100644
index 0000000..1296122
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/router/package.html
@@ -0,0 +1,28 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A simple router component which based on boolean predicates will route normalized messages
+to different endpoints.
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/rss/FeedWriter.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/rss/FeedWriter.java
new file mode 100644
index 0000000..3df023e
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/rss/FeedWriter.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.rss;
+
+import com.sun.syndication.feed.synd.SyndContent;
+import com.sun.syndication.feed.synd.SyndContentImpl;
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndEntryImpl;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.SyndFeedOutput;
+import com.sun.syndication.io.XmlReader;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.apache.servicemix.expression.Expression;
+import org.apache.servicemix.expression.ExpressionHelper;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * This component generates an RSS/Atom Feed from the JBI messages it receives.
+ *
+ * @version $Revision: 579627 $
+ */
+public class FeedWriter extends OutBinding {
+
+ private String feedType = "atom_0.3";
+ private SyndFeed cachedFeed;
+ private String title;
+ private String link = "http://servicemix.org/RSS";
+ private Expression entryTitle;
+ private Expression entryValue;
+ private String feedDescription = "This feed is auto-generated by ServiceMix";
+ private int maximumEntryCount = 200;
+ private File feedFile;
+ private String contentType = "text/plain";
+ private SourceTransformer sourceTransformer = new SourceTransformer();
+ private boolean loadOnStartup = true;
+
+ public synchronized SyndFeed getCachedFeed() throws IllegalArgumentException, FeedException, IOException {
+ if (cachedFeed == null) {
+ cachedFeed = loadOrCreateFeed();
+ }
+ return cachedFeed;
+ }
+
+ public void setCachedFeed(SyndFeed feed) {
+ this.cachedFeed = feed;
+ }
+
+ public String getFeedType() {
+ return feedType;
+ }
+
+ public void setFeedType(String feedType) {
+ this.feedType = feedType;
+ }
+
+ public String getFeedDescription() {
+ return feedDescription;
+ }
+
+ public void setFeedDescription(String feedDescription) {
+ this.feedDescription = feedDescription;
+ }
+
+ public String getTitle() {
+ if (title == null) {
+ title = "ServiceMix feed for service: " + getService();
+ }
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getLink() {
+ return link;
+ }
+
+ public void setLink(String link) {
+ this.link = link;
+ }
+
+ public Expression getEntryTitle() {
+ return entryTitle;
+ }
+
+ public void setEntryTitle(Expression title) {
+ this.entryTitle = title;
+ }
+
+ public Expression getEntryValue() {
+ return entryValue;
+ }
+
+ public void setEntryValue(Expression entryValue) {
+ this.entryValue = entryValue;
+ }
+
+ public int getMaximumEntryCount() {
+ return maximumEntryCount;
+ }
+
+ public void setMaximumEntryCount(int maximumEntryCount) {
+ this.maximumEntryCount = maximumEntryCount;
+ }
+
+ public File getFeedFile() {
+ if (feedFile == null) {
+ throw new IllegalArgumentException("You must set the 'feedFile' property");
+ }
+ return feedFile;
+ }
+
+ public void setFeedFile(File feedFile) {
+ this.feedFile = feedFile;
+ }
+
+ public String getContentType() {
+ return contentType;
+ }
+
+ public void setContentType(String contentType) {
+ this.contentType = contentType;
+ }
+
+ public SourceTransformer getSourceTransformer() {
+ return sourceTransformer;
+ }
+
+ public void setSourceTransformer(SourceTransformer sourceTransformer) {
+ this.sourceTransformer = sourceTransformer;
+ }
+
+ public boolean isLoadOnStartup() {
+ return loadOnStartup;
+ }
+
+ public void setLoadOnStartup(boolean loadOnStartup) {
+ this.loadOnStartup = loadOnStartup;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+
+ protected void init() throws JBIException {
+ super.init();
+
+ // enforce validation
+ File file = getFeedFile();
+ if (file.exists() && file.isDirectory()) {
+ throw new IllegalArgumentException("Cannot generate the cachedFeed as the cachedFeed file is a directory: " + file);
+ }
+ }
+
+ protected void process(MessageExchange exchange, NormalizedMessage message) throws Exception {
+ SyndFeed feed = getCachedFeed();
+ synchronized (feed) {
+ addMessageToFeed(feed, exchange, message);
+ removeExpiredEntries(feed);
+ writeFeed(feed, exchange, message);
+ }
+ done(exchange);
+ }
+
+ protected void addMessageToFeed(SyndFeed feed, MessageExchange exchange, NormalizedMessage message) throws TransformerException, MessagingException {
+ List entries = feed.getEntries();
+ SyndEntry entry = createEntry(exchange, message);
+ SyndContent description = createEntryContent(exchange, message);
+ entry.setDescription(description);
+
+ // TODO this line really should work but for some reason it doesn't
+ // entries.add(0, entry);
+
+ List temp = new ArrayList();
+ temp.add(entry);
+ temp.addAll(entries);
+ feed.setEntries(temp);
+ }
+
+ protected SyndEntry createEntry(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
+ SyndEntry entry = new SyndEntryImpl();
+
+ entry.setTitle(ExpressionHelper.asString(getEntryTitle(), exchange, message, "ServiceMix Feed"));
+ entry.setLink(getLink());
+ entry.setPublishedDate(new Date());
+ return entry;
+ }
+
+ protected SyndContent createEntryContent(MessageExchange exchange, NormalizedMessage message) throws TransformerException, MessagingException {
+ SyndContent description = new SyndContentImpl();
+ description.setType(contentType);
+ Source content = message.getContent();
+
+ String value = ExpressionHelper.asString(getEntryValue(), exchange, message, null);
+ if (value == null && content != null) {
+ value = getSourceTransformer().toString(content);
+ value = encodeContent(value);
+ }
+ if (value != null) {
+ description.setValue(value);
+ }
+ return description;
+ }
+
+ /**
+ * Encodes the content so its valid XML when used inside an entry
+ */
+ protected String encodeContent(String value) {
+ return "<![CDATA[" + value + "]]>";
+ }
+
+ protected void writeFeed(SyndFeed feed, MessageExchange messageExchange, NormalizedMessage message) throws IOException, FeedException {
+ Writer writer = new FileWriter(feedFile);
+ SyndFeedOutput output = new SyndFeedOutput();
+ output.output(feed, writer);
+ writer.close();
+ }
+
+ /**
+ * Removes any old entires no longer required in the cachedFeed
+ *
+ * @param feed
+ */
+ protected void removeExpiredEntries(SyndFeed feed) {
+ // lets limit the count
+ if (maximumEntryCount > 0) {
+ List entries = feed.getEntries();
+ int size = entries.size();
+ if (size > maximumEntryCount) {
+ entries.subList(maximumEntryCount, size).clear();
+ }
+ }
+ }
+
+ protected SyndFeed loadOrCreateFeed() throws IllegalArgumentException, FeedException, IOException {
+ if (isLoadOnStartup()) {
+ File file = getFeedFile();
+ if (file.exists() && file.isFile()) {
+ SyndFeedInput input = new SyndFeedInput();
+ XmlReader xmlReader = new XmlReader(file);
+ return input.build(xmlReader);
+ }
+ }
+ return createFeed();
+ }
+
+ protected SyndFeed createFeed() {
+ SyndFeed feed = new SyndFeedImpl();
+ feed.setFeedType(feedType);
+
+ feed.setTitle(getTitle());
+ feed.setLink(getLink());
+ feed.setDescription(getFeedDescription());
+ return feed;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/rss/RssPollingComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/rss/RssPollingComponent.java
new file mode 100644
index 0000000..2640829
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/rss/RssPollingComponent.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.rss;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.PollingComponentSupport;
+
+import com.sun.syndication.feed.synd.SyndEntry;
+import com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.feed.synd.SyndFeedImpl;
+import com.sun.syndication.io.SyndFeedInput;
+import com.sun.syndication.io.SyndFeedOutput;
+import com.sun.syndication.io.XmlReader;
+
+/**
+ * The RssPollingComponent polls for updates to RSS feeds
+ *
+ * @version $Revision: 426415 $
+ */
+public class RssPollingComponent extends PollingComponentSupport {
+ private static final Log log = LogFactory.getLog(RssPollingComponent.class);
+ private List urlStrings = new ArrayList();
+ private List urls = new ArrayList();
+ private Date lastPolledDate = new Date();
+ private String outputType = "rss_2.0";
+
+
+
+ /**
+ * @return Returns the urlStrings.
+ */
+ public List getUrlStrings() {
+ return urlStrings;
+ }
+
+ /**
+ * @param urlStrings The urlStrings to set.
+ */
+ public void setUrlStrings(List urlStrings) {
+ this.urlStrings = urlStrings;
+ }
+
+ /**
+ * @return Returns the outputType.
+ */
+ public String getOutputType() {
+ return outputType;
+ }
+
+ /**
+ * @param outputType The outputType to set.
+ */
+ public void setOutputType(String outputType) {
+ this.outputType = outputType;
+ }
+
+ /**
+ * @return Returns the lastPolledDate.
+ */
+ public Date getLastPolledDate() {
+ return lastPolledDate;
+ }
+
+ /**
+ * @param lastPolledDate The lastPolledDate to set.
+ */
+ public void setLastPolledDate(Date lastPolledDate) {
+ this.lastPolledDate = lastPolledDate;
+ }
+
+
+
+ protected void init() throws JBIException {
+ urls.clear();
+ if (urlStrings != null) {
+ for (int i = 0;i < urlStrings.size();i++) {
+ try {
+ urls.add(new URL(urlStrings.get(i).toString()));
+ }
+ catch (MalformedURLException e) {
+ log.warn("URL: " + urlStrings.get(i) + " is badly formed", e);
+ }
+ }
+ }
+ super.init();
+
+ }
+
+ /**
+ * Poll for updates
+ */
+ public void poll() {
+ List list = getLastesEntries();
+ if (list != null && !list.isEmpty()) {
+ SyndFeed feed = new SyndFeedImpl();
+ feed.setFeedType(outputType);
+ feed.setTitle("Aggregated Feed");
+ feed.setDescription("Anonymous Aggregated Feed");
+ feed.setAuthor("servicemix");
+ feed.setLink("http://www.servicemix.org");
+ feed.setEntries(list);
+ // send on to the nmr ...
+ SyndFeedOutput output = new SyndFeedOutput();
+ try {
+ Source source = new DOMSource(output.outputW3CDom(feed));
+ InOnly exchange = getExchangeFactory().createInOnlyExchange();
+ NormalizedMessage message = exchange.createMessage();
+ message.setContent(source);
+ exchange.setInMessage(message);
+ send(exchange);
+ }
+ catch (Exception e) {
+ log.error("Failed to send RSS message to the NMR");
+ }
+ finally {
+ lastPolledDate = new Date();
+ }
+ }
+ }
+
+ protected List getLastesEntries() {
+ List result = new ArrayList();
+ SyndFeedInput input = new SyndFeedInput();
+ for (int i = 0;i < urls.size();i++) {
+ URL inputUrl = (URL) urls.get(i);
+ SyndFeed inFeed;
+ try {
+ inFeed = input.build(new XmlReader(inputUrl));
+ List entries = inFeed.getEntries();
+ for (int k = 0;k < entries.size();k++) {
+ SyndEntry entry = (SyndEntry) entries.get(k);
+ if (entry.getPublishedDate().after(getLastPolledDate())) {
+ result.add(entry);
+ }
+ }
+ }
+ catch (Exception e) {
+ log.warn("Failed to process feed from: " + inputUrl, e);
+ }
+ }
+ return result;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajBinding.java
new file mode 100644
index 0000000..71671dc
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajBinding.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.saaj;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPConnection;
+import javax.xml.soap.SOAPConnectionFactory;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+
+/**
+ * Converts an inbound JBI message into a <a href="http://java.sun.com/xml/saaj/">SAAJ</a> (Soap With Attachments for Java)
+ * request-response and outputs the response back into JBI Bindings. This provides
+ * a message centric way of invoking SOAP services inside providers such as <a href="http://ws.apache.org/axis/">Apache Axis</a>
+ *
+ * @version $Revision: 429277 $
+ */
+public class SaajBinding extends TransformComponentSupport implements MessageExchangeListener {
+
+ private static final transient Log log = LogFactory.getLog(SaajBinding.class);
+
+ private SaajMarshaler marshaler = new SaajMarshaler();
+ private SOAPConnectionFactory connectionFactory;
+ private Object soapEndpoint;
+ private String soapAction;
+
+
+ public SOAPConnectionFactory getConnectionFactory() throws SOAPException {
+ if (connectionFactory == null) {
+ connectionFactory = createConnectionFactory();
+ }
+ return connectionFactory;
+ }
+
+ public void setConnectionFactory(SOAPConnectionFactory connectionFactory) {
+ this.connectionFactory = connectionFactory;
+ }
+
+ public Object getSoapEndpoint() {
+ return soapEndpoint;
+ }
+
+ public void setSoapEndpoint(Object soapEndpoint) {
+ this.soapEndpoint = soapEndpoint;
+ }
+
+ /**
+ * @deprecated use getMarshaler instead
+ */
+ public SaajMarshaler getMarshaller() {
+ return marshaler;
+ }
+
+ /**
+ * @deprecated use setMarshaler instead
+ */
+ public void setMarshaller(SaajMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return the marshaler
+ */
+ public SaajMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ /**
+ * @param marshaler the marshaler to set
+ */
+ public void setMarshaler(SaajMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
+ SOAPConnection connection = getConnectionFactory().createConnection();
+ try {
+ SOAPMessage inMessage = marshaler.createSOAPMessage(in);
+ MimeHeaders mh = inMessage.getMimeHeaders();
+ if (mh.getHeader("SOAPAction") == null) {
+ if (soapAction != null && soapAction.length() > 0) {
+ mh.addHeader("SOAPAction", soapAction);
+ } else {
+ mh.addHeader("SOAPAction", "\"\"");
+ }
+ inMessage.saveChanges();
+ }
+
+ if (log.isDebugEnabled()) {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ inMessage.writeTo(buffer);
+ log.debug(new String(buffer.toByteArray()));
+ }
+
+ SOAPMessage response = connection.call(inMessage, soapEndpoint);
+ if (response != null) {
+ marshaler.toNMS(out, response);
+ return true;
+ } else {
+ return false;
+ }
+ }
+ finally {
+ try {
+ connection.close();
+ }
+ catch (SOAPException e) {
+ log.warn("Failed to close connection: " + e, e);
+ }
+ }
+ }
+
+ protected SOAPConnectionFactory createConnectionFactory() throws SOAPException {
+ return SOAPConnectionFactory.newInstance();
+ }
+
+
+ protected SOAPConnection createConnection() throws SOAPException {
+ return getConnectionFactory().createConnection();
+ }
+
+ /**
+ * @return Returns the soapAction.
+ */
+ public String getSoapAction() {
+ return soapAction;
+ }
+
+ /**
+ * @param soapAction
+ * The soapAction to set.
+ */
+ public void setSoapAction(String soapAction) {
+ this.soapAction = soapAction;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java
new file mode 100644
index 0000000..1f9c604
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/SaajMarshaler.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.saaj;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Iterator;
+
+import javax.activation.DataHandler;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeader;
+import javax.xml.soap.SOAPBody;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPEnvelope;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.xml.sax.SAXException;
+
+/**
+ * @version $Revision: 431309 $
+ */
+public class SaajMarshaler {
+
+ private static final transient Log log = LogFactory.getLog(SaajMarshaler.class);
+
+ protected SourceTransformer transformer = new SourceTransformer();
+ private MessageFactory messageFactory;
+
+ public void toNMS(NormalizedMessage normalizedMessage, SOAPMessage soapMessage) throws MessagingException, SOAPException {
+
+ if (log.isDebugEnabled()) {
+ try {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ soapMessage.writeTo(buffer);
+ log.debug(new String(buffer.toByteArray()));
+ } catch (Exception e) { }
+ }
+
+ addNmsProperties(normalizedMessage, soapMessage);
+
+ SOAPPart soapPart = soapMessage.getSOAPPart();
+ SOAPBody soapBody = soapPart.getEnvelope().getBody();
+ SOAPElement elem = null;
+ for (Iterator it = soapBody.getChildElements(); it.hasNext();) {
+ Object child = it.next();
+ if (child instanceof SOAPElement) {
+ elem = (SOAPElement) child;
+ break;
+ }
+ }
+ if (elem == null) {
+ throw new IllegalStateException("Could not find any element in soap body");
+ }
+
+ for (SOAPElement parent = elem.getParentElement(); parent != null; parent = parent.getParentElement()) {
+ // The following code works with sun saaj implementation
+ NamedNodeMap attributes = parent.getAttributes();
+ if (attributes != null) {
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Attr att = (Attr) parent.getAttributes().item(i);
+ if (att.getName().startsWith(XMLConstants.XMLNS_ATTRIBUTE + ":")
+ && elem.getAttributeNodeNS(att.getNamespaceURI(), att.getLocalName()) == null) {
+ elem.addNamespaceDeclaration(att.getName().substring(XMLConstants.XMLNS_ATTRIBUTE.length() + 1), att.getValue());
+ elem.setAttributeNS(att.getNamespaceURI(), att.getName(), att.getValue());
+ }
+ }
+ }
+ // The following code works with axis saaj implementation
+ for (Iterator itNs = parent.getNamespacePrefixes(); itNs.hasNext();) {
+ String prefix = (String) itNs.next();
+ String nsuri = parent.getNamespaceURI(prefix);
+ if (elem.getAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix) == null) {
+ elem.addNamespaceDeclaration(prefix, nsuri);
+ elem.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE + ":" + prefix, nsuri);
+ }
+ }
+ }
+
+ if (log.isDebugEnabled()) {
+ try {
+ log.debug(transformer.toString(elem));
+ } catch (Exception e) { }
+ }
+
+ normalizedMessage.setContent(new DOMSource(elem));
+
+ addNmsAttachments(normalizedMessage, soapMessage);
+ }
+
+ public SOAPMessage createSOAPMessage(NormalizedMessage normalizedMessage) throws SOAPException, IOException, TransformerException, MessagingException, ParserConfigurationException, SAXException {
+ SOAPMessage soapMessage = getMessageFactory().createMessage();
+
+ addSoapProperties(soapMessage, normalizedMessage);
+
+ SOAPPart soapPart = soapMessage.getSOAPPart();
+ SOAPEnvelope envelope = soapPart.getEnvelope();
+ SOAPBody body = envelope.getBody();
+
+ // lets turn the payload into a DOM Node to avoid blatting over the envelope
+ // Do not use DOMResult to transform as namespaces are lost (why ?)
+ //DOMResult result = new DOMResult(null);
+ //transformer.toResult(normalizedMessage.getContent(), result);
+ //Document document = (Document) result.getNode();
+ Document document = transformer.toDOMDocument(normalizedMessage);
+ body.addDocument(document);
+
+ addSoapAttachments(soapMessage, normalizedMessage);
+
+ return soapMessage;
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public MessageFactory getMessageFactory() throws SOAPException {
+ if (messageFactory == null) {
+ messageFactory = createMessageFactory();
+ }
+ return messageFactory;
+ }
+
+ public void setMessageFactory(MessageFactory messageFactory) {
+ this.messageFactory = messageFactory;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+
+ protected void addNmsProperties(NormalizedMessage normalizedMessage, SOAPMessage soapMessage) {
+ Iterator iter = soapMessage.getMimeHeaders().getAllHeaders();
+ while (iter.hasNext()) {
+ MimeHeader header = (MimeHeader) iter.next();
+ normalizedMessage.setProperty(header.getName(), header.getValue());
+ }
+ }
+
+ protected void addNmsAttachments(NormalizedMessage normalizedMessage, SOAPMessage soapMessage) throws MessagingException, SOAPException {
+ Iterator iter = soapMessage.getAttachments();
+ while (iter.hasNext()) {
+ AttachmentPart attachment = (AttachmentPart) iter.next();
+ normalizedMessage.addAttachment(attachment.getContentId(), asDataHandler(attachment));
+ }
+ }
+
+ protected void addSoapProperties(SOAPMessage soapMessage, NormalizedMessage normalizedMessage) throws SOAPException {
+ for (Iterator iter = normalizedMessage.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = normalizedMessage.getProperty(name);
+ if (shouldIncludeHeader(normalizedMessage, name, value)) {
+ soapMessage.getMimeHeaders().addHeader(name, value.toString());
+ }
+ if (shouldIncludeProperty(normalizedMessage, name, value)) {
+ soapMessage.setProperty(name, value);
+ }
+ }
+ }
+
+ protected void addSoapAttachments(SOAPMessage soapMessage, NormalizedMessage normalizedMessage) throws IOException {
+ Iterator iterator = normalizedMessage.getAttachmentNames().iterator();
+ while (iterator.hasNext()) {
+ String name = (String) iterator.next();
+ DataHandler attachment = normalizedMessage.getAttachment(name);
+ AttachmentPart attachmentPart = soapMessage.createAttachmentPart(attachment.getContent(), attachment.getContentType());
+ attachmentPart.setContentId(name);
+ soapMessage.addAttachmentPart(attachmentPart);
+ }
+ }
+
+ /**
+ * Decides whether or not the given header should be included in the SAAJ message as a MimeHeader
+ */
+ protected boolean shouldIncludeHeader(NormalizedMessage normalizedMessage, String name, Object value) {
+ // TODO: remove http headers that may come from a consumer http BC
+ return true;
+ }
+
+ /**
+ * Decides whether or not the given property should be included in the SAAJ message as a property
+ */
+ protected boolean shouldIncludeProperty(NormalizedMessage normalizedMessage, String name, Object value) {
+ return true;
+ }
+
+ protected DataHandler asDataHandler(AttachmentPart attachment) throws SOAPException {
+ return new DataHandler(attachment.getContent(), attachment.getContentType());
+ }
+
+
+ protected MessageFactory createMessageFactory() throws SOAPException {
+ return MessageFactory.newInstance();
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/package.html
new file mode 100644
index 0000000..86a4da0
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/saaj/package.html
@@ -0,0 +1,28 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for <a href="http://java.sun.com/xml/saaj/">SAAJ</a> (Soap With Attachments for Java - which used to be called JAXM). This provides
+a message centric way of invoking SOAP services inside providers such as <a href="http://ws.apache.org/axis/">Apache Axis</a>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/ScriptComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/ScriptComponent.java
new file mode 100644
index 0000000..711436a
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/ScriptComponent.java
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.script;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.script.Bindings;
+import javax.script.Compilable;
+import javax.script.CompiledScript;
+import javax.script.ScriptEngine;
+import javax.script.ScriptEngineManager;
+import javax.script.ScriptException;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
+import org.springframework.core.io.Resource;
+
+/**
+ * A component which is capable of invoking a compiledScript using
+ * <a href="http://servicemix.org/JSR+223">JSR 223</a> to allow any scripting language to be integrated.
+ *
+ * @version $Revision: 556864 $
+ */
+public class ScriptComponent extends TransformComponentSupport {
+
+ public static final QName SERVICE = new QName("http://servicemix.org/example/", "receiver");
+ public static final String ENDPOINT = "receiver";
+
+ private ScriptEngine engine;
+ private String scriptEngineName;
+ private CompiledScript compiledScript;
+ private String scriptText;
+ private Resource script;
+ private String logResourceBundle;
+
+ private boolean disableOutput;
+ private Logger scriptLogger;
+ private Map bindings = new HashMap();
+
+ public ScriptComponent() {
+ super(SERVICE, ENDPOINT);
+ }
+
+ public ScriptComponent(QName service, String endpoint) {
+ super(service, endpoint);
+ }
+
+ public void start() throws JBIException {
+
+ if (engine == null) {
+ if (compiledScript != null) {
+ engine = compiledScript.getEngine();
+ }
+ else {
+ if (scriptEngineName != null) {
+ engine = createScriptEngine();
+ }
+ if (engine == null) {
+ throw new JBIException("Must be configured with either the 'compiledScript' or 'engine' property");
+ }
+ }
+ }
+ if (compiledScript == null) {
+ checkScriptTextAvailable();
+ }
+ if (compiledScript == null) {
+ if (engine instanceof Compilable) {
+ Compilable compilable = (Compilable) engine;
+ compileScript(compilable);
+ }
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public ScriptEngine getEngine() {
+ return engine;
+ }
+
+ public void setEngine(ScriptEngine engine) {
+ this.engine = engine;
+ }
+
+ public CompiledScript getCompiledScript() {
+ return compiledScript;
+ }
+
+ public void setCompiledScript(CompiledScript compiledScript) {
+ this.compiledScript = compiledScript;
+ }
+
+ public String getScriptText() {
+ return scriptText;
+ }
+
+ /**
+ * Sets the script as a String
+ *
+ * @param scriptText
+ */
+ public void setScriptText(String scriptText) {
+ this.scriptText = scriptText;
+ }
+
+ /**
+ * Returns the script as a spring resource
+ *
+ * @return
+ */
+ public Resource getScript() {
+ return script;
+ }
+
+ /**
+ * Sets the script as a Spring resource
+ *
+ * @param script
+ */
+ public void setScript(Resource script) {
+ this.script = script;
+ }
+
+ public String getScriptEngineName() {
+ return scriptEngineName;
+ }
+
+ public void setScriptEngineName(String scriptEngineName) {
+ this.scriptEngineName = scriptEngineName;
+ }
+
+ public boolean isDisableOutput() {
+ return disableOutput;
+ }
+
+ public void setDisableOutput(boolean disableOutput) {
+ this.disableOutput = disableOutput;
+ }
+
+ public String getLogResourceBundle() {
+ return logResourceBundle;
+ }
+
+ public Map getBindings() {
+ return bindings;
+ }
+
+ /**
+ * Sets the component level bindings available to scripts as a variable called 'bindings'
+ *
+ * @param bindings
+ */
+ public void setBindings(Map bindings) {
+ this.bindings = bindings;
+ }
+
+ /**
+ * Sets the resource bundle to use when creating a logger, if one is not
+ * explicitly configured.
+ *
+ * @param logResourceBundle
+ */
+ public void setLogResourceBundle(String logResourceBundle) {
+ this.logResourceBundle = logResourceBundle;
+ }
+
+ public Logger getScriptLogger() throws MessagingException {
+ if (scriptLogger == null) {
+ scriptLogger = createScriptLogger();
+ }
+ return scriptLogger;
+ }
+
+ /**
+ * Sets the logger to use if the script decides to log
+ *
+ * @param scriptLogger
+ */
+ public void setScriptLogger(Logger scriptLogger) {
+ this.scriptLogger = scriptLogger;
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception {
+ Bindings bindings = engine.createBindings();
+
+ populateBindings(bindings, exchange, in, out);
+ try {
+ runScript(bindings);
+ return !isDisableOutput();
+ }
+ catch (ScriptException e) {
+ throw new MessagingException("Failed to run compiledScript. Reason: " + e, e);
+ }
+ }
+
+ protected void populateBindings(Bindings bindings, MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ bindings.put("componentContext", getContext());
+ bindings.put("deliveryChannel", getDeliveryChannel());
+ bindings.put("exchange", exchange);
+ bindings.put("inMessage", in);
+ bindings.put("log", getScriptLogger());
+ bindings.put("componentNamespace", bindings);
+ bindings.put("bindings", this.bindings);
+
+ InOnly outExchange = null;
+ if (isInAndOut(exchange)) {
+ bindings.put("outMessage", out);
+ }
+ else if (!isDisableOutput()) {
+ outExchange = getExchangeFactory().createInOnlyExchange();
+ if (out instanceof NormalizedMessageImpl) {
+ bindings.put("outExchange", ((NormalizedMessageImpl) out).getExchange());
+ }
+ bindings.put("outMessage", out);
+ }
+ }
+
+ protected Logger createScriptLogger() throws MessagingException {
+ if (logResourceBundle != null) {
+ try {
+ return getContext().getLogger(getClass().getName(), logResourceBundle);
+ }
+ catch (JBIException e) {
+ throw new MessagingException(e);
+ }
+ }
+ else {
+ return Logger.getLogger(getClass().getName());
+ }
+ }
+
+ protected void runScript(Bindings bindings) throws ScriptException {
+ if (compiledScript != null) {
+ compiledScript.eval(bindings);
+ }
+ else {
+ evaluteScript(bindings);
+ }
+ }
+
+ protected void evaluteScript(Bindings bindings) throws ScriptException {
+ engine.eval(scriptText, bindings);
+ }
+
+ protected void compileScript(Compilable compilable) throws JBIException {
+ try {
+ if (scriptText != null) {
+ compiledScript = compilable.compile(scriptText);
+ }
+ else if (script != null) {
+ compiledScript = compilable.compile(new InputStreamReader(script.getInputStream()));
+
+ }
+ }
+ catch (ScriptException e) {
+ throw new JBIException("Failed to parse compiledScript. Reason: " + e, e);
+ }
+ catch (IOException e) {
+ throw new JBIException("Failed to parse compiledScript. Reason: " + e, e);
+ }
+ }
+
+ protected ScriptEngine createScriptEngine() {
+ ScriptEngineManager manager = new ScriptEngineManager();
+ return manager.getEngineByName(scriptEngineName);
+ }
+
+ protected void checkScriptTextAvailable() throws JBIException {
+ if (scriptText == null && script == null) {
+ throw new JBIException("If no 'compiledScript' is specified you must specify the 'scriptText' or 'script'");
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/ScriptExpression.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/ScriptExpression.java
new file mode 100644
index 0000000..a157549
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/ScriptExpression.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.script;
+
+import org.apache.servicemix.expression.Expression;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.MessagingException;
+import javax.script.CompiledScript;
+import javax.script.ScriptContext;
+import javax.script.ScriptException;
+
+/**
+ * An {@link Expression} implementation using
+ * <a href="http://servicemix.org/JSR+223">JSR 223</a> to allow any scripting language to be used as an expression
+ * language.
+ *
+ * @version $Revision: 426415 $
+ */
+public class ScriptExpression implements Expression {
+ private CompiledScript compiledScript;
+
+ public Object evaluate(MessageExchange exchange, NormalizedMessage message) throws MessagingException {
+ try {
+ /** TODO */
+ ScriptContext namespace = null;
+ return compiledScript.eval(namespace);
+ }
+ catch (ScriptException e) {
+ throw new MessagingException(e);
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/package.html
new file mode 100644
index 0000000..affeaa7
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/script/package.html
@@ -0,0 +1,30 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+<p>
+A component which uses <a href="http://servicemix.org/JSR+223">JSR 223</a>
+to allow any scripting language to be integrated.
+</p>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/splitter/SplitterComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/splitter/SplitterComponent.java
new file mode 100644
index 0000000..736105d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/splitter/SplitterComponent.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.splitter;
+
+import java.io.IOException;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.servicemix.jbi.MissingPropertyException;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+/**
+ * This Component splits a message according to a XPath expression.
+ *
+ * @author george
+ * @deprecated use the XPathSplitter pattern from the EIP component instead
+ */
+public class SplitterComponent extends TransformComponentSupport {
+
+ /** Holds value of property nodePath. */
+ private String nodePath;
+
+ private XPathExpression expression;
+
+ private SourceTransformer st = new SourceTransformer();
+
+ protected void init() throws JBIException {
+ super.init();
+
+ if (nodePath == null) {
+ throw new MissingPropertyException("nodePath");
+ }
+ }
+
+ protected boolean transform(MessageExchange me, NormalizedMessage in,
+ NormalizedMessage out) throws MessagingException {
+ NodeList nodes;
+ try {
+ Node doc = st.toDOMNode(in);
+ if (expression == null) {
+ XPath xpath = XPathFactory.newInstance().newXPath();
+ expression = xpath.compile(nodePath);
+ }
+ nodes = (NodeList) expression.evaluate(doc, XPathConstants.NODESET);
+ } catch (TransformerException e) {
+ throw new MessagingException(e);
+ } catch (IOException e) {
+ throw new MessagingException(e);
+ } catch (SAXException e) {
+ throw new MessagingException(e);
+ } catch (ParserConfigurationException e) {
+ throw new MessagingException(e);
+ } catch (XPathExpressionException e) {
+ // If XPath Expression is mal formed
+ throw new MessagingException(e);
+ }
+ int total = nodes.getLength();
+ for (int i = 0; i < total; i++) {
+ out.setContent(new DOMSource(nodes.item(i)));
+ InOnly outExchange = getExchangeFactory().createInOnlyExchange();
+ outExchange.setInMessage(out);
+ getDeliveryChannel().sendSync(outExchange);
+ outExchange.setStatus(ExchangeStatus.DONE);
+ }
+ return false;
+ }
+
+ /**
+ * Getter for property nodePath.
+ *
+ * @return Value of property nodePath.
+ */
+ public String getNodePath() {
+ return nodePath;
+ }
+
+ /**
+ * @org.xbean.Property alias="select"
+ *
+ * Setter for property nodePath.
+ * @param nodePath
+ * New value of property nodePath.
+ */
+ public void setNodePath(String nodePath) {
+ this.nodePath = nodePath;
+ this.expression = null;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandler.java
new file mode 100644
index 0000000..b82bb93
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandler.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+import javax.jbi.messaging.MessagingException;
+
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.SAXException;
+
+/**
+ * A simple implementation of {@link ErrorHandler} which just counts the number of warnings, errors and fatal errors.
+ *
+ * @version $Revision: 430194 $
+ */
+public class CountingErrorHandler implements MessageAwareErrorHandler {
+ private int warningCount;
+ private int errorCount;
+ private int fatalErrorCount;
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#hasErrors()
+ */
+ public boolean hasErrors() {
+ return getErrorCount() > 0 || getFatalErrorCount() > 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getWarningCount()
+ */
+ public int getWarningCount() {
+ return warningCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getErrorCount()
+ */
+ public int getErrorCount() {
+ return errorCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getFatalErrorCount()
+ */
+ public int getFatalErrorCount() {
+ return fatalErrorCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+ */
+ public void warning(SAXParseException e) throws SAXException {
+ ++warningCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+ */
+ public void error(SAXParseException e) throws SAXException {
+ ++errorCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+ */
+ public void fatalError(SAXParseException e) throws SAXException {
+ ++fatalErrorCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#capturesMessages()
+ */
+ public boolean capturesMessages() {
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getMessagesAs(java.lang.Class)
+ */
+ public Object getMessagesAs(Class format) throws MessagingException {
+ throw new MessagingException("Unsupported message format: " + format.getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#supportsMessageFormat(java.lang.Class)
+ */
+ public boolean supportsMessageFormat(Class format) {
+ return false;
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
new file mode 100644
index 0000000..da3b06c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/CountingErrorHandlerFactory.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+/**
+ * @author gmcdonald
+ *
+ */
+public class CountingErrorHandlerFactory implements
+ MessageAwareErrorHandlerFactory {
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandlerFactory#createMessageAwareErrorHandler()
+ */
+ public MessageAwareErrorHandler createMessageAwareErrorHandler() {
+ return new CountingErrorHandler();
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java
new file mode 100644
index 0000000..8741953
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandler.java
@@ -0,0 +1,314 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.jbi.messaging.MessagingException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.SAXException;
+
+/**
+ * An implementation of {@link ErrorHandler} which aggregates all warnings and
+ * error messages into a StringBuffer.
+ *
+ * @version $Revision: 359186 $
+ */
+public class MessageAggregatingErrorHandler implements MessageAwareErrorHandler {
+
+ private static final String openCDATA = "<![CDATA[";
+ private static final String closeCDATA = "]]>";
+ private static final String openError = "<error>";
+ private static final String closeError = "</error>";
+ private static final String openFatalError = "<fatalError>";
+ private static final String closeFatalError = "</fataError>";
+ private static final String openWarning = "<warning>";
+ private static final String closeWarning = "</warning>";
+
+ private String openRootElement;
+ private String closeRootElement;
+
+ /**
+ * Number of warnings.
+ */
+ private int warningCount;
+
+ /**
+ * Number of errors.
+ */
+ private int errorCount;
+
+ /**
+ * Number of fatal errors.
+ */
+ private int fatalErrorCount;
+
+ /**
+ * The root element name for the fault xml message
+ */
+ private String rootPath;
+
+ /**
+ * The namespace for the fault xml message
+ */
+ private String namespace;
+
+ /**
+ * Determines whether or not to include stacktraces in the fault xml message
+ */
+ private boolean includeStackTraces;
+
+ /**
+ * Variable to hold the warning/error messages from the validator
+ */
+ private StringBuffer messages = new StringBuffer();
+
+ private SourceTransformer sourceTransformer = new SourceTransformer();
+
+ /**
+ * Constructor.
+ *
+ * @param rootElement
+ * The root element name of the fault xml message
+ * @param namespace
+ * The namespace for the fault xml message
+ * @param includeStackTraces
+ * Include stracktraces in the final output
+ */
+ public MessageAggregatingErrorHandler(String rootPath, String namespace, boolean includeStackTraces) throws IllegalArgumentException {
+ if (rootPath == null || rootPath.trim().length() == 0) {
+ throw new IllegalArgumentException("rootPath must not be null or an empty string");
+ }
+ this.rootPath = rootPath;
+ this.namespace = namespace;
+ this.includeStackTraces = includeStackTraces;
+ createRootElementTags();
+ }
+
+ /**
+ * Creates the root element tags for later use down to n depth.
+ * Note: the rootPath here is of the form:
+ *
+ * <code>rootElementName/elementName-1/../elementName-n</code>
+ *
+ * The namespace will be appended to the root element if it is not
+ * null or empty.
+ */
+ private void createRootElementTags() {
+ /*
+ * since the rootPath is constrained to be not null or empty
+ * then we have at least one path element.
+ */
+ String[] pathElements = rootPath.split("/");
+
+ StringBuffer openRootElementSB = new StringBuffer().append("<").append(pathElements[0]);
+ StringBuffer closeRootElementSB = new StringBuffer();
+
+ if (namespace != null && namespace.trim().length() > 0) {
+ openRootElementSB.append(" xmlns=\"").append(namespace).append("\">");
+ } else {
+ openRootElementSB.append(">");
+ }
+
+ if (pathElements.length > 0) {
+ for (int i = 1, j = pathElements.length - 1; i < pathElements.length; i++, j--) {
+ openRootElementSB.append("<").append(pathElements[i]).append(">");
+ closeRootElementSB.append("</").append(pathElements[j]).append(">");
+ }
+ }
+
+ // create the closing root element tag
+ closeRootElementSB.append("</").append(pathElements[0]).append(">");
+
+ openRootElement = openRootElementSB.toString();
+ closeRootElement = closeRootElementSB.toString();
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#hasErrors()
+ */
+ public boolean hasErrors() {
+ return getErrorCount() > 0 || getFatalErrorCount() > 0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getWarningCount()
+ */
+ public int getWarningCount() {
+ return warningCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getErrorCount()
+ */
+ public int getErrorCount() {
+ return errorCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getFatalErrorCount()
+ */
+ public int getFatalErrorCount() {
+ return fatalErrorCount;
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#warning(org.xml.sax.SAXParseException)
+ */
+ public void warning(SAXParseException e) throws SAXException {
+ ++warningCount;
+
+ // open warning and CDATA tags
+ messages.append(openWarning).append(openCDATA);
+
+ // append the fatal error message
+ appendErrorMessage(e);
+
+ // close CDATA and warning tags
+ messages.append(closeCDATA).append(closeWarning);
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#error(org.xml.sax.SAXParseException)
+ */
+ public void error(SAXParseException e) throws SAXException {
+ ++errorCount;
+
+ // open fatal error and CDATA tags
+ messages.append(openError).append(openCDATA);
+
+ // append the error message
+ appendErrorMessage(e);
+
+ // close CDATA and error tags
+ messages.append(closeCDATA).append(closeError);
+ }
+
+ /* (non-Javadoc)
+ * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
+ */
+ public void fatalError(SAXParseException e) throws SAXException {
+ ++fatalErrorCount;
+
+ // open fatal error and CDATA tags
+ messages.append(openFatalError).append(openCDATA);
+
+ // append the fatal error message
+ appendErrorMessage(e);
+
+ // close CDATA and fatal error tags
+ messages.append(closeCDATA).append(closeFatalError);
+ }
+
+ /**
+ * Append the error message or stacktrace to the messages attribute.
+ *
+ * @param e
+ */
+ private void appendErrorMessage(SAXParseException e) {
+ if (includeStackTraces) {
+ StringWriter sw = new StringWriter();
+ e.printStackTrace(new PrintWriter(sw));
+ messages.append(sw.toString());
+ } else {
+ messages.append(e.getLocalizedMessage());
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#capturesMessages()
+ */
+ public boolean capturesMessages() {
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#getMessagesAs(java.lang.Class)
+ */
+ public Object getMessagesAs(Class format) throws MessagingException {
+ if (format == DOMSource.class) {
+ return getDOMSource();
+ } else if (format == StringSource.class) {
+ return getStringSource();
+ } else if (format == String.class) {
+ return getMessagesWithRootElement();
+ }
+ throw new MessagingException("Unsupported message format: " + format.getName());
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandler#supportsMessageFormat(java.lang.Class)
+ */
+ public boolean supportsMessageFormat(Class format) {
+ if (format == DOMSource.class) {
+ return true;
+ } else if (format == StringSource.class) {
+ return true;
+ } else if (format == String.class) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return the messages encapsulated with the root element.
+ *
+ * @return
+ */
+ private String getMessagesWithRootElement() {
+ return new StringBuffer().append(openRootElement).append(messages).append(closeRootElement).toString();
+ }
+
+ /**
+ * Get the error messages as a String Source.
+ *
+ * @return
+ */
+ private StringSource getStringSource() {
+ return new StringSource(getMessagesWithRootElement());
+ }
+
+ /**
+ * Get the error messages as a DOMSource.
+ *
+ * @return
+ * @throws MessagingException
+ */
+ private DOMSource getDOMSource() throws MessagingException {
+ try {
+ return sourceTransformer.toDOMSource(getStringSource());
+ } catch (ParserConfigurationException e) {
+ throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e);
+ } catch (IOException e) {
+ throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e);
+ } catch (SAXException e) {
+ throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e);
+ } catch (TransformerException e) {
+ throw new MessagingException("Failed to create DOMSource for Schema validation messages: " + e, e);
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
new file mode 100644
index 0000000..b7524db
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAggregatingErrorHandlerFactory.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+/**
+ * @author gmcdonald
+ *
+ */
+public class MessageAggregatingErrorHandlerFactory implements
+ MessageAwareErrorHandlerFactory {
+
+ /**
+ * The root element name for the fault xml message
+ */
+ private String rootPath;
+
+ /**
+ * The namespace for the fault xml message
+ */
+ private String namespace;
+
+ /**
+ * Determines whether or not to include stacktraces in the fault xml message
+ */
+ private boolean includeStackTraces;
+
+ /**
+ * @return Returns the includeStackTraces.
+ */
+ public boolean isIncludeStackTraces() {
+ return includeStackTraces;
+ }
+
+ /**
+ * @param includeStackTraces The includeStackTraces to set.
+ */
+ public void setIncludeStackTraces(boolean includeStackTraces) {
+ this.includeStackTraces = includeStackTraces;
+ }
+
+ /**
+ * @return Returns the namespace.
+ */
+ public String getNamespace() {
+ return namespace;
+ }
+
+ /**
+ * @param namespace The namespace to set.
+ */
+ public void setNamespace(String namespace) {
+ this.namespace = namespace;
+ }
+
+ /**
+ * @return Returns the rootPath.
+ */
+ public String getRootPath() {
+ return rootPath;
+ }
+
+ /**
+ * @param rootPath The rootPath to set.
+ */
+ public void setRootPath(String rootPath) {
+ this.rootPath = rootPath;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.servicemix.components.validation.MessageAwareErrorHandlerFactory#createMessageAwareErrorHandler()
+ */
+ public MessageAwareErrorHandler createMessageAwareErrorHandler() {
+ return new MessageAggregatingErrorHandler(rootPath, namespace, includeStackTraces);
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandler.java
new file mode 100644
index 0000000..a8a7d5d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandler.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+import javax.jbi.messaging.MessagingException;
+
+import org.xml.sax.ErrorHandler;
+
+public interface MessageAwareErrorHandler extends ErrorHandler {
+
+ /**
+ * Does the error handler contain any error messages?
+ *
+ * @return
+ */
+ public boolean hasErrors();
+
+ /**
+ * Return the number of warnings.
+ *
+ * @return
+ */
+ public int getWarningCount();
+
+ /**
+ * Return the number of errors.
+ *
+ * @return
+ */
+ public int getErrorCount();
+
+ /**
+ * Return the number of fatal errors.
+ *
+ * @return
+ */
+ public int getFatalErrorCount();
+
+ /**
+ * Does this ErrorHandler implementation capture error messages?
+ *
+ * @return
+ */
+ public boolean capturesMessages();
+
+ /**
+ * Get the messages from this ErrorHandler in a particular format.
+ *
+ * @return
+ */
+ public Object getMessagesAs(Class format) throws MessagingException;
+
+ /**
+ * Does the message support a given format?
+ *
+ * @param clazz
+ * The Class of the format for which support is required.
+ * @return
+ */
+ public boolean supportsMessageFormat(Class format);
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
new file mode 100644
index 0000000..ef70bf1
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/MessageAwareErrorHandlerFactory.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+/**
+ * Simple factory interface to a MessageAwareErrorHandler implementation
+ *
+ * @author gmcdonald
+ *
+ */
+public interface MessageAwareErrorHandlerFactory {
+
+ /**
+ * Create and return a concrete MessageAwareErrorHandler implementation
+ *
+ * @return
+ */
+ public MessageAwareErrorHandler createMessageAwareErrorHandler();
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java
new file mode 100644
index 0000000..58a7117
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/ValidateComponent.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.servicemix.jbi.FaultException;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.MessageUtil;
+import org.springframework.core.io.Resource;
+import org.xml.sax.SAXException;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Validator;
+import java.io.IOException;
+
+/**
+ * This component performs a schema validation on the incoming document
+ * and returning a fault if the document does not conform to the schema
+ * otherwise the message is passed on its way.
+ *
+ * @version $Revision: 631926 $
+ */
+public class ValidateComponent extends TransformComponentSupport {
+ private Schema schema;
+ private String schemaLanguage = "http://www.w3.org/2001/XMLSchema";
+ private Source schemaSource;
+ private Resource schemaResource;
+ private MessageAwareErrorHandlerFactory errorHandlerFactory = new CountingErrorHandlerFactory();
+
+ public static final String FAULT_FLOW = "FAULT_FLOW";
+ public static final String FAULT_JBI = "FAULT_JBI";
+
+ private String handlingErrorMethod = "FAULT_JBI";
+
+ public Schema getSchema() {
+ return schema;
+ }
+
+ public void setSchema(Schema schema) {
+ this.schema = schema;
+ }
+
+ public String getSchemaLanguage() {
+ return schemaLanguage;
+ }
+
+ public void setSchemaLanguage(String schemaLanguage) {
+ this.schemaLanguage = schemaLanguage;
+ }
+
+ public Source getSchemaSource() {
+ return schemaSource;
+ }
+
+ public void setSchemaSource(Source schemaSource) {
+ this.schemaSource = schemaSource;
+ }
+
+ public Resource getSchemaResource() {
+ return schemaResource;
+ }
+
+ public void setSchemaResource(Resource schemaResource) {
+ this.schemaResource = schemaResource;
+ }
+
+ public MessageAwareErrorHandlerFactory getErrorHandlerFactory() {
+ return errorHandlerFactory;
+ }
+
+ public void setErrorHandlerFactory(MessageAwareErrorHandlerFactory errorHandlerFactory) {
+ this.errorHandlerFactory = errorHandlerFactory;
+ }
+
+ protected void init() throws JBIException {
+ super.init();
+
+ try {
+ if (schema == null) {
+ SchemaFactory factory = SchemaFactory.newInstance(schemaLanguage);
+
+ if (schemaSource == null) {
+ if (schemaResource == null) {
+ throw new JBIException("You must specify a schema, schemaSource or schemaResource property");
+ }
+ if (schemaResource.getURL() == null) {
+ schemaSource = new StreamSource(schemaResource.getInputStream());
+ } else {
+ schemaSource = new StreamSource(schemaResource.getInputStream(), schemaResource.getURL().toExternalForm());
+ }
+ }
+ schema = factory.newSchema(schemaSource);
+ }
+ }
+ catch (IOException e) {
+ throw new JBIException("Failed to load schema: " + e, e);
+ }
+ catch (SAXException e) {
+ throw new JBIException("Failed to load schema: " + e, e);
+ }
+ }
+
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ Validator validator = schema.newValidator();
+
+ // create a new errorHandler and set it on the validator
+ MessageAwareErrorHandler errorHandler = errorHandlerFactory.createMessageAwareErrorHandler();
+ validator.setErrorHandler(errorHandler);
+ DOMResult result = new DOMResult();
+
+ // Transform first so that the input source will be parsed only once
+ // if it is a StreamSource
+ getMessageTransformer().transform(exchange, in, out);
+ try {
+ SourceTransformer sourceTransformer = new SourceTransformer();
+ // Only DOMSource and SAXSource are allowed for validating
+ // See http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/Validator.html#validate(javax.xml.transform.Source,%20javax.xml.transform.Result)
+ // As we expect a DOMResult as output, we must ensure that the input is a
+ // DOMSource
+ DOMSource src = sourceTransformer.toDOMSource(out.getContent());
+ doValidation(validator,src,result);
+ if (errorHandler.hasErrors()) {
+ Fault fault = exchange.createFault();
+
+ // Dont set the schema and source document as properties on the fault
+ // because they are not serializable
+ //fault.setProperty("org.apache.servicemix.xml", src);
+ // Dont set the schema because it contains an instance of
+ // com.sun.org.apache.xerces.internal.jaxp.validation.xs.SchemaImpl that
+ // is not serializable
+ //fault.setProperty("org.apache.servicemix.schema", schema);
+
+ /*
+ * check if this error handler supports the capturing of
+ * error messages.
+ */
+ if (errorHandler.capturesMessages()) {
+
+ /*
+ * In descending order of preference select a format to use. If
+ * neither DOMSource, StringSource or String are supported throw
+ * a messaging exception.
+ */
+ if (errorHandler.supportsMessageFormat(DOMSource.class)) {
+ fault.setContent(
+ (DOMSource)errorHandler.getMessagesAs(DOMSource.class));
+ } else if (errorHandler.supportsMessageFormat(StringSource.class)) {
+ fault.setContent(sourceTransformer.toDOMSource(
+ (StringSource)errorHandler.getMessagesAs(StringSource.class)));
+ } else if (errorHandler.supportsMessageFormat(String.class)) {
+ fault.setContent(
+ sourceTransformer.toDOMSource(
+ new StringSource(
+ (String)errorHandler.getMessagesAs(String.class))));
+ } else {
+ throw new MessagingException("MessageAwareErrorHandler implementation " +
+ errorHandler.getClass().getName() +
+ " does not support a compatible error message format.");
+ }
+ } else {
+ /*
+ * we can't do much here if the ErrorHandler implementation does
+ * not support capturing messages
+ */
+ fault.setContent(new DOMSource(result.getNode(), result.getSystemId()));
+ }
+ if (!handlingErrorMethod.equalsIgnoreCase(FAULT_FLOW)) {
+ // HANDLE AS JBI FAULT
+ throw new FaultException("Failed to validate against schema: " + schema, exchange, fault);
+ } else {
+ MessageUtil.transfer(fault, out);
+ return true;
+ }
+ }
+ else {
+ // Retrieve the ouput of the validation
+ // as it may have been changed by the validator
+ out.setContent(new DOMSource(result.getNode(), result.getSystemId()));
+ return true;
+ }
+ }
+ catch (SAXException e) {
+ throw new MessagingException(e);
+ }
+ catch (IOException e) {
+ throw new MessagingException(e);
+ }
+ catch (ParserConfigurationException e) {
+ throw new MessagingException(e);
+ }
+ catch (TransformerException e) {
+ throw new MessagingException(e);
+ }
+ }
+
+ protected void doValidation(Validator validator, DOMSource src, DOMResult result) throws SAXException, IOException {
+ validator.validate(src,result);
+ }
+
+ public String getHandlingErrorMethod() {
+ return handlingErrorMethod;
+ }
+
+ public void setHandlingErrorMethod(String handlingErrorMethod) {
+ this.handlingErrorMethod = handlingErrorMethod;
+ }
+}
+
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/package.html
new file mode 100644
index 0000000..25e0feb
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/validation/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Performs XML validation using <a href="http://java.sun.com/xml/jaxp/index.jsp">JAXP</a> for validating against XSD or RelaxNG
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FileObjectEditor.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FileObjectEditor.java
new file mode 100644
index 0000000..1200234
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FileObjectEditor.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.vfs;
+
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemException;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.commons.vfs.VFS;
+
+import javax.jbi.JBIException;
+
+/**
+ * A bean editor to make it easier to create new file system objects using VFS
+ *
+ * @version $Revision: 426415 $
+ */
+public class FileObjectEditor {
+ private String path;
+ private FileSystemManager fileSystemManager;
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public FileSystemManager getFileSystemManager() {
+ return fileSystemManager;
+ }
+
+ public void setFileSystemManager(FileSystemManager fileSystemManager) {
+ this.fileSystemManager = fileSystemManager;
+ }
+
+ public FileObject getFileObject() throws JBIException {
+ try {
+ if (fileSystemManager == null) {
+ fileSystemManager = VFS.getManager();
+ }
+ if (path == null) {
+ throw new IllegalArgumentException("You must specify a path property");
+ }
+ FileObject answer = fileSystemManager.resolveFile(path);
+ if (answer == null) {
+ throw new JBIException("Could not resolve file: " + path);
+ }
+ try {
+ answer.createFolder();
+ }
+ catch (FileSystemException e) {
+ throw new JBIException("Failed to create folder: " + e, e);
+ }
+ return answer;
+ }
+ catch (FileSystemException e) {
+ throw new JBIException("Failed to initialize file system manager: " + e, e);
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FilePoller.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FilePoller.java
new file mode 100644
index 0000000..883e2da
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FilePoller.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.vfs;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSelector;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.components.util.FileMarshaler;
+import org.apache.servicemix.components.util.PollingComponentSupport;
+
+import java.util.concurrent.CopyOnWriteArraySet;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.RobustInOnly;
+import javax.jbi.messaging.NormalizedMessage;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Set;
+
+/**
+ * A polling component which looks for a file in a file system using the
+ * <a href="http://jakarta.apache.org/commons/vfs.html">Jakarta Commons VFS</a> library
+ * for handling various file systems like files, Samba, WebDAV, FTP, SFTP and temporary files.
+ *
+ * @version $Revision: 666120 $
+ */
+public class FilePoller extends PollingComponentSupport {
+ private static final Log log = LogFactory.getLog(FilePoller.class);
+
+ private FileMarshaler marshaler = new DefaultFileMarshaler();
+ private FileObjectEditor editor = new FileObjectEditor();
+ private FileObject directory;
+ private FileSelector selector;
+ private Set workingSet = new CopyOnWriteArraySet();
+ private boolean deleteFile = true;
+
+ public void poll() throws Exception {
+ FileObject[] files = null;
+ // SM-192: Force close the file, so that the cached informations are cleared
+ directory.close();
+ if (selector != null) {
+ files = directory.findFiles(selector);
+ }
+ else {
+ files = directory.getChildren();
+ }
+ for (int i = 0; i < files.length; i++) {
+ pollFile(files[i]);
+ }
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public FileObject getDirectory() {
+ return directory;
+ }
+
+ public void setDirectory(FileObject directory) {
+ this.directory = directory;
+ }
+
+ public FileSelector getSelector() {
+ return selector;
+ }
+
+ public void setSelector(FileSelector selector) {
+ this.selector = selector;
+ }
+
+ public String getPath() {
+ return editor.getPath();
+ }
+
+ public void setPath(String path) {
+ editor.setPath(path);
+ }
+
+ /**
+ * Returns whether or not we should delete the file when its processed
+ */
+ public boolean isDeleteFile() {
+ return deleteFile;
+ }
+
+ public void setDeleteFile(boolean deleteFile) {
+ this.deleteFile = deleteFile;
+ }
+
+ public FileSystemManager getFileSystemManager() {
+ return editor.getFileSystemManager();
+ }
+
+ public void setFileSystemManager(FileSystemManager fileSystemManager) {
+ editor.setFileSystemManager(fileSystemManager);
+ }
+
+ public FileMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(FileMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * The set of FTPFiles that this component is currently working on
+ *
+ * @return
+ */
+ public Set getWorkingSet() {
+ return workingSet;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ if (directory == null) {
+ directory = editor.getFileObject();
+ }
+ super.init();
+ }
+
+ protected void pollFile(final FileObject aFile) {
+ if (workingSet.add(aFile)) {
+ if (log.isDebugEnabled()) {
+ log.debug("Scheduling file " + aFile + " for processing");
+ }
+ getExecutor().execute(new Runnable() {
+ public void run() {
+ try {
+ processFileAndDelete(aFile);
+ } finally {
+ workingSet.remove(aFile);
+ }
+ }
+ });
+ }
+ }
+
+ protected void processFileAndDelete(FileObject file) {
+ try {
+ processFile(file);
+ if (isDeleteFile()) {
+ if (!file.delete()) {
+ throw new IOException("Could not delete file " + file);
+ }
+ }
+ }
+ catch (Exception e) {
+ log.error("Failed to process file: " + file + ". Reason: " + e, e);
+ }
+ }
+
+ protected void processFile(FileObject file) throws Exception {
+ // SM-192: Force close the file, so that the cached informations are cleared
+ file.close();
+ String name = file.getName().getURI();
+ FileContent content = file.getContent();
+ content.close();
+ InputStream in = content.getInputStream();
+ if (in == null) {
+ throw new JBIException("No input available for file!");
+ }
+ RobustInOnly exchange = getExchangeFactory().createRobustInOnlyExchange();
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setInMessage(message);
+ marshaler.readMessage(exchange, message, in, name);
+ getDeliveryChannel().sendSync(exchange);
+ in.close();
+ content.close();
+ if (exchange.getError() != null) {
+ throw exchange.getError();
+ }
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FileWriter.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FileWriter.java
new file mode 100644
index 0000000..f5167e3
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/FileWriter.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.vfs;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.vfs.FileContent;
+import org.apache.commons.vfs.FileObject;
+import org.apache.commons.vfs.FileSystemManager;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.components.util.FileMarshaler;
+import org.apache.servicemix.components.util.OutBinding;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * A component which receives a message and writes the content to a file using the
+ * <a href="http://jakarta.apache.org/commons/vfs.html">Jakarta Commons VFS</a> library
+ * for handling various file systems like files, Samba, WebDAV, FTP, SFTP and temporary files.
+ *
+ * @version $Revision: 426415 $
+ */
+public class FileWriter extends OutBinding {
+ private static final Log log = LogFactory.getLog(FileWriter.class);
+
+ private FileObject directory;
+ private FileObjectEditor editor = new FileObjectEditor();
+ private FileMarshaler marshaler = new DefaultFileMarshaler();
+ private String uniqueFileName = "ServiceMix";
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public FileObject getDirectory() {
+ return directory;
+ }
+
+ public void setDirectory(FileObject directory) {
+ this.directory = directory;
+ }
+
+ public String getPath() {
+ return editor.getPath();
+ }
+
+ public void setPath(String path) {
+ editor.setPath(path);
+ }
+
+ public FileSystemManager getFileSystemManager() {
+ return editor.getFileSystemManager();
+ }
+
+ public void setFileSystemManager(FileSystemManager fileSystemManager) {
+ editor.setFileSystemManager(fileSystemManager);
+ }
+
+ public FileMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(FileMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public String getUniqueFileName() {
+ return uniqueFileName;
+ }
+
+ /**
+ * Sets the name used to make a unique name if no file name is available on the message.
+ *
+ * @param uniqueFileName the new value of the unique name to use for generating unique names
+ */
+ public void setUniqueFileName(String uniqueFileName) {
+ this.uniqueFileName = uniqueFileName;
+ }
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void init() throws JBIException {
+ if (directory == null) {
+ directory = editor.getFileObject();
+ }
+ super.init();
+ }
+
+ protected void process(MessageExchange exchange, NormalizedMessage message) throws Exception {
+ OutputStream out = null;
+ try {
+ String name = marshaler.getOutputName(exchange, message);
+ if (name == null) {
+ throw new MessagingException("No output name available. Cannot output message!");
+ }
+ directory.close(); // remove any cached informations
+ FileObject newFile = directory.resolveFile(name);
+ newFile.close(); // remove any cached informations
+ FileContent content = newFile.getContent();
+ content.close();
+ if (content != null) {
+ out = content.getOutputStream();
+ }
+ if (out == null) {
+ throw new MessagingException("No output stream available for output name: " + name);
+ }
+ marshaler.writeMessage(exchange, message, out, name);
+ done(exchange);
+ }
+ finally {
+ if (out != null) {
+ try {
+ out.close();
+ }
+ catch (IOException e) {
+ log.error("Caught exception while closing stream on error: " + e, e);
+ }
+ }
+ }
+ }
+}
+
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/package.html
new file mode 100644
index 0000000..8fa1f12
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/vfs/package.html
@@ -0,0 +1,29 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+A collection of file system components using the
+<a href="http://jakarta.apache.org/commons/vfs.html">Jakarta Commons VFS</a> library
+for handling various file systems like files, Samba, WebDAV, FTP, SFTP and temporary files.
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/FailedToCreateDOMException.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/FailedToCreateDOMException.java
new file mode 100644
index 0000000..a07e10a
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/FailedToCreateDOMException.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+/**
+ * Thrown if the lazily created DOM node could not be created for the WSIF response.
+ *
+ * @version $Revision: 426415 $
+ */
+public class FailedToCreateDOMException extends RuntimeException {
+ public FailedToCreateDOMException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFBinding.java
new file mode 100644
index 0000000..e8615f4
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFBinding.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.wsdl.Binding;
+import javax.wsdl.Definition;
+import javax.wsdl.WSDLException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.wsif.WSIFException;
+import org.apache.wsif.WSIFMessage;
+import org.apache.wsif.WSIFOperation;
+import org.apache.wsif.WSIFService;
+import org.apache.wsif.WSIFServiceFactory;
+import org.apache.wsif.util.WSIFUtils;
+import org.springframework.core.io.Resource;
+
+/**
+ * Consumers JBI messages and sends them as a synchronous request/response into WSIF
+ * then forwards the response
+ *
+ * @version $Revision: 556864 $
+ */
+public class WSIFBinding extends TransformComponentSupport {
+
+ private static transient Log log = LogFactory.getLog(WSIFBinding.class);
+
+ private WSIFMarshaler marshaler = new WSIFMarshaler();
+ private WSIFService serviceHelper;
+ private Definition definition;
+ private Resource definitionResource;
+ private WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
+ private WSIFOperationMap operationMap;
+
+ protected void init() throws JBIException {
+ try {
+ if (definition == null) {
+ if (definitionResource == null) {
+ throw new JBIException("You must specify a definition or definitionResource property");
+ }
+ String uri = definitionResource.getURL().toString();
+ InputStreamReader reader = new InputStreamReader(definitionResource.getInputStream());
+ definition = WSIFUtils.readWSDL(uri, reader);
+ }
+
+ if (serviceHelper == null) {
+ serviceHelper = factory.getService(definition);
+ }
+
+ if (log.isDebugEnabled()) {
+ for (Iterator iter = serviceHelper.getAvailablePortNames(); iter.hasNext();) {
+ log.debug("Available port name: " + iter.next());
+ }
+ }
+
+ operationMap = new WSIFOperationMap(serviceHelper);
+
+ Map bindings = definition.getBindings();
+ for (Iterator iter = bindings.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ Binding binding = (Binding) entry.getValue();
+ operationMap.addBinding(binding);
+ }
+ }
+ catch (IOException e) {
+ throw new JBIException(e);
+ }
+ catch (WSDLException e) {
+ throw new JBIException(e);
+ }
+ }
+
+ /**
+ * @deprecated use getMarshaler instead
+ */
+ public WSIFMarshaler getMarshaller() {
+ return marshaler;
+ }
+
+ /**
+ * @deprecated use setMarshaler instead
+ */
+ public void setMarshaller(WSIFMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public WSIFMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ public void setMarshaler(WSIFMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public Definition getDefinition() {
+ return definition;
+ }
+
+ public void setDefinition(Definition definition) {
+ this.definition = definition;
+ }
+
+ public Resource getDefinitionResource() {
+ return definitionResource;
+ }
+
+ public void setDefinitionResource(Resource definitionResource) {
+ this.definitionResource = definitionResource;
+ }
+
+ public WSIFServiceFactory getFactory() {
+ return factory;
+ }
+
+ public void setFactory(WSIFServiceFactory factory) {
+ this.factory = factory;
+ }
+
+ public WSIFService getServiceHelper() {
+ return serviceHelper;
+ }
+
+ public void setServiceHelper(WSIFService serviceHelper) {
+ this.serviceHelper = serviceHelper;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException {
+ try {
+ WSIFOperationInfo operationInfo = operationMap.getOperationForExchange(exchange);
+
+ WSIFOperation operation = operationInfo.createWsifOperation();
+ WSIFMessage inMessage = operation.createInputMessage();
+ Object body = getBody(in);
+ marshaler.fromNMS(operationInfo, inMessage, in, body);
+
+ WSIFMessage outMessage = operation.createInputMessage();
+ WSIFMessage faultMessage = operation.createInputMessage();
+ boolean answer = operation.executeRequestResponseOperation(inMessage, outMessage, faultMessage);
+ if (answer) {
+ marshaler.toNMS(exchange, out, operationInfo, outMessage);
+ }
+ else {
+ Fault fault = exchange.createFault();
+ marshaler.toNMS(exchange, fault, operationInfo, outMessage);
+ exchange.setFault(fault);
+ }
+ return true;
+ }
+ catch (WSIFException e) {
+ throw new MessagingException(e);
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFMarshaler.java
new file mode 100644
index 0000000..408de76
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFMarshaler.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.jbi.util.LazyDOMSource;
+import org.apache.wsif.WSIFException;
+import org.apache.wsif.WSIFMessage;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.wsdl.Part;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * A class which marshalls a WSIF messages into and out of NMS
+ *
+ * @version $Revision: 431309 $
+ */
+public class WSIFMarshaler {
+ public static final String WSDL_WRAPPER_NAMESPACE = "http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper";
+
+ private SourceTransformer transformer = new SourceTransformer();
+
+ public void toNMS(final MessageExchange exchange, final NormalizedMessage nmsMessage, final WSIFOperationInfo operationInfo, final WSIFMessage wsifMessage) throws WSIFException, MessagingException {
+ addNmsProperties(nmsMessage, wsifMessage);
+ for (Iterator iter = wsifMessage.getPartNames(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = wsifMessage.getObjectPart(name);
+ nmsMessage.setProperty(name, value);
+ }
+ nmsMessage.setContent(new LazyDOMSource() {
+ protected Node loadNode() {
+ return createResultDocument(exchange, nmsMessage, operationInfo, wsifMessage);
+ }
+ });
+ }
+
+ public void fromNMS(WSIFOperationInfo operationInfo, WSIFMessage wsifMessage, NormalizedMessage nmsMessage, Object body) throws WSIFException, MessagingException {
+ addWSIFProperties(wsifMessage, nmsMessage);
+ try {
+ Element element = transformer.toDOMElement(nmsMessage);
+ Map parts = wsifMessage.getMessageDefinition().getParts();
+ for (Iterator iter = parts.entrySet().iterator(); iter.hasNext();) {
+ Map.Entry entry = (Map.Entry) iter.next();
+ String name = (String) entry.getKey();
+ Part part = (Part) entry.getValue();
+
+ Object value = getPartValue(name, part, nmsMessage, element);
+ wsifMessage.setObjectPart(name, value);
+ }
+ }
+ catch (TransformerException e) {
+ throw new MessagingException(e);
+ }
+ catch (ParserConfigurationException e) {
+ throw new MessagingException(e);
+ }
+ catch (IOException e) {
+ throw new MessagingException(e);
+ }
+ catch (SAXException e) {
+ throw new MessagingException(e);
+ }
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public SourceTransformer getTransformer() {
+ return transformer;
+ }
+
+ public void setTransformer(SourceTransformer transformer) {
+ this.transformer = transformer;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void addNmsProperties(NormalizedMessage nmsMessage, WSIFMessage wsifMessage) throws WSIFException {
+ Iterator iter = wsifMessage.getPartNames();
+ while (iter.hasNext()) {
+ String name = (String) iter.next();
+ Object value = wsifMessage.getObjectPart(name);
+ nmsMessage.setProperty(name, value);
+ }
+ }
+
+ protected void addWSIFProperties(WSIFMessage wsifMessage, NormalizedMessage nmsMessage) throws WSIFException {
+ for (Iterator iter = nmsMessage.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = nmsMessage.getProperty(name);
+ if (shouldIncludeHeader(nmsMessage, name, value)) {
+ wsifMessage.setObjectPart(name, value);
+ }
+ }
+ }
+
+
+ /**
+ * Decides whether or not the given header should be included in the WSIF message.
+ * By default this includes all values
+ */
+ protected boolean shouldIncludeHeader(NormalizedMessage normalizedMessage, String name, Object value) {
+ return true;
+ }
+
+ protected Object getPartValue(String name, Part part, NormalizedMessage nmsMessage, Element body) throws MessagingException, TransformerException, ParserConfigurationException, IOException, SAXException {
+ if (isSimpleType(part)) {
+ // lets extract the text content
+ return DOMUtil.getElementText(body).trim();
+ }
+ // TODO we should be extracting each part of the XML using XPath
+ return transformer.toDOMNode(nmsMessage);
+
+ }
+
+ /**
+ * Returns true if the given part is a string type
+ */
+ protected boolean isSimpleType(Part part) {
+ QName typeName = part.getTypeName();
+ if (typeName != null) {
+ return "http://www.w3.org/2001/XMLSchema".equals(typeName.getNamespaceURI());
+ }
+ return false;
+ }
+
+ protected Node createResultDocument(MessageExchange exchange, NormalizedMessage normalizedMessage, WSIFOperationInfo operationInfo, WSIFMessage wsifMessage) {
+ try {
+ Document document = transformer.createDocument();
+ Element root = document.createElementNS(WSDL_WRAPPER_NAMESPACE, "jbi:message");
+ document.appendChild(root);
+ root.setAttribute("xmlns:jbi", WSDL_WRAPPER_NAMESPACE);
+ QName operation = exchange.getOperation();
+ String operationName = "unknown";
+ if (operation != null) {
+ operationName = operation.getLocalPart();
+ String uri = operation.getNamespaceURI();
+ if (uri != null && uri.length() > 0) {
+ root.setAttribute("xmlns:op", uri);
+ }
+ }
+ root.setAttribute("version", "1.0");
+ root.setAttribute("type", "op:" + operationName);
+ root.setAttribute("name", operationName);
+
+
+ for (Iterator iter = wsifMessage.getPartNames(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = normalizedMessage.getProperty(name);
+
+ Element element = document.createElementNS(WSDL_WRAPPER_NAMESPACE, "jbi:part");
+ root.appendChild(element);
+ addPartValue(element, name, value);
+ }
+
+ return document;
+ }
+ catch (Exception e) {
+ throw new FailedToCreateDOMException(e);
+ }
+ }
+
+ protected void addPartValue(Element element, String name, Object value) {
+ if (value instanceof Document) {
+ Document doc = (Document) value;
+ Element root = doc.getDocumentElement();
+ doc.removeChild(root);
+ element.appendChild(root);
+ }
+ else if (value != null) {
+ String text = value.toString();
+ element.appendChild(element.getOwnerDocument().createTextNode(text));
+ }
+ }
+
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOperationInfo.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOperationInfo.java
new file mode 100644
index 0000000..fc9d872
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOperationInfo.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+import org.apache.wsif.WSIFException;
+import org.apache.wsif.WSIFOperation;
+import org.apache.wsif.WSIFPort;
+
+/**
+ * The information about an operation.
+ *
+ * @version $Revision: 426415 $
+ */
+public class WSIFOperationInfo {
+ private WSIFPort port;
+ private String name;
+
+ public WSIFOperationInfo(WSIFPort port, String name) {
+ this.port = port;
+ this.name = name;
+ }
+
+ public WSIFOperation createWsifOperation() throws WSIFException {
+ return this.port.createOperation(name);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOperationMap.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOperationMap.java
new file mode 100644
index 0000000..a93b5ee
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOperationMap.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.wsdl.Binding;
+import javax.wsdl.BindingOperation;
+import javax.wsdl.Operation;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.jbi.NoSuchOperationException;
+import org.apache.wsif.WSIFException;
+import org.apache.wsif.WSIFService;
+
+/**
+ * Maintains a Map of the available operations for the binding.
+ *
+ * @version $Revision: 426415 $
+ */
+public class WSIFOperationMap {
+
+ private WSIFService service;
+ private Map operationMap = new HashMap();
+ private WSIFOperationInfo defaultOperation;
+
+ public WSIFOperationMap(WSIFService service) {
+ this.service = service;
+ }
+
+ /**
+ * Returns the operation information for the current message exchange.
+ *
+ * @param exchange the current message exchange
+ * @return the operation information
+ * @throws NoSuchOperationException if the operation is not available
+ */
+ public WSIFOperationInfo getOperationForExchange(MessageExchange exchange) throws NoSuchOperationException {
+ QName operationName = exchange.getOperation();
+ WSIFOperationInfo operationInfo = getOperation(operationName);
+ if (operationInfo == null) {
+ throw new NoSuchOperationException(operationName);
+ }
+ return operationInfo;
+ }
+
+ /**
+ * Returns the operation information for the given QName
+ *
+ * @param operationName is the name of the operation
+ * @return the operation information or null if it is not available
+ */
+ public WSIFOperationInfo getOperation(QName operationName) {
+ if (operationName == null) {
+ // lets try a default operation
+ return defaultOperation;
+ }
+ return (WSIFOperationInfo) operationMap.get(operationName);
+ }
+
+ public int getOperationCount() {
+ return operationMap.values().size();
+ }
+
+ /**
+ * Returns the operation for the given name
+ *
+ * @param operationName is the name of the operation
+ * @return the operation instance or null if it is not available
+ */
+ public WSIFOperationInfo getOperation(String operationName) {
+ return (WSIFOperationInfo) operationMap.get(operationName);
+ }
+
+ public void addBinding(Binding binding) throws WSIFException {
+ List list = binding.getBindingOperations();
+ for (Iterator iter = list.iterator(); iter.hasNext();) {
+ BindingOperation bindingOperation = (BindingOperation) iter.next();
+ addBindingOperation(binding, bindingOperation);
+ }
+ }
+
+ protected void addBindingOperation(Binding binding, BindingOperation bindingOperation) throws WSIFException {
+ Operation operation = bindingOperation.getOperation();
+ String name = operation.getName();
+ WSIFOperationInfo info = new WSIFOperationInfo(service.getPort(), name);
+ operationMap.put(name, info);
+ operationMap.put(new QName(name), info);
+ if (defaultOperation == null) {
+ defaultOperation = info;
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOutBinding.java
new file mode 100644
index 0000000..9657c1c
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/WSIFOutBinding.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.apache.wsif.WSIFMessage;
+import org.apache.wsif.WSIFOperation;
+
+/**
+ * Consumers JBI messages and sends them as a oneway into WSIF
+ *
+ * @version $Revision: 429277 $
+ */
+public class WSIFOutBinding extends OutBinding {
+
+ private WSIFMarshaler marshaler = new WSIFMarshaler();
+ private WSIFOperationMap operationMap;
+
+ /**
+ * @deprecated use getMarshaler instead
+ */
+ public WSIFMarshaler getMarshaller() {
+ return marshaler;
+ }
+
+ /**
+ * @deprecated use setMarshaler instead
+ */
+ public void setMarshaller(WSIFMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ /**
+ * @return the marshaler
+ */
+ public WSIFMarshaler getMarshaler() {
+ return marshaler;
+ }
+
+ /**
+ * @param marshaler the marshaler to set
+ */
+ public void setMarshaler(WSIFMarshaler marshaler) {
+ this.marshaler = marshaler;
+ }
+
+ public WSIFOperationMap getOperationMap() {
+ return operationMap;
+ }
+
+ public void setOperationMap(WSIFOperationMap operationMap) {
+ this.operationMap = operationMap;
+ }
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void process(MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception {
+ WSIFOperationInfo operationInfo = operationMap.getOperationForExchange(exchange);
+ WSIFOperation operation = operationInfo.createWsifOperation();
+ WSIFMessage message = operation.createInputMessage();
+ marshaler.fromNMS(operationInfo, message, normalizedMessage, getBody(normalizedMessage));
+ operation.executeInputOnlyOperation(message);
+ done(exchange);
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/package.html
new file mode 100644
index 0000000..776bd98
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/wsif/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for <a href="http://ws.apache.org/wsif/">WSIF</a>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XFireBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XFireBinding.java
new file mode 100644
index 0000000..ae399b1
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XFireBinding.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xfire;
+
+import java.io.ByteArrayOutputStream;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.codehaus.xfire.MessageContext;
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.exchange.InMessage;
+import org.codehaus.xfire.transport.Channel;
+import org.codehaus.xfire.transport.Transport;
+import org.codehaus.xfire.transport.local.LocalTransport;
+
+public class XFireBinding extends OutBinding {
+ private XMarshaler marshaler;
+
+ private XFire xfire;
+
+ public XFireBinding()
+ {
+ super();
+
+ this.marshaler = new XMarshaler();
+ }
+
+ protected void process(MessageExchange messageExchange, NormalizedMessage nm) throws Exception {
+
+ XMLStreamReader reader = marshaler.createStreamReader(nm);
+ if (reader == null) {
+ throw new JBIException("Could not get source as XMLStreamReader.");
+ }
+
+ InMessage in = new InMessage(reader, "");
+ MessageContext context = new MessageContext();
+ context.setXFire(xfire);
+ context.setService(xfire.getServiceRegistry().getService(getService().getLocalPart()));
+
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ context.setProperty(Channel.BACKCHANNEL_URI, buffer);
+
+ Transport transport = xfire.getTransportManager().getTransport(LocalTransport.BINDING_ID);
+ Channel channel = transport.createChannel();
+ channel.receive(context, in);
+
+ NormalizedMessage outMessage = messageExchange.createMessage();
+
+ marshaler.setContent(outMessage, buffer.toString());
+ marshaler.toNMS(outMessage, context.getOutMessage());
+
+ answer(messageExchange, outMessage);
+ }
+
+ public XFire getXfire() {
+ return xfire;
+ }
+
+ public void setXfire(XFire xfire) {
+ this.xfire = xfire;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XFireOutBinding.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XFireOutBinding.java
new file mode 100644
index 0000000..f5f855d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XFireOutBinding.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xfire;
+
+import org.apache.servicemix.components.util.OutBinding;
+import org.codehaus.xfire.MessageContext;
+import org.codehaus.xfire.XFire;
+import org.codehaus.xfire.exchange.InMessage;
+import org.codehaus.xfire.transport.Channel;
+import org.codehaus.xfire.transport.Transport;
+import org.codehaus.xfire.transport.local.LocalTransport;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLStreamReader;
+
+public class XFireOutBinding extends OutBinding {
+ private XMarshaler marshaler;
+
+ private XFire xfire;
+
+ public XFireOutBinding()
+ {
+ super();
+
+ this.marshaler = new XMarshaler();
+ }
+
+ protected void process(MessageExchange messageExchange, NormalizedMessage nm) throws Exception {
+
+ XMLStreamReader reader = marshaler.createStreamReader(nm);
+ if (reader == null) {
+ throw new JBIException("Could not get source as XMLStreamReader.");
+ }
+
+ InMessage in = new InMessage(reader, "");
+ MessageContext context = new MessageContext();
+ context.setXFire(xfire);
+ context.setService(xfire.getServiceRegistry().getService(getService().getLocalPart()));
+
+ Transport transport = xfire.getTransportManager().getTransport(LocalTransport.BINDING_ID);
+ Channel channel = transport.createChannel();
+ channel.receive(context, in);
+
+ done(messageExchange);
+ }
+
+ public XFire getXfire() {
+ return xfire;
+ }
+
+ public void setXfire(XFire xfire) {
+ this.xfire = xfire;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XMarshaler.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XMarshaler.java
new file mode 100644
index 0000000..062379d
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/XMarshaler.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xfire;
+
+import java.io.InputStream;
+import java.io.Writer;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StAXSourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.codehaus.xfire.exchange.OutMessage;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class XMarshaler {
+
+ private StAXSourceTransformer transformer;
+
+ public XMarshaler()
+ {
+ transformer = new StAXSourceTransformer();
+ }
+
+ public void setContent(NormalizedMessage message, String xml) throws MessagingException {
+ message.setContent(new StringSource(xml));
+ }
+
+ public XMLStreamReader createStreamReader(NormalizedMessage message) throws XMLStreamException, TransformerException {
+ Source content = message.getContent();
+ return transformer.toXMLStreamReader(content);
+ }
+
+
+ public XMLStreamWriter createStreamWriter(Writer writer) throws XMLStreamException {
+ return transformer.getOutputFactory().createXMLStreamWriter(writer);
+ }
+
+ /**
+ * Converts from an NMS message to an ActiveSOAP message exchange
+ */
+ public void fromNMS(MessageExchange asExchange, NormalizedMessage normalizedMessage) {
+ }
+
+ /**
+ * Converts from an ActiveSOAP message exchange to an NMS message
+ */
+ public void toNMS(NormalizedMessage normalizedMessage, OutMessage outMessage) {
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/package.html
new file mode 100644
index 0000000..fd14389
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xfire/package.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+Bindings for integrating with the <a href="http://xfire.codehaus.org/">XFire</a> SOAP framework
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XalanExtension.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XalanExtension.java
new file mode 100644
index 0000000..6dc5ec6
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XalanExtension.java
@@ -0,0 +1,255 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import org.apache.commons.lang.math.NumberUtils;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.components.util.CopyTransformer;
+import org.apache.servicemix.components.util.MarshalerSupport;
+import org.apache.xalan.extensions.XSLProcessorContext;
+import org.apache.xalan.lib.ExsltDynamic;
+import org.apache.xalan.templates.ElemTemplateElement;
+import org.apache.xalan.transformer.TransformerImpl;
+import org.apache.xml.utils.DOMBuilder;
+import org.apache.xml.utils.PrefixResolver;
+import org.apache.xpath.objects.XObject;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.SAXNotSupportedException;
+
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.dom.DOMSource;
+
+/**
+ * An extension to allow <a href="http://xml.apache.org/xalan/">Xalan</a> to perform XPath based routing using
+ * ServiceMix.
+ *
+ * @version $Revision: 426415 $
+ */
+public class XalanExtension extends MarshalerSupport {
+
+ // Extension elements
+ //-------------------------------------------------------------------------
+
+
+ /**
+ * Forwards the inbound message to the destination copying the content and properties
+ */
+ public void forward(XSLProcessorContext context, Element element) throws MessagingException {
+ ComponentSupport component = getComponent(context, element);
+ if (component == null) {
+ throw new MessagingException("Could not find a component on which to perform the service invocation!");
+ }
+
+ TransformerImpl transformer = context.getTransformer();
+ PrefixResolver namespaceContext = transformer.getXPathContext().getNamespaceContext();
+
+ QName service = getQNameAttribute(namespaceContext, element, "service");
+ QName interfaceName = getQNameAttribute(namespaceContext, element, "interface");
+ QName operation = getQNameAttribute(namespaceContext, element, "operation");
+
+ MessageExchange exchange = getExchange(context, element);
+ NormalizedMessage in = getInMessage(context, element);
+
+ // TODO we should allow nested setOutProperty tags
+
+ component.invoke(exchange, in, service, interfaceName, operation);
+ }
+
+ /**
+ * Invokes the service with the XML content included in the XML element
+ */
+ public void invoke(XSLProcessorContext context, ElemTemplateElement element) throws MessagingException, ParserConfigurationException, TransformerException {
+ ComponentSupport component = getComponent(context, element);
+ if (component == null) {
+ throw new MessagingException("Could not find a component on which to perform the service invocation!");
+ }
+
+ TransformerImpl transformer = context.getTransformer();
+ PrefixResolver namespaceContext = transformer.getXPathContext().getNamespaceContext();
+
+ QName service = getQNameAttribute(namespaceContext, element, "service");
+ QName interfaceName = getQNameAttribute(namespaceContext, element, "interface");
+ QName operation = getQNameAttribute(namespaceContext, element, "operation");
+
+ InOnly outExchange = component.createInOnlyExchange(service, interfaceName, operation);
+ NormalizedMessage out = outExchange.createMessage();
+ outExchange.setInMessage(out);
+
+ transformer.setParameter("out", out);
+
+ // lets copy the content into the body
+ Document document = getTransformer().createDocument();
+ DOMBuilder builder = new DOMBuilder(document);
+ transformer.executeChildTemplates(element, context.getContextNode(), context.getMode(), builder);
+
+ out.setContent(new DOMSource(document));
+
+ // now lets perform the invocation
+ component.send(outExchange);
+ }
+
+ /**
+ * Calls the service with the XML content included in the XML element and outputs the XML content
+ */
+ public void call(XSLProcessorContext context, ElemTemplateElement element) throws MessagingException, ParserConfigurationException, TransformerException {
+ ComponentSupport component = getComponent(context, element);
+ if (component == null) {
+ throw new MessagingException("Could not find a component on which to perform the service invocation!");
+ }
+
+ TransformerImpl transformer = context.getTransformer();
+ PrefixResolver namespaceContext = transformer.getXPathContext().getNamespaceContext();
+
+ QName service = getQNameAttribute(namespaceContext, element, "service");
+ QName interfaceName = getQNameAttribute(namespaceContext, element, "interface");
+ QName operation = getQNameAttribute(namespaceContext, element, "operation");
+
+ InOut outExchange = component.createInOutExchange(service, interfaceName, operation);
+ NormalizedMessage out = outExchange.createMessage();
+ outExchange.setInMessage(out);
+
+
+ // lets copy the content into the body
+ Document document = getTransformer().createDocument();
+ DOMBuilder builder = new DOMBuilder(document);
+ transformer.executeChildTemplates(element, context.getContextNode(), context.getMode(), builder);
+
+ out.setContent(new DOMSource(document));
+
+ // now lets perform the invocation
+ if (component.getDeliveryChannel().sendSync(outExchange)) {
+ NormalizedMessage result = outExchange.getOutMessage();
+ String outVarName = getAttribute(element, "outVar", "out");
+ transformer.setParameter(outVarName, result);
+ }
+ else {
+ Exception error = outExchange.getError();
+ if (error != null) {
+ transformer.setParameter("error", error);
+ }
+ Fault fault = outExchange.getFault();
+ if (fault != null) {
+ transformer.setParameter("fault", fault);
+ }
+ }
+
+ }
+
+ /**
+ * Copies the properties from the input to the output message
+ */
+ public void copyProperties(XSLProcessorContext context, Element element) throws MessagingException {
+ NormalizedMessage in = getInMessage(context, element);
+ NormalizedMessage out = getOutMessage(context, element);
+ CopyTransformer.copyProperties(in, out);
+ }
+
+ /**
+ * Sets a named property on the output message
+ */
+ public void setOutProperty(XSLProcessorContext context, ElemTemplateElement element) throws MessagingException, SAXNotSupportedException {
+ NormalizedMessage out = getOutMessage(context, element);
+ String name = element.getAttribute("name");
+ if (name == null) {
+ throw new IllegalArgumentException("Must specify a 'name' attribute to set a property on the output message");
+ }
+ String xpath = element.getAttribute("select");
+ if (xpath == null) {
+ throw new IllegalArgumentException("Must specify a 'select' attribute to set a property on the output message");
+ }
+ XObject answer = ExsltDynamic.evaluate(context.getTransformer().getXPathContext().getExpressionContext(), xpath);
+ Object value;
+ try {
+ if (answer.getType() == XObject.CLASS_NUMBER) {
+ value = NumberUtils.createNumber(answer.str());
+ } else if (answer.getType() == XObject.CLASS_BOOLEAN) {
+ value = new Boolean(answer.bool());
+ } else {
+ // XObject guarantees we are never null.
+ value = answer.str();
+ }
+ } catch (TransformerException e) {
+ value = answer.str();
+ } catch (NumberFormatException e) {
+ value = answer.str();
+ }
+ out.setProperty(name, value);
+ }
+
+ // Extension XPath functions
+ //-------------------------------------------------------------------------
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected ComponentSupport getComponent(XSLProcessorContext context, Element element) {
+ return (ComponentSupport) getParameter(context, "component");
+ }
+
+ protected MessageExchange getExchange(XSLProcessorContext context, Element element) {
+ return (MessageExchange) getParameter(context, "exchange");
+ }
+
+ protected NormalizedMessage getInMessage(XSLProcessorContext context, Element element) {
+ return (NormalizedMessage) getParameter(context, "in");
+ }
+
+ protected NormalizedMessage getOutMessage(XSLProcessorContext context, Element element) {
+ return (NormalizedMessage) getParameter(context, "out");
+ }
+
+ protected Object getParameter(XSLProcessorContext context, String name) {
+ return context.getTransformer().getParameter(name);
+ }
+
+ protected QName getQNameAttribute(PrefixResolver namespaceContext, Element element, String name) {
+ String qualifiedName = element.getAttribute(name);
+ if (qualifiedName != null) {
+ int index = qualifiedName.indexOf(':');
+ if (index >= 0) {
+ String prefix = qualifiedName.substring(0, index);
+ String localName = qualifiedName.substring(index + 1);
+ String uri = namespaceContext.getNamespaceForPrefix(prefix);
+ return new QName(uri, localName, prefix);
+ }
+ else {
+ String uri = namespaceContext.getNamespaceForPrefix("");
+ if (uri != null) {
+ return new QName(uri, qualifiedName);
+ }
+ return new QName(qualifiedName);
+ }
+ }
+ return null;
+ }
+
+ protected String getAttribute(Element element, String attribute, String defaultValue) {
+ String answer = element.getAttribute(attribute);
+ if (answer == null || answer.length() == 0) {
+ answer = defaultValue;
+ }
+ return answer;
+ }
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java
new file mode 100644
index 0000000..8c804ce
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/XsltComponent.java
@@ -0,0 +1,275 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Templates;
+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.servicemix.MessageExchangeListener;
+import org.apache.servicemix.components.util.TransformComponentSupport;
+import org.apache.servicemix.jbi.jaxp.BytesSource;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.springframework.core.io.Resource;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * An <a href="http://www.w3.org/TR/xslt">XSLT</a> based JBI component using <a
+ * href="http://java.sun.com/xml/jaxp/">JAXP</a> to perform the XSLT
+ * transformation.
+ *
+ * @version $Revision: 464270 $
+ */
+public class XsltComponent extends TransformComponentSupport implements MessageExchangeListener {
+
+ private TransformerFactory transformerFactory;
+ private Source xsltSource;
+ private Resource xsltResource;
+ private Templates templates;
+ private boolean disableOutput;
+ private boolean useStringBuffer = true;
+ private boolean forceDocIfDom = true;
+ private Map xsltParameters;
+
+ /**
+ * @return the forceDocIfDom
+ */
+ public boolean isForceDocIfDom() {
+ return forceDocIfDom;
+ }
+
+ /**
+ * @param forceDocIfDom the forceDocIfDom to set
+ */
+ public void setForceDocIfDom(boolean forceDocIfDom) {
+ this.forceDocIfDom = forceDocIfDom;
+ }
+
+ // Properties
+ // -------------------------------------------------------------------------
+ public TransformerFactory getTransformerFactory() {
+ if (transformerFactory == null) {
+ transformerFactory = TransformerFactory.newInstance();
+ }
+ return transformerFactory;
+ }
+
+ public void setTransformerFactory(TransformerFactory transformerFactory) {
+ this.transformerFactory = transformerFactory;
+ }
+
+ public Source getXsltSource() throws Exception {
+ if (xsltSource == null) {
+ // lets create a new one each time
+ // as we can only read a stream once
+ xsltSource = createXsltSource();
+ }
+ return xsltSource;
+ }
+
+ public void setXsltSource(Source xsltSource) {
+ this.xsltSource = xsltSource;
+ }
+
+ public Resource getXsltResource() {
+ return xsltResource;
+ }
+
+ public void setXsltResource(Resource xsltResource) {
+ this.xsltResource = xsltResource;
+ }
+
+ public boolean isDisableOutput() {
+ return disableOutput;
+ }
+
+ public void setDisableOutput(boolean disableOutput) {
+ this.disableOutput = disableOutput;
+ }
+
+ public boolean isUseStringBuffer() {
+ return useStringBuffer;
+ }
+
+ public void setUseStringBuffer(boolean useStringBuffer) {
+ this.useStringBuffer = useStringBuffer;
+ }
+
+ /**
+ * @return the xsltParameters
+ */
+ public Map getXsltParameters() {
+ return xsltParameters;
+ }
+
+ /**
+ * @param xsltParameters the xsltParameters to set
+ */
+ public void setXsltParameters(Map xsltParameters) {
+ this.xsltParameters = xsltParameters;
+ }
+
+ // Implementation methods
+ // -------------------------------------------------------------------------
+ protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out)
+ throws MessagingException {
+ try {
+ Transformer transformer = createTransformer(exchange, in);
+ configureTransformer(transformer, exchange, in);
+ copyPropertiesAndAttachments(exchange, in, out);
+ transformContent(transformer, exchange, in, out);
+ return shouldOutputResult(transformer);
+ }
+ catch (Exception e) {
+ throw new MessagingException("Failed to transform: " + e, e);
+ }
+ }
+
+ protected void transformContent(Transformer transformer, MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws TransformerException, MessagingException, ParserConfigurationException {
+ Source src = in.getContent();
+ if (forceDocIfDom && src instanceof DOMSource) {
+ Node n = ((DOMSource) src).getNode();
+ if (n instanceof Document == false) {
+ Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+ doc.appendChild(doc.importNode(n, true));
+ src = new DOMSource(doc);
+ }
+ }
+ if (isUseStringBuffer()) {
+ StringWriter buffer = new StringWriter();
+ Result result = new StreamResult(buffer);
+ transformer.transform(src, result);
+ out.setContent(new StringSource(buffer.toString()));
+ }
+ else {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ Result result = new StreamResult(buffer);
+ transformer.transform(src, result);
+ out.setContent(new BytesSource(buffer.toByteArray()));
+ }
+ }
+
+ /**
+ * Should we disable output of the result of the XSLT?
+ */
+ protected boolean shouldOutputResult(Transformer transformer) {
+ if (disableOutput) {
+ return false;
+ }
+ return true;
+ /**
+ * String value = transformer.getOutputProperty("disableOutput"); return
+ * value == null || !value.equals("true");
+ */
+ }
+
+ protected Source createXsltSource() throws Exception {
+ if (xsltResource != null) {
+ return new DOMSource(parse(xsltResource));
+ }
+ return null;
+ }
+
+ protected Document parse(Resource res) throws Exception {
+ URL url = null;
+ try {
+ res.getURL();
+ } catch (IOException e) {
+ // Ignore
+ }
+ DocumentBuilder builder = new SourceTransformer().createDocumentBuilder();
+ return builder.parse(res.getInputStream(), url != null ? url.toExternalForm() : null);
+ }
+
+
+ public Templates getTemplates() throws Exception {
+ if (templates == null) {
+ templates = createTemplates();
+ }
+ return templates;
+ }
+
+ /**
+ * Factory method to create a new transformer instance
+ */
+ protected Templates createTemplates() throws Exception {
+ Source source = getXsltSource();
+ return getTransformerFactory().newTemplates(source);
+ }
+
+ /**
+ * Factory method to create a new transformer instance
+ */
+ protected Transformer createTransformer(MessageExchange exchange, NormalizedMessage in)
+ throws Exception {
+ Source source = getXsltSource();
+ if (source == null) {
+ return getTransformerFactory().newTransformer();
+ }
+ else {
+ return getTemplates().newTransformer();
+ }
+ }
+
+ /**
+ * A hook to allow the transformer to be configured from the current
+ * exchange and inbound message
+ */
+ protected void configureTransformer(Transformer transformer, MessageExchange exchange, NormalizedMessage in) {
+ for (Iterator iter = exchange.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = exchange.getProperty(name);
+ transformer.setParameter(name, value);
+ }
+ for (Iterator iter = in.getPropertyNames().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = in.getProperty(name);
+ transformer.setParameter(name, value);
+ }
+ if (xsltParameters != null) {
+ for (Iterator iter = xsltParameters.keySet().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = xsltParameters.get(name);
+ transformer.setParameter(name, value);
+ }
+ }
+ transformer.setParameter("exchange", exchange);
+ transformer.setParameter("in", in);
+ transformer.setParameter("component", this);
+ }
+
+}
diff --git a/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/package.html b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/package.html
new file mode 100644
index 0000000..c831662
--- /dev/null
+++ b/common/servicemix-components/src/main/java/org/apache/servicemix/components/xslt/package.html
@@ -0,0 +1,30 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<html>
+<head>
+</head>
+<body>
+
+<p>
+An <a href="http://www.w3.org/TR/xslt">XSLT</a> based JBI component using
+<a href="http://java.sun.com/xml/jaxp/">JAXP</a> to perform the XSLT transformation.
+</p>
+
+</body>
+</html>
diff --git a/common/servicemix-components/src/main/resources/META-INF/drools-servicemix.conf b/common/servicemix-components/src/main/resources/META-INF/drools-servicemix.conf
new file mode 100644
index 0000000..66ed265
--- /dev/null
+++ b/common/servicemix-components/src/main/resources/META-INF/drools-servicemix.conf
@@ -0,0 +1,25 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+module.uri=http://drools.org/semantics/servicemix
+
+ImportEntry(import) : org.drools.semantics.base.BaseImportEntryFactory
+ObjectType(class) : org.drools.semantics.base.ClassObjectTypeFactory
+Condition(condition) : org.apache.servicemix.components.drools.dsl.JaxenConditionFactory
+Consequence(invoke) : org.apache.servicemix.components.drools.dsl.InvokeConsequenceFactory
+Consequence(forward) : org.apache.servicemix.components.drools.dsl.ForwardConsequenceFactory
+Consequence(route) : org.apache.servicemix.components.drools.dsl.RouteConsequenceFactory
diff --git a/common/servicemix-components/src/main/resources/META-INF/drools.conf b/common/servicemix-components/src/main/resources/META-INF/drools.conf
new file mode 100644
index 0000000..0eade3c
--- /dev/null
+++ b/common/servicemix-components/src/main/resources/META-INF/drools.conf
@@ -0,0 +1,17 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+drools-servicemix
\ No newline at end of file
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/cache/CacheTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/cache/CacheTest.java
new file mode 100644
index 0000000..1ca363b
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/cache/CacheTest.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.cache;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.api.EndpointResolver;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Revision: 690396 $
+ */
+public class CacheTest extends TestSupport {
+ private static transient Log log = LogFactory.getLog(CacheTest.class);
+
+ public void testCache() throws Exception {
+ EndpointResolver cachedService = client.createResolverForService(new QName("http://servicemix.org/cheese/", "myService"));
+ EndpointResolver service = client.createResolverForService(new QName("http://servicemix.org/cheese/", "myServiceImpl"));
+
+ Object object = client.request(cachedService, null, null, "<foo id='123'/>");
+ if (object instanceof Node) {
+ object = new DOMSource((Node) object);
+ }
+ String text = transformer.toString((Source) object);
+
+ log.info("Cache: Received response: " + text);
+
+ object = client.request(cachedService, null, null, "<foo id='123'/>");
+ if (object instanceof Node) {
+ object = new DOMSource((Node) object);
+ }
+ String text2 = transformer.toString((Source) object);
+
+ log.info("Cache: Received response: " + text2);
+
+ assertEquals("Responses should be equal", text, text2);
+
+
+ // now lets try the underlying service to check we get different results each time
+ object = client.request(service, null, null, "<foo id='123'/>");
+ if (object instanceof Node) {
+ object = new DOMSource((Node) object);
+ }
+ text = transformer.toString((Source) object);
+
+ log.info("ServiceImpl: Received response: " + text);
+
+ object = client.request(service, null, null, "<foo id='123'/>");
+ if (object instanceof Node) {
+ object = new DOMSource((Node) object);
+ }
+ text2 = transformer.toString((Source) object);
+
+ log.info("ServiceImpl: Received response: " + text2);
+
+ assertTrue("Responses should be different but were both: " + text, !text.equals(text2));
+
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/cache/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsRouteTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsRouteTest.java
new file mode 100644
index 0000000..1f8d3a9
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsRouteTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * @version $Revision: 376451 $
+ */
+public class DroolsRouteTest extends TestSupport {
+
+ public void testFiringRules() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "droolsRouter");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.setService(service);
+ NormalizedMessage message = exchange.getInMessage();
+ message.setContent(new StringSource(createMessageXmlText(1)));
+ client.sendSync(exchange);
+ assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+ Node node = transformer.toDOMNode(exchange.getOutMessage().getContent());
+ Element e = null;
+ if (node instanceof Element) {
+ e = (Element) node;
+ } else if (node instanceof Document) {
+ e = ((Document) node).getDocumentElement();
+ } else {
+ fail("Node should be an Element or a Document");
+ }
+ assertEquals("hello", e.getLocalName());
+ client.done(exchange);
+
+ exchange = client.createInOutExchange();
+ exchange.setService(service);
+ message = exchange.getInMessage();
+ message.setContent(new StringSource(createMessageXmlText(2)));
+ client.sendSync(exchange);
+ assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+ node = transformer.toDOMNode(exchange.getOutMessage().getContent());
+ e = null;
+ if (node instanceof Element) {
+ e = (Element) node;
+ } else if (node instanceof Document) {
+ e = ((Document) node).getDocumentElement();
+ } else {
+ fail("Node should be an Element or a Document");
+ }
+ assertEquals("world", e.getLocalName());
+ client.done(exchange);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/drools/jbi-example-route.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsTest.java
new file mode 100644
index 0000000..6a89031
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class DroolsTest extends TestSupport {
+
+ public void testFiringRules() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "droolsRouter");
+
+ sendMessages(service, 20);
+ assertMessagesReceived(19);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/drools/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsWithJbiRulesForwardTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsWithJbiRulesForwardTest.java
new file mode 100644
index 0000000..dd94610
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsWithJbiRulesForwardTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools;
+
+import javax.xml.namespace.QName;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class DroolsWithJbiRulesForwardTest extends DroolsTest {
+
+ public void testFiringRules() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "droolsRouter");
+
+ sendMessages(service, 3);
+ assertMessagesReceived(4);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new org.apache.xbean.spring.context.ClassPathXmlApplicationContext("org/apache/servicemix/components/drools/jbi-example-forward.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsWithJbiRulesTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsWithJbiRulesTest.java
new file mode 100644
index 0000000..92c46c5
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/drools/DroolsWithJbiRulesTest.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.drools;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class DroolsWithJbiRulesTest extends DroolsTest {
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/drools/jbi-example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/EmailTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/EmailTest.java
new file mode 100644
index 0000000..34c401b
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/EmailTest.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import java.util.Date;
+
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class EmailTest extends TestSupport {
+
+ public void testSendUsingMessageProperties() throws Exception {
+
+ // START SNIPPET: email
+ InOnly exchange = client.createInOnlyExchange();
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setProperty("org.apache.servicemix.email.to", "scm@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.from", "junit@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.subject", "Hello from JUnit!");
+ message.setProperty("org.apache.servicemix.email.text", "Hi from test case: " + getName() + " running at: " + new Date());
+
+ client.sendSync(exchange);
+ // END SNIPPET: email
+
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/email/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java
new file mode 100644
index 0000000..e6609b1
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/MimeMailTest.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.activation.DataHandler;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.mail.Part;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMultipart;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
+import org.apache.servicemix.jbi.util.ByteArrayDataSource;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class MimeMailTest extends TestSupport {
+
+ private static transient Log log = LogFactory.getLog(MimeMailTest.class);
+
+ public void testSendUsingMessageProperties() throws Exception {
+
+ // START SNIPPET: email
+ InOnly exchange = client.createInOnlyExchange();
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setProperty("org.apache.servicemix.email.to", "scm@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.from", "junit@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.subject", "Hello from JUnit!");
+ message.setProperty("org.apache.servicemix.email.text", "Hi from test case: " + getName() + " running at: " + new Date());
+
+ client.send(exchange);
+ // END SNIPPET: email
+
+ // lest find the test sender
+ StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender");
+ sender.assertMessagesReceived(1);
+ List messages = sender.getMessages();
+ assertEquals("message size: " + messages, 1, messages.size());
+
+ MimeMessage mail = (MimeMessage) messages.get(0);
+
+ log.info("Created message: " + message);
+
+ assertEquals("subject", "Hello from JUnit!", mail.getSubject());
+ }
+
+ public void testSendUsingMessagePropertiesWithMultipleRecipients() throws Exception {
+
+ // START SNIPPET: email
+ InOnly exchange = client.createInOnlyExchange();
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setProperty("org.apache.servicemix.email.to", "scm@servicemix.org,foo@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.cc", "bar@servicemix.org,baz@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.bcc", "guinness@servicemix.org,harper@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.from", "junit@servicemix.org");
+ message.setProperty("org.apache.servicemix.email.subject", "Hello from JUnit!");
+ message.setProperty("org.apache.servicemix.email.text", "Hi from test case: " + getName() + " running at: " + new Date());
+
+ client.send(exchange);
+ // END SNIPPET: email
+
+ // lest find the test sender
+ StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender");
+ sender.assertMessagesReceived(1);
+ List messages = sender.getMessages();
+ assertEquals("message size: " + messages, 1, messages.size());
+
+ MimeMessage mail = (MimeMessage) messages.get(0);
+
+ log.info("Created message: " + message);
+
+ assertEquals("subject", "Hello from JUnit!", mail.getSubject());
+ }
+
+ public void testUsingXPathExpressionsInEmail() throws Exception {
+
+ // START SNIPPET: xpath
+ QName xpathSender = new QName("http://servicemix.org/cheese/", "emailSenderWithExpressions");
+ ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(xpathSender);
+
+ InOnly exchange = client.createInOnlyExchange(resolver);
+
+ Source source = getSourceFromClassPath("request.xml");
+ exchange.getInMessage().setContent(source);
+
+ client.send(exchange);
+ // END SNIPPET: xpath
+
+ // lest find the test sender
+ StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender");
+ sender.assertMessagesReceived(1);
+ List messages = sender.getMessages();
+ assertEquals("message size: " + messages, 1, messages.size());
+
+ MimeMessage message = (MimeMessage) messages.get(0);
+
+ log.info("Created message: " + message);
+
+ assertEquals("subject", "Drink a beer James", message.getSubject());
+ }
+
+ public void testUsingXPathExpressionsInEmailWithAttachment() throws Exception {
+
+ // START SNIPPET: xpath
+ QName xpathSender = new QName("http://servicemix.org/cheese/", "emailSenderWithExpressionsAndAttachment");
+ ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(xpathSender);
+
+ InOnly exchange = client.createInOnlyExchange(resolver);
+
+ Source source = getSourceFromClassPath("request.xml");
+ exchange.getInMessage().setContent(source);
+ ByteArrayDataSource ds = new ByteArrayDataSource("hello".getBytes(), "text/plain");
+ ds.setName("id");
+ exchange.getInMessage().addAttachment("id", new DataHandler(ds));
+
+ client.send(exchange);
+ // END SNIPPET: xpath
+
+ // lest find the test sender
+ StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender");
+ sender.assertMessagesReceived(1);
+ List messages = sender.getMessages();
+ assertEquals("message size: " + messages, 1, messages.size());
+
+ MimeMessage message = (MimeMessage) messages.get(0);
+
+ log.info("Created message: " + message);
+ Object content = message.getContent();
+ assertTrue(content instanceof MimeMultipart);
+ MimeMultipart contentMP = (MimeMultipart) content;
+ assertEquals(contentMP.getCount(), 3); // first attachement for text body and second for file attached
+ Part part = contentMP.getBodyPart(0);
+ assertTrue(part.isMimeType("text/plain"));
+ Set names = new HashSet();
+ part = contentMP.getBodyPart(1);
+ String disposition = part.getDisposition();
+ assertTrue(disposition.equalsIgnoreCase(Part.ATTACHMENT));
+ DataHandler att = part.getDataHandler();
+ names.add(att.getName().toLowerCase());
+ part = contentMP.getBodyPart(2);
+ disposition = part.getDisposition();
+ assertTrue(disposition.equalsIgnoreCase(Part.ATTACHMENT));
+ att = part.getDataHandler();
+ names.add(att.getName().toLowerCase());
+ assertTrue(names.contains("example.xml"));
+ assertTrue(names.contains("id"));
+ assertEquals("subject", "Drink a beer James", message.getSubject());
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/email/mimeMail.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/SimpleMailTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/SimpleMailTest.java
new file mode 100644
index 0000000..90cfd80
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/SimpleMailTest.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.mail.SimpleMailMessage;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class SimpleMailTest extends TestSupport {
+
+ private static final transient Log log = LogFactory.getLog(SimpleMailTest.class);
+
+ public void testUsingXPathExpressionsInSimpleEmail() throws Exception {
+
+ // START SNIPPET: xpathSimple
+ QName xpathSender = new QName("http://servicemix.org/cheese/", "simpleMailSenderWithExpressions");
+ ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(xpathSender);
+
+ InOnly exchange = client.createInOnlyExchange(resolver);
+
+ Source source = getSourceFromClassPath("request.xml");
+ exchange.getInMessage().setContent(source);
+
+ client.send(exchange);
+ // END SNIPPET: xpathSimple
+
+ // lest find the test sender
+ StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender");
+ sender.assertMessagesReceived(1);
+
+ List messages = sender.getMessages();
+ assertEquals("message size: " + messages, 1, messages.size());
+
+ SimpleMailMessage message = (SimpleMailMessage) messages.get(0);
+
+ log.info("Created message: " + message);
+
+ assertEquals("text", "Hello there James how are you today?", message.getText());
+ assertEquals("from", "james@nowhere.com", message.getFrom());
+ }
+
+ public void testUsingPropertyExpressionsInSimpleEmail() throws Exception {
+ // START SNIPPET: xpathSimple
+ QName xpathSender = new QName("http://servicemix.org/cheese/", "simpleMailSenderWithPropertyExpressions");
+ ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(xpathSender);
+
+ InOnly exchange = client.createInOnlyExchange(resolver);
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setProperty("to", "scm@servicemix.org");
+ message.setProperty("from", "junit@servicemix.org");
+ message.setProperty("text", "Hi from test case: " + getName() + " running at: " + new Date());
+
+ client.send(exchange);
+ // END SNIPPET: xpathSimple
+
+ // lest find the test sender
+ StubJavaMailSender sender = (StubJavaMailSender) getBean("javaMailSender");
+ sender.assertMessagesReceived(1);
+
+ List messages = sender.getMessages();
+
+ assertEquals("message size: " + messages, 1, messages.size());
+
+ SimpleMailMessage mailMessage = (SimpleMailMessage) messages.get(0);
+
+ log.info("Created message: " + mailMessage);
+
+ assertEquals("subject", "Subject came from expression", mailMessage.getSubject());
+ assertEquals("from", "junit@servicemix.org", mailMessage.getFrom());
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/email/simpleMail.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/StubJavaMailSender.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/StubJavaMailSender.java
new file mode 100644
index 0000000..fea7aad
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/email/StubJavaMailSender.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.email;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.mail.Session;
+import javax.mail.internet.MimeMessage;
+
+import junit.framework.Assert;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.mail.MailException;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMessagePreparator;
+
+/**
+ * A stub {@link JavaMailSender} useful for testing.
+ *
+ * @version $Revision: 556864 $
+ */
+public class StubJavaMailSender extends Assert implements JavaMailSender {
+
+ private static transient Log log = LogFactory.getLog(StubJavaMailSender.class);
+
+ private List messages = new ArrayList();
+ private Object semaphore = new Object();
+
+ public void send(MimeMessage mimeMessage) throws MailException {
+ addMessage(mimeMessage);
+ }
+
+ public void send(MimeMessagePreparator preparator) throws MailException {
+ try {
+ MimeMessage message = createMimeMessage();
+ preparator.prepare(message);
+ send(message);
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public MimeMessage createMimeMessage() {
+ return new MimeMessage((Session) null);
+ }
+
+ public MimeMessage createMimeMessage(InputStream inputStream) throws MailException {
+ return createMimeMessage();
+ }
+
+ public void send(MimeMessage[] messages) throws MailException {
+ for (int i = 0; i < messages.length; i++) {
+ MimeMessage message = messages[i];
+ send(message);
+ }
+ }
+
+ public void send(MimeMessagePreparator[] preparators) throws MailException {
+ for (int i = 0; i < preparators.length; i++) {
+ MimeMessagePreparator preparator = preparators[i];
+ send(preparator);
+ }
+ }
+
+ public void send(SimpleMailMessage simpleMailMessage) throws MailException {
+ addMessage(simpleMailMessage);
+ }
+
+ public void send(SimpleMailMessage[] simpleMailMessages) throws MailException {
+ for (int i = 0; i < simpleMailMessages.length; i++) {
+ SimpleMailMessage simpleMailMessage = simpleMailMessages[i];
+ send(simpleMailMessage);
+ }
+ }
+
+
+ /**
+ * @return all the messages on the list so far, clearing the buffer
+ */
+ public List flushMessages() {
+ synchronized (semaphore) {
+ List answer = new ArrayList(messages);
+ messages.clear();
+ return answer;
+ }
+ }
+
+ public synchronized List getMessages() {
+ synchronized (semaphore) {
+ return new ArrayList(messages);
+ }
+ }
+
+ public void addMessage(Object message) {
+ synchronized (semaphore) {
+ messages.add(message);
+ semaphore.notifyAll();
+ }
+ }
+
+ public int getMessageCount() {
+ synchronized (semaphore) {
+ return messages.size();
+ }
+ }
+
+
+ public void waitForMessagesToArrive(int messageCount) {
+ log.info("Waiting for message to arrive");
+
+ long start = System.currentTimeMillis();
+
+ for (int i = 0; i < messageCount; i++) {
+ try {
+ if (hasReceivedMessages(messageCount)) {
+ break;
+ }
+ synchronized (semaphore) {
+ semaphore.wait(4000);
+ }
+ }
+ catch (InterruptedException e) {
+ log.info("Caught: " + e);
+ }
+ }
+ long end = System.currentTimeMillis() - start;
+
+ log.info("End of wait for " + end + " millis");
+ }
+
+
+ /**
+ * Performs a testing assertion that the correct number of messages have been received
+ *
+ * @param messageCount
+ */
+ public void assertMessagesReceived(int messageCount) {
+ waitForMessagesToArrive(messageCount);
+
+ assertEquals("expected number of messages", messageCount, getMessageCount());
+ log.info("Received messages: " + getMessages());
+ }
+
+ public boolean hasReceivedMessage() {
+ return getMessageCount() == 0;
+ }
+
+ public boolean hasReceivedMessages(int messageCount) {
+ return getMessageCount() >= messageCount;
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/file/BinaryFileTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/file/BinaryFileTest.java
new file mode 100644
index 0000000..2387d78
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/file/BinaryFileTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.file;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileWriter;
+
+import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 359213 $
+ */
+public class BinaryFileTest extends TestSupport {
+
+ protected void setUp() throws Exception {
+ FileUtil.deleteFile(new File("target/test-data/in"));
+ FileUtil.deleteFile(new File("target/test-data/out"));
+ super.setUp();
+ }
+
+ public void testSendBinary() throws Exception {
+ String contents = "Binary content";
+ FileWriter fw = new FileWriter("target/test-data/in/file.txt");
+ fw.write(contents);
+ fw.close();
+
+ File output = null;
+ long start = System.currentTimeMillis();
+ while (System.currentTimeMillis() - start < 5000) {
+ File outDir = new File("target/test-data/out");
+ File[] files = outDir.listFiles();
+ if (files != null && files.length > 0) {
+ output = files[0];
+ break;
+ }
+ Thread.sleep(50);
+ }
+ if (output == null) {
+ fail("No output file found");
+ }
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileUtil.copyInputStream(new FileInputStream(output), baos);
+ String outContents = baos.toString();
+ assertEquals(contents, outContents);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/file/binary-example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/file/FileTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/file/FileTest.java
new file mode 100644
index 0000000..dadf930
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/file/FileTest.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.file;
+
+import java.io.File;
+
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class FileTest extends TestSupport {
+
+ protected void setUp() throws Exception {
+ FileUtil.deleteFile(new File("target/test-data/file"));
+ super.setUp();
+ }
+
+ public void testSendMessagesToFileSystemThenPoollThem() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "fileSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/file/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/GroovyChainTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/GroovyChainTest.java
new file mode 100644
index 0000000..46fdfdf
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/GroovyChainTest.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.groovy;
+
+import java.io.StringReader;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.tck.Receiver;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class GroovyChainTest extends TestCase {
+ private static transient Log log = LogFactory.getLog(GroovyChainTest.class);
+
+ protected AbstractXmlApplicationContext context;
+ protected ServiceMixClient client;
+ protected Receiver receiver;
+
+ protected SourceTransformer transformer = new SourceTransformer();
+
+
+ // Send methods
+ //-------------------------------------------------------------------------
+ public void testChain() throws Exception {
+
+ InOut exchange = client.createInOutExchange();
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ QName service = new QName("http://servicemix.org/cheese/", "receiver");
+ exchange.setService(service);
+ client.sendSync(exchange);
+
+ log.info(transformer.toString(exchange.getMessage("out").getContent()));
+ }
+
+
+ protected void setUp() throws Exception {
+ context = createBeanFactory();
+ //context.setXmlValidating(false);
+
+ client = (ServiceMixClient) getBean("client");
+
+ // TODO
+ //receiver = (Receiver) getBean("receiver");
+
+ SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
+ assertNotNull(jbi);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ if (context != null) {
+ context.close();
+ }
+ }
+
+ protected Object getBean(String name) {
+ Object answer = context.getBean(name);
+ assertNotNull("Could not find object in Spring for key: " + name, answer);
+ return answer;
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/groovy/groovy-chain.xml");
+
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/GroovyTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/GroovyTest.java
new file mode 100644
index 0000000..157e573
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/GroovyTest.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.groovy;
+
+import org.apache.servicemix.components.groovy.GroovyComponent;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class GroovyTest extends SpringTestSupport {
+
+ public void testSendingAndReceivingMessagesUsingSpring() throws Exception {
+ GroovyComponent component = (GroovyComponent) getBean("receiver");
+ assertNotNull(component);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/groovy/spring-groovy.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/ServiceMixClientTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/ServiceMixClientTest.java
new file mode 100644
index 0000000..91697b1
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/ServiceMixClientTest.java
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.groovy;
+
+import java.io.StringReader;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.api.EndpointResolver;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.tck.Receiver;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 733499 $
+ */
+public class ServiceMixClientTest extends TestCase {
+ private static transient Log log = LogFactory.getLog(ServiceMixClientTest.class);
+
+ protected AbstractXmlApplicationContext context;
+ protected SpringJBIContainer container;
+ protected ServiceMixClient client;
+ protected Receiver receiver;
+
+ protected SourceTransformer transformer = new SourceTransformer();
+
+
+ // Send methods
+ //-------------------------------------------------------------------------
+ public void testSendUsingJbiAPIs() throws Exception {
+
+ InOnly exchange = client.createInOnlyExchange();
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setProperty("name", "James");
+ message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ QName service = new QName("http://servicemix.org/cheese/", "receiver");
+ exchange.setService(service);
+ client.send(exchange);
+
+ receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ public void testSendWithErrorUsingJbiAPIs() throws Exception {
+
+ MessageExchange exchange = client.createInOnlyExchange();
+
+ NormalizedMessage message = exchange.getMessage("in");
+ message.setProperty("name", "James");
+ message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ activateComponent(new ReturnErrorComponent(), "error");
+
+ QName service = new QName("error");
+ exchange.setService(service);
+ client.send(exchange);
+
+ exchange = client.receive();
+ assertEquals(ExchangeStatus.ERROR, exchange.getStatus());
+ }
+
+ public void testSendWithFaultUsingJbiAPIs() throws Exception {
+
+ MessageExchange exchange = client.createRobustInOnlyExchange();
+
+ NormalizedMessage message = exchange.getMessage("in");
+ message.setProperty("name", "James");
+ message.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ activateComponent(new ReturnFaultComponent(), "fault");
+
+ QName service = new QName("fault");
+ exchange.setService(service);
+ client.send(exchange);
+
+ exchange = client.receive();
+ assertEquals(ExchangeStatus.ACTIVE, exchange.getStatus());
+ assertNotNull(exchange.getFault());
+ client.done(exchange);
+ }
+
+ public void testSendUsingMapAndPOJOsByServiceName() throws Exception {
+
+ Map properties = new HashMap();
+ properties.put("name", "James");
+
+ QName service = new QName("http://servicemix.org/cheese/", "receiver");
+ EndpointResolver resolver = client.createResolverForService(service);
+ client.send(resolver, null, properties, "<hello>world</hello>");
+
+ receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ public void testSendUsingMapAndPOJOsUsingContainerRouting() throws Exception {
+
+ ServiceMixClient clientNoRouting = (ServiceMixClient) context.getBean("clientWithRouting");
+
+ Map properties = new HashMap();
+ properties.put("name", "James");
+
+ clientNoRouting.send(null, null, properties, "<hello>world</hello>");
+
+ receiver.getMessageList().assertMessagesReceived(1);
+ }
+
+ public void testSendUsingMapAndPOJOsUsingContainerRoutingWithNoConfiguration() throws Exception {
+
+
+ try {
+ Map properties = new HashMap();
+ properties.put("name", "James");
+
+ client.send(null, null, properties, "<hello>world</hello>");
+ fail("Should have thrown an exception as we have not wired in any container routing information to this client");
+ }
+ catch (JBIException e) {
+ log.info("Caught expected exception as we have specified no endpoint resolver: " + e);
+ assertNotNull(e);
+ }
+ }
+
+
+ // Request methods
+ //-------------------------------------------------------------------------
+ public void testRequestUsingJbiAPIsByServiceName() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myService");
+ assertRequestUsingJBIAPIs(service);
+ }
+
+ public void testRequestUsingMapAndPOJOsByServiceName() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myService");
+ assertRequestUsingMapAndPOJOByServiceName(service);
+ }
+
+ public void testRequestUsingPOJOWithXStreamMarshaling() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myService");
+
+ ServiceMixClient client = (ServiceMixClient) context.getBean("clientWithXStream");
+
+ Map properties = new HashMap();
+ properties.put("name", "James");
+
+ EndpointResolver resolver = client.createResolverForService(service);
+ TestBean bean = new TestBean();
+ bean.setName("James");
+ bean.setLength(12);
+ bean.getAddresses().addAll(Arrays.asList(new String[] {"London", "LA"}));
+
+ Object response = client.request(resolver, null, properties, bean);
+
+ assertNotNull("Should have returned a non-null response!", response);
+
+ log.info("Received result: " + response);
+ }
+
+
+
+ // Implementation methods
+ //-------------------------------------------------------------------------
+ protected void assertRequestUsingJBIAPIs(QName service) throws Exception {
+ InOut exchange = client.createInOutExchange();
+
+ NormalizedMessage inMessage = exchange.getInMessage();
+ inMessage.setProperty("name", "James");
+ inMessage.setContent(new StreamSource(new StringReader("<hello>world</hello>")));
+
+ exchange.setService(service);
+ boolean answer = client.sendSync(exchange);
+ assertTrue("Should have successed", answer);
+
+ NormalizedMessage outMessage = exchange.getOutMessage();
+ assertNotNull("outMessage is null!", outMessage);
+
+ assertEquals("foo header", "hello", outMessage.getProperty("foo"));
+ log.info("Received result: " + outMessage.getContent());
+ log.info("XML is: " + transformer.toString(outMessage.getContent()));
+ }
+
+ protected void assertRequestUsingMapAndPOJOByServiceName(QName service) throws Exception {
+ Map properties = new HashMap();
+ properties.put("name", "James");
+
+ EndpointResolver resolver = (EndpointResolver)client.createResolverForService(service);
+ Object response = client.request(resolver, null, properties, "<hello>world</hello>");
+
+ assertNotNull("Should have returned a non-null response!", response);
+
+ log.info("Received result: " + response);
+ }
+
+ protected void setUp() throws Exception {
+ context = createBeanFactory();
+ //context.setXmlValidating(false);
+
+ client = (ServiceMixClient) getBean("client");
+
+ // TODO
+ //receiver = (Receiver) getBean("receiver");
+
+ container = (SpringJBIContainer) getBean("jbi");
+ receiver = (Receiver) container.getBean("receiver");
+ assertNotNull("receiver not found in JBI container", receiver);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+
+ if (context != null) {
+ context.close();
+ }
+ }
+
+ protected Object getBean(String name) {
+ Object answer = context.getBean(name);
+ assertNotNull("Could not find object in Spring for key: " + name, answer);
+ return answer;
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/groovy/example.xml");
+
+ }
+
+ protected void activateComponent(ComponentSupport comp, String name) throws Exception {
+ comp.setService(new QName(name));
+ comp.setEndpoint("endpoint");
+ container.activateComponent(comp, name);
+ }
+
+ public static class ReturnErrorComponent extends ComponentSupport implements MessageExchangeListener {
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ fail(exchange, new Exception());
+ }
+ }
+ }
+
+ public static class ReturnFaultComponent extends ComponentSupport implements MessageExchangeListener {
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ Fault fault = exchange.createFault();
+ fault.setContent(new StringSource("<fault/>"));
+ fail(exchange, fault);
+ }
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/TestBean.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/TestBean.java
new file mode 100644
index 0000000..2b6a611
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/groovy/TestBean.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.groovy;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A sample test bean used to test out XStream marshalling
+ *
+ * @version $Revision: 426415 $
+ */
+public class TestBean {
+ private String name;
+ private int length;
+ private List addresses = new ArrayList();
+
+ public List getAddresses() {
+ return addresses;
+ }
+
+ public void setAddresses(List addresses) {
+ this.addresses = addresses;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public void setLength(int length) {
+ this.length = length;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
new file mode 100644
index 0000000..047120c
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAndSaajTest.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.messaging.URLEndpoint;
+import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+
+import junit.framework.TestCase;
+
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.xbean.BrokerFactoryBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.saaj.SaajBinding;
+import org.apache.servicemix.components.util.MockServiceComponent;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
+import org.apache.xpath.CachedXPathAPI;
+import org.springframework.core.io.ClassPathResource;
+
+public class HttpSoapAndSaajTest extends TestCase {
+
+ private static final int PORT_1 = 7012;
+ private static final int PORT_2 = 7012;
+ private static final int PORT_WS_1 = 7014;
+ private static final int PORT_WS_2 = 7014;
+
+ private static transient Log log = LogFactory.getLog(HttpSoapAndSaajTest.class);
+
+ protected JBIContainer container;
+ protected BrokerService broker;
+
+ protected void setUp() throws Exception {
+ BrokerFactoryBean bfb = new BrokerFactoryBean(new ClassPathResource("broker.xml"));
+ bfb.afterPropertiesSet();
+ broker = bfb.getBroker();
+ broker.start();
+ container = new JBIContainer();
+ container.setMonitorInstallationDirectory(false);
+ container.setUseMBeanServer(false);
+ container.setCreateMBeanServer(false);
+ container.setEmbedded(true);
+ container.setFlowName("jms?jmsURL=tcp://localhost:61626");
+ container.init();
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ if (container != null) {
+ container.shutDown();
+ }
+ if (broker != null) {
+ broker.stop();
+ }
+ }
+
+ public void testInOut() throws Exception {
+ ActivationSpec as = new ActivationSpec();
+ as.setId("saaj");
+ SaajBinding saaj = new SaajBinding();
+ saaj.setSoapEndpoint(new URLEndpoint("http://localhost:" + PORT_WS_1));
+ as.setComponent(saaj);
+ as.setService(new QName("saaj"));
+ container.activateComponent(as);
+
+ as = new ActivationSpec();
+ as.setId("xfireBinding");
+ as.setComponent(new HttpSoapConnector(null, PORT_2, true));
+ as.setDestinationService(new QName("saaj"));
+ container.activateComponent(as);
+
+ as = new ActivationSpec();
+ as.setId("webservice");
+ as.setComponent(new HttpConnector(null, PORT_WS_2));
+ as.setDestinationService(new QName("mock"));
+ container.activateComponent(as);
+
+ as = new ActivationSpec();
+ as.setId("mock");
+ MockServiceComponent mock = new MockServiceComponent();
+ mock.setResponseResource(new ClassPathResource("soap-response.xml", getClass()));
+ as.setComponent(mock);
+ as.setService(new QName("mock"));
+ container.activateComponent(as);
+
+ URLConnection connection = new URL("http://localhost:" + PORT_1).openConnection();
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ ((HttpURLConnection) connection).setRequestProperty("Content-Type", "text/xml; charset=utf-8;");
+ OutputStream os = connection.getOutputStream();
+ // Post the request file.
+ InputStream fis = getClass().getResourceAsStream("soap-request.xml");
+ FileUtil.copyInputStream(fis, os);
+ // Read the response.
+ InputStream is = connection.getInputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileUtil.copyInputStream(is, baos);
+
+ // Check xml validity
+ Node node = new SourceTransformer().toDOMNode(new StringSource(baos.toString()));
+
+ OutputFormat format = new OutputFormat((Document) node);
+ format.setLineWidth(65);
+ format.setIndenting(true);
+ format.setIndent(2);
+
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ XMLSerializer serializer = new XMLSerializer(output, format);
+ serializer.serialize((Document) node);
+ log.info(output.toString());
+
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'userId']");
+ Element root = (Element) iterator.nextNode();
+ QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
+ assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+ assertEquals("string", qname.getLocalPart());
+
+ }
+
+ protected String textValueOfXPath(Node node, String xpath) throws TransformerException {
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, xpath);
+ Node root = iterator.nextNode();
+ if (root instanceof Element) {
+ Element element = (Element) root;
+ if (element == null) {
+ return "";
+ }
+ String text = DOMUtil.getElementText(element);
+ return text;
+ }
+ else {
+ return root.getNodeValue();
+ }
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAttachmentsTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAttachmentsTest.java
new file mode 100644
index 0000000..a265806
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapAttachmentsTest.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+import javax.mail.MessagingException;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.EchoComponent;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.codehaus.xfire.attachments.JavaMailAttachments;
+import org.codehaus.xfire.attachments.SimpleAttachment;
+
+public class HttpSoapAttachmentsTest extends TestCase {
+ private static transient Log log = LogFactory.getLog(HttpSoapAttachmentsTest.class);
+
+ private static final int PORT = 7012;
+
+ protected JBIContainer container;
+
+ protected void setUp() throws Exception {
+ container = new JBIContainer();
+ container.setMonitorInstallationDirectory(false);
+ container.setUseMBeanServer(false);
+ container.setCreateMBeanServer(false);
+ container.setEmbedded(true);
+ container.init();
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ if (container != null) {
+ container.shutDown();
+ }
+ }
+
+ public void testWithAttachments() throws Exception {
+ ActivationSpec as = new ActivationSpec();
+ as.setId("echo");
+ as.setComponent(new EchoComponent());
+ as.setService(new QName("echo"));
+ container.activateComponent(as);
+ as = new ActivationSpec();
+ as.setId("xfireBinding");
+ as.setComponent(new HttpSoapConnector(null, PORT, true));
+ as.setDestinationService(new QName("echo"));
+ container.activateComponent(as);
+
+ JavaMailAttachments sendAtts = new JavaMailAttachments();
+ sendAtts.setSoapMessage(new SimpleAttachment("soap-request.xml",
+ createDataHandler("soap-request.xml")));
+ sendAtts.addPart(new SimpleAttachment("ServiceMix.jpg",
+ createDataHandler("ServiceMix.jpg")));
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ sendAtts.write(bos);
+ InputStream is = new ByteArrayInputStream(bos.toByteArray());
+ PostMethod method = new PostMethod("http://localhost:" + PORT);
+ method.setRequestEntity(new InputStreamRequestEntity(is));
+ method.setRequestHeader("Content-Type", sendAtts.getContentType());
+ new HttpClient().executeMethod(method);
+ log.info(method.getResponseBodyAsString());
+ }
+
+ private DataHandler createDataHandler(String name) throws MessagingException {
+ File f = new File(getClass().getResource(name).getPath());
+ FileDataSource fs = new FileDataSource(f);
+ return new DataHandler(fs);
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapTest.java
new file mode 100644
index 0000000..9367755
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapTest.java
@@ -0,0 +1,253 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.StringRequestEntity;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.util.EchoComponent;
+import org.apache.servicemix.components.util.MockServiceComponent;
+import org.apache.servicemix.components.util.TraceComponent;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.messaging.InOnlyImpl;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.servicemix.tck.ReceiverComponent;
+import org.apache.xpath.CachedXPathAPI;
+import org.springframework.core.io.ClassPathResource;
+
+public class HttpSoapTest extends TestCase {
+ private static transient Log log = LogFactory.getLog(HttpSoapTest.class);
+
+ protected JBIContainer container;
+
+ protected void setUp() throws Exception {
+ System.setProperty("DEBUG", "true");
+ container = new JBIContainer();
+ container.setMonitorInstallationDirectory(false);
+ container.setUseMBeanServer(false);
+ container.setCreateMBeanServer(false);
+ container.setEmbedded(true);
+ container.init();
+ container.start();
+ }
+
+ protected void tearDown() throws Exception {
+ if (container != null) {
+ container.shutDown();
+ }
+ }
+
+ public void testInOut() throws Exception {
+ int PORT = 7012;
+ ActivationSpec as = new ActivationSpec();
+ as.setId("echo");
+ as.setComponent(new EchoComponent());
+ as.setService(new QName("echo"));
+ container.activateComponent(as);
+ as = new ActivationSpec();
+ as.setId("xfireBinding");
+ as.setComponent(new HttpSoapConnector(null, PORT, true));
+ as.setDestinationService(new QName("echo"));
+ container.activateComponent(as);
+
+ URLConnection connection = new URL("http://localhost:" + PORT).openConnection();
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ OutputStream os = connection.getOutputStream();
+ // Post the request file.
+ InputStream fis = getClass().getResourceAsStream("soap-request.xml");
+ FileUtil.copyInputStream(fis, os);
+ // Read the response.
+ InputStream is = connection.getInputStream();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ FileUtil.copyInputStream(is, baos);
+ log.info(baos.toString());
+ }
+
+ public void testInOnly() throws Exception {
+ int PORT = 7013;
+ ActivationSpec as = new ActivationSpec();
+ as.setId("trace");
+ as.setComponent(new TraceComponent());
+ as.setService(new QName("trace"));
+ container.activateComponent(as);
+ as = new ActivationSpec();
+ as.setId("xfireBinding");
+ as.setComponent(new HttpSoapConnector(null, PORT, false));
+ as.setDestinationService(new QName("trace"));
+ container.activateComponent(as);
+
+ PostMethod method = new PostMethod("http://localhost:" + PORT + "/?name=Guillaume");
+ method.setRequestEntity(new InputStreamRequestEntity(getClass().getResourceAsStream("soap-request.xml")));
+ new HttpClient().executeMethod(method);
+ log.info(method.getResponseBodyAsString());
+ }
+
+ public void testMarhaler() throws Exception {
+ String url = "http://64.124.140.30:9090/soap";
+ HttpSoapClientMarshaler marshaler = new HttpSoapClientMarshaler();
+ PostMethod method = new PostMethod(url);
+ method.addRequestHeader("Content-Type", "text/xml");
+ method.addRequestHeader("SOAPAction", "urn:xmethods-delayed-quotes#getQuote");
+
+ InOnly exchange = new InOnlyImpl("id");
+ NormalizedMessage in = exchange.createMessage();
+ exchange.setInMessage(in);
+ in.setContent(new StringSource("<?xml version='1.0'?><ns1:getQuote xmlns:ns1='urn:xmethods-delayed-quotes' xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance' xmlns:se='http://schemas.xmlsoap.org/soap/envelope/' se:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><symbol xsi:type='xsd:string'>SUNW</symbol></ns1:getQuote>"));
+ marshaler.fromNMS(method, exchange, in);
+ log.info(((StringRequestEntity) method.getRequestEntity()).getContent());
+
+ HttpClient httpClient = new HttpClient();
+ httpClient.executeMethod(method);
+ log.info(method.getResponseBodyAsString());
+
+ exchange = new InOnlyImpl("id");
+ in = exchange.createMessage();
+ exchange.setInMessage(in);
+ marshaler.toNMS(in, method);
+
+ log.info(new SourceTransformer().toString(in.getContent()));
+ }
+
+ public void testMarshalerNamespaces() throws Exception {
+ ActivationSpec as = new ActivationSpec();
+ as.setId("mock");
+ MockServiceComponent mock = new MockServiceComponent();
+ mock.setResponseResource(new ClassPathResource("org/apache/servicemix/components/http/soap-response.xml"));
+ as.setComponent(mock);
+ as.setService(new QName("mock"));
+ container.activateComponent(as);
+
+ as = new ActivationSpec();
+ as.setId("http");
+ as.setDestinationService(new QName("mock"));
+ HttpConnector http = new HttpConnector();
+ http.setPort(8100);
+ as.setComponent(http);
+ container.activateComponent(as);
+
+ String url = "http://localhost:8100";
+ HttpSoapClientMarshaler marshaler = new HttpSoapClientMarshaler();
+ PostMethod method = new PostMethod(url);
+ method.addRequestHeader("Content-Type", "text/xml");
+ method.addRequestHeader("SOAPAction", "urn:xmethods-delayed-quotes#getQuote");
+
+ InOnly exchange = new InOnlyImpl("id");
+ NormalizedMessage in = exchange.createMessage();
+ exchange.setInMessage(in);
+ in.setContent(new StringSource("<?xml version='1.0'?><ns1:getQuote xmlns:ns1='urn:xmethods-delayed-quotes' xmlns:xsi='http://www.w3.org/1999/XMLSchema-instance' xmlns:se='http://schemas.xmlsoap.org/soap/envelope/' se:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'><symbol xsi:type='xsd:string'>SUNW</symbol></ns1:getQuote>"));
+ marshaler.fromNMS(method, exchange, in);
+ log.info(((StringRequestEntity) method.getRequestEntity()).getContent());
+
+ HttpClient httpClient = new HttpClient();
+ httpClient.executeMethod(method);
+ log.info(method.getResponseBodyAsString());
+
+ exchange = new InOnlyImpl("id");
+ in = exchange.createMessage();
+ exchange.setInMessage(in);
+ marshaler.toNMS(in, method);
+
+
+ Node node = new SourceTransformer().toDOMNode(new SourceTransformer().toStreamSource(in.getContent()));
+ log.info(new SourceTransformer().toString(node));
+
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'userId']");
+ Element root = (Element) iterator.nextNode();
+ QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
+ assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+ assertEquals("string", qname.getLocalPart());
+ }
+
+ public void testNamespaces() throws Exception {
+ ActivationSpec as = new ActivationSpec();
+ as.setId("receiver");
+ ReceiverComponent receiver = new ReceiverComponent();
+ as.setComponent(receiver);
+ as.setService(new QName("receiver"));
+ container.activateComponent(as);
+
+ as = new ActivationSpec();
+ as.setId("http");
+ as.setDestinationService(new QName("receiver"));
+ HttpSoapConnector http = new HttpSoapConnector();
+ http.setDefaultInOut(false);
+ http.setPort(8100);
+ as.setComponent(http);
+ container.activateComponent(as);
+
+ URLConnection connection = new URL("http://localhost:8100").openConnection();
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ OutputStream os = connection.getOutputStream();
+ // Post the request file.
+ InputStream fis = getClass().getResourceAsStream("soap-response.xml");
+ FileUtil.copyInputStream(fis, os);
+ connection.getInputStream();
+
+ receiver.getMessageList().assertMessagesReceived(1);
+ NormalizedMessage msg = (NormalizedMessage) receiver.getMessageList().flushMessages().get(0);
+
+ Node node = new SourceTransformer().toDOMNode(new SourceTransformer().toStreamSource(msg.getContent()));
+ log.info(new SourceTransformer().toString(node));
+
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'userId']");
+ Element root = (Element) iterator.nextNode();
+ QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
+ assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+ assertEquals("string", qname.getLocalPart());
+ }
+
+ public void testMaxThreadsForJettySocketListener()
+ throws Exception {
+ int maxThreads = 512;
+
+ HttpSoapConnector httpSoap = new HttpSoapConnector();
+ httpSoap.setMaxThreads(maxThreads);
+ assertEquals("The maxThreads value on the HttpSoapConnector is not correct!", maxThreads, httpSoap.getMaxThreads());
+
+ HttpConnector http = new HttpConnector();
+ http.setMaxThreads(maxThreads);
+ assertEquals("The maxThreads value on the HttpConnector is not correct!", maxThreads, http.getMaxThreads());
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapWsTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapWsTest.java
new file mode 100644
index 0000000..cbc23f5
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpSoapWsTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 359186 $
+ */
+public class HttpSoapWsTest extends TestSupport {
+ private static transient Log log = LogFactory.getLog(HttpSoapWsTest.class);
+
+ protected String quote = "SUNW";
+
+ public void testWithURLConnection() throws Exception {
+ URLConnection connection = new URL("http://localhost:8912").openConnection();
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ OutputStream os = connection.getOutputStream();
+
+ // Post the request file.
+ InputStream fis = getClass().getResourceAsStream("soap-request.xml");
+ int c;
+ while ((c = fis.read()) >= 0) {
+ os.write(c);
+ }
+ os.flush();
+ os.close();
+ fis.close();
+
+ // Read the response.
+ BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ log.info(inputLine);
+ }
+ in.close();
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/http/ws-example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java
new file mode 100644
index 0000000..ea3cb57
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/http/HttpTest.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.http;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class HttpTest extends TestSupport {
+ private static transient Log log = LogFactory.getLog(HttpTest.class);
+
+ protected String quote = "SUNW";
+
+ protected void setUp() throws Exception {
+ System.setProperty("javax.net.debug", "all");
+ // The following properties will be used by default if not specified in the xml conf
+ /*
+ System.setProperty("javax.net.ssl.trustStore", getResourceFilePath("client.keystore"));
+ System.setProperty("javax.net.ssl.trustStorePassword", "password");
+ System.setProperty("javax.net.ssl.keyStore", getResourceFilePath("server.keystore"));
+ System.setProperty("javax.net.ssl.keyStorePassword", "password");
+ */
+ super.setUp();
+ }
+
+ String getResourceFilePath(String resource) throws Exception {
+ URL url = getClass().getResource(resource);
+ File f = new File(url.toURI());
+ return f.toString();
+ }
+
+ public void testCurrencyQuotes() throws Exception {
+ QName serviceName = new QName("http://servicemix.org/cheese/", "httpSender");
+ String file = "request.xml";
+
+ Object answer = requestServiceWithFileRequest(serviceName, file);
+ assertTrue("Shoud return a DOM Node: " + answer, answer instanceof Node);
+ Node node = (Node) answer;
+ log.info(transformer.toString(node));
+
+ String text = textValueOfXPath(node, "//Result").trim();
+
+ log.info("Found price: " + text);
+
+ assertTrue("price text should not be empty", text.length() > 0);
+
+ }
+
+ public void testWithURLConnection() throws Exception {
+ URLConnection connection = new URL("http://localhost:8912").openConnection();
+ connection.setDoOutput(true);
+ connection.setDoInput(true);
+ OutputStream os = connection.getOutputStream();
+
+ // Post the request file.
+ InputStream fis = getClass().getResourceAsStream("request.xml");
+ int c;
+ while ((c = fis.read()) >= 0) {
+ os.write(c);
+ }
+ os.flush();
+ os.close();
+ fis.close();
+
+ // Read the response.
+ BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
+ String inputLine;
+ while ((inputLine = in.readLine()) != null) {
+ log.info(inputLine);
+ }
+ in.close();
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/http/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberChatTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberChatTest.java
new file mode 100644
index 0000000..ff0adbd
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberChatTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JabberChatTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJabberSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jabber/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberChatWithActiveMQTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberChatWithActiveMQTest.java
new file mode 100644
index 0000000..cc88fc7
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberChatWithActiveMQTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JabberChatWithActiveMQTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJabberSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jabber/activemqAsServer.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberGroupChatTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberGroupChatTest.java
new file mode 100644
index 0000000..886b0c3
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jabber/JabberGroupChatTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jabber;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JabberGroupChatTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJabberSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jabber/group-example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaTest.java
new file mode 100644
index 0000000..f59999c
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jca;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JmsOverJcaTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJmsSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jca/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaWithFullXATest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaWithFullXATest.java
new file mode 100644
index 0000000..4cb897b
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaWithFullXATest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jca;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JmsOverJcaWithFullXATest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJmsSender");
+
+ sendMessages(service, messageCount, false, null);
+ assertMessagesReceived(messageCount);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jca/xa-on-jca-flow.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaWithXATest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaWithXATest.java
new file mode 100644
index 0000000..1ab2b73
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jca/JmsOverJcaWithXATest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jca;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JmsOverJcaWithXATest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJmsSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jca/exampleWithXA.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
new file mode 100644
index 0000000..cea0715
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jdbc;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import javax.jbi.messaging.InOut;
+import javax.sql.DataSource;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.hsqldb.jdbc.jdbcDataSource;
+
+public class JdbcComponentTest extends TestCase {
+ private static transient Log log = LogFactory.getLog(JdbcComponentTest.class);
+
+ private JBIContainer jbi;
+ private DataSource dataSource;
+ private JdbcComponent jdbc;
+
+ protected void setUp() throws Exception {
+ jdbcDataSource ds = new jdbcDataSource();
+ ds.setDatabase("jdbc:hsqldb:mem:aname");
+ ds.setUser("sa");
+ dataSource = ds;
+
+ jbi = new JBIContainer();
+ jbi.setEmbedded(true);
+ jbi.init();
+ jbi.start();
+
+ jdbc = new JdbcComponent();
+ jdbc.setService(new QName("urn:jdbc", "service"));
+ jdbc.setEndpoint("endpoint");
+ jdbc.setDataSource(dataSource);
+ jbi.activateComponent(jdbc, "jdbc");
+ }
+
+ protected void tearDown() throws Exception {
+ jbi.shutDown();
+ }
+
+ public void testInOut() throws Exception {
+ Connection con = dataSource.getConnection("sa", "");
+ Statement st = con.createStatement();
+ st.execute("create table MyTable (id varchar(80) not null, name varchar(80))");
+ st.execute("insert into MyTable values ('1', 'One')");
+ st.execute("insert into MyTable values ('2', 'Two')");
+
+ DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+ InOut me = client.createInOutExchange();
+ me.setService(new QName("urn:jdbc", "service"));
+ me.getInMessage().setContent(new StringSource("<sql>select * from MyTable</sql>"));
+ client.sendSync(me);
+ String out = new SourceTransformer().contentToString(me.getOutMessage());
+ log.info(out);
+ assertTrue(out.contains("One"));
+ assertTrue(out.contains("Two"));
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java
new file mode 100644
index 0000000..db75849
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jdbc;
+
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+
+import junit.framework.TestCase;
+
+public class JdbcComponentUniqueNamesTest extends TestCase {
+
+ public void testNames() throws Exception {
+
+ JdbcComponent comp = new JdbcComponent();
+
+ String[] names = new String[]{"name", "name", "name", "id", "test_1", "test_1", "test_1"};
+
+ ResultSetMetaData metaData = new MetaMock(names);
+ String[] uniqueColumnNames = comp.getUniqueColumnNames(metaData);
+
+ String[] expected =
+ new String[]{
+ "name",
+ "name_1",
+ "name_2",
+ "id",
+ "test_1",
+ "test_1_1",
+ "test_1_2"};
+
+ for (int i = 0; i < uniqueColumnNames.length; i++) {
+ assertEquals(expected[i], uniqueColumnNames[i]);
+ }
+ }
+
+ private static class MetaMock implements ResultSetMetaData {
+
+ private final String[] names;
+
+ MetaMock(String[] names) {
+ this.names = names;
+ }
+
+ public int getColumnCount() throws SQLException {
+ return names.length;
+ }
+
+ public String getColumnName(int column) throws SQLException {
+ return names[column-1];
+ }
+
+ public String getCatalogName(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public String getColumnClassName(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public int getColumnDisplaySize(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public String getColumnLabel(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public int getColumnType(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public String getColumnTypeName(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public int getPrecision(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public int getScale(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public String getSchemaName(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public String getTableName(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isAutoIncrement(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isCaseSensitive(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isCurrency(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isDefinitelyWritable(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public int isNullable(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isReadOnly(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isSearchable(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isSigned(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isWritable(int column) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public boolean isWrapperFor(Class arg0) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ public Object unwrap(Class arg0) throws SQLException {
+ throw new RuntimeException("not implemented");
+ }
+
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingClusterTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingClusterTest.java
new file mode 100644
index 0000000..145c86b
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingClusterTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 359186 $
+ */
+public class JmsBindingClusterTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJmsSender");
+
+ assertSendAndReceiveMessages(service);
+
+ // Wait for all messages to be processsed
+ Thread.sleep(100);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jms/example-cluster.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingTest.java
new file mode 100644
index 0000000..4da1781
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JmsBindingTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJmsSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jms/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingUsingEndpointSubscriptionTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingUsingEndpointSubscriptionTest.java
new file mode 100644
index 0000000..4af9f73
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jms/JmsBindingUsingEndpointSubscriptionTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jms;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class JmsBindingUsingEndpointSubscriptionTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "jmsSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jms/example-endpoint-subscription.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/jmx/CounterMonitorComponentTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jmx/CounterMonitorComponentTest.java
new file mode 100644
index 0000000..3432578
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/jmx/CounterMonitorComponentTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.jmx;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 359186 $
+ */
+public class CounterMonitorComponentTest extends TestSupport {
+
+ public void testCounter() throws Exception {
+ int nb = 10;
+ for (int i = 0; i < nb; i++) {
+ client.send(null, new StringSource("<hello>world</hello>"));
+ // We need to sleep more than the granularity period length
+ // so that we do not loose notifications
+ Thread.sleep(50);
+ }
+ receiver.getMessageList().assertMessagesReceived(nb);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/jmx/example.xml");
+ }
+
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/MPSSettingTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/MPSSettingTest.java
new file mode 100644
index 0000000..f899a7f
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/MPSSettingTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @author Rmaon Buckland
+ * @version $Revision: $
+ */
+public class MPSSettingTest extends TestSupport {
+
+
+ /**
+ * load the property set from the spring injects string (fixed set)
+ * @throws Exception
+ */
+ public void testStaticStringPropertySet() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "mpsFixed");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.setService(service);
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setContent(new StringSource(createMessageXmlText(777888)));
+ message.setProperty("prop.xpath.or.keep.existing","someValue");
+ message.setProperty("other.set.property","thatOtherValue");
+ client.sendSync(exchange);
+
+ NormalizedMessage outMessage = exchange.getOutMessage();
+
+ assertTrue(outMessage.getProperty("property.1").equals("foobarAndCheese"));
+ assertTrue(outMessage.getProperty("property.2").equals("777888"));
+ assertTrue(outMessage.getProperty("prop.xpath.or.keep.existing").equals("someValue"));
+ // this property is configured, but there is no "value to resolve it to"
+ assertTrue(outMessage.getProperty("new.prop.name") == null);
+ assertTrue(outMessage.getProperty("property.3").equals("thatOtherValue"));
+
+ }
+
+
+ /**
+ * Load the property set using an xpath applied to the in message
+ * @throws Exception
+ */
+ public void testtestXpathLoadingPropertySet() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "mpsXpath");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.setService(service);
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setContent(new StringSource(createMessageXmlText(400)));
+ client.sendSync(exchange);
+
+ NormalizedMessage outMessage = exchange.getOutMessage();
+
+ assertTrue(outMessage.getProperty("my-superdooper.property").equals("wishAusMadeItTotheFinals"));
+
+ }
+
+ /**
+ * load the property set from a JBI property value
+ * @throws Exception
+ */
+ public void testJBIPropertyLoadingPropertySet() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "mpsJBIPropsPS");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.setService(service);
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setProperty(MessagePropertySetterXML.MPS_PROP_NAME_PROPERTYSET,"hello");
+ message.setContent(new StringSource(createMessageXmlText(54)));
+ client.sendSync(exchange);
+
+ NormalizedMessage outMessage = exchange.getOutMessage();
+
+ assertTrue(outMessage.getProperty("my-superdooper.property").equals("wishAusMadeItTotheFinals"));
+
+ }
+
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/mps/servicemix-mps-test.xml");
+ }
+}
+
+
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertySetTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertySetTest.java
new file mode 100644
index 0000000..339ae32
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertySetTest.java
@@ -0,0 +1,344 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import java.io.StringReader;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.components.mps.ConfigNotSupportedException;
+import org.apache.servicemix.components.mps.PropertySet;
+import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+public class PropertySetTest extends TestCase {
+
+ private final transient Log logger = LogFactory.getLog(getClass());
+ private final static String TEST_STRING = "PROP_TEST_STRING";
+ private final static String PROPNAME = "property1";
+ private final static String SAMPLE_MSG_XML = "<sample><get x='911'>me</get></sample>";
+ private final static String SAMPLE_MSG_XML2 = "<this><is><some attr='1234'>xml123</some></is></this>";
+
+ private final static String XML_EXISTING_PROP = "<existing-property/>";
+ private final static String XML_EXISTING_PROP_OTHER_PROP = "<existing-property name=\"newname\"/>";
+ private final static String XML_STATICVAL = "<static-value><![CDATA[a value in the raw]]></static-value>";
+ private final static String XML_XPATH = "<xpath-expression><![CDATA[//get[@x='911']]]></xpath-expression>";
+
+ private Document makeDocument(String xml) {
+ DocumentBuilder db;
+ try {
+ db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ return db.parse(new InputSource(new StringReader(xml)));
+ } catch (Exception e) {
+ fail(e.getLocalizedMessage());
+ return null;
+ }
+ }
+
+ /**
+ * helper method to return a new JBI NormalizedMessage
+ * when we need one
+ * @return
+ */
+ private NormalizedMessage makeTestMessage(String xml) {
+ NormalizedMessage message = new NormalizedMessageImpl();
+ message.setProperty(PROPNAME,TEST_STRING);
+ if (xml == null) {
+ xml = SAMPLE_MSG_XML2;
+ }
+ try {
+ DocumentBuilder db;
+ db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document dom = db.parse(new InputSource(new StringReader(xml)));
+ message.setContent(new DOMSource(dom));
+ } catch (Exception e) {
+ fail(e.getLocalizedMessage());
+ }
+ return message;
+ }
+
+ /**
+ * Test
+ * <property-set name="somename">
+ * <property name="newProperty">
+ * <existing-property name="property1"/>
+ * </property>
+ * </property-set>
+ *
+ */
+ public void testSimpleStaticValue() {
+ String xmlConfig = new StringBuffer("<property-set name='somename'>")
+ .append("<property name='testSimpleStaticValue.property'>")
+ .append("<existing-property name='property1'/>")
+ .append("</property>")
+ .append("</property-set>").toString();
+ Document propertySet = makeDocument(xmlConfig);
+ try {
+ PropertySet ps = new PropertySet("somename",propertySet.getDocumentElement());
+ NormalizedMessage inMessage = makeTestMessage(null);
+ NormalizedMessage outMessage = makeTestMessage(null);
+ ps.applyProperties(inMessage,outMessage);
+
+ assertTrue(TEST_STRING.equals(outMessage.getProperty("testSimpleStaticValue.property")));
+ } catch (ConfigNotSupportedException e) {
+ fail(e.getLocalizedMessage());
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());// TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Test
+ * <property-set name="somename">
+ * <property name="newProperty">
+ * <existing-property name="property1"/>
+ * </property>
+ * </property-set>
+ *
+ */
+ public void testSimpleExistingPropInvalidXPath() {
+ String xmlConfig = new StringBuffer("<property-set name='somename'>")
+ .append("<property name='testSimpleExistingPropInvalidXPath.property'>")
+ .append("<xpath-expression><![CDATA[/someexpath/statement]]></xpath-expression>")
+ .append("<existing-property name='property1'/>")
+ .append("</property>")
+ .append("</property-set>").toString();
+ Document propertySet = makeDocument(xmlConfig);
+ try {
+ PropertySet ps = new PropertySet("somename",propertySet.getDocumentElement());
+ NormalizedMessage inMessage = makeTestMessage(null);
+ NormalizedMessage outMessage = makeTestMessage(null);
+ ps.applyProperties(inMessage,outMessage);
+
+ assertTrue(TEST_STRING.equals(outMessage.getProperty("testSimpleExistingPropInvalidXPath.property")));
+ } catch (ConfigNotSupportedException e) {
+ fail(e.getLocalizedMessage());
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());// TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Test
+ * <property-set name="somename">
+ * <property name="newProperty">
+ * <existing-property name="property1"/>
+ * </property>
+ * </property-set>
+ *
+ */
+ public void testStaticValueDefaultWithBadXpath() {
+ String xmlConfig = new StringBuffer("<property-set name='somename'>")
+ .append("<property name='testStaticValueDefaultWithBadXpath.property'>")
+ .append("<xpath-expression><![CDATA[/someexpath/statement]]></xpath-expression>")
+ .append("<static-value>myvalue</static-value>")
+ .append("</property>")
+ .append("</property-set>").toString();
+ Document propertySet = makeDocument(xmlConfig);
+ try {
+ PropertySet ps = new PropertySet("somename",propertySet.getDocumentElement());
+ NormalizedMessage inMessage = makeTestMessage(null);
+ NormalizedMessage outMessage = makeTestMessage(null);
+ ps.applyProperties(inMessage,outMessage);
+
+ assertTrue("myvalue".equals(outMessage.getProperty("testStaticValueDefaultWithBadXpath.property")));
+ } catch (ConfigNotSupportedException e) {
+ fail(e.getLocalizedMessage());
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());// TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ /**
+ * Test
+ * <property-set name="somename">
+ * <property name="newProperty">
+ * <existing-property name="property1"/>
+ * </property>
+ * </property-set>
+ *
+ */
+ public void testSimpleValidXPath() {
+ String xmlConfig = new StringBuffer("<property-set name='somename'>")
+ .append("<property name='testSimpleValidXPath.property'>")
+ .append("<xpath-expression><![CDATA[/this//some/@attr]]></xpath-expression>")
+ .append("<existing-property name='property1'/>")
+ .append("</property>")
+ .append("</property-set>").toString();
+ Document propertySet = makeDocument(xmlConfig);
+ try {
+ PropertySet ps = new PropertySet("somename",propertySet.getDocumentElement());
+ NormalizedMessage inMessage = makeTestMessage("<this><is><some attr='1234'>xml123</some></is></this>");
+ NormalizedMessage outMessage = makeTestMessage(null);
+ ps.applyProperties(inMessage,outMessage);
+
+ assertTrue(outMessage.getProperty("testSimpleValidXPath.property").toString().equals("1234"));
+ } catch (ConfigNotSupportedException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ } catch (JBIException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+
+ /**
+ * Test
+ * <property-set name="somename">
+ * <property name="newProperty">
+ * <existing-property name="property1"/>
+ * </property>
+ * </property-set>
+ *
+ */
+ public void testInvalidXPathSingle() {
+ String xmlConfig = new StringBuffer("<property-set name='somename'>")
+ .append("<property name='testInvalidXPathSingle.property'>")
+ .append("<xpath-expression><![CDATA[/NoNode]]></xpath-expression>")
+ .append("</property>")
+ .append("</property-set>").toString();
+ Document propertySet = makeDocument(xmlConfig);
+ try {
+ PropertySet ps = new PropertySet("somename",propertySet.getDocumentElement());
+ NormalizedMessage inMessage = makeTestMessage("<this><is><some attr='1234'>xml123</some></is></this>");
+ NormalizedMessage outMessage = makeTestMessage(null);
+ ps.applyProperties(inMessage,outMessage);
+
+ assertTrue("Node is not null",outMessage.getProperty("testInvalidXPathSingle.property") == null);
+ } catch (ConfigNotSupportedException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ } catch (JBIException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test
+ * <property-set name="somename">
+ * <property name="newProperty">
+ * <existing-property name="property1"/>
+ * </property>
+ * </property-set>
+ *
+ */
+ public void testXPATH2MessagesOneHasOneHasnt() {
+ String xmlConfig = new StringBuffer("<property-set name='somename'>")
+ .append("<property name='testXPATH2MessagesOneHasOneHasnt.property'>")
+ .append("<xpath-expression><![CDATA[/this//some/@attr]]></xpath-expression>")
+ .append("<existing-property name='property1'/>")
+ .append("</property>")
+ .append("</property-set>").toString();
+ Document propertySet = makeDocument(xmlConfig);
+ try {
+ PropertySet ps = new PropertySet("somename",propertySet.getDocumentElement());
+ NormalizedMessage inMessage = makeTestMessage("<this><is><some attr='1234'>xml123</some></is></this>");
+ // inMessage will have a property1=TEST_STRING
+
+ NormalizedMessage inMessage2 = makeTestMessage("<this><is><some>xml123</some></is></this>");
+ // inMessage2 will have a property1=TEST_STRING
+ NormalizedMessage outMessage = makeTestMessage(null);
+
+ ps.applyProperties(inMessage,outMessage);
+ assertTrue(outMessage.getProperty("testXPATH2MessagesOneHasOneHasnt.property").toString().equals("1234"));
+
+ ps.applyProperties(inMessage2,outMessage);
+ assertTrue(outMessage.getProperty("testXPATH2MessagesOneHasOneHasnt.property").toString().equals(TEST_STRING));
+
+ } catch (ConfigNotSupportedException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ } catch (JBIException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test
+ * <property-set name="somename">
+ * <property name="newProperty">
+ * <existing-property name="property1"/>
+ * </property>
+ * </property-set>
+ *
+ */
+ public void testManyProperties() {
+ String xmlConfig = new StringBuffer("<property-set name='somename'>")
+ .append("<property name='newProperty1'>")
+ .append("<xpath-expression><![CDATA[/this//some/@attr]]></xpath-expression>")
+ .append("<existing-property name='property1'/>")
+ .append("</property>")
+ .append("<property name='newProperty2'>")
+ .append("<xpath-expression><![CDATA[/this//some/@attrNoExisting]]></xpath-expression>")
+ .append("<static-value><![CDATA[Some String I expect to be Set]]></static-value>")
+ .append("</property>")
+ .append("<property name='newProperty3'>")
+ .append("<existing-property name='missingProperty'/>")
+ .append("<existing-property name='missingProperty2'/>")
+ .append("<static-value><![CDATA[Some String I expect to be Set]]></static-value>")
+ .append("</property>")
+ .append("<property name='newProperty4'>")
+ .append("<xpath-expression><![CDATA[/this//some/nothere/@attr]]></xpath-expression>")
+ .append("<existing-property name='property1WhichIsNoteThere'/>")
+ .append("<existing-property name='testProperty'/>")
+ .append("</property>")
+ .append("<property name='newProperty5'>")
+ .append("<static-value><![CDATA[tagged]]></static-value>")
+ .append("<static-value><![CDATA[taggedNotSet]]></static-value>")
+ .append("</property>")
+ .append("<property name='newProperty6'>")
+ .append("<xpath-expression><![CDATA[/this//some/@attrNoExisting]]></xpath-expression>")
+ .append("</property>")
+ .append("</property-set>").toString();
+ Document propertySet = makeDocument(xmlConfig);
+ try {
+ PropertySet ps = new PropertySet("somename",propertySet.getDocumentElement());
+ NormalizedMessage inMessage = makeTestMessage("<this><is><some attr='1234'>xml123</some></is></this>");
+ inMessage.setProperty("testProperty","value123");
+ NormalizedMessage outMessage = makeTestMessage(null);
+ ps.applyProperties(inMessage,outMessage);
+
+ assertTrue("newProperty1 was not set to expected value",outMessage.getProperty("newProperty1").toString().equals("1234"));
+ assertTrue("newProperty2 was not set to expected value",outMessage.getProperty("newProperty2").toString().equals("Some String I expect to be Set"));
+ assertTrue("newProperty3 was not set to expected value",outMessage.getProperty("newProperty3").toString().equals("Some String I expect to be Set"));
+ assertTrue("newProperty4 was not set to expected value",outMessage.getProperty("newProperty4").toString().equals("value123"));
+ assertTrue("newProperty5 was not set to expected value",outMessage.getProperty("newProperty5").toString().equals("tagged"));
+ assertTrue("newProperty5 was not set to expected value",outMessage.getProperty("newProperty6") == null);
+ } catch (ConfigNotSupportedException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ } catch (JBIException e) {
+ e.printStackTrace();
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertyValueResolverTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertyValueResolverTest.java
new file mode 100644
index 0000000..8513cce
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertyValueResolverTest.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import java.io.StringReader;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+/**
+ * Test cases for the PropertyValueResolver class
+ *
+ * @author rbuckland
+ *
+ */
+public class PropertyValueResolverTest extends TestCase {
+
+ private final transient Log logger = LogFactory.getLog(getClass());
+
+ private final static String TEST_STRING = "PROP_TEST_STRING";
+
+ private final static String PROPNAME = "property1";
+
+ private final static String SAMPLE_MSG_XML = "<sample><get x='911'>me</get></sample>";
+
+ private final static String XML_EXISTING_PROP = "<existing-property/>";
+
+ private final static String XML_EXISTING_PROP_OTHER_PROP = "<existing-property name=\"newname\"/>";
+
+ private final static String XML_STATICVAL = "<static-value><![CDATA[a value in the raw]]></static-value>";
+
+ private final static String XML_XPATH = "<xpath-expression><![CDATA[//get[@x='911']]]></xpath-expression>";
+
+ private Document makeDocument(String xml) {
+ DocumentBuilder db;
+ try {
+ db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ return db.parse(new InputSource(new StringReader(xml)));
+ } catch (Exception e) {
+ fail(e.getLocalizedMessage());
+ return null;
+ }
+ }
+
+ /**
+ * helper method to return a new JBI NormalizedMessage when we need one
+ *
+ * @return
+ */
+ private NormalizedMessage makeTestMessage(String xml) {
+ NormalizedMessage message = new NormalizedMessageImpl();
+ message.setProperty(PROPNAME, TEST_STRING);
+ if (xml == null) {
+ xml = "<this><is><some attr='1234'>xml123</some></is></this>";
+ }
+ try {
+ DocumentBuilder db;
+ db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document dom = db.parse(new InputSource(new StringReader(xml)));
+ message.setContent(new DOMSource(dom));
+ } catch (Exception e) {
+ fail(e.getLocalizedMessage());
+ }
+ return message;
+ }
+
+ /**
+ * Test that a static string, does return a static string
+ *
+ */
+ public void testStaticStringAsFirst() {
+ String propertyNode = (new StringBuffer("<").append(
+ PropertyValueResolver.XML_ELEMENT_NAME).append(
+ " name='newproperty'>").append(XML_STATICVAL).append("</")
+ .append(PropertyValueResolver.XML_ELEMENT_NAME).append(">"))
+ .toString();
+
+ NormalizedMessage in = makeTestMessage(SAMPLE_MSG_XML);
+ NormalizedMessage out = makeTestMessage(SAMPLE_MSG_XML);
+ Document doc = makeDocument(propertyNode);
+ try {
+ PropertyValueResolver pvr = new PropertyValueResolver(
+ "newproperty", doc.getDocumentElement());
+ pvr.setProperty(in, out);
+ logger.debug("prop = " + out.getProperty("newproperty"));
+ assertTrue(out.getProperty("newproperty").toString().equals(
+ "a value in the raw"));
+
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ } catch (ConfigNotSupportedException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test the xpath PVR
+ *
+ */
+ public void testXPath() {
+ String propertyNode = (new StringBuffer("<").append(
+ PropertyValueResolver.XML_ELEMENT_NAME).append(
+ " name='newproperty'>").append(XML_XPATH).append(XML_STATICVAL)
+ .append("</").append(PropertyValueResolver.XML_ELEMENT_NAME)
+ .append(">")).toString();
+
+ NormalizedMessage in = makeTestMessage(PropertyValueResolverTest.SAMPLE_MSG_XML);
+ NormalizedMessage out = makeTestMessage(SAMPLE_MSG_XML);
+ Document doc = makeDocument(propertyNode);
+ try {
+ PropertyValueResolver pvr = new PropertyValueResolver(
+ "newproperty", doc.getDocumentElement());
+ pvr.setProperty(in, out);
+ logger
+ .debug("xpath:@newproperty = "
+ + out.getProperty("newproperty"));
+ assertTrue(out.getProperty("newproperty") != null);
+ assertTrue(out.getProperty("newproperty").toString().equals("me"));
+
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ } catch (ConfigNotSupportedException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test that a existing copier thingo
+ *
+ */
+ public void testExistCopier() {
+ String propertyNode = (new StringBuffer("<").append(
+ PropertyValueResolver.XML_ELEMENT_NAME).append(
+ " name='prop.xyz'>").append(XML_EXISTING_PROP).append(
+ XML_STATICVAL).append("</").append(
+ PropertyValueResolver.XML_ELEMENT_NAME).append(">")).toString();
+
+ NormalizedMessage in = makeTestMessage(PropertyValueResolverTest.SAMPLE_MSG_XML);
+ in.setProperty("prop.xyz", "ahahaha");
+ NormalizedMessage out = makeTestMessage(SAMPLE_MSG_XML);
+ Document doc = makeDocument(propertyNode);
+ try {
+ PropertyValueResolver pvr = new PropertyValueResolver("prop.xyz",
+ doc.getDocumentElement());
+ pvr.setProperty(in, out);
+ logger.debug("prop = " + out.getProperty("prop.xyz"));
+ assertTrue(out.getProperty("prop.xyz") != null);
+ assertTrue(out.getProperty("prop.xyz").toString().equals("ahahaha"));
+
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ } catch (ConfigNotSupportedException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertyValueTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertyValueTest.java
new file mode 100644
index 0000000..bb5a6cf
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/mps/PropertyValueTest.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.mps;
+
+import java.io.StringReader;
+
+import javax.jbi.JBIException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+/**
+ * Test cases for the PeoprtyValue type Objects
+ * @author rbuckland
+ *
+ */
+public class PropertyValueTest extends TestCase {
+
+ private final static String TEST_STRING = "PROP_TEST_STRING";
+ private final static String PROPNAME = "property1";
+ /**
+ * helper method to return a new JBI NormalizedMessage
+ * when we need one
+ * @return
+ */
+ private NormalizedMessage getTestMessage() {
+ NormalizedMessage message = new NormalizedMessageImpl();
+ message.setProperty(PROPNAME,TEST_STRING);
+ String xml = "<this><is><some attr='1234'>xml123</some></is></this>";
+ try {
+ DocumentBuilder db;
+ db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document dom = db.parse(new InputSource(new StringReader(xml)));
+ message.setContent(new DOMSource(dom));
+ } catch (Exception e) {
+ fail(e.getLocalizedMessage());
+ }
+ return message;
+ }
+
+ /**
+ * Test that a static string, does return a static string
+ *
+ */
+ public void testStaticString() {
+ PropertyValue pv = new StaticStringPropertyValue("someValueX");
+ try {
+ assertTrue(pv.getPropertyValue(getTestMessage()).equals("someValueX"));
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test that a existing property copier works
+ *
+ */
+ public void testExistingCopier() {
+ PropertyValue pv = new ExistingPropertyCopier(PROPNAME);
+ try {
+ assertTrue(pv.getPropertyValue(getTestMessage()).equals(TEST_STRING));
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test that a existing property copier works
+ *
+ */
+ public void testXPathElementPropertyValue() {
+ PropertyValue pv = new XPathContentMessagePropertyValue("/this/is/some");
+ try {
+ assertTrue(pv.getPropertyValue(getTestMessage()).equals("xml123"));
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test that a existing property copier works
+ *
+ */
+ public void testXPathAttrPropertyValue() {
+ PropertyValue pv = new XPathContentMessagePropertyValue("/this/is/some/@attr");
+ try {
+ assertTrue(pv.getPropertyValue(getTestMessage()).equals("1234"));
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+ /**
+ * Test that a existing property copier works
+ *
+ */
+ public void testXPathConcatPropertyValue() {
+ PropertyValue pv = new XPathContentMessagePropertyValue("concat('x','y')");
+ try {
+ assertTrue(pv.getPropertyValue(getTestMessage()).equals("xy"));
+ } catch (JBIException e) {
+ fail(e.getLocalizedMessage());
+ }
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/net/FTPPollTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/net/FTPPollTest.java
new file mode 100644
index 0000000..0079ecc
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/net/FTPPollTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.net;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class FTPPollTest extends TestSupport {
+
+ public void testSendMessagesToFTPThenPollThemAgain() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "ftpSender");
+
+ sendMessages(service, messageCount, false, null);
+ assertMessagesReceived(messageCount);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/net/ftpPoll.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/net/FTPTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/net/FTPTest.java
new file mode 100644
index 0000000..3dae307
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/net/FTPTest.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.net;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+/**
+ * Warning: this test case requires an FTP server running on localhost with user / password
+ * of [servicemix/rocks].
+ * <p/>
+ * For details of how to set this up on OS X see
+ * <a href="http://www.ldml.com/services/support/macosx/ftpUserCreate.html">this tutorial</a>
+ *
+ * @version $Revision: 426415 $
+ */
+public class FTPTest extends TestSupport {
+
+ public void testSendUsingMessageContentAndUniquelyGeneratedName() throws Exception {
+
+ // START SNIPPET: content
+ InOnly exchange = client.createInOnlyExchange();
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setContent(new StringSource("<hello>world!</hello>"));
+
+ client.sendSync(exchange);
+ // END SNIPPET: content
+ }
+
+ public void testSendUsingMessageProperties() throws Exception {
+
+ // START SNIPPET: properties
+ InOnly exchange = client.createInOnlyExchange();
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setProperty("org.apache.servicemix.file.name", "cheese.txt");
+ message.setProperty("org.apache.servicemix.file.content", "Hello World!");
+
+ client.sendSync(exchange);
+ // END SNIPPET: properties
+ }
+
+ public void testSendUsingMessageContentAndExpressionName() throws Exception {
+
+ QName service = new QName("http://servicemix.org/cheese/", "ftpSenderWithExpression");
+ ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(service);
+
+ InOnly exchange = client.createInOnlyExchange(resolver);
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setContent(new StringSource("<order id='abc123'><customer>Duff Beer</customer><value>599.99</value></order>"));
+
+ client.sendSync(exchange);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/net/ftp.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MorePojoTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MorePojoTest.java
new file mode 100644
index 0000000..f44ff43
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MorePojoTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.pojo;
+
+import org.apache.servicemix.components.util.PojoLifecycleAdaptor;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class MorePojoTest extends SpringTestSupport {
+
+ public void testSendAndReceiveOfMessages() throws Exception {
+ PojoSender sender = (PojoSender) getBean("sender");
+ sender.sendMessages(messageCount);
+
+ PojoLifecycleAdaptor adaptor = (PojoLifecycleAdaptor) getBean("receiver");
+ PojoReceiver receiver = (PojoReceiver) adaptor.getPojo();
+ assertMessagesReceived(receiver.getMessageList(), messageCount);
+ }
+
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/pojo/example-more-pojo.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MyReceiver.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MyReceiver.java
new file mode 100644
index 0000000..6f21c25
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MyReceiver.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.pojo;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.component.ComponentLifeCycle;
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.management.ObjectName;
+import javax.xml.namespace.QName;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.tck.MessageList;
+
+/**
+ * @version $Revision: 426415 $
+ */
+
+// START SNIPPET: receive
+public class MyReceiver implements ComponentLifeCycle, MessageExchangeListener {
+ private static final Log log = LogFactory.getLog(MyReceiver.class);
+
+ private ComponentContext context;
+ private ObjectName extensionMBeanName;
+ private MessageList messageList = new MessageList();
+
+
+ // ComponentLifeCycle interface
+ //-------------------------------------------------------------------------
+ public ObjectName getExtensionMBeanName() {
+ return extensionMBeanName;
+ }
+
+ public void init(ComponentContext context) throws JBIException {
+ this.context = context;
+
+ // Lets activate myself
+ context.activateEndpoint(new QName("http://servicemix.org/cheese/", "receiver"), "receiver");
+ }
+
+ public void shutDown() throws JBIException {
+ }
+
+ public void start() throws JBIException {
+ }
+
+ public void stop() throws JBIException {
+ }
+
+ // MessageExchangeListener interface
+ //-------------------------------------------------------------------------
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ log.info("Received message " + exchange);
+ NormalizedMessage message = exchange.getMessage("in");
+ getMessageList().addMessage(message);
+ exchange.setStatus(ExchangeStatus.DONE);
+ context.getDeliveryChannel().send(exchange);
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public void setExtensionMBeanName(ObjectName extensionMBeanName) {
+ this.extensionMBeanName = extensionMBeanName;
+ }
+
+ public MessageList getMessageList() {
+ return messageList;
+ }
+
+ public void setMessageList(MessageList messageList) {
+ this.messageList = messageList;
+ }
+}
+// END SNIPPET: receive
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MySender.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MySender.java
new file mode 100644
index 0000000..ec19e33
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/MySender.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.pojo;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.component.ComponentLifeCycle;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchangeFactory;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.management.ObjectName;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+/**
+ * @version $Revision: 426415 $
+ */
+// START SNIPPET: send
+public class MySender implements ComponentLifeCycle {
+ private ComponentContext context;
+ private ObjectName extensionMBeanName;
+
+
+ /**
+ * Sends a number of messages
+ */
+ public void sendMessages(int count) throws MessagingException {
+ DeliveryChannel deliveryChannel = context.getDeliveryChannel();
+ MessageExchangeFactory factory = deliveryChannel.createExchangeFactory();
+
+ for (int i = 0; i < count; i++) {
+ InOnly exchange = factory.createInOnlyExchange();
+ NormalizedMessage message = exchange.createMessage();
+ exchange.setInMessage(message);
+
+ message.setProperty("id", new Integer(i));
+ message.setContent(new StringSource("<example id='" + i + "'/>"));
+
+ deliveryChannel.send(exchange);
+ }
+ }
+
+ // ComponentLifeCycle interface
+ //-------------------------------------------------------------------------
+ public ObjectName getExtensionMBeanName() {
+ return extensionMBeanName;
+ }
+
+ public void init(ComponentContext context) throws JBIException {
+ this.context = context;
+ }
+
+ public void shutDown() throws JBIException {
+ }
+
+ public void start() throws JBIException {
+ }
+
+ public void stop() throws JBIException {
+ }
+
+
+ // Properties
+ //-------------------------------------------------------------------------
+ public void setExtensionMBeanName(ObjectName extensionMBeanName) {
+ this.extensionMBeanName = extensionMBeanName;
+ }
+}
+
+// END SNIPPET: send
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoReceiver.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoReceiver.java
new file mode 100644
index 0000000..100abff
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoReceiver.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.pojo;
+
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.tck.MessageList;
+
+/**
+ * @version $Revision: 426415 $
+ */
+// START SNIPPET: receive
+public class PojoReceiver implements MessageExchangeListener {
+ private MessageList messageList = new MessageList();
+
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ NormalizedMessage message = exchange.getMessage("in");
+ getMessageList().addMessage(message);
+ }
+
+ public MessageList getMessageList() {
+ return messageList;
+ }
+}
+// END SNIPPET: receive
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoSender.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoSender.java
new file mode 100644
index 0000000..fb27c50
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoSender.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.pojo;
+
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+
+/**
+ * @version $Revision: 426415 $
+ */
+// START SNIPPET: send
+public class PojoSender {
+ private ServiceMixClient client;
+
+ public void sendMessages(int count) throws MessagingException {
+ for (int i = 0; i < count; i++) {
+ InOnly exchange = client.createInOnlyExchange();
+ NormalizedMessage message = exchange.getInMessage();
+
+ message.setProperty("id", new Integer(i));
+ message.setContent(new StringSource("<example id='" + i + "'/>"));
+
+ client.send(exchange);
+ }
+ }
+
+ public ServiceMixClient getClient() {
+ return client;
+ }
+
+ public void setClient(ServiceMixClient client) {
+ this.client = client;
+ }
+}
+// END SNIPPET: send
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoTest.java
new file mode 100644
index 0000000..3e34944
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/pojo/PojoTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.pojo;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class PojoTest extends SpringTestSupport {
+ private static transient Log log = LogFactory.getLog(PojoTest.class);
+
+ public void testSendAndReceiveOfMessages() throws Exception {
+ MySender sender = (MySender) getBean("sender");
+ sender.sendMessages(messageCount);
+
+ MyReceiver receiver = (MyReceiver) getBean("receiver");
+ assertMessagesReceived(receiver.getMessageList(), messageCount);
+ }
+
+ public void testPerfSendAndReceiveOfMessages() throws Exception {
+ MySender sender = (MySender) getBean("sender");
+ MyReceiver receiver = (MyReceiver) getBean("receiver");
+ sender.sendMessages(100);
+ assertMessagesReceived(receiver.getMessageList(), 100);
+ receiver.getMessageList().flushMessages();
+
+ int messageCount = 500;
+ long start = System.currentTimeMillis();
+ sender.sendMessages(messageCount);
+ assertMessagesReceived(receiver.getMessageList(), messageCount);
+ long end = System.currentTimeMillis();
+
+ log.info((end - start) + " ms to send " + messageCount + " messages");
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/pojo/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/quartz/QuartzComponentClusterTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/quartz/QuartzComponentClusterTest.java
new file mode 100644
index 0000000..8b58af0
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/quartz/QuartzComponentClusterTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.quartz;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 359186 $
+ */
+public class QuartzComponentClusterTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ assertMessagesReceived();
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/quartz/example-cluster.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/quartz/QuartzComponentTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/quartz/QuartzComponentTest.java
new file mode 100644
index 0000000..908546a
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/quartz/QuartzComponentTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.quartz;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class QuartzComponentTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ assertMessagesReceived();
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/quartz/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/Counter.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/Counter.java
new file mode 100644
index 0000000..060f686
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/Counter.java
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.reflection;
+
+public interface Counter {
+ void increment();
+ void decrement();
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/ReflectionBindingTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/ReflectionBindingTest.java
new file mode 100644
index 0000000..027a9af
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/ReflectionBindingTest.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.reflection;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.components.reflection.ProxyInOnlyBinding;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision: 681324 $
+ */
+public class ReflectionBindingTest extends TestCase {
+
+ private AbstractXmlApplicationContext context;
+ protected int messageCount = 20;
+ private SpringJBIContainer jbi;
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ Counter counter = (Counter) ((ProxyInOnlyBinding)jbi.getBean("proxyCounter")).createProxy();
+ for (int i = 1; i <= messageCount; i++) {
+ counter.increment();
+ }
+ Thread.sleep(2000);
+ SimpleCounter simpleCounter = (SimpleCounter) getBean("counter");
+ assertEquals(messageCount, simpleCounter.getValue() );
+
+ }
+
+ protected void setUp() throws Exception {
+ context = createBeanFactory();
+ jbi = (SpringJBIContainer) getBean("jbi");
+ }
+
+ protected void tearDown() throws Exception {
+ if (context != null) {
+ context.close();
+ }
+ }
+
+ protected Object getBean(String name) {
+ Object answer = context.getBean(name);
+ assertNotNull("Could not find object in Spring for key: " + name, answer);
+ return answer;
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/reflection/example.xml");
+ }
+
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/SimpleCounter.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/SimpleCounter.java
new file mode 100644
index 0000000..c8017f9
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/reflection/SimpleCounter.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.reflection;
+
+public class SimpleCounter implements Counter {
+
+ int counter;
+
+ public void increment() {
+ counter++;
+ }
+
+ public void decrement() {
+ counter--;
+ }
+
+ int getValue() {
+ return counter;
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/rss/FeedWriterTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/rss/FeedWriterTest.java
new file mode 100644
index 0000000..7952f79
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/rss/FeedWriterTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.rss;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class FeedWriterTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenOutofJmsToReceiver() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "feedWriter");
+
+ sendMessages(service, 5);
+
+ // now lets assert that the RSS feed has data in it.
+
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/rss/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java
new file mode 100644
index 0000000..4d01944
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajMarshalerTest.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.saaj;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.transform.stream.StreamSource;
+
+import junit.framework.TestCase;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.messaging.NormalizedMessageImpl;
+import org.apache.servicemix.jbi.util.DOMUtil;
+import org.apache.xpath.CachedXPathAPI;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.NodeIterator;
+
+public class SaajMarshalerTest extends TestCase {
+
+ private static final transient Log log = LogFactory.getLog(SaajMarshalerTest.class);
+
+ public void testAxisToNMS() throws Exception {
+ MessageFactory messageFactory = new org.apache.axis.soap.MessageFactoryImpl();
+ testToNMS(messageFactory);
+ }
+
+ public void testAxisCreateSOAPMessage() throws Exception {
+ MessageFactory messageFactory = new org.apache.axis.soap.MessageFactoryImpl();
+ testCreateSOAPMessage(messageFactory);
+ }
+
+ /*
+ public void testAxis2() throws Exception {
+ MessageFactory messageFactory = new org.apache.axis2.saaj.MessageFactoryImpl();
+ testFactory(messageFactory);
+ }
+ */
+
+ /*
+ public void testSunToNMS() throws Exception {
+ MessageFactory messageFactory = new com.sun.xml.messaging.saaj.soap.MessageFactoryImpl();
+ testToNMS(messageFactory);
+ }
+ */
+
+ /*
+ public void testSunCreateSOAPMessage() throws Exception {
+ MessageFactory messageFactory = new com.sun.xml.messaging.saaj.soap.MessageFactoryImpl();
+ testCreateSOAPMessage(messageFactory);
+ }
+ */
+
+ protected void testToNMS(MessageFactory messageFactory) throws Exception {
+ MimeHeaders headers = new MimeHeaders();
+ headers.addHeader("Content-Type", "text/xml;");
+ InputStream is = getClass().getClassLoader().getResourceAsStream("org/apache/servicemix/components/http/soap-response.xml");
+ SOAPMessage sm = messageFactory.createMessage(headers, is);
+ NormalizedMessage nm = new NormalizedMessageImpl();
+ new SaajMarshaler().toNMS(nm, sm);
+
+ Node node = new SourceTransformer().toDOMNode(new SourceTransformer().toStreamSource(nm.getContent()));
+ log.info(new SourceTransformer().toString(node));
+
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node, "//*[local-name() = 'userId']");
+ Element root = (Element) iterator.nextNode();
+ QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
+ assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+ assertEquals("string", qname.getLocalPart());
+ }
+
+ protected void testCreateSOAPMessage(MessageFactory messageFactory) throws Exception {
+ MimeHeaders headers = new MimeHeaders();
+ headers.addHeader("Content-Type", "text/xml;");
+
+ InputStream is = getClass().getClassLoader().getResourceAsStream("org/apache/servicemix/components/saaj/xml-request.xml");
+ log.info("Raw XML: " + new SourceTransformer().toString(new StreamSource(is)));
+
+ is = getClass().getClassLoader().getResourceAsStream("org/apache/servicemix/components/saaj/xml-request.xml");
+ NormalizedMessage nm = new NormalizedMessageImpl();
+ nm.setContent(new StreamSource(is));
+
+ SaajMarshaler marshaler = new SaajMarshaler();
+ marshaler.setMessageFactory(messageFactory);
+ SOAPMessage msg = marshaler.createSOAPMessage(nm);
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ msg.writeTo(baos);
+ String soapEnv = new String(baos.toByteArray());
+ log.info("Prepared SOAP: " + soapEnv);
+ Node node2 = new SourceTransformer().toDOMNode(new StringSource(soapEnv));
+
+ CachedXPathAPI cachedXPathAPI = new CachedXPathAPI();
+ NodeIterator iterator = cachedXPathAPI.selectNodeIterator(node2, "//*[local-name() = 'userId']");
+ Element root = (Element) iterator.nextNode();
+ QName qname = DOMUtil.createQName(root, root.getAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "type"));
+ assertEquals("http://www.w3.org/2001/XMLSchema", qname.getNamespaceURI());
+ assertEquals("string", qname.getLocalPart());
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajSoapActionTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajSoapActionTest.java
new file mode 100644
index 0000000..6096c25
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajSoapActionTest.java
@@ -0,0 +1,166 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.saaj;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.messaging.MessagingException;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.messaging.URLEndpoint;
+import javax.xml.namespace.QName;
+import javax.xml.soap.MessageFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.MessageExchangeListener;
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.components.http.HttpConnector;
+import org.apache.servicemix.components.util.ComponentSupport;
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+
+public class SaajSoapActionTest extends TestCase {
+
+ private JBIContainer jbi;
+ private SaajBinding saaj;
+ private HttpConnector http;
+
+ protected void setUp() throws Exception {
+ jbi = new JBIContainer();
+ jbi.setEmbedded(true);
+ jbi.setUseMBeanServer(false);
+ jbi.setCreateMBeanServer(false);
+ jbi.init();
+ }
+
+ protected void tearDown() throws Exception {
+ jbi.shutDown();
+ }
+
+ protected String testSoapAction(String soapAction, MessageFactory messageFactory) throws Exception {
+ saaj = new SaajBinding();
+ saaj.setService(new QName("saaj"));
+ saaj.setEndpoint("endpoint");
+ saaj.setSoapEndpoint(new URLEndpoint("http://localhost:8192/"));
+ saaj.setSoapAction(soapAction);
+ SaajMarshaler marshaler = new SaajMarshaler();
+ marshaler.setMessageFactory(messageFactory);
+ saaj.setMarshaler(marshaler);
+ jbi.activateComponent(saaj, "saaj");
+
+ http = new HttpConnector(new org.mortbay.jetty.nio.SelectChannelConnector());
+ http.setHost("localhost");
+ http.setPort(8192);
+ //http.setDefaultInOut(false);
+ ActivationSpec httpAs = new ActivationSpec();
+ httpAs.setComponent(http);
+ httpAs.setComponentName("http");
+ httpAs.setDestinationService(new QName("receiver"));
+ jbi.activateComponent(httpAs);
+
+ SoapActionReceiver receiver = new SoapActionReceiver();
+ jbi.activateComponent(receiver, "receiver");
+
+ jbi.start();
+
+ DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+ InOut me = client.createInOutExchange();
+ me.setService(new QName("saaj"));
+ me.getInMessage().setContent(new StringSource("<hello>world</hello>"));
+ client.sendSync(me);
+ if (me.getStatus() == ExchangeStatus.ERROR) {
+ if (me.getError() != null) {
+ throw me.getError();
+ }
+ }
+ assertEquals(ExchangeStatus.ACTIVE, me.getStatus());
+ client.done(me);
+
+ Thread.sleep(50);
+
+ return receiver.sentSoapAction;
+ }
+
+ public void testNullSoapActionAxis() throws Exception {
+ String received = testSoapAction(null, new org.apache.axis.soap.MessageFactoryImpl());
+ assertEquals("\"\"", received);
+ }
+
+ /*
+ public void testNullSoapActionSun() throws Exception {
+ String received = testSoapAction(null, new com.sun.xml.messaging.saaj.soap.MessageFactoryImpl());
+ assertEquals("\"\"", received);
+ }
+ */
+
+ public void testEmptySoapActionAxis() throws Exception {
+ String received = testSoapAction("", new org.apache.axis.soap.MessageFactoryImpl());
+ assertEquals("\"\"", received);
+ }
+
+ /*
+ public void testEmptySoapActionSun() throws Exception {
+ String received = testSoapAction("", new com.sun.xml.messaging.saaj.soap.MessageFactoryImpl());
+ assertEquals("", received);
+ }
+ */
+
+ public void testQuotesSoapActionAxis() throws Exception {
+ String received = testSoapAction("\"\"", new org.apache.axis.soap.MessageFactoryImpl());
+ assertEquals("\"\"", received);
+ }
+
+ /*
+ public void testQuotesSoapActionSun() throws Exception {
+ String received = testSoapAction("\"\"", new com.sun.xml.messaging.saaj.soap.MessageFactoryImpl());
+ assertEquals("\"\"", received);
+ }
+ */
+
+ public void testWithSoapActionAxis() throws Exception {
+ String received = testSoapAction("action", new org.apache.axis.soap.MessageFactoryImpl());
+ assertEquals("action", received);
+ }
+
+ /*
+ public void testWithSoapActionSun() throws Exception {
+ String received = testSoapAction("action", new com.sun.xml.messaging.saaj.soap.MessageFactoryImpl());
+ assertEquals("action", received);
+ }
+ */
+
+ protected static class SoapActionReceiver extends ComponentSupport implements MessageExchangeListener {
+ public String sentSoapAction;
+ public SoapActionReceiver() {
+ setService(new QName("receiver"));
+ setEndpoint("endpoint");
+ }
+ public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+ if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+ NormalizedMessage msg = exchange.getMessage("in");
+ sentSoapAction = (String) msg.getProperty("SOAPAction");
+ NormalizedMessage out = exchange.createMessage();
+ out.setContent(msg.getContent());
+ answer(exchange, out);
+ }
+ }
+
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajTest.java
new file mode 100644
index 0000000..a7fe4c9
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/saaj/SaajTest.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.saaj;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class SaajTest extends TestSupport {
+ private static transient Log log = LogFactory.getLog(SaajTest.class);
+
+ protected String quote = "SUNW";
+
+ public void testCurrencyQuotes() throws Exception {
+ QName serviceName = new QName("http://servicemix.org/cheese/", "stockQuote");
+ String file = "request.xml";
+
+ Object answer = requestServiceWithFileRequest(serviceName, file);
+ assertTrue("Shoud return a DOM Node: " + answer, answer instanceof Node);
+ Node node = (Node) answer;
+ log.info(transformer.toString(node));
+
+ String text = textValueOfXPath(node, "//Result").trim();
+
+ log.info("Found price: " + text);
+
+ assertTrue("price text should not be empty", text.length() > 0);
+
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/saaj/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/script/GroovyTransformTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/script/GroovyTransformTest.java
new file mode 100644
index 0000000..f7412b1
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/script/GroovyTransformTest.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.script;
+
+import java.util.List;
+
+import javax.jbi.component.Component;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.servicemix.components.util.ComponentAdaptor;
+import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
+import org.apache.servicemix.tck.MessageList;
+import org.apache.servicemix.tck.Receiver;
+import org.apache.servicemix.tck.Sender;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class GroovyTransformTest extends org.apache.servicemix.tck.SpringTestSupport {
+
+ public void testSendingAndReceivingMessagesUsingSpring() throws Exception {
+ Sender sender = getSender();
+
+ sender.sendMessages(messageCount);
+
+ MessageList messageList = getReceivedMessageList();
+ messageList.assertMessagesReceived(messageCount);
+
+ // lets now look into the received messages
+ List list = messageList.getMessages();
+ NormalizedMessage message = (NormalizedMessage) list.get(0);
+ Object property = message.getProperty("foo");
+ assertEquals("Message 'foo' header", "hello", property);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/script/groovy-transform.xml");
+ }
+
+ protected Sender getSender() {
+ Object cmp = getComponent("sender");
+ if (cmp instanceof ComponentAdaptor) {
+ cmp = ((ComponentAdaptor) cmp).getLifeCycle();
+ }
+ return (Sender) cmp;
+ }
+
+ protected Receiver getReceiver() {
+ Object cmp = getComponent("receiver");
+ if (cmp instanceof ComponentAdaptor) {
+ cmp = ((ComponentAdaptor) cmp).getLifeCycle();
+ }
+ return (Receiver) cmp;
+ }
+
+ protected MessageList getReceivedMessageList() {
+ return getReceiver().getMessageList();
+ }
+
+ protected Component getComponent(String name) {
+ ComponentMBeanImpl lcc = jbi.getComponent(name);
+ return lcc != null ? lcc.getComponent() : null;
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/script/ScriptTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/script/ScriptTest.java
new file mode 100644
index 0000000..1eed514
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/script/ScriptTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.script;
+
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.tck.Sender;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class ScriptTest extends org.apache.servicemix.tck.SpringTestSupport {
+ private static transient Log log = LogFactory.getLog(ScriptTest.class);
+
+ private static List result;
+
+ public static List getResult() {
+ return result;
+ }
+
+ public static void setResult(List result) {
+ ScriptTest.result = result;
+ }
+
+ public void testSendingAndReceivingMessagesUsingSpring() throws Exception {
+ Sender sender = (Sender) getBean("sender");
+ assertNotNull(sender);
+ ScriptComponent component = (ScriptComponent) getBean("receiver");
+ assertNotNull(component);
+ sender.sendMessages(1);
+
+ List result = getResult();
+ assertNotNull("Have not received any results from groovy!", result);
+ log.info("Found results: " + result);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/script/spring-groovy.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/splitter/SplitterComponentTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/splitter/SplitterComponentTest.java
new file mode 100644
index 0000000..8932a35
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/splitter/SplitterComponentTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.splitter;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.jbi.container.ActivationSpec;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.tck.ReceiverComponent;
+import org.apache.servicemix.tck.SenderComponent;
+
+public class SplitterComponentTest extends TestCase {
+ private JBIContainer jbiContainer;
+
+ protected SenderComponent sender;
+
+ protected ReceiverComponent receiver;
+
+ protected SplitterComponent fec;
+
+ protected void setUp() throws Exception {
+ jbiContainer = new JBIContainer();
+ jbiContainer.setUseMBeanServer(false);
+ jbiContainer.setCreateMBeanServer(false);
+ jbiContainer.setFlowName("seda");
+ jbiContainer.init();
+ jbiContainer.start();
+ setUpReceiver();
+ setUpSender();
+ setUpComponent();
+ }
+
+ protected QName getComponentService() {
+ return new QName("http://www.neogrid.com.br", "component");
+ }
+
+ private void setUpSender() throws Exception {
+ sender = new SenderComponent();
+ ActivationSpec as = new ActivationSpec(SenderComponent.ENDPOINT, sender);
+ as.setService(SenderComponent.SERVICE);
+ as.setDestinationService(getComponentService());
+ jbiContainer.activateComponent(as);
+ }
+
+ private void setUpReceiver() throws Exception {
+ receiver = new ReceiverComponent();
+ ActivationSpec as = new ActivationSpec(ReceiverComponent.ENDPOINT,
+ receiver);
+ as.setService(ReceiverComponent.SERVICE);
+ jbiContainer.activateComponent(as);
+ }
+
+ private void setUpComponent() throws Exception {
+ fec = new SplitterComponent();
+ fec.setNodePath("");
+ ActivationSpec as = new ActivationSpec("component", fec);
+ as.setService(getComponentService());
+ as.setDestinationService(ReceiverComponent.SERVICE);
+ jbiContainer.activateComponent(as);
+ }
+
+ public void testForEach() throws Exception {
+ fec.setNodePath("ROOT/DOC[@att = 2]");
+ sender
+ .setMessage("<ROOT><DOC att=\"1\"/><DOC att=\"2\"/><DOC att=\"2\"/></ROOT>");
+ sender.sendMessages(1);
+ Thread.sleep(1000);
+ assertEquals(2, receiver.getMessageList().getMessageCount());
+ }
+
+ protected void tearDown() throws Exception {
+ if (jbiContainer != null)
+ jbiContainer.shutDown();
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/validation/ValidationTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/validation/ValidationTest.java
new file mode 100644
index 0000000..91c8705
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/validation/ValidationTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.validation;
+
+import javax.jbi.messaging.Fault;
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.jbi.container.SpringJBIContainer;
+import org.apache.servicemix.tck.Receiver;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class ValidationTest extends SpringTestSupport {
+ private static transient Log log = LogFactory.getLog(ValidationTest.class);
+
+ protected ServiceMixClient client;
+ protected Receiver receiver;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ SpringJBIContainer jbi = (SpringJBIContainer) getBean("jbi");
+ receiver = (Receiver) jbi.getBean("receiver");
+ }
+
+ public void testValidMessage() throws Exception {
+ client = (ServiceMixClient) getBean("defaultErrorHandlerClient");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.getInMessage().setContent(getSourceFromClassPath("requestValid.xml"));
+ client.sendSync(exchange);
+
+ NormalizedMessage out = exchange.getOutMessage();
+ Fault fault = exchange.getFault();
+ Exception error = exchange.getError();
+
+ assertEquals("error", null, error);
+ assertEquals("fault", null, fault);
+
+ assertNotNull("Should have an out message", out);
+ }
+
+ public void testInvalidMessage() throws Exception {
+ client = (ServiceMixClient) getBean("defaultErrorHandlerClient");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.getInMessage().setContent(getSourceFromClassPath("requestInvalid.xml"));
+ client.sendSync(exchange);
+
+ NormalizedMessage out = exchange.getOutMessage();
+ Fault fault = exchange.getFault();
+ Exception error = exchange.getError();
+
+ assertEquals("out", null, out);
+ assertNotNull("Should have a fault", fault);
+
+ log.info("error is: " + error);
+
+ log.info("Fault is...");
+ log.info(transformer.toString(fault.getContent()));
+
+ // TODO?
+ //assertEquals("error", null, error);
+ }
+
+ public void testInvalidMessageWithMessageAwareErrorHandler() throws Exception {
+ client = (ServiceMixClient) getBean("messageAwareErrorHandlerClient");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.getInMessage().setContent(getSourceFromClassPath("requestInvalid.xml"));
+ client.sendSync(exchange);
+
+ NormalizedMessage out = exchange.getOutMessage();
+ Fault fault = exchange.getFault();
+ Exception error = exchange.getError();
+
+ assertEquals("out", null, out);
+ assertNotNull("Should have a fault", fault);
+
+ log.info("error is: " + error);
+
+ log.info("Fault is...");
+ log.info(transformer.toString(fault.getContent()));
+
+ // TODO?
+ //assertEquals("error", null, error);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/validation/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/vfs/FileTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/vfs/FileTest.java
new file mode 100644
index 0000000..78fce48
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/vfs/FileTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.vfs;
+
+import java.io.File;
+
+import org.apache.servicemix.jbi.util.FileUtil;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class FileTest extends TestSupport {
+
+ private static final String SYSTEM_OS_KEY = "os.name";
+ private static final String WINDOWS = "Windows";
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ if (isWindowsOS()) {
+ FileUtil.deleteFile(new File("c:/tmp/servicemix/vfs/test"));
+ } else {
+ FileUtil.deleteFile(new File("/tmp/servicemix/vfs/test"));
+ }
+ }
+
+ public void testSendMessagesToFileSystemThenPoollThem() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "fileSender");
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext(getSystemSupportedXMLConfig());
+ }
+
+ protected String getSystemSupportedXMLConfig(){
+ if (isWindowsOS()) {
+ return "org/apache/servicemix/components/vfs/example_win.xml";
+ } else {
+ return "org/apache/servicemix/components/vfs/example.xml";
+ }
+ }
+
+ protected boolean isWindowsOS() {
+ String os = System.getProperty(SYSTEM_OS_KEY);
+ boolean isWindows = false;
+ int index = (os==null?-1:os.indexOf(WINDOWS));
+ if(index > -1 ){
+ isWindows = true;
+ }
+ return isWindows;
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/wsif/SampleServiceMessageListener.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/wsif/SampleServiceMessageListener.java
new file mode 100644
index 0000000..7eabca6
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/wsif/SampleServiceMessageListener.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageListener;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.jms.core.JmsTemplate;
+import org.springframework.jms.core.MessageCreator;
+
+/**
+ * This is a simple MDB that processes a message containing an integer
+ * that represents a zip code, and returns a message containing a
+ * boolean indicating whether DSL service is available at that zip code
+ * or not.
+ * Internally the bean just returns true for zip codes < 50000 and
+ * false otherwise.
+ *
+ * @version $Revision: 556864 $
+ */
+public class SampleServiceMessageListener implements MessageListener, InitializingBean {
+ private static transient Log log = LogFactory.getLog(SampleServiceMessageListener.class);
+
+ private JmsTemplate template;
+
+ public JmsTemplate getTemplate() {
+ return template;
+ }
+
+ public void setTemplate(JmsTemplate template) {
+ this.template = template;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ if (template == null) {
+ throw new IllegalArgumentException("The template property is not set");
+ }
+ }
+
+ public void onMessage(Message msg) {
+ try {
+ TextMessage message = (TextMessage) msg;
+ // assume we have an integer
+ String text = message.getText();
+ log.info("Text: " + text);
+ int zipCode = new Integer(text).intValue();
+ // return true if zip code < 50000, false otherwise
+ if (zipCode < 50000) {
+ sendMessage(message, "true");
+ }
+ else {
+ sendMessage(message, "false");
+ }
+ }
+ catch (Exception e) {
+ // aargh - this should not happen usually
+ log.error(e.getMessage(), e);
+ }
+ }
+
+ public void sendMessage(final TextMessage requestMsg, final String serviceAvailable) throws JMSException {
+ template.send(requestMsg.getJMSReplyTo(), new MessageCreator() {
+ public Message createMessage(Session session) throws JMSException {
+ TextMessage message = session.createTextMessage();
+ // set the correlation ID
+ message.setJMSCorrelationID(requestMsg.getJMSMessageID());
+ // set the text
+ message.setText(serviceAvailable);
+ return message;
+ }
+ });
+ }
+}
+
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/wsif/WsifTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/wsif/WsifTest.java
new file mode 100644
index 0000000..bef92d9
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/wsif/WsifTest.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.wsif;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+/**
+ * @version $Revision: 556864 $
+ */
+public class WsifTest extends TestSupport {
+ private static transient Log log = LogFactory.getLog(WsifTest.class);
+
+ QName serviceName = new QName("http://servicemix.org/cheese/", "checkAvailability");
+
+ public static final int MESSAGES = 2;
+
+ public void testUsingXMLMessaging() throws Exception {
+ for (int i = 0; i < MESSAGES; i++) {
+ String file = "request.xml";
+
+ Object answer = requestServiceWithFileRequest(serviceName, file);
+ assertTrue("Shoud return a DOM Node: " + answer, answer instanceof Node);
+ Node node = (Node) answer;
+ log.info(transformer.toString(node));
+
+ String text = textValueOfXPath(node, "/*/*[local-name()='part']").trim();
+
+ log.info("Found value: " + text);
+
+ assertTrue("price text should not be empty", text.length() > 0);
+ }
+ }
+
+ public void testUsingWSIFStyleJBI() throws Exception {
+ for (int i = 0; i < MESSAGES; i++) {
+ // START SNIPPET: wsif
+ InOut exchange = client.createInOutExchange();
+
+ exchange.getInMessage().setProperty("zipCode", "10505");
+ client.sendSync(exchange);
+
+ NormalizedMessage out = exchange.getOutMessage();
+ String result = (String) out.getProperty("result");
+
+ log.info("Found value: " + result);
+ // END SNIPPET: wsif
+
+ assertEquals("should have no fault", null, exchange.getFault());
+ Exception error = exchange.getError();
+ if (error != null) {
+ throw error;
+ }
+ assertEquals("should have no error", null, error);
+ assertNotNull("must have an output message!", out);
+
+ assertTrue("price text should not be empty", result.length() > 0);
+ }
+ }
+
+ public void testUsingWSIFStyleJBIWithEarlyErrorHandling() throws Exception {
+ for (int i = 0; i < MESSAGES; i++) {
+ InOut exchange = client.createInOutExchange();
+
+ exchange.getInMessage().setProperty("zipCode", "10505");
+ client.sendSync(exchange);
+
+ Exception error = exchange.getError();
+ if (error != null) {
+ throw error;
+ }
+
+ assertEquals("should have no fault", null, exchange.getFault());
+ assertEquals("should have no error", null, error);
+
+ NormalizedMessage out = exchange.getOutMessage();
+ assertNotNull("must have an output message!", out);
+
+ String result = (String) out.getProperty("result");
+
+ log.info("Found value: " + result);
+
+ assertTrue("price text should not be empty", result.length() > 0);
+ }
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/wsif/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/Echo.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/Echo.java
new file mode 100644
index 0000000..9b39eb2
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/Echo.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xfire;
+
+public class Echo {
+
+ private int count = 0;
+
+ public String echo(String msg) {
+ count++;
+ return msg;
+ }
+
+ protected int getCount() {
+ return count;
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/OneWayService.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/OneWayService.java
new file mode 100644
index 0000000..8a37e75
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/OneWayService.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xfire;
+
+import org.apache.servicemix.tck.MessageList;
+
+import javax.jbi.messaging.MessagingException;
+
+public class OneWayService {
+
+ public MessageList messageList = new MessageList();
+
+ public void receive(String msg) throws MessagingException {
+ messageList.addMessage(msg);
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/XFireBindingTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/XFireBindingTest.java
new file mode 100644
index 0000000..8db1fc6
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/XFireBindingTest.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xfire;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Node;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+
+public class XFireBindingTest extends TestSupport {
+ private static transient Log log = LogFactory.getLog(XFireBindingTest.class);
+
+ public void testSendingAndReceivingMessagesUsingSpring() throws Exception {
+ Object answer = requestServiceWithFileRequest(new QName("http://xfire.components.servicemix.org", "Echo"),
+ "/org/apache/servicemix/components/xfire/echo.xml");
+ assertTrue("Shoud return a DOM Node: " + answer, answer instanceof Node);
+ Node node = (Node) answer;
+ log.info(transformer.toString(node));
+
+ Echo echo = (Echo) context.getBean("xfireReceiverService");
+ assertEquals(1, echo.getCount());
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext(new String[] {
+ "/org/apache/servicemix/components/xfire/xfire-inout.xml",
+ "/org/codehaus/xfire/spring/xfire.xml"
+ });
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/XFireOutBindingTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/XFireOutBindingTest.java
new file mode 100644
index 0000000..6771238
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xfire/XFireOutBindingTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xfire;
+
+import javax.jbi.JBIException;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
+import org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+public class XFireOutBindingTest extends TestSupport {
+ private OneWayService receiverService;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ receiverService = (OneWayService) getBean("xfireReceiverService");
+ }
+
+ public void testSendingAndReceivingMessagesUsingSpring() throws Exception {
+ sendFile(new QName("http://xfire.components.servicemix.org", "OneWayService"),
+ "/org/apache/servicemix/components/xfire/oneway.xml");
+
+ receiverService.messageList.assertMessagesReceived(1);
+ }
+
+ protected void sendFile(QName serviceName, String fileOnClassPath) throws JBIException {
+ Source content = getSourceFromClassPath(fileOnClassPath);
+
+ ServiceNameEndpointResolver resolver = new ServiceNameEndpointResolver(serviceName);
+
+ client.send(resolver, null, null, content);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext(new String[] {
+ "/org/apache/servicemix/components/xfire/xfire-out.xml",
+ "/org/codehaus/xfire/spring/xfire.xml"
+ });
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/OptionalAxisQueriesTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/OptionalAxisQueriesTest.java
new file mode 100644
index 0000000..2ae7924
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/OptionalAxisQueriesTest.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.servicemix.tck.MessageList;
+
+import javax.xml.namespace.QName;
+
+
+public class OptionalAxisQueriesTest extends TestSupport {
+
+ public void testOptionalAxisQuery() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "transformer");
+
+ String message = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
+ " <prod:resolveItemXrefResponse " +
+ " xmlns:prod=\"http://foo.org/prod\" " +
+ " xmlns:xsi=\"http://foo.org/msi\"" +
+ " xmlns:ms=\"http://foo.org/ms\">" +
+ " <prod:response xsi:type=\"wn4:HashMap\">" +
+ " <ms:Keys>" +
+ " <ms:Item xsi:type=\"d:string\">DESCR</ms:Item>" +
+ " <ms:Item xsi:type=\"d:string\">LIST</ms:Item>" +
+ " <ms:Item xsi:type=\"d:string\">XREF</ms:Item>" +
+ " <ms:Item xsi:type=\"d:string\">MSTR</ms:Item>" +
+ " </ms:Keys>" +
+ " <ms:Values>" +
+ " <ms:Item xsi:type=\"d:string\">PPR,CPY,20#,84B,LGL,WE</ms:Item>" +
+ " <ms:Item xsi:type=\"d:double\">17.25</ms:Item>" +
+ " <ms:Item xsi:type=\"d:string\">EXP8514</ms:Item>" +
+ " <ms:Item xsi:type=\"d:string\">10040300</ms:Item>" +
+ " </ms:Values>" +
+ " </prod:response>" +
+ " </prod:resolveItemXrefResponse>";
+
+ // send a custom xml message
+ sendMessages(service, 1, message);
+ assertMessagesReceived(1);
+
+ MessageList messageList1 = assertMessagesReceived("service1", 1);
+ MessageList messageList2 = assertMessagesReceived("service2", 1);
+ MessageList messageList3 = assertMessagesReceived("service3", 1);
+ MessageList messageList4 = assertMessagesReceived("service4", 1);
+ MessageList messageList5 = assertMessagesReceived("service5", 1);
+ MessageList messageList6 = assertMessagesReceived("service6", 1);
+
+ assertMessageHeader(messageList1, 0, "foo", "PPR,CPY,20#,84B,LGL,WE");
+ assertMessageHeader(messageList2, 0, "foo", "17.25");
+ assertMessageHeader(messageList3, 0, "foo", "EXP8514");
+ assertMessageHeader(messageList4, 0, "foo", "10040300");
+ assertMessageHeader(messageList5, 0, "foo", new Integer(4));
+ assertMessageHeader(messageList6, 0, "foo", "PPR,CPY,20#,84B,LGL,WE");
+
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/xslt/optional-axis-example.xml");
+ }
+
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/TransformComponentTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/TransformComponentTest.java
new file mode 100644
index 0000000..88013cb
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/TransformComponentTest.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class TransformComponentTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenReceiveItTransformItThenRepublishAndReceive() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "myJmsSender");
+
+ assertSendAndReceiveMessages(service);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/xslt/example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java
new file mode 100644
index 0000000..36fe1fb
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltParameterTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import javax.jbi.messaging.InOut;
+import javax.jbi.messaging.NormalizedMessage;
+import javax.xml.namespace.QName;
+import javax.xml.transform.Source;
+
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.tck.TestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.Node;
+
+/**
+ * @author rbuckland
+ * @version $Revision$
+ */
+public class XsltParameterTest extends TestSupport {
+
+ public void testSendMessagesToJmsThenReceiveItTransformItThenRepublishAndReceive() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "transformer");
+
+ InOut exchange = client.createInOutExchange();
+ exchange.setService(service);
+
+ NormalizedMessage message = exchange.getInMessage();
+ message.setContent(new StringSource(createMessageXmlText(777888)));
+ client.sendSync(exchange);
+
+ NormalizedMessage outMessage = exchange.getOutMessage();
+
+ Source content = outMessage.getContent();
+ Node node = transformer.toDOMNode(content);
+
+ String value = textValueOfXPath(node, "//param");
+ String integer = textValueOfXPath(node, "//integer");
+
+ assertTrue(value.equals("cheeseyCheese"));
+ assertTrue(integer.equals("4002"));
+
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/xslt/servicemix-parameter-test.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltPublisherTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltPublisherTest.java
new file mode 100644
index 0000000..a218695
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltPublisherTest.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import org.apache.servicemix.tck.MessageList;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class XsltPublisherTest extends TestSupport {
+
+ public void testUseXsltAsRouter() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "transformer");
+
+ sendMessages(service, 20);
+ assertMessagesReceived(20);
+
+ MessageList messageList1 = assertMessagesReceived("service1", 20);
+ MessageList messageList2 = assertMessagesReceived("service2", 20);
+ MessageList messageList3 = assertMessagesReceived("service3", 20);
+
+ assertMessageHeader(messageList1, 0, "foo", "hello world!");
+ assertMessageHeader(messageList1, 1, "foo", "hello world!");
+ assertMessageHeader(messageList1, 19, "foo", "hello world!");
+
+ assertMessageHeader(messageList2, 0, "bar", "1");
+ assertMessageHeader(messageList2, 1, "bar", "2");
+
+ assertMessageHeader(messageList3, 0, "bar", "1");
+ assertMessageHeader(messageList3, 1, "bar", "2");
+ assertMessageHeader(messageList3, 0, "foo", "hello world!");
+ assertMessageHeader(messageList3, 1, "foo", "hello world!");
+ assertMessageHeader(messageList3, 19, "foo", "hello world!");
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/xslt/publish.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltRouterTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltRouterTest.java
new file mode 100644
index 0000000..00876cb
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltRouterTest.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class XsltRouterTest extends TestSupport {
+
+ public void testUseXsltAsRouter() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "transformer");
+
+ sendMessages(service, 20);
+ assertMessagesReceived(17);
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/xslt/router-example.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltSplitTest.java b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltSplitTest.java
new file mode 100644
index 0000000..1abbe8c
--- /dev/null
+++ b/common/servicemix-components/src/test/java/org/apache/servicemix/components/xslt/XsltSplitTest.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.servicemix.components.xslt;
+
+import org.apache.servicemix.tck.MessageList;
+import org.apache.servicemix.tck.TestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+
+import javax.xml.namespace.QName;
+import java.util.Date;
+
+/**
+ * @version $Revision: 426415 $
+ */
+public class XsltSplitTest extends TestSupport {
+
+ public void testUseXsltAsRouter() throws Exception {
+ QName service = new QName("http://servicemix.org/cheese/", "transformer");
+
+ sendMessages(service, 20);
+ assertMessagesReceived(20);
+
+ MessageList messageList1 = assertMessagesReceived("service1", 20);
+ MessageList messageList2 = assertMessagesReceived("service2", 20);
+ MessageList messageList3 = assertMessagesReceived("service3", 40);
+
+ assertMessageXPath(messageList1, 0, "/cheese", "Edam");
+ assertMessageXPath(messageList1, 1, "/cheese", "Edam");
+ assertMessageXPath(messageList1, 19, "/cheese", "Edam");
+ assertMessageXPath(messageList1, 0, "/cheese/@id", "1");
+ assertMessageXPath(messageList1, 1, "/cheese/@id", "2");
+
+ assertMessageXPath(messageList2, 0, "/beer", "Stella");
+ assertMessageXPath(messageList2, 19, "/beer", "Stella");
+
+ assertMessageXPath(messageList3, 0, "/lineitem", "Beer");
+ assertMessageXPath(messageList3, 1, "/lineitem", "Food");
+ assertMessageXPath(messageList3, 38, "/lineitem", "Beer");
+ assertMessageXPath(messageList3, 39, "/lineitem", "Food");
+ }
+
+ protected String createMessageXmlText(int index) {
+ return "<foo id='" + index + "' sent='" + new Date() + "'>"
+ + "<cheese>Edam</cheese><beer>Stella</beer><lineitem>Beer</lineitem><lineitem>Food</lineitem></foo>";
+ }
+
+ protected AbstractXmlApplicationContext createBeanFactory() {
+ return new ClassPathXmlApplicationContext("org/apache/servicemix/components/xslt/split.xml");
+ }
+}
diff --git a/common/servicemix-components/src/test/resources/broker.xml b/common/servicemix-components/src/test/resources/broker.xml
new file mode 100644
index 0000000..dcd840f
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/broker.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans>
+
+ <broker persistent="false" xmlns="http://activemq.apache.org/schema/core">
+
+ <transportConnectors>
+ <transportConnector uri="tcp://localhost:61626" />
+ </transportConnectors>
+
+ </broker>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/jndi.properties b/common/servicemix-components/src/test/resources/jndi.properties
new file mode 100644
index 0000000..e92089f
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/jndi.properties
@@ -0,0 +1,23 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+# START SNIPPET: jndi
+
+java.naming.factory.initial = org.apache.xbean.spring.jndi.SpringInitialContextFactory
+java.naming.provider.url = jndi.xml
+
+# END SNIPPET: jndi
diff --git a/common/servicemix-components/src/test/resources/jndi.xml b/common/servicemix-components/src/test/resources/jndi.xml
new file mode 100644
index 0000000..1edfbbd
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/jndi.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans>
+ <bean id="jndi"
+ class="org.apache.xbean.spring.jndi.SpringInitialContextFactory"
+ factory-method="makeInitialContext"
+ singleton="true">
+ <property name="entries">
+ <map>
+ </map>
+ </property>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/log4j-tests.properties b/common/servicemix-components/src/test/resources/log4j-tests.properties
new file mode 100644
index 0000000..08847de
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/log4j-tests.properties
@@ -0,0 +1,38 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=DEBUG, out
+
+log4j.logger.org.apache.activemq=INFO
+log4j.logger.org.apache.activemq.spring=WARN
+log4j.logger.org.apache.activemq.store.journal=INFO
+log4j.logger.org.activeio.journal=INFO
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/servicemix-test.log
+log4j.appender.out.append=true
diff --git a/common/servicemix-components/src/test/resources/log4j.properties b/common/servicemix-components/src/test/resources/log4j.properties
new file mode 100644
index 0000000..c052902
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/log4j.properties
@@ -0,0 +1,39 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+#
+# The logging properties used during tests..
+#
+log4j.rootLogger=DEBUG, stdout
+
+log4j.logger.org.springframework=INFO
+log4j.logger.org.apache.activemq=INFO
+log4j.logger.org.apache.activemq.spring=WARN
+log4j.logger.org.apache.activemq.store.journal=INFO
+log4j.logger.org.activeio.journal=INFO
+
+# CONSOLE appender not used by default
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+
+# File appender
+log4j.appender.out=org.apache.log4j.FileAppender
+log4j.appender.out.layout=org.apache.log4j.PatternLayout
+log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
+log4j.appender.out.file=target/servicemix-test.log
+log4j.appender.out.append=true
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/cache/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/cache/example.xml
new file mode 100644
index 0000000..ab2fd9c
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/cache/example.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <container id="jbi" xmlns="http://servicemix.apache.org/config/1.0" embedded="true">
+ <activationSpecs>
+
+ <!-- START SNIPPET: cache -->
+ <activationSpec componentName="myService" service="foo:myService" destinationService="foo:myServiceImpl">
+ <component><bean xmlns="" class="org.apache.servicemix.components.cache.CacheComponent">
+ <!-- we could use a JCache here if we want -->
+ <property name="cache">
+ <bean class="org.apache.servicemix.components.cache.LRUCache">
+ <constructor-arg value="100"/>
+ </bean>
+ </property>
+
+ <!-- lets define the cache key expression -->
+ <property name="keyExpression">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/*/@id"/>
+ </bean>
+ </property></bean>
+ </component></activationSpec>
+ <!-- END SNIPPET: cache -->
+
+ <!-- START SNIPPET: groovy -->
+ <activationSpec componentName="myServiceImpl" service="foo:myServiceImpl">
+ <component>
+ <bean xmlns="" class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+if (bindings.counter == null) {
+ bindings.counter = 1
+}
+else {
+ ++bindings.counter
+}
+
+def date = new Date()
+
+outMessage.bodyText = "<response counter='$bindings.counter' date='$date'></response>"
+ ]]>
+ </value>
+ </property>
+ </bean></component></activationSpec>
+ <!-- END SNIPPET: groovy -->
+
+ </activationSpecs>
+ </container>
+
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/example.xml
new file mode 100644
index 0000000..102fbe7
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/example.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: drools -->
+ <sm:activationSpec componentName="droolsRouter"
+ service="foo:droolsRouter">
+ <sm:component><bean class="org.apache.servicemix.components.drools.DroolsComponent">
+ <property name="ruleBaseResource" value="classpath:org/apache/servicemix/components/drools/rulebase.xml" />
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: drools -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example-forward.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example-forward.xml
new file mode 100644
index 0000000..597325d
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example-forward.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: drools -->
+ <sm:activationSpec componentName="droolsRouter"
+ service="foo:droolsRouter">
+ <sm:component><bean class="org.apache.servicemix.components.drools.DroolsComponent">
+ <property name="ruleBaseResource" value="classpath:org/apache/servicemix/components/drools/jbi-rules-forward.xml" />
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: drools -->
+
+ <sm:activationSpec componentName="receiver"
+ service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example-route.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example-route.xml
new file mode 100644
index 0000000..9892172
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example-route.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: drools -->
+ <sm:activationSpec componentName="droolsRouter"
+ service="foo:droolsRouter">
+ <sm:component><bean class="org.apache.servicemix.components.drools.DroolsComponent">
+ <property name="ruleBaseResource" value="classpath:org/apache/servicemix/components/drools/jbi-rules-route.xml" />
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: drools -->
+
+ <sm:activationSpec componentName="target1"
+ service="foo:target1">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.util.MockServiceComponent">
+ <property name="responseXml" value="<hello/>" />
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="target2"
+ service="foo:target2">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.util.MockServiceComponent">
+ <property name="responseXml" value="<world/>" />
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example.xml
new file mode 100644
index 0000000..c75ddc2
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-example.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: drools -->
+ <sm:activationSpec componentName="droolsRouter"
+ service="foo:droolsRouter">
+ <sm:component><bean class="org.apache.servicemix.components.drools.DroolsComponent">
+ <property name="ruleBaseResource" value="classpath:org/apache/servicemix/components/drools/jbi-rules.xml" />
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: drools -->
+
+ <sm:activationSpec componentName="receiver"
+ service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules-forward.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules-forward.xml
new file mode 100644
index 0000000..0040618
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules-forward.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: drools -->
+<rule-set name="cheese rules"
+ xmlns="http://drools.org/rules"
+ xmlns:jbi="http://drools.org/semantics/servicemix"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <application-data identifier="jbi">org.apache.servicemix.components.drools.JbiHelper</application-data>
+ <application-data identifier="context">javax.jbi.component.ComponentContext</application-data>
+ <application-data identifier="deliveryChannel">javax.jbi.messaging.DeliveryChannel</application-data>
+
+ <rule name="Ignore 2 message">
+ <parameter identifier="exchange">
+ <class>javax.jbi.messaging.MessageExchange</class>
+ </parameter>
+
+ <jbi:condition>/*/@id != 2</jbi:condition>
+ <jbi:forward service="foo:receiver,foo:receiver"/>
+ </rule>
+
+</rule-set>
+<!-- END SNIPPET: drools -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules-route.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules-route.xml
new file mode 100644
index 0000000..326df2a
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules-route.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: drools -->
+<rule-set name="cheese rules"
+ xmlns="http://drools.org/rules"
+ xmlns:jbi="http://drools.org/semantics/servicemix"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <application-data identifier="jbi">org.apache.servicemix.components.drools.JbiHelper</application-data>
+ <application-data identifier="context">javax.jbi.component.ComponentContext</application-data>
+ <application-data identifier="deliveryChannel">javax.jbi.messaging.DeliveryChannel</application-data>
+
+ <rule name="Ignore 2 message">
+ <parameter identifier="exchange">
+ <class>javax.jbi.messaging.MessageExchange</class>
+ </parameter>
+
+ <jbi:condition>/*/@id != 2</jbi:condition>
+ <jbi:route service="foo:target1"/>
+ </rule>
+
+ <rule name="Default">
+ <parameter identifier="exchange">
+ <class>javax.jbi.messaging.MessageExchange</class>
+ </parameter>
+ <jbi:condition>/*/@id = 2</jbi:condition>
+ <jbi:route service="foo:target2"/>
+ </rule>
+
+</rule-set>
+<!-- END SNIPPET: drools -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules.xml
new file mode 100644
index 0000000..aabad2d
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/jbi-rules.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: drools -->
+<rule-set name="cheese rules"
+ xmlns="http://drools.org/rules"
+ xmlns:jbi="http://drools.org/semantics/servicemix"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <application-data identifier="jbi">org.apache.servicemix.components.drools.JbiHelper</application-data>
+ <application-data identifier="context">javax.jbi.component.ComponentContext</application-data>
+ <application-data identifier="deliveryChannel">javax.jbi.messaging.DeliveryChannel</application-data>
+
+ <rule name="Ignore 2 message">
+ <parameter identifier="exchange">
+ <class>javax.jbi.messaging.MessageExchange</class>
+ </parameter>
+
+ <jbi:condition>/*/@id != 2</jbi:condition>
+ <jbi:invoke service="foo:receiver"/>
+ </rule>
+
+</rule-set>
+<!-- END SNIPPET: drools -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/rulebase.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/rulebase.xml
new file mode 100644
index 0000000..e4470a8
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/drools/rulebase.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: drools -->
+<rule-set name="cheese rules"
+ xmlns="http://drools.org/rules"
+ xmlns:java="http://drools.org/semantics/java">
+
+ <application-data identifier="jbi">org.apache.servicemix.components.drools.JbiHelper</application-data>
+ <application-data identifier="context">javax.jbi.component.ComponentContext</application-data>
+ <application-data identifier="deliveryChannel">javax.jbi.messaging.DeliveryChannel</application-data>
+
+ <rule name="Ignore 2 message">
+
+ <parameter identifier="exchange">
+ <class>javax.jbi.messaging.MessageExchange</class>
+ </parameter>
+ <java:condition>"2".equals(exchange.getMessage("in").getProperty("idText")) == false</java:condition>
+ <java:consequence>
+ // lets try send a message
+ jbi.forwardToService("http://servicemix.org/cheese/", "receiver");
+ </java:consequence>
+ </rule>
+
+</rule-set>
+<!-- END SNIPPET: drools -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/example.xml
new file mode 100644
index 0000000..da66c22
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/example.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: mime -->
+ <sm:activationSpec componentName="mimeSender" service="foo:mimeSender">
+ <sm:component><bean class="org.apache.servicemix.components.email.MimeMailSender">
+ <property name="sender">
+ <bean class="org.springframework.mail.javamail.JavaMailSenderImpl">
+ <property name="host" value="localhost"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: mime -->
+
+ <!-- START SNIPPET: simple -->
+ <sm:activationSpec componentName="emailSender" service="foo:emailSender">
+ <sm:component><bean class="org.apache.servicemix.components.email.SimpleMailSender">
+ <property name="sender" ref="cosMailSender"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: simple -->
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <sm:activationSpec destinationService="foo:emailSender"/>
+ </constructor-arg>
+ </bean>
+
+ <!-- TODO lets try with COS -->
+ <bean id="cosMailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
+ <property name="host" value="localhost"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/mimeMail.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/mimeMail.xml
new file mode 100644
index 0000000..deb3b33
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/mimeMail.xml
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: expr -->
+ <sm:activationSpec componentName="emailSender" service="foo:emailSender">
+ <sm:component><bean class="org.apache.servicemix.components.email.MimeMailSender">
+ <property name="sender" ref="javaMailSender"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: expr -->
+
+ <!-- START SNIPPET: simpleExpr -->
+ <sm:activationSpec componentName="emailSenderWithExpressions" service="foo:emailSenderWithExpressions">
+ <sm:component><bean class="org.apache.servicemix.components.email.MimeMailSender">
+ <property name="sender" ref="javaMailSender"/>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.email.MimeMailMarshaler">
+ <property name="from">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/person/email"/>
+ </bean>
+ </property>
+ <property name="to">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/person/accountant/email"/>
+ </bean>
+ </property>
+ <property name="subject">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('Drink a beer ', /person/name)"/>
+ </bean>
+ </property>
+ <property name="text">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('Hello there ', /person/name, ' how are you today?')"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="emailSenderWithExpressionsAndAttachment" service="foo:emailSenderWithExpressionsAndAttachment">
+ <sm:component><bean class="org.apache.servicemix.components.email.MimeMailSender">
+ <property name="sender" ref="javaMailSender"/>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.email.MimeMailMarshaler">
+ <property name="from">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/person/email"/>
+ </bean>
+ </property>
+ <property name="to">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/person/accountant/email"/>
+ </bean>
+ </property>
+ <property name="subject">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('Drink a beer ', /person/name)"/>
+ </bean>
+ </property>
+ <property name="text">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('Hello there ', /person/name, ' how are you today?')"/>
+ </bean>
+ </property>
+ <property name="attachments">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/person/attachments"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: simpleExpr -->
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <sm:activationSpec destinationService="foo:emailSender"/>
+ </constructor-arg>
+ </bean>
+
+ <!-- a testing mail sender -->
+ <bean id="javaMailSender" class="org.apache.servicemix.components.email.StubJavaMailSender"/>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/request.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/request.xml
new file mode 100644
index 0000000..74195d2
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/request.xml
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<person>
+ <name>James</name>
+ <email>james@nowhere.com</email>
+ <accountant>
+ <email>foo@bar.com</email>
+ </accountant>
+ <attachments>example.xml</attachments>
+</person>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/simpleMail.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/simpleMail.xml
new file mode 100644
index 0000000..e80715b
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/email/simpleMail.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: xpath -->
+ <sm:activationSpec componentName="simpleMailSenderWithExpressions" service="foo:simpleMailSenderWithExpressions">
+ <sm:component><bean class="org.apache.servicemix.components.email.SimpleMailSender">
+ <property name="sender" ref="javaMailSender"/>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.email.SimpleMailMarshaler">
+ <property name="from">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/person/email"/>
+ </bean>
+ </property>
+ <property name="to">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="/person/accountant/email"/>
+ </bean>
+ </property>
+ <property name="subject">
+ <bean class="org.apache.servicemix.expression.ConstantExpression">
+ <constructor-arg value="Drink a beer"/>
+ </bean>
+ </property>
+ <property name="text">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('Hello there ', /person/name, ' how are you today?')"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xpath -->
+
+ <!-- START SNIPPET: simpleExpr -->
+ <sm:activationSpec componentName="simpleMailSenderWithPropertyExpressions" service="foo:simpleMailSenderWithPropertyExpressions">
+ <sm:component><bean class="org.apache.servicemix.components.email.SimpleMailSender">
+ <property name="sender" ref="javaMailSender"/>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.email.SimpleMailMarshaler">
+ <property name="from">
+ <bean class="org.apache.servicemix.expression.PropertyExpression">
+ <constructor-arg value="from"/>
+ </bean>
+ </property>
+ <property name="to">
+ <bean class="org.apache.servicemix.expression.PropertyExpression">
+ <constructor-arg value="to"/>
+ </bean>
+ </property>
+ <property name="subject">
+ <bean class="org.apache.servicemix.expression.ConstantExpression">
+ <constructor-arg value="Subject came from expression"/>
+ </bean>
+ </property>
+ <property name="text">
+ <bean class="org.apache.servicemix.expression.PropertyExpression">
+ <constructor-arg value="text"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: simpleExpr -->
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <!-- a testing mail sender -->
+ <bean id="javaMailSender" class="org.apache.servicemix.components.email.StubJavaMailSender"/>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/file/binary-example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/file/binary-example.xml
new file mode 100644
index 0000000..1ac2ad5
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/file/binary-example.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: poll -->
+ <sm:activationSpec componentName="filePoller" service="foo:filePoller" destinationService="foo:fileSender">
+ <sm:component><bean class="org.apache.servicemix.components.file.FilePoller">
+ <property name="file" value="target/test-data/in"/>
+ <property name="period" value="100"/>
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: poll -->
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="fileSender" service="foo:fileSender">
+ <sm:component><bean class="org.apache.servicemix.components.file.FileWriter">
+ <property name="directory" value="target/test-data/out"/>
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.BinaryFileMarshaler" />
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/file/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/file/example.xml
new file mode 100644
index 0000000..68e65cb
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/file/example.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="fileSender" service="foo:fileSender">
+ <sm:component><bean class="org.apache.servicemix.components.file.FileWriter">
+ <property name="directory" value="target/test-data/file"/>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.DefaultFileMarshaler">
+ <property name="fileName">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('sample_', /sample/@id, '.xml')"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+
+
+ <!-- START SNIPPET: poll -->
+ <sm:activationSpec componentName="filePoller" service="foo:filePoller" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.file.FilePoller">
+ <property name="workManager" ref="workManager"/>
+ <property name="file" value="target/test-data/file"/>
+ <!--
+ <property name="delete" value="false"/>
+ -->
+ <property name="period" value="1000"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: poll -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="workManager" class="org.jencks.factory.WorkManagerFactoryBean"/>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/example.xml
new file mode 100644
index 0000000..fcaac79
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/example.xml
@@ -0,0 +1,159 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component>
+ <bean class="org.apache.servicemix.tck.ReceiverComponent" />
+ </sm:component>
+ </sm:activationSpec>
+
+ <!-- output using a POJO -->
+ <sm:activationSpec componentName="myService" service="foo:myService">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value><![CDATA[
+
+println "Called with inbound message $inMessage"
+
+// lets output some message properties
+outMessage.properties.foo = "hello"
+outMessage.properties.someList = [1, 2, 3]
+
+// lets output some non-xml body
+outMessage.body = [3, 2, 1]
+ ]]></value>
+ </property>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <!-- output using a String -->
+ <!-- START SNIPPET: xmlText -->
+ <sm:activationSpec componentName="myServiceUsingXMLText"
+ service="foo:myServiceUsingXMLText">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+// lets output some message properties
+outMessage.properties = [foo:"hello", someList:[1, 2, 3]]
+
+// lets output some non-xml body
+outMessage.bodyText = """
+<hello>
+ <world person="$inMessage.properties.name" location="London"/>
+</hello>
+"""
+ ]]>
+ </value>
+ </property>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xmlText -->
+
+ <!-- output using Groovy Markup -->
+ <sm:activationSpec componentName="myServiceWithBuilder" service="foo:myServiceWithBuilder">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+// lets output some message properties
+def props = outMessage.properties
+props.foo = "hello"
+props.someList = [1, 2, 3]
+
+// lets output some XML using GroovyMarkup
+outMessage.body = builder.hello(version:1.2) {
+ world(person:inMessage.properties.name, location:'London')
+}
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!-- output using a POJO reqeust and sends a POJO response -->
+ <sm:activationSpec componentName="myServicePOJO" service="foo:myServicePOJO">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+def body = inMessage.body
+
+println "Called with input $body"
+
+// lets output some message properties
+outMessage.properties.foo = "hello"
+outMessage.properties.someList = [1, 2, 3]
+
+// lets output some non-xml body
+outMessage.body = [body.name, body.length, body.addresses]
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+
+ <!-- START SNIPPET: client -->
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ </bean>
+ <!-- END SNIPPET: client -->
+
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <!-- START SNIPPET: clientroute -->
+ <bean id="clientWithRouting" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ <constructor-arg>
+ <sm:activationSpec destinationService="foo:receiver"/>
+ </constructor-arg>
+ </bean>
+ <!-- END SNIPPET: clientroute -->
+
+
+ <bean id="clientWithXStream" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ <constructor-arg>
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <sm:activationSpec>
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.xstream.XStreamMarshaler" />
+ </property>
+ </sm:activationSpec>
+ </constructor-arg>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/groovy-chain.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/groovy-chain.xml
new file mode 100644
index 0000000..ef67bed
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/groovy-chain.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns="http://xbean.org/schemas/spring/1.0"
+ xmlns:spring="http://xbean.org/schemas/spring/1.0"
+ xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container spring:id="jbi" flowName="st" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- chaining router -->
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="script" value="classpath:/org/apache/servicemix/components/groovy/script.groovy" />
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service1"
+ service="foo:service1">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+// lets output some message properties
+println "In Service1"
+def txt = inMessage.bodyText
+println "Content: " + txt
+
+// lets output some non-xml body
+outMessage.bodyText = txt.replace("world", "<service1>world</service1>")
+ ]]>
+ </value>
+ </property>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service2"
+ service="foo:service2">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+// lets output some message properties
+println "In Service2"
+def txt = inMessage.bodyText
+println "Content: " + txt
+
+// lets output some non-xml body
+outMessage.bodyText = """
+<service2>
+ <![CDATA[
+ $txt
+ ]""" + """]>
+</service2>
+"""
+ ]]>
+ </value>
+ </property>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+
+ <!-- START SNIPPET: client -->
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ </bean>
+ <!-- END SNIPPET: client -->
+
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <!-- START SNIPPET: clientroute -->
+ <bean id="clientWithRouting" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ <constructor-arg>
+ <sm:activationSpec destinationService="foo:receiver"/>
+ </constructor-arg>
+ </bean>
+ <!-- END SNIPPET: clientroute -->
+
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/script.groovy b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/script.groovy
new file mode 100644
index 0000000..0906ae3
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/script.groovy
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
+
+println "Called with inbound message $inMessage"
+
+// lets output some message properties
+def me1 = deliveryChannel.createExchangeFactoryForService(new javax.xml.namespace.QName("http://servicemix.org/cheese/", "service1")).createInOutExchange()
+def in1 = me1.createMessage()
+in1.bodyText = inMessage.bodyText
+me1.setMessage(in1, "in")
+deliveryChannel.sendSync(me1)
+println "Received: " + me1.getMessage("out").bodyText
+
+// lets output some message properties
+def me2 = deliveryChannel.createExchangeFactoryForService(new javax.xml.namespace.QName("http://servicemix.org/cheese/", "service2")).createInOutExchange()
+def in2 = me2.createMessage()
+in2.bodyText = me1.getMessage("out").bodyText
+me2.setMessage(in2, "in")
+deliveryChannel.sendSync(me2)
+println "Received: " + me2.getMessage("out").bodyText
+
+// lets output some non-xml body
+outMessage.bodyText = me2.getMessage("out").bodyText
+
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/spring-groovy.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/spring-groovy.xml
new file mode 100644
index 0000000..fa1f974
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/groovy/spring-groovy.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+
+ <!-- the JBI container -->
+ <bean id="jbi" class="org.apache.servicemix.jbi.container.SpringJBIContainer">
+ <property name="componentNames">
+ <list>
+ <value>sender</value>
+ <value>receiver</value>
+ </list>
+ </property>
+ <property name="embedded" value="true" />
+ </bean>
+
+ <!-- components within the JBI container -->
+
+ <!-- these are more lightweight POJOs which don't implement the full JBI Component interface -->
+ <bean id="sender" class="org.apache.servicemix.tck.SenderPojo"/>
+
+ <bean id="receiver" class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+System.out.println """
+Groovy script evaluated with the following variables
+message: $message
+message exchange: $messageExchange
+componentContext: $componentContext
+deliveryChannel: $deliveryChannel
+"""
+ </value>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/ServiceMix.jpg b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/ServiceMix.jpg
new file mode 100644
index 0000000..2e66503
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/ServiceMix.jpg
Binary files differ
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/client.keystore b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/client.keystore
new file mode 100644
index 0000000..8580672
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/client.keystore
Binary files differ
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml
new file mode 100644
index 0000000..25a4181
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/example.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="httpSender" service="foo:httpSender">
+ <sm:component><bean class="org.apache.servicemix.components.http.HttpInvoker">
+ <property name="url" value="http://localhost:8912"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+ <!-- START SNIPPET: binding -->
+ <sm:activationSpec componentName="httpReceiver" service="foo:httpBinding" destinationService="foo:httpSender2">
+ <sm:component><bean class="org.apache.servicemix.components.http.HttpConnector">
+ <property name="host" value="localhost"/>
+ <property name="port" value="8912"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: binding -->
+
+ <sm:activationSpec componentName="httpSender2" service="foo:httpSender2">
+ <sm:component><bean class="org.apache.servicemix.components.http.HttpsInvoker">
+ <property name="url" value="https://localhost:8913"/>
+ <property name="keyStore" value="classpath:org/apache/servicemix/components/http/server.keystore" />
+ <property name="keyStorePassword" value="password" />
+ <property name="trustStore" value="classpath:org/apache/servicemix/components/http/client.keystore" />
+ <property name="trustStorePassword" value="password" />
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="httpReceiver2" service="foo:httpBinding2" destinationService="foo:stockQuote">
+ <sm:component><bean class="org.apache.servicemix.components.http.HttpsConnector">
+ <property name="host" value="localhost"/>
+ <property name="port" value="8913"/>
+ <property name="keyStore" value="classpath:org/apache/servicemix/components/http/server.keystore" />
+ <property name="keyStorePassword" value="password" />
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="stockQuote" service="foo:stockQuote">
+ <sm:component><bean class="org.apache.servicemix.components.saaj.SaajBinding">
+ <property name="soapEndpoint">
+ <bean class="javax.xml.messaging.URLEndpoint">
+ <constructor-arg value="http://64.124.140.30:9090/soap"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/request.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/request.xml
new file mode 100644
index 0000000..ecfcd94
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/request.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: request -->
+<ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:se="http://schemas.xmlsoap.org/soap/envelope/" se:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+
+ <symbol xsi:type="xsd:string">IBM</symbol>
+
+</ns1:getQuote>
+<!-- END SNIPPET: request -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/server.keystore b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/server.keystore
new file mode 100644
index 0000000..d9223d8
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/server.keystore
Binary files differ
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-request.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-request.xml
new file mode 100644
index 0000000..a63cbe2
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-request.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
+ xmlns:ns1="urn:xmethods-delayed-quotes"
+ xmlns:se="http://schemas.xmlsoap.org/soap/envelope/">
+ <env:Body>
+ <!-- Comment -->
+ <ns1:getQuote
+ se:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+
+ <ns1:symbol>IBM</ns1:symbol>
+
+ </ns1:getQuote>
+ </env:Body>
+</env:Envelope>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml
new file mode 100644
index 0000000..4a37d5d
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/soap-response.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<e:Envelope xmlns:e="http://schemas.xmlsoap.org/soap/envelope/"
+xmlns:d="http://www.w3.org/2001/XMLSchema"
+xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
+xmlns:wn0="http://systinet.com/xsd/SchemaTypes/"
+xmlns:wn1="http://systinet.com/wsdl/com/cexp/coe/bob/ws/customer/"
+xmlns:wn2="http://systinet.com/soap-jta/"
+xmlns:wn3="http://systinet.com/wsdl/com/cexp/coe/bob/services/order/pojo/">
+ <e:Body>
+ <wn1:getCustomerInfo>
+ <wn1:userId i:type="d:string">akayali</wn1:userId>
+ </wn1:getCustomerInfo>
+ </e:Body>
+</e:Envelope>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/ws-example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/ws-example.xml
new file mode 100644
index 0000000..6627895
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/http/ws-example.xml
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: binding -->
+ <sm:activationSpec componentName="httpReceiver" service="foo:httpBinding" destinationService="foo:httpSender2">
+ <sm:component><bean class="org.apache.servicemix.components.http.HttpSoapConnector">
+ <property name="host" value="localhost"/>
+ <property name="port" value="8912"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: binding -->
+
+ <sm:activationSpec componentName="httpSender2" service="foo:httpSender2">
+ <sm:component><bean class="org.apache.servicemix.components.http.HttpSoapInvoker">
+ <property name="url" value="http://localhost:8913"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="httpReceiver2" service="foo:httpBinding2" destinationService="foo:stockQuote">
+ <sm:component><bean class="org.apache.servicemix.components.http.HttpSoapConnector">
+ <property name="host" value="localhost"/>
+ <property name="port" value="8913"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="stockQuote" service="foo:stockQuote">
+ <sm:component><bean class="org.apache.servicemix.components.util.EchoComponent">
+ </bean></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/activemqAsServer.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/activemqAsServer.xml
new file mode 100644
index 0000000..5ffebfc
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/activemqAsServer.xml
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- lets run an embedded broker -->
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
+ <property name="config" value="classpath:org/apache/servicemix/components/jabber/broker.xml"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true">
+ <sm:activationSpecs>
+ <sm:activationSpec componentName="myJabberSender" service="foo:myJabberSender">
+ <sm:component><bean class="org.apache.servicemix.components.jabber.JabberChatSender">
+ <property name="host" value="localhost"/>
+ <property name="port" value="6222"/>
+ <property name="login" value="false"/>
+ <property name="participant" value="test2@servicemix.org"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="myJabberReceiver" service="foo:myJabberReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jabber.JabberReceiver">
+ <property name="host" value="localhost"/>
+ <property name="port" value="61626"/>
+ <property name="user" value="test2@servicemix.org"/>
+ <property name="password" value="rocks"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/broker.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/broker.xml
new file mode 100644
index 0000000..c32a8ce
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/broker.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns="http://activemq.apache.org/schema/core">
+
+ <broker persistent="false">
+
+ <transportConnectors>
+ <transportConnector uri="jabber://localhost:6222" />
+ </transportConnectors>
+
+ </broker>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/example.xml
new file mode 100644
index 0000000..33558ce
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/example.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- lets run an embedded broker -->
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
+ <property name="config" value="classpath:org/apache/servicemix/components/jabber/broker.xml"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="myJabberSender" service="foo:myJabberSender" endpoint="myJabberSender">
+ <sm:component><bean class="org.apache.servicemix.components.jabber.JabberChatSender">
+ <property name="host" value="localhost"/>
+ <property name="port" value="6222"/>
+ <property name="user" value="test1@servicemix.org"/>
+ <property name="password" value="rocks"/>
+ <property name="participant" value="test2@servicemix.org"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+ <!-- START SNIPPET: receive -->
+ <sm:activationSpec componentName="myJabberReceiver" service="foo:myJabberReceiver" endpoint="myJabberReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jabber.JabberReceiver">
+ <property name="host" value="localhost"/>
+ <property name="port" value="6222"/>
+ <property name="user" value="test2@servicemix.org"/>
+ <property name="password" value="rocks"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: receive -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/group-example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/group-example.xml
new file mode 100644
index 0000000..0a4e05b
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jabber/group-example.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- lets run an embedded broker -->
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
+ <property name="config" value="classpath:org/apache/servicemix/components/jabber/broker.xml"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="myJabberSender" service="foo:myJabberSender" endpoint="myJabberSender">
+ <sm:component><bean class="org.apache.servicemix.components.jabber.JabberGroupChatSender">
+ <property name="host" value="localhost"/>
+ <property name="port" value="6222"/>
+ <property name="user" value="test1@servicemix.org"/>
+ <property name="password" value="rocks"/>
+ <property name="room" value="servicemixroom"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+ <!-- START SNIPPET: receive -->
+ <sm:activationSpec componentName="myJabberReceiver" service="foo:myJabberReceiver" endpoint="myJabberReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jabber.JabberReceiver">
+ <property name="host" value="localhost"/>
+ <property name="port" value="6222"/>
+ <property name="user" value="test2@servicemix.org"/>
+ <property name="password" value="rocks"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: receive -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/example.xml
new file mode 100644
index 0000000..747ba8b
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/example.xml
@@ -0,0 +1,135 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: config -->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!--
+ || ActiveMQ Broker
+ -->
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean" singleton="true">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- START SNIPPET: jca -->
+ <bean id="jencks" class="org.jencks.JCAContainer">
+
+ <!-- lets use the default configuration of work manager and transaction manager-->
+ <property name="bootstrapContext">
+ <bean class="org.jencks.factory.BootstrapContextFactoryBean">
+ <property name="threadPoolSize" value="25"/>
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean>
+ </property>
+
+
+ <!-- the JCA Resource Adapter -->
+ <property name="resourceAdapter">
+ <bean id="activeMQResourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter">
+ <property name="serverUrl" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+ <!-- END SNIPPET: jca -->
+
+ <bean id="transactionManager" class="org.jencks.factory.TransactionManagerFactoryBean">
+ <property name="transactionLogDir" value="target/txlog"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true" transactionManager="#transactionManager">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="myJmsSender" service="foo:myJmsSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory" ref="jmsFactory"/>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.jca"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!-- START SNIPPET: receive -->
+ <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsInUsingJCABinding">
+
+ <property name="jcaContainer" ref="jencks"/>
+
+ <property name="activationSpec">
+ <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="test.org.apache.servicemix.example.jca"/>
+ <property name="destinationType" value="javax.jms.Topic"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: receive -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <!-- just to test that we are sending messages, lets trace the messages we receive -->
+ <sm:activationSpec componentName="jmsTrace" service="foo:jmsTrace" destinationService="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsInUsingJCABinding">
+
+ <property name="jcaContainer" ref="jencks"/>
+
+ <property name="activationSpec">
+ <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="test.org.apache.servicemix.example.jca"/>
+ <property name="destinationType" value="javax.jms.Topic"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true"/>
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+log.info "Received message $inMessage with content $inMessage.bodyText"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
+<!-- END SNIPPET: config -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/exampleWithXA.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/exampleWithXA.xml
new file mode 100644
index 0000000..c027d9f
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/exampleWithXA.xml
@@ -0,0 +1,142 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!--
+ || ActiveMQ Broker
+ -->
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean" singleton="true">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- START SNIPPET: jca -->
+ <bean id="jencks" class="org.jencks.JCAContainer">
+
+ <!-- lets use the default configuration of work manager and transaction manager-->
+ <property name="bootstrapContext">
+ <bean class="org.jencks.factory.BootstrapContextFactoryBean">
+ <property name="threadPoolSize" value="25"/>
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean>
+ </property>
+
+
+ <!-- the JCA Resource Adapter -->
+ <property name="resourceAdapter">
+ <bean id="activeMQResourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter">
+ <property name="serverUrl" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+ <!-- END SNIPPET: jca -->
+
+ <!-- START SNIPPET: tm -->
+ <bean id="transactionManager" class="org.jencks.factory.TransactionManagerFactoryBean">
+ <property name="transactionLogDir" value="target/txlog" />
+ </bean>
+ <!-- END SNIPPET: tm -->
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="myJmsSender" service="foo:myJmsSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory" ref="jmsFactory"/>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.jca"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!-- START SNIPPET: receive -->
+ <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsInUsingJCABinding">
+
+ <property name="jcaContainer" ref="jencks"/>
+
+ <property name="activationSpec">
+ <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="test.org.apache.servicemix.example.jca"/>
+ <property name="destinationType" value="javax.jms.Topic"/>
+ </bean>
+ </property>
+
+ <!-- use XA transactions -->
+ <property name="transactionManager" ref="transactionManager"/>
+ <property name="synchronous" value="true"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: receive -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- just to test that we are sending messages, lets trace the messages we receive -->
+ <sm:activationSpec componentName="jmsTrace" service="foo:jmsTrace" destinationService="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsInUsingJCABinding">
+
+ <property name="jcaContainer" ref="jencks"/>
+
+ <property name="activationSpec">
+ <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="test.org.apache.servicemix.example.jca"/>
+ <property name="destinationType" value="javax.jms.Topic"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true"/>
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+log.info "Received message $inMessage with content $inMessage.bodyText"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/xa-on-jca-flow.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/xa-on-jca-flow.xml
new file mode 100644
index 0000000..9b67998
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jca/xa-on-jca-flow.xml
@@ -0,0 +1,153 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!--
+ || ActiveMQ Broker
+ -->
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean" singleton="true">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- START SNIPPET: jca -->
+ <bean id="jencks" class="org.jencks.JCAContainer">
+
+ <!-- lets use the default configuration of work manager and transaction manager-->
+ <property name="bootstrapContext">
+ <bean class="org.jencks.factory.BootstrapContextFactoryBean">
+ <property name="threadPoolSize" value="25"/>
+ <property name="transactionManager" ref="transactionManager" />
+ </bean>
+ </property>
+
+
+ <!-- the JCA Resource Adapter -->
+ <property name="resourceAdapter">
+ <bean id="activeMQResourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter">
+ <property name="serverUrl" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+ <!-- END SNIPPET: jca -->
+
+ <!-- START SNIPPET: tm -->
+ <bean id="transactionManager" class="org.jencks.factory.TransactionManagerFactoryBean">
+ <property name="transactionLogDir" value="target/txlog" />
+ </bean>
+ <!-- END SNIPPET: tm -->
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker">
+
+ <!-- use JCA flow -->
+ <property name="flow">
+ <bean class="org.apache.servicemix.jbi.nmr.flow.jca.JCAFlow">
+ <property name="jmsURL" value="tcp://localhost:61626" />
+ </bean>
+ </property>
+ <!-- use XA transactions -->
+ <property name="transactionManager" ref="transactionManager"/>
+ <!-- use autoEnlistInTransaction -->
+ <property name="autoEnlistInTransaction" value="true"/>
+ <property name="embedded" value="true" />
+
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="myJmsSender" service="foo:myJmsSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory" ref="jmsFactory"/>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.jca"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!-- START SNIPPET: receive -->
+ <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsInUsingJCABinding">
+
+ <property name="jcaContainer" ref="jencks"/>
+
+ <property name="activationSpec">
+ <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="test.org.apache.servicemix.example.jca"/>
+ <property name="destinationType" value="javax.jms.Topic"/>
+ </bean>
+ </property>
+
+ <!-- use XA transactions -->
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: receive -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- just to test that we are sending messages, lets trace the messages we receive -->
+ <sm:activationSpec componentName="jmsTrace" service="foo:jmsTrace" destinationService="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsInUsingJCABinding">
+
+ <property name="jcaContainer" ref="jencks"/>
+
+ <property name="activationSpec">
+ <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="test.org.apache.servicemix.example.jca"/>
+ <property name="destinationType" value="javax.jms.Topic"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true"/>
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+log.info "Received message $inMessage with content $inMessage.bodyText"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example-cluster.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example-cluster.xml
new file mode 100644
index 0000000..799dc42
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example-cluster.xml
@@ -0,0 +1,113 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean" singleton="true">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true"
+ flowName="jms?brokerURL=tcp://localhost:61626">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="myJmsSender" service="foo:myJmsSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- just to test that we are sending messages, lets trace the messages we receive -->
+ <sm:activationSpec componentName="jmsTrace" service="foo:jmsTrace" destinationService="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!--
+ <sm:activationSpec componentName="jmsTrace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.util.TraceComponent"/></sm:component>
+ </sm:activationSpec>
+ -->
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true"/>
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+log.info "Received message $inMessage with body: $inMessage.bodyText"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626" />
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example-endpoint-subscription.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example-endpoint-subscription.xml
new file mode 100644
index 0000000..6e942af
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example-endpoint-subscription.xml
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean" singleton="true">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="jmsSender" service="foo:jmsSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory" ref="jmsFactory" />
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1" />
+ <property name="pubSubDomain" value="true" />
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!-- START SNIPPET: publish -->
+ <sm:activationSpec componentName="jmsReceiver" service="foo:jmsReceiver"
+ failIfNoDestinationEndpoint="false">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <!-- END SNIPPET: publish -->
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory" ref="jmsFactory" />
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1" />
+ <property name="pubSubDomain" value="true" />
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- START SNIPPET: subscribe -->
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+
+ <!-- lets subscribe to the output of the foo:jmsReceiver component -->
+ <sm:subscriptions>
+ <sm:subscriptionSpec service="foo:jmsReceiver" />
+ </sm:subscriptions>
+ </sm:activationSpec>
+ <!-- END SNIPPET: subscribe -->
+
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true" />
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+log.info "Received message $inMessage with body: $inMessage.bodyText"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ <sm:subscriptions>
+ <sm:subscriptionSpec service="foo:jmsReceiver" />
+ </sm:subscriptions>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client"
+ class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626" />
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example.xml
new file mode 100644
index 0000000..0b10bc2
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jms/example.xml
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean" singleton="true">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="myJmsSender" service="foo:myJmsSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- just to test that we are sending messages, lets trace the messages we receive -->
+ <sm:activationSpec componentName="jmsTrace" service="foo:jmsTrace" destinationService="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.1"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!--
+ <sm:activationSpec componentName="jmsTrace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.util.TraceComponent"/></sm:component>
+ </sm:activationSpec>
+ -->
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true"/>
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+log.info "Received message $inMessage with body: $inMessage.bodyText"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626" />
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jmx/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jmx/example.xml
new file mode 100644
index 0000000..3107849
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/jmx/example.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.apache.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true" useMBeanServer="true" createMBeanServer="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="trace"
+ endpoint="trace"
+ service="foo:trace">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.util.TraceComponent"/>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="jmxMonitor"
+ service="foo:jmxMonitor"
+ endpoint="jmxMonitor"
+ destinationService="foo:receiver">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.jmx.CounterMonitorComponent">
+ <property name="observedObjectName" value="org.apache.servicemix:ContainerName=ServiceMix,Type=Component,Name=trace,SubType=Statistics"/>
+ <property name="attributeName" value="inboundExchangeCount" />
+ <property name="threshold">
+ <bean class="java.lang.Long">
+ <constructor-arg value="1"/>
+ </bean>
+ </property>
+ <property name="offset">
+ <bean class="java.lang.Long">
+ <constructor-arg value="1"/>
+ </bean>
+ </property>
+ <property name="granularityPeriod" value="10" />
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver"
+ endpoint="receiver"
+ service="foo:receiver">
+ <sm:component>
+ <bean class="org.apache.servicemix.tck.ReceiverComponent"/>
+ </sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <sm:activationSpec destinationService="foo:trace" />
+ </constructor-arg>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/mps/sample-mps-config.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/mps/sample-mps-config.xml
new file mode 100644
index 0000000..1afe4d4
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/mps/sample-mps-config.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<mps>
+
+ <property-set name="hello">
+
+ <!-- set a static string value -->
+ <property name="my-superdooper.property">
+ <static-value><![CDATA[wishAusMadeItTotheFinals]]></static-value>
+ </property>
+ </property-set>
+
+
+ <property-set name="propertySetOne">
+
+ <!-- set a static string value -->
+ <property name="property.1">
+ <static-value><![CDATA[foobarAndCheese]]></static-value>
+ </property>
+
+ <!--
+ xpath and a default string
+ -->
+ <property name="property.2">
+ <xpath-expression>
+ <![CDATA[/sample/@id]]>
+ </xpath-expression>
+ <static-value><![CDATA[sampleIdNotFound]]></static-value>
+ </property>
+
+ <!--
+ an xpath that doesn't work
+ -->
+ <property name="prop.xpath.or.keep.existing">
+ <xpath-expression>
+ <![CDATA[/someexpath/statement/that/wont/match]]>
+ </xpath-expression>
+ <existing-property/>
+ </property>
+
+ <property name="new.prop.name">
+ <existing-property name="other.property"/>
+ </property>
+
+ <property name="property.3">
+ <existing-property name="other.set.property"/>
+ </property>
+
+ </property-set>
+
+
+
+</mps>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/mps/servicemix-mps-test.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/mps/servicemix-mps-test.xml
new file mode 100644
index 0000000..fde7951
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/mps/servicemix-mps-test.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: fixedPropertySet -->
+ <sm:activationSpec componentName="mpsFixed" service="foo:mpsFixed">
+ <sm:component><bean class="org.apache.servicemix.components.mps.MessagePropertySetterXML">
+ <property name="xmlConfiguration" value="classpath:org/apache/servicemix/components/mps/sample-mps-config.xml"/>
+ <property name="propertySet" value="propertySetOne"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: -->
+
+
+ <!-- START SNIPPET: fixedPropertySet -->
+ <sm:activationSpec componentName="mpsXpath" service="foo:mpsXpath">
+ <sm:component><bean class="org.apache.servicemix.components.mps.MessagePropertySetterXML">
+ <property name="xmlConfiguration" value="classpath:org/apache/servicemix/components/mps/sample-mps-config.xml"/>
+ <property name="xpathForPropertySet" value="substring-before(/sample[@id=400],' world')"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: -->
+
+ <!-- START SNIPPET: propsLoadedFromProperty -->
+ <sm:activationSpec componentName="mpsJBIPropsPS" service="foo:mpsJBIPropsPS">
+ <sm:component><bean class="org.apache.servicemix.components.mps.MessagePropertySetterXML">
+ <property name="xmlConfiguration" value="classpath:org/apache/servicemix/components/mps/sample-mps-config.xml"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: -->
+
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="workManager" class="org.jencks.factory.WorkManagerFactoryBean"/>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/net/ftp.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/net/ftp.xml
new file mode 100644
index 0000000..2da71cd
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/net/ftp.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: sender -->
+ <sm:activationSpec componentName="ftpSender" service="foo:ftpSender">
+ <sm:component><bean class="org.apache.servicemix.components.net.FTPSender">
+ <property name="clientPool">
+ <bean id="ftpClientPool" class="org.apache.servicemix.components.net.FTPClientPool">
+ <property name="host" value="localhost"/>
+ <property name="username" value="servicemix"/>
+ <property name="password" value="rocks"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: sender -->
+
+ <!-- START SNIPPET: expression -->
+ <sm:activationSpec componentName="ftpSenderWithExpression" service="foo:ftpSenderWithExpression">
+ <sm:component><bean class="org.apache.servicemix.components.net.FTPSender">
+ <property name="clientPool">
+ <bean id="ftpClientPool" class="org.apache.servicemix.components.net.FTPClientPool">
+ <property name="host" value="localhost"/>
+ <property name="username" value="servicemix"/>
+ <property name="password" value="rocks"/>
+ </bean>
+ </property>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.DefaultFileMarshaler">
+ <property name="fileName">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('order_', order/@id, '.csv')"/>
+ </bean>
+ </property>
+ <property name="content">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat(/order/customer, ',', /order/value, ',', /order/@id)"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: expression -->
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <sm:activationSpec destinationService="foo:ftpSender"/>
+ </constructor-arg>
+ </bean>
+
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/net/ftpPoll.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/net/ftpPoll.xml
new file mode 100644
index 0000000..ebb6469
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/net/ftpPoll.xml
@@ -0,0 +1,79 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="ftpSender" service="foo:ftpSender">
+ <sm:component><bean class="org.apache.servicemix.components.net.FTPSender">
+ <property name="clientPool" ref="ftpClientPool"/>
+ <property name="overwrite" value="true"/>
+ <!--
+ <property name="uniqueFileName" value="foo/TestFile"/>
+ -->
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.DefaultFileMarshaler">
+ <property name="fileName">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('sample_', /sample/@id, '.xml')"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- START SNIPPET: poll -->
+ <sm:activationSpec componentName="ftpPoller" service="foo:ftpPoller" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.net.FTPPoller">
+ <property name="clientPool" ref="ftpClientPool"/>
+ <property name="workManager" ref="workManager"/>
+ <!--
+ <property name="path" value="foo"/>
+ -->
+ <property name="period" value="1000"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: poll -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver" endpoint="receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="ftpClientPool" class="org.apache.servicemix.components.net.FTPClientPool">
+ <property name="host" value="localhost"/>
+ <property name="username" value="servicemix"/>
+ <property name="password" value="rocks"/>
+ </bean>
+
+ <bean id="workManager" class="org.jencks.factory.WorkManagerFactoryBean" />
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/pojo/example-more-pojo.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/pojo/example-more-pojo.xml
new file mode 100644
index 0000000..cc6388e
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/pojo/example-more-pojo.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: example -->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.pojo.PojoReceiver"/></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+
+ <bean id="sender" class="org.apache.servicemix.components.pojo.PojoSender">
+ <property name="client">
+
+ <!-- lets configure a ServiceMix client which is bound to the required service -->
+ <bean class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <sm:activationSpec destinationService="foo:receiver" />
+ </constructor-arg>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
+<!-- END SNIPPET: example -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/pojo/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/pojo/example.xml
new file mode 100644
index 0000000..642970c
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/pojo/example.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: example -->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="sender" service="foo:sender" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.pojo.MySender" /></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec id="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.pojo.MyReceiver"/></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+</beans>
+<!-- END SNIPPET: example -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/quartz/example-cluster.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/quartz/example-cluster.xml
new file mode 100644
index 0000000..e8d5307
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/quartz/example-cluster.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:my="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true"
+ flowName="jms?brokerURL=tcp://localhost:61626">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: timer -->
+ <sm:activationSpec componentName="timer" service="my:timer" destinationService="my:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.quartz.QuartzComponent">
+ <property name="triggers">
+ <map>
+ <entry>
+ <key>
+ <bean class="org.quartz.SimpleTrigger">
+ <property name="repeatInterval" value="200"/>
+ <property name="repeatCount" value="20"/>
+ </bean>
+ </key>
+ <bean class="org.quartz.JobDetail">
+ <property name="name" value="My Example Job"/>
+ <property name="group" value="ServiceMix"/>
+ </bean>
+ </entry>
+ </map>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: timer -->
+
+ <sm:activationSpec componentName="receiver" service="my:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="vm://localhost"/>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/quartz/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/quartz/example.xml
new file mode 100644
index 0000000..74e7f1b
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/quartz/example.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:my="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: timer -->
+ <sm:activationSpec componentName="timer" service="my:timer" destinationService="my:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.quartz.QuartzComponent">
+ <property name="triggers">
+ <map>
+ <entry>
+ <key>
+ <bean class="org.quartz.SimpleTrigger">
+ <property name="repeatInterval" value="200"/>
+ <property name="repeatCount" value="20"/>
+ </bean>
+ </key>
+ <bean class="org.quartz.JobDetail">
+ <property name="name" value="My Example Job"/>
+ <property name="group" value="ServiceMix"/>
+ </bean>
+ </entry>
+ </map>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: timer -->
+
+ <sm:activationSpec componentName="receiver" service="my:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="vm://localhost"/>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/reflection/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/reflection/example.xml
new file mode 100644
index 0000000..633eb9b
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/reflection/example.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: inOnly -->
+ <sm:activationSpec componentName="proxyCounter"
+ endpoint="proxyCounter"
+ service="foo:proxyCounter"
+ destinationService="foo:reflectionCounter">
+ <sm:component><bean class="org.apache.servicemix.components.reflection.ProxyInOnlyBinding">
+ <property name="target" ref="counter"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: inOnly -->
+
+ <sm:activationSpec componentName="trace"
+ service="foo:trace"
+ endpoint="trace">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true"/>
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+println "Received message $inMessage.properties.method"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <!-- START SNIPPET: out -->
+ <sm:activationSpec componentName="reflectionCounter"
+ service="foo:reflectionCounter"
+ endpoint="reflectionCounter">
+ <sm:component><bean class="org.apache.servicemix.components.reflection.ReflectionOutBinding">
+ <property name="target" ref="counter"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: out -->
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="counter" class="org.apache.servicemix.components.reflection.SimpleCounter"/>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/rss/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/rss/example.xml
new file mode 100644
index 0000000..04bf992
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/rss/example.xml
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: rss -->
+ <sm:activationSpec componentName="feedWriter"
+ service="foo:feedWriter">
+ <sm:component><bean class="org.apache.servicemix.components.rss.FeedWriter">
+
+ <property name="feedFile" value="file:target/serviceMixFeed.xml" />
+
+ <!-- define expressions for the entry title and value -->
+ <property name="entryTitle">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('Message ', /sample/@id, ' - ', /sample/@sent)" />
+ </bean>
+ </property>
+ <property name="entryValue">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('This is an entry with ID ', /sample/@id, ' sent: ', /sample/@sent, '. There is not much else in the message to tell :)')" />
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: rss -->
+
+ <sm:activationSpec componentName="receiver"
+ service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi" />
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/example.xml
new file mode 100644
index 0000000..e7188aa
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/example.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+ <!-- START SNIPPET: saaj -->
+ <sm:activationSpec componentName="stockQuote" service="foo:stockQuote" endpoint="stockQuote">
+ <sm:component><bean class="org.apache.servicemix.components.saaj.SaajBinding">
+ <property name="soapEndpoint">
+ <bean class="javax.xml.messaging.URLEndpoint">
+ <constructor-arg value="http://64.124.140.30:9090/soap"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: saaj -->
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/request.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/request.xml
new file mode 100644
index 0000000..b20dbaa
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/request.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: request -->
+<ns1:getQuote xmlns:ns1="urn:xmethods-delayed-quotes" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:se="http://schemas.xmlsoap.org/soap/envelope/" se:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
+
+ <symbol xsi:type="xsd:string">SUNW</symbol>
+
+</ns1:getQuote>
+<!-- END SNIPPET: request -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/response.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/response.xml
new file mode 100644
index 0000000..b6caf5d
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/response.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: example -->
+<n:getQuoteResponse xmlns:n="urn:xmethods-delayed-quotes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <Result xsi:type="xsd:float">3.67</Result>
+</n:getQuoteResponse>
+<!-- END SNIPPET: example -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/xml-request.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/xml-request.xml
new file mode 100644
index 0000000..0d542f5
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/saaj/xml-request.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<wn1:getCustomerInfo
+ xmlns:d="http://www.w3.org/2001/XMLSchema"
+ xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:wn0="http://systinet.com/xsd/SchemaTypes/"
+ xmlns:wn1="http://systinet.com/wsdl/com/cexp/coe/bob/ws/customer/"
+ xmlns:wn2="http://systinet.com/soap-jta/"
+ xmlns:wn3="http://systinet.com/wsdl/com/cexp/coe/bob/services/order/pojo/">
+
+ <wn1:userId i:type="d:string">akayali</wn1:userId>
+
+</wn1:getCustomerInfo>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/script/groovy-transform.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/script/groovy-transform.xml
new file mode 100644
index 0000000..d01e12a
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/script/groovy-transform.xml
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+<beans>
+
+ <!-- the JBI container -->
+ <bean id="jbi" class="org.apache.servicemix.jbi.container.SpringJBIContainer">
+ <property name="componentNames">
+ <list>
+ <value>sender</value>
+ <value>pipeline</value>
+ <value>transformer</value>
+ <value>receiver</value>
+ </list>
+ </property>
+ <property name="embedded" value="true"/>
+ </bean>
+
+ <!-- components within the JBI container -->
+
+ <!-- these are more lightweight POJOs which don't implement the full JBI Component interface -->
+ <bean id="sender" class="org.apache.servicemix.tck.SenderComponent">
+ <property name="resolver">
+ <bean class="org.apache.servicemix.jbi.resolver.ServiceNameEndpointResolver">
+ <property name="serviceName" ref="pipelineServiceName"/>
+ </bean>
+ </property>
+ </bean>
+
+ <!-- pipelines the transformation script to the receiver -->
+ <bean id="pipeline" class="org.apache.servicemix.components.util.PipelineComponent">
+ <constructor-arg ref="pipelineServiceName"/>
+ <constructor-arg value="pipeline"/>
+
+ <property name="requestResponseServiceName" ref="transformerServiceName"/>
+ <property name="outputEndpointServiceName" ref="receiverServiceName"/>
+ </bean>
+
+
+ <!-- the groovy transformation -->
+ <bean id="transformer" class="org.apache.servicemix.components.script.ScriptComponent">
+ <constructor-arg ref="transformerServiceName"/>
+ <constructor-arg value="transformer"/>
+
+ <property name="scriptEngineName" value="groovy"/>
+ <property name="scriptText">
+ <value>
+outMessage.setProperty("foo", "hello")
+
+println "Received message $inMessage in Groovy script"
+
+ </value>
+ </property>
+ </bean>
+
+ <bean id="receiver" class="org.apache.servicemix.tck.ReceiverPojo">
+ <constructor-arg ref="receiverServiceName"/>
+ <constructor-arg value="receiver"/>
+ </bean>
+
+
+ <!-- QNames - would be nice to have an easier way of doing this -->
+ <bean id="pipelineServiceName" class="javax.xml.namespace.QName">
+ <constructor-arg value="http://www.example.com/pipeline"/>
+ <constructor-arg value="pipeline"/>
+ </bean>
+
+ <bean id="transformerServiceName" class="javax.xml.namespace.QName">
+ <constructor-arg value="http://www.example.com/transformer"/>
+ <constructor-arg value="transformer"/>
+ </bean>
+
+ <bean id="receiverServiceName" class="javax.xml.namespace.QName">
+ <constructor-arg value="http://www.example.com/receiver"/>
+ <constructor-arg value="receiver"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/script/spring-groovy.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/script/spring-groovy.xml
new file mode 100644
index 0000000..bf8bc31
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/script/spring-groovy.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <sm:container id="jbi" flowName="st" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="sender" service="foo:sender" endpoint="sender"
+ destinationService="foo:receiver" destinationEndpoint="receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.SenderComponent"/></sm:component>
+ </sm:activationSpec>
+
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver" endpoint="receiver">
+ <sm:component><bean class="org.apache.servicemix.components.script.ScriptComponent">
+ <property name="scriptEngineName" value="groovy"/>
+ <property name="disableOutput" value="true"/>
+ <property name="scriptText">
+ <value>
+import org.apache.servicemix.components.script.ScriptTest
+
+System.out.println """
+Groovy script evaluated with the following variables
+context: $context
+deliveryChannel: $deliveryChannel
+exchange: $exchange
+inMessage: inMessage
+"""
+
+// lets output some values
+def result = [1, 2, 3]
+ScriptTest.setResult(result)
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/address/address.xsd b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/address/address.xsd
new file mode 100644
index 0000000..1d2380f
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/address/address.xsd
@@ -0,0 +1,33 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:complexType name="USAddress">
+ <xsd:sequence>
+ <xsd:element name="name" type="xsd:string"/>
+ <xsd:element name="street" type="xsd:string"/>
+ <xsd:element name="city" type="xsd:string"/>
+ <xsd:element name="state" type="xsd:string"/>
+ <xsd:element name="zip" type="xsd:decimal"/>
+ </xsd:sequence>
+ <xsd:attribute name="country" type="xsd:NMTOKEN" fixed="US"/>
+ </xsd:complexType>
+
+</xsd:schema>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/example.xml
new file mode 100644
index 0000000..c9e7732
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/example.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: example -->
+ <sm:activationSpec componentName="myDefaultErrorHandlerService" service="foo:myDefaultErrorHandlerService" endpoint="myDefaultErrorHandlerService" destinationService="foo:myServiceImpl">
+ <sm:component><bean class="org.apache.servicemix.components.validation.ValidateComponent">
+ <property name="schemaResource" value="classpath:org/apache/servicemix/components/validation/schema.xsd"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="myMessageAwareErrorHandlerService" service="foo:myMessageAwareErrorHandlerService" endpoint="myMessageAwareErrorHandlerService" destinationService="foo:myServiceImpl">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.validation.ValidateComponent">
+ <property name="schemaResource" value="classpath:org/apache/servicemix/components/validation/schema.xsd"/>
+ <property name="errorHandlerFactory" ref="messageAggregatingErrorHandlerFactory"/>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+ <!-- END SNIPPET: example -->
+
+ <!-- START SNIPPET: groovy -->
+ <sm:activationSpec componentName="myServiceImpl" service="foo:myServiceImpl" endpoint="myService">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+if (bindings.counter == null) {
+ bindings.counter = 1
+}
+else {
+ ++bindings.counter
+}
+
+def date = new Date()
+
+outMessage.bodyText = "<response counter='$bindings.counter' date='$date'></response>"
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: groovy -->
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="messageAggregatingErrorHandlerFactory" class="org.apache.servicemix.components.validation.MessageAggregatingErrorHandlerFactory">
+ <property name="rootPath" value="Fault/payload/messages"/>
+ <property name="namespace" value="http://www.servicemix.org/fault"/>
+ </bean>
+
+ <bean id="defaultErrorHandlerClient" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <sm:activationSpec destinationService="foo:myDefaultErrorHandlerService"/>
+ </constructor-arg>
+ </bean>
+
+ <bean id="messageAwareErrorHandlerClient" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <sm:activationSpec destinationService="foo:myMessageAwareErrorHandlerService"/>
+ </constructor-arg>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/requestInvalid.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/requestInvalid.xml
new file mode 100644
index 0000000..e853959
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/requestInvalid.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<wrongElement orderDate="1999-10-20">
+ <shipTo country="US">
+ <name>Alice Smith</name>
+ <street>123 Maple Street</street>
+ <city>Mill Valley</city>
+ <state>CA</state>
+ <zip>90952</zip>
+ </shipTo>
+ <billTo country="US">
+ <name>Robert Smith</name>
+ <street>8 Oak Avenue</street>
+ <city>Old Town</city>
+ <state>PA</state>
+ <zip>95819</zip>
+ </billTo>
+ <comment>Hurry, my lawn is going wild</comment>
+ <items>
+ <item partNum="872-AA">
+ <productName>Lawnmower</productName>
+ <quantity>1</quantity>
+ <USPrice>148.95</USPrice>
+ <comment>Confirm this is electric</comment>
+ </item>
+ <item partNum="926-AA">
+ <productName>Baby Monitor</productName>
+ <quantity>1</quantity>
+ <USPrice>39.98</USPrice>
+ <shipDate>1999-05-21</shipDate>
+ </item>
+ </items>
+</wrongElement>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/requestValid.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/requestValid.xml
new file mode 100644
index 0000000..abc29a6
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/requestValid.xml
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<purchaseOrder orderDate="1999-10-20">
+ <shipTo country="US">
+ <name>Alice Smith</name>
+ <street>123 Maple Street</street>
+ <city>Mill Valley</city>
+ <state>CA</state>
+ <zip>90952</zip>
+ </shipTo>
+ <billTo country="US">
+ <name>Robert Smith</name>
+ <street>8 Oak Avenue</street>
+ <city>Old Town</city>
+ <state>PA</state>
+ <zip>95819</zip>
+ </billTo>
+ <comment>Hurry, my lawn is going wild</comment>
+ <items>
+ <item partNum="872-AA">
+ <productName>Lawnmower</productName>
+ <quantity>1</quantity>
+ <USPrice>148.95</USPrice>
+ <comment>Confirm this is electric</comment>
+ </item>
+ <item partNum="926-AA">
+ <productName>Baby Monitor</productName>
+ <quantity>1</quantity>
+ <USPrice>39.98</USPrice>
+ <shipDate>1999-05-21</shipDate>
+ </item>
+ </items>
+</purchaseOrder>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/schema.xsd b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/schema.xsd
new file mode 100644
index 0000000..2fc2298
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/validation/schema.xsd
@@ -0,0 +1,75 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+
+ <xsd:annotation>
+ <xsd:documentation xml:lang="en">
+ Purchase order schema for Example.com.
+ Copyright 2000 Example.com. All rights reserved.
+ </xsd:documentation>
+ </xsd:annotation>
+
+ <xsd:include schemaLocation="address/address.xsd"/>
+
+ <xsd:element name="purchaseOrder" type="PurchaseOrderType"/>
+
+ <xsd:element name="comment" type="xsd:string"/>
+
+ <xsd:complexType name="PurchaseOrderType">
+ <xsd:sequence>
+ <xsd:element name="shipTo" type="USAddress"/>
+ <xsd:element name="billTo" type="USAddress"/>
+ <xsd:element ref="comment" minOccurs="0"/>
+ <xsd:element name="items" type="Items"/>
+ </xsd:sequence>
+ <xsd:attribute name="orderDate" type="xsd:date"/>
+ </xsd:complexType>
+
+ <xsd:complexType name="Items">
+ <xsd:sequence>
+ <xsd:element name="item" minOccurs="0" maxOccurs="unbounded">
+ <xsd:complexType>
+ <xsd:sequence>
+ <xsd:element name="productName" type="xsd:string"/>
+ <xsd:element name="quantity">
+ <xsd:simpleType>
+ <xsd:restriction base="xsd:positiveInteger">
+ <xsd:maxExclusive value="100"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+ </xsd:element>
+ <xsd:element name="USPrice" type="xsd:decimal"/>
+ <xsd:element ref="comment" minOccurs="0"/>
+ <xsd:element name="shipDate" type="xsd:date" minOccurs="0"/>
+ </xsd:sequence>
+ <xsd:attribute name="partNum" type="SKU" use="required"/>
+ </xsd:complexType>
+ </xsd:element>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <!-- Stock Keeping Unit, a code for identifying products -->
+ <xsd:simpleType name="SKU">
+ <xsd:restriction base="xsd:string">
+ <xsd:pattern value="\d{3}-[A-Z]{2}"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+
+</xsd:schema>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/vfs/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/vfs/example.xml
new file mode 100644
index 0000000..de9ae6f
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/vfs/example.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="fileSender" service="foo:fileSender">
+ <sm:component><bean class="org.apache.servicemix.components.vfs.FileWriter">
+ <property name="path" value="file:/tmp/servicemix/vfs/test"/>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.DefaultFileMarshaler">
+ <property name="fileName">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('sample_', /sample/@id, '.xml')"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+
+
+ <!-- START SNIPPET: poll -->
+ <sm:activationSpec componentName="filePoller" service="foo:filePoller" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.vfs.FilePoller">
+ <property name="workManager" ref="workManager"/>
+ <property name="path" value="file:/tmp/servicemix/vfs/test"/>
+ <property name="period" value="1000"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: poll -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver" endpoint="receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="workManager" class="org.jencks.factory.WorkManagerFactoryBean"/>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/vfs/example_win.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/vfs/example_win.xml
new file mode 100644
index 0000000..d1b9703
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/vfs/example_win.xml
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="fileSender" service="foo:fileSender">
+ <sm:component><bean class="org.apache.servicemix.components.vfs.FileWriter">
+ <property name="path" value="file://c:/tmp/servicemix/vfs/test"/>
+
+ <property name="marshaler">
+ <bean class="org.apache.servicemix.components.util.DefaultFileMarshaler">
+ <property name="fileName">
+ <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
+ <constructor-arg value="concat('sample_', /sample/@id, '.xml')"/>
+ </bean>
+ </property>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+
+
+ <!-- START SNIPPET: poll -->
+ <sm:activationSpec componentName="filePoller" service="foo:filePoller" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.vfs.FilePoller">
+ <property name="workManager" ref="workManager"/>
+ <property name="path" value="file://c:/tmp/servicemix/vfs/test"/>
+ <property name="period" value="1000"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: poll -->
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver" endpoint="receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="workManager" class="org.jencks.factory.WorkManagerFactoryBean"/>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/example.xml
new file mode 100644
index 0000000..d403441
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/example.xml
@@ -0,0 +1,109 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- ActiveMQ message broker -->
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- JCA container -->
+ <bean id="jencks" class="org.jencks.JCAContainer">
+
+ <!-- lets use the default configuration of work manager and transaction manager-->
+ <property name="bootstrapContext">
+ <bean class="org.jencks.factory.BootstrapContextFactoryBean">
+ <property name="threadPoolSize" value="25"/>
+ </bean>
+ </property>
+
+
+ <!-- the JCA Resource Adapter -->
+ <property name="resourceAdapter">
+ <bean id="activeMQResourceAdapter" class="org.apache.activemq.ra.ActiveMQResourceAdapter">
+ <property name="serverUrl" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+
+ <!-- JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+ <!-- START SNIPPET: wsif -->
+ <sm:activationSpec componentName="checkAvailability" service="foo:checkAvailability">
+ <sm:component><bean class="org.apache.servicemix.components.wsif.WSIFBinding">
+ <property name="definitionResource" value="classpath:org/apache/servicemix/components/wsif/service.wsdl"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: wsif -->
+ </sm:activationSpecs>
+ </sm:container>
+
+
+ <!--
+ || an inbound message connector using a stateless, thread safe MessageListener
+ -->
+ <bean id="inboundMessageA" class="org.jencks.JCAConnector">
+
+ <property name="jcaContainer" ref="jencks" />
+
+ <!-- subscription details -->
+ <property name="activationSpec">
+ <bean class="org.apache.activemq.ra.ActiveMQActivationSpec">
+ <property name="destination" value="test.org.apache.servicemix.example.wsif"/>
+ <property name="destinationType" value="javax.jms.Queue"/>
+ </bean>
+ </property>
+
+ <property name="ref" value="jmsService"/>
+ </bean>
+
+ <bean id="jmsService" class="org.apache.servicemix.components.wsif.SampleServiceMessageListener">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.example.wsif"/>
+ <property name="pubSubDomain" value="false"/>
+ </bean>
+ </property>
+ </bean>
+
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+
+ <constructor-arg ref="jbi"/>
+ <constructor-arg>
+ <!-- lets hardwire this client to talk to instances of a service by default -->
+ <sm:activationSpec destinationService="foo:checkAvailability"/>
+ </constructor-arg>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/request.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/request.xml
new file mode 100644
index 0000000..477c83c
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/request.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: request -->
+<ca:checkAvailabilityRequest xmlns:ca="http://xml.apache.org/axis/wsif/samples/jms/ServiceAvailability">
+10505
+</ca:checkAvailabilityRequest>
+<!-- END SNIPPET: request -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/service.wsdl b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/service.wsdl
new file mode 100644
index 0000000..c997331
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/wsif/service.wsdl
@@ -0,0 +1,76 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<definitions name='ServiceAvailability'
+ targetNamespace='http://xml.apache.org/axis/wsif/samples/jms/ServiceAvailability'
+ xmlns:tns='http://xml.apache.org/axis/wsif/samples/jms/ServiceAvailability'
+ xmlns:format="http://schemas.xmlsoap.org/wsdl/formatbinding/"
+ xmlns:jms='http://schemas.xmlsoap.org/wsdl/jms/'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns='http://schemas.xmlsoap.org/wsdl/'>
+
+ <!-- START SNIPPET: wsdl -->
+ <message name='checkAvailabilityRequest'>
+ <part name='zipCode' type='xsd:string'/>
+ </message>
+
+ <message name='checkAvailabilityResponse'>
+ <part name='result' type='xsd:string'/>
+ </message>
+
+ <portType name='CheckAvailabilityPortType'>
+ <operation name='checkAvailability'>
+ <input message='tns:checkAvailabilityRequest'/>
+ <output message='tns:checkAvailabilityResponse'/>
+ </operation>
+ </portType>
+
+ <binding name='CheckAvailabilityJMSBinding' type='tns:CheckAvailabilityPortType'>
+ <jms:binding type="TextMessage"/>
+ <format:typeMapping encoding="XML" style="Java">
+ <format:typeMap typeName="xsd:string" formatType="java.lang.String"/>
+ </format:typeMapping>
+ <operation name='checkAvailability'>
+ <input>
+ <jms:input parts="zipCode"/>
+ <jms:property message="Request" part="myInt"/>
+ <jms:propertyValue name="myLiteralString" type="xsd:string" value="Hello World"/>
+ </input>
+ <output>
+ <jms:output parts="result"/>
+ </output>
+ </operation>
+ </binding>
+ <!-- END SNIPPET: wsdl -->
+
+ <!-- START SNIPPET: wsif -->
+ <service name='CheckServiceAvailability'>
+ <port name='CheckAvailabilityPort' binding='tns:CheckAvailabilityJMSBinding'>
+
+ <!-- ActiveMQ configuration -->
+ <jms:address destinationStyle="queue"
+ jndiDestinationName="dynamicQueues/test.org.apache.servicemix.example.wsif"
+ jndiConnectionFactoryName="ConnectionFactory"
+ initialContextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory"
+ jndiProviderURL="tcp://localhost:61626"/>
+ </port>
+ </service>
+ <!-- END SNIPPET: wsif -->
+</definitions>
+
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/echo.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/echo.xml
new file mode 100644
index 0000000..9b8fa53
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/echo.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
+ <env:Body>
+ <m:echo xmlns:m="http://xfire.components.servicemix.org">
+ <m:in0>Yo Yo</m:in0>
+ </m:echo>
+ </env:Body>
+</env:Envelope>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/oneway.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/oneway.xml
new file mode 100644
index 0000000..ded2a04
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/oneway.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
+ <env:Body>
+ <m:receive xmlns:m="http://xfire.components.servicemix.org">
+ <m:in0>Yo Yo</m:in0>
+ </m:receive>
+ </env:Body>
+</env:Envelope>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/xfire-inout.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/xfire-inout.xml
new file mode 100644
index 0000000..36ed789
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/xfire-inout.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:xfire="http://xfire.components.servicemix.org">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+ <sm:activationSpec componentName="sender" service="xfire:sender" destinationService="xfire:OneWayService">
+ <sm:component><bean class="org.apache.servicemix.tck.SenderComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <!-- START SNIPPET: xfire -->
+ <sm:activationSpec componentName="binding" service="xfire:Echo">
+ <sm:component><bean class="org.apache.servicemix.components.xfire.XFireBinding">
+ <property name="xfire" ref="xfire"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xfire -->
+ </sm:activationSpecs>
+ </sm:container>
+
+ <!-- The Service Bean -->
+ <bean id="xfireReceiverService" class="org.apache.servicemix.components.xfire.Echo" singleton="true"/>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean name="Echo" class="org.codehaus.xfire.spring.ServiceBean">
+ <property name="serviceBean" ref="xfireReceiverService"/>
+ <property name="serviceFactory" ref="xfire.serviceFactory"/>
+ <property name="xfire" ref="xfire"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/xfire-out.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/xfire-out.xml
new file mode 100644
index 0000000..eda6cf0
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xfire/xfire-out.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:xfire="http://xfire.components.servicemix.org">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+ <sm:activationSpec componentName="sender" endpoint="sender" service="xfire:sender" destinationService="xfire:OneWayService">
+ <sm:component><bean class="org.apache.servicemix.tck.SenderComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <!-- START SNIPPET: xfire -->
+ <sm:activationSpec componentName="binding" service="xfire:OneWayService">
+ <sm:component><bean class="org.apache.servicemix.components.xfire.XFireOutBinding">
+ <property name="xfire" ref="xfire"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xfire -->
+ </sm:activationSpecs>
+ </sm:container>
+
+ <!-- The Service Bean -->
+ <bean id="xfireReceiverService" class="org.apache.servicemix.components.xfire.OneWayService" singleton="true"/>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="messageServiceFactory"
+ class="org.codehaus.xfire.service.binding.ObjectServiceFactory"
+ singleton="true">
+ <constructor-arg index="0">
+ <ref bean="xfire.transportManager"/>
+ </constructor-arg>
+ <constructor-arg index="1">
+ <ref bean="xfire.aegisBindingProvider"/>
+ </constructor-arg>
+ <property name="voidOneWay" value="true"/>
+ <property name="style" value="message"/>
+ </bean>
+
+ <bean name="OneWayService" class="org.codehaus.xfire.spring.ServiceBean">
+ <property name="serviceBean" ref="xfireReceiverService"/>
+ <property name="serviceFactory" ref="messageServiceFactory"/>
+ <property name="xfire" ref="xfire"/>
+ </bean>
+
+</beans>
+
+
+
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/example.xml
new file mode 100644
index 0000000..a9a57f5
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/example.xml
@@ -0,0 +1,143 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean" singleton="true">
+ <property name="config" value="classpath:broker.xml"/>
+ </bean>
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" depends-on="broker" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: send -->
+ <sm:activationSpec componentName="myJmsSender" service="foo:myJmsSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.components.xslt.source"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: send -->
+
+ <!-- lets subscribe, transform and republish -->
+ <!-- START SNIPPET: receive -->
+ <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:transformer">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.components.xslt.source"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: receive -->
+
+ <!-- START SNIPPET: xslt -->
+ <sm:activationSpec componentName="transformer" service="foo:transformer" destinationService="foo:transformedSender">
+ <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
+ <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/transform.xsl"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xslt -->
+
+
+ <sm:activationSpec componentName="transformedSender" service="foo:transformedSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.components.xslt.result"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- ultimate endpoint -->
+ <sm:activationSpec componentName="resultReader" service="foo:resultReader" destinationService="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.components.xslt.result"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver" endpoint="receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+
+ <!-- just to test that we are sending messages, lets trace the messages we receive -->
+ <!-- START SNIPPET: log -->
+ <sm:activationSpec componentName="jmsTrace" service="foo:jmsTrace" destinationService="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="test.org.apache.servicemix.components.xslt.result"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.util.TraceComponent"/></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: log -->
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="tcp://localhost:61626"/>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/optional-axis-example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/optional-axis-example.xml
new file mode 100644
index 0000000..7be4288
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/optional-axis-example.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="transformer" service="foo:transformer">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.xslt.XsltComponent">
+ <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/optional-axis.xsl"/>
+
+ <!-- lets disable automatic output of the result of the transform; only if we perform
+ an invoke in the XSLT will we invoke another endpoint -->
+ <property name="disableOutput" value="true"/>
+ </bean>
+ </sm:component>
+ </sm:activationSpec>
+
+
+ <sm:activationSpec componentName="service1" service="foo:service1">
+ <sm:component>
+ <bean class="org.apache.servicemix.tck.ReceiverComponent"/>
+ </sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service2" service="foo:service2">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service3" service="foo:service3">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service4" service="foo:service4">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service5" service="foo:service5">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="service6" service="foo:service6">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component>
+ <bean class="org.apache.servicemix.tck.ReceiverComponent"/>
+ </sm:component>
+ </sm:activationSpec>
+
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component>
+ <bean class="org.apache.servicemix.components.util.TraceComponent"/>
+ </sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/optional-axis.xsl b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/optional-axis.xsl
new file mode 100644
index 0000000..de749ea
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/optional-axis.xsl
@@ -0,0 +1,79 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: route -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:jbi="xalan://org.apache.servicemix.components.xslt.XalanExtension"
+ extension-element-prefixes="jbi"
+
+ xmlns:foo="http://servicemix.org/cheese/"
+
+ xmlns:prod="http://foo.org/prod" xmlns:ms="http://foo.org/ms" xmlns:xsi="http://foo.org/msi"
+
+ version="1.0">
+
+ <!--xsl:strip-space elements="*"/-->
+ <xsl:template match="/">
+
+ <jbi:invoke service="foo:service1">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="prod:resolveItemXrefResponse/prod:response/ms:Values/ms:Item[position() = 1]"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:service2">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="prod:resolveItemXrefResponse/prod:response/ms:Values/ms:Item[position() = 2]"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:service3">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="prod:resolveItemXrefResponse/prod:response/ms:Values/ms:Item[position() = 3]"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:service4">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="prod:resolveItemXrefResponse/prod:response/ms:Values/ms:Item[position() = 4]"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:service5">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="count(prod:resolveItemXrefResponse/prod:response/ms:Keys/ms:Item[text()='MSTR']/preceding-sibling::*) + 1"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:service6">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="prod:resolveItemXrefResponse/prod:response/ms:Values/ms:Item[position() = count(prod:resolveItemXrefResponse/prod:response/ms:Keys/ms:Item[text()='MSTR']/preceding-sibling::*) + 1]"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:receiver">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="bar" select="/"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ </xsl:template>
+ <!-- /prod:resolveItemXrefResponse/prod:response/ms:Values/ms:Item[position()=count(/prod:resolveItemXrefResponse/prod:response/ms:Keys/ms:Item[text()='MSTR']/preceding-sibling::*) + 1])-->
+</xsl:stylesheet>
+<!-- END SNIPPET: route -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl
new file mode 100644
index 0000000..4a2d6fb
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/parameter-test.xsl
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<xsl:stylesheet
+ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+ version='1.0'>
+
+ <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+ <xsl:param name="stringParam"/>
+ <xsl:param name="integerParam"/>
+
+ <xsl:template match="*">
+ <rootNode>
+ <param><xsl:value-of select="$stringParam"/></param>
+ <integer><xsl:value-of select="$integerParam"/></integer>
+ </rootNode>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/pipeline.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/pipeline.xml
new file mode 100644
index 0000000..fd258c8
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/pipeline.xml
@@ -0,0 +1,75 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: pipeline -->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/demo/pipeline/">
+
+ <!-- the JBI container and its components -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <sm:activationSpec componentName="myJmsReceiver" service="foo:myJmsReceiver" destinationService="foo:transformer">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsReceiverComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="demo.cheese.source"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="transformer" service="foo:transformer" destinationService="foo:transformedSender">
+ <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
+ <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/transform.xsl"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="transformedSender" service="foo:transformedSender">
+ <sm:component><bean class="org.apache.servicemix.components.jms.JmsSenderComponent">
+ <property name="template">
+ <bean class="org.springframework.jms.core.JmsTemplate">
+ <property name="connectionFactory">
+ <ref local="jmsFactory"/>
+ </property>
+ <property name="defaultDestinationName" value="demo.cheese.result"/>
+ <property name="pubSubDomain" value="true"/>
+ </bean>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="jmsFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="connectionFactory">
+ <bean class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="vm://localhost?broker.persistent=false"/>
+ </bean>
+ </property>
+ </bean>
+
+</beans>
+
+<!-- END SNIPPET: pipeline -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/publish.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/publish.xml
new file mode 100644
index 0000000..9dd1e98
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/publish.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: xslt -->
+ <sm:activationSpec componentName="transformer" service="foo:transformer">
+ <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
+ <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/publish.xsl"/>
+
+ <!-- lets disable automatic output of the result of the transform; only if we perform
+ an invoke in the XSLT will we invoke another endpoint -->
+ <property name="disableOutput" value="true"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xslt -->
+
+
+ <sm:activationSpec componentName="service1" service="foo:service1">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ <sm:activationSpec componentName="service2" service="foo:service2">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ <sm:activationSpec componentName="service3" service="foo:service3">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.util.TraceComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/publish.xsl b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/publish.xsl
new file mode 100644
index 0000000..29a1d5b
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/publish.xsl
@@ -0,0 +1,61 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: route -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:jbi="xalan://org.apache.servicemix.components.xslt.XalanExtension"
+ extension-element-prefixes="jbi"
+
+ xmlns:foo="http://servicemix.org/cheese/"
+ version="1.0">
+
+ <xsl:strip-space elements="*"/>
+
+ <xsl:template match="/">
+
+ <!-- lets invoke a number of services one after the other -->
+ <jbi:invoke service="foo:service1">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="/sample"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:service2">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="bar" select="/sample/@id"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:service3">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="string(/sample)"/>
+ <jbi:setOutProperty name="bar" select="string(/sample/@id)"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ <jbi:invoke service="foo:receiver">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="bar" select="/sample/@id"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ </xsl:template>
+
+</xsl:stylesheet>
+<!-- END SNIPPET: route -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router-example.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router-example.xml
new file mode 100644
index 0000000..28821ff
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router-example.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: xslt -->
+ <sm:activationSpec componentName="transformer" service="foo:transformer">
+ <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
+ <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/router.xsl"/>
+
+ <!-- lets disable automatic output of the result of the transform; only if we perform
+ an invoke in the XSLT will we invoke another endpoint -->
+ <property name="disableOutput" value="true"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xslt -->
+
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.util.TraceComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="script" service="foo:script">
+ <sm:component><bean class="org.apache.servicemix.components.groovy.GroovyComponent">
+ <property name="disableOutput" value="true"/>
+
+ <property name="scriptText">
+ <value>
+ <![CDATA[
+
+println """
+
+########################################
+## script called with message: $inMessage
+## properties: $inMessage.properties
+## XML content: $inMessage.bodyText
+########################################
+
+"""
+ ]]>
+ </value>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router.xsl b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router.xsl
new file mode 100644
index 0000000..7470916
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/router.xsl
@@ -0,0 +1,58 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: route -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:jbi="xalan://org.apache.servicemix.components.xslt.XalanExtension"
+ extension-element-prefixes="jbi"
+
+ xmlns:foo="http://servicemix.org/cheese/"
+ version="1.0">
+
+ <xsl:template match="/*">
+ <xsl:choose>
+
+ <!-- lets forward the inbound message to a service -->
+ <xsl:when test="@id = '4'">
+ <jbi:forward service="foo:trace"/>
+ </xsl:when>
+
+ <!-- lets generate the output XML to use as input, copy the input properties and define some new propertes -->
+ <xsl:when test="@id = '12'">
+ <jbi:invoke service="foo:script">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="foo" select="@sent"/>
+ <cheese code="{@id}">
+ <description>This is some content generated from the routing XSL</description>
+ </cheese>
+ </jbi:invoke>
+ </xsl:when>
+
+ <xsl:when test="@id != '2'">
+ <jbi:forward service="foo:receiver"/>
+ </xsl:when>
+
+ <xsl:otherwise>
+ <jbi:forward service="foo:trace"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:template>
+
+</xsl:stylesheet>
+<!-- END SNIPPET: route -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml
new file mode 100644
index 0000000..6c9a2de
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/servicemix-parameter-test.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" embedded="true">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: xslt -->
+ <sm:activationSpec componentName="transformer" service="foo:transformer">
+ <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
+ <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/parameter-test.xsl"/>
+ <property name="xsltParameters">
+ <map>
+ <entry key="stringParam" value="cheeseyCheese"/>
+ <entry key="integerParam" value-ref="javaIntegerObject"/>
+ </map>
+ </property>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xslt -->
+
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="javaIntegerObject" class="java.lang.Integer">
+ <constructor-arg index="0" value="4002"/>
+ </bean>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+
+
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/split.xml b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/split.xml
new file mode 100644
index 0000000..4195927
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/split.xml
@@ -0,0 +1,63 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0"
+ xmlns:foo="http://servicemix.org/cheese/">
+
+ <!-- the JBI container -->
+ <sm:container id="jbi" flowName="st">
+ <sm:activationSpecs>
+
+ <!-- START SNIPPET: xslt -->
+ <sm:activationSpec componentName="transformer" service="foo:transformer">
+ <sm:component><bean class="org.apache.servicemix.components.xslt.XsltComponent">
+ <property name="xsltResource" value="classpath:org/apache/servicemix/components/xslt/split.xsl"/>
+
+ <!-- lets disable automatic output of the result of the transform; only if we perform
+ an invoke in the XSLT will we invoke another endpoint -->
+ <property name="disableOutput" value="true"/>
+ </bean></sm:component>
+ </sm:activationSpec>
+ <!-- END SNIPPET: xslt -->
+
+
+ <sm:activationSpec componentName="service1" service="foo:service1">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ <sm:activationSpec componentName="service2" service="foo:service2">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+ <sm:activationSpec componentName="service3" service="foo:service3">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="receiver" service="foo:receiver">
+ <sm:component><bean class="org.apache.servicemix.tck.ReceiverComponent"/></sm:component>
+ </sm:activationSpec>
+
+ <sm:activationSpec componentName="trace" service="foo:trace">
+ <sm:component><bean class="org.apache.servicemix.components.util.TraceComponent"/></sm:component>
+ </sm:activationSpec>
+ </sm:activationSpecs>
+ </sm:container>
+
+ <bean id="client" class="org.apache.servicemix.client.DefaultServiceMixClient">
+ <constructor-arg ref="jbi"/>
+ </bean>
+</beans>
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/split.xsl b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/split.xsl
new file mode 100644
index 0000000..d369bd5
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/split.xsl
@@ -0,0 +1,54 @@
+<?xml version="1.0"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<!-- START SNIPPET: example -->
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:jbi="xalan://org.apache.servicemix.components.xslt.XalanExtension"
+ extension-element-prefixes="jbi"
+ xmlns:foo="http://servicemix.org/cheese/" version="1.0">
+
+ <xsl:template match="/">
+
+ <!-- lets pass a new message body -->
+ <jbi:invoke service="foo:service1">
+ <cheese id="{/foo/@id}">Edam</cheese>
+ </jbi:invoke>
+
+ <!-- lets split the message -->
+ <jbi:invoke service="foo:service2">
+ <xsl:copy-of select="/foo/beer"/>
+ </jbi:invoke>
+
+ <!-- 1-many split -->
+ <xsl:for-each select="/foo/lineitem">
+ <jbi:invoke service="foo:service3">
+ <xsl:copy-of select="."/>
+ </jbi:invoke>
+ </xsl:for-each>
+
+ <!-- pass the entire message to the final endpoint -->
+ <jbi:invoke service="foo:receiver">
+ <jbi:copyProperties/>
+ <jbi:setOutProperty name="bar" select="/sample/@id"/>
+ <xsl:copy-of select="/"/>
+ </jbi:invoke>
+
+ </xsl:template>
+</xsl:stylesheet>
+<!-- END SNIPPET: example -->
diff --git a/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/transform.xsl b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/transform.xsl
new file mode 100644
index 0000000..127dc07
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/org/apache/servicemix/components/xslt/transform.xsl
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<xsl:stylesheet
+ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+ version='1.0'>
+
+ <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+ <xsl:template match="*">
+ <xsl:copy>
+ <xsl:copy-of select="attribute::*"/>
+ <xsl:apply-templates/>
+ </xsl:copy>
+ </xsl:template>
+
+ <xsl:template match="sample">
+ <transformed>
+ <cheese>
+ <xsl:apply-templates select="*|@*"/>
+ </cheese>
+ </transformed>
+ </xsl:template>
+
+</xsl:stylesheet>
diff --git a/common/servicemix-components/src/test/resources/xbean/xbean.xml b/common/servicemix-components/src/test/resources/xbean/xbean.xml
new file mode 100644
index 0000000..7f9b860
--- /dev/null
+++ b/common/servicemix-components/src/test/resources/xbean/xbean.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<beans xmlns:x="java://org.apache.servicemix.components.xbean">
+
+ <classpath>
+ <location>SpringLoaderTest.jar</location>
+ </classpath>
+
+ <x:EndpointSpec
+ xmlns:foo="http://foo.bar.com"
+ serviceName="foo:myService"
+ endpointName="myEndpoint">
+ <pojo>
+ <bean class="TestClass"/>
+ </pojo>
+ </x:EndpointSpec>
+
+</beans>
diff --git a/distributions/apache-servicemix/pom.xml b/distributions/apache-servicemix/pom.xml
index 93df0da..6ebb1b4 100644
--- a/distributions/apache-servicemix/pom.xml
+++ b/distributions/apache-servicemix/pom.xml
@@ -59,6 +59,10 @@
</dependency>
<dependency>
<groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-components</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-common</artifactId>
</dependency>
<dependency>
diff --git a/distributions/apache-servicemix/src/main/assembly/unix-bin.xml b/distributions/apache-servicemix/src/main/assembly/unix-bin.xml
index 7591969..d0de665 100644
--- a/distributions/apache-servicemix/src/main/assembly/unix-bin.xml
+++ b/distributions/apache-servicemix/src/main/assembly/unix-bin.xml
@@ -112,6 +112,7 @@
<dependencySet>
<outputDirectory>extras</outputDirectory>
<includes>
+ <include>org.apache.servicemix:servicemix-components</include>
<include>org.apache.servicemix:servicemix-beanflow</include>
</includes>
</dependencySet>
diff --git a/distributions/apache-servicemix/src/main/assembly/windows-bin.xml b/distributions/apache-servicemix/src/main/assembly/windows-bin.xml
index b3e850d..952856d 100644
--- a/distributions/apache-servicemix/src/main/assembly/windows-bin.xml
+++ b/distributions/apache-servicemix/src/main/assembly/windows-bin.xml
@@ -104,6 +104,7 @@
<dependencySet>
<outputDirectory>extras</outputDirectory>
<includes>
+ <include>org.apache.servicemix:servicemix-components</include>
<include>org.apache.servicemix:servicemix-beanflow</include>
</includes>
</dependencySet>
diff --git a/pom.xml b/pom.xml
index 46525db..621e5dc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,7 +81,7 @@
<servicemix-mail-version>2011.01</servicemix-mail-version>
<servicemix-osworkflow-version>2011.01</servicemix-osworkflow-version>
<servicemix-wsn2005-version>2011.01</servicemix-wsn2005-version>
- <servicemix-lwcontainer-version>3.4-SNAPSHOT</servicemix-lwcontainer-version>
+ <servicemix-lwcontainer-version>${project.version}</servicemix-lwcontainer-version>
<servicemix-bean-version>2011.01</servicemix-bean-version>
<servicemix-eip-version>2011.01</servicemix-eip-version>
<servicemix-script-version>2011.01</servicemix-script-version>
@@ -150,6 +150,7 @@
<modules>
<module>parent</module>
<module>core</module>
+ <module>common</module>
<module>deployables</module>
<module>servicemix-itests</module>
<module>samples</module>
@@ -193,6 +194,7 @@
<id>deploy</id>
<modules>
<module>core</module>
+ <module>common</module>
<module>servicemix-itests</module>
<module>samples</module>
<module>web</module>
@@ -239,6 +241,7 @@
<modules>
<module>parent</module>
<module>core</module>
+ <module>common</module>
<module>servicemix-itests</module>
<module>samples</module>
<module>web</module>
@@ -464,6 +467,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-components</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.servicemix.geronimo</groupId>
<artifactId>deployer-service</artifactId>
<version>${project.version}</version>
@@ -988,6 +996,11 @@
<version>${derby-version}</version>
</dependency>
<dependency>
+ <groupId>drools</groupId>
+ <artifactId>drools-all-jdk1.4</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>5.1.1</version>
@@ -1137,6 +1150,11 @@
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-servlet_2.4_spec</artifactId>
+ <version>1.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-servlet_3.0_spec</artifactId>
<version>1.0</version>
</dependency>
@@ -1364,6 +1382,11 @@
<version>1.0</version>
</dependency>
<dependency>
+ <groupId>quartz</groupId>
+ <artifactId>quartz</artifactId>
+ <version>1.5.2</version>
+ </dependency>
+ <dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>1.8.3</version>