You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by jb...@apache.org on 2009/06/09 17:04:59 UTC

svn commit: r783026 - in /servicemix/smx3/trunk/samples/database-bean: ./ database-bean-sa/ database-bean-su/ database-bean-su/src/ database-bean-su/src/main/ database-bean-su/src/main/java/ database-bean-su/src/main/java/org/ database-bean-su/src/main...

Author: jbonofre
Date: Tue Jun  9 15:04:59 2009
New Revision: 783026

URL: http://svn.apache.org/viewvc?rev=783026&view=rev
Log:
[SM-1864] Initial release of the new database bean sample.

Added:
    servicemix/smx3/trunk/samples/database-bean/
    servicemix/smx3/trunk/samples/database-bean/database-bean-sa/
    servicemix/smx3/trunk/samples/database-bean/database-bean-sa/pom.xml   (with props)
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/pom.xml   (with props)
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/samples/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/samples/DatabaseQueryBean.java   (with props)
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/resources/
    servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/resources/xbean.xml   (with props)
    servicemix/smx3/trunk/samples/database-bean/pom.xml   (with props)

Added: servicemix/smx3/trunk/samples/database-bean/database-bean-sa/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/samples/database-bean/database-bean-sa/pom.xml?rev=783026&view=auto
==============================================================================
--- servicemix/smx3/trunk/samples/database-bean/database-bean-sa/pom.xml (added)
+++ servicemix/smx3/trunk/samples/database-bean/database-bean-sa/pom.xml Tue Jun  9 15:04:59 2009
@@ -0,0 +1,55 @@
+<?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.samples</groupId>
+        <artifactId>database-bean</artifactId>
+        <version>3.3.1-SNAPSHOT</version>
+    </parent>         
+    
+    <groupId>org.apache.servicemix.samples.database-bean</groupId>
+    <artifactId>database-bean-sa</artifactId>
+    <packaging>jbi-service-assembly</packaging>
+    <name>ServiceMix :: Samples :: Database Bean :: SA</name>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix.samples.database-bean</groupId>
+            <artifactId>database-bean-su</artifactId>
+            <version>3.3.1-SNAPSHOT</version>
+        </dependency>
+    </dependencies>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>jbi-maven-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+         
+</project>
\ No newline at end of file

Propchange: servicemix/smx3/trunk/samples/database-bean/database-bean-sa/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/smx3/trunk/samples/database-bean/database-bean-su/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/samples/database-bean/database-bean-su/pom.xml?rev=783026&view=auto
==============================================================================
--- servicemix/smx3/trunk/samples/database-bean/database-bean-su/pom.xml (added)
+++ servicemix/smx3/trunk/samples/database-bean/database-bean-su/pom.xml Tue Jun  9 15:04:59 2009
@@ -0,0 +1,75 @@
+<?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.samples</groupId>
+        <artifactId>database-bean</artifactId>
+        <version>3.3.1-SNAPSHOT</version>
+    </parent>
+    
+    <groupId>org.apache.servicemix.samples.database-bean</groupId>
+    <artifactId>database-bean-su</artifactId>
+    <packaging>jbi-service-unit</packaging>
+    <name>ServiceMix :: Samples :: Database Bean :: SU</name>
+    
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.servicemix</groupId>
+            <artifactId>servicemix-bean</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>commons-dbcp</groupId>
+            <artifactId>commons-dbcp</artifactId>
+            <version>1.2.2</version>
+        </dependency>
+        <dependency>
+            <groupId>com.oracle</groupId>
+            <artifactId>ojdbc14</artifactId>
+            <version>10.2.0.3.0</version>
+        </dependency>
+    </dependencies>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.5</source>
+                    <target>1.5</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>jbi-maven-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+         
+</project>
\ No newline at end of file

Propchange: servicemix/smx3/trunk/samples/database-bean/database-bean-su/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/samples/DatabaseQueryBean.java
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/samples/DatabaseQueryBean.java?rev=783026&view=auto
==============================================================================
--- servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/samples/DatabaseQueryBean.java (added)
+++ servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/samples/DatabaseQueryBean.java Tue Jun  9 15:04:59 2009
@@ -0,0 +1,93 @@
+package org.apache.servicemix.samples;
+
+import javax.annotation.Resource;
+import javax.jbi.messaging.DeliveryChannel;
+import javax.jbi.messaging.ExchangeStatus;
+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 javax.xml.transform.TransformerException;
+
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.listener.MessageExchangeListener;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+public class DatabaseQueryBean implements MessageExchangeListener {
+    
+    @Resource
+    private DeliveryChannel channel;
+    
+    private JdbcTemplate jdbcTemplate;
+    
+    public void setDataSource(DataSource dataSource) {
+        this.jdbcTemplate = new JdbcTemplate(dataSource);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.servicemix.jbi.listener.MessageExchangeListener#onMessageExchange(javax.jbi.messaging.MessageExchange)
+     */
+    public void onMessageExchange(MessageExchange exchange) throws MessagingException {
+        if (exchange.getStatus() == ExchangeStatus.ACTIVE) {
+            // the exchange is active.
+            // get the in message.
+            NormalizedMessage message = exchange.getMessage("in");
+            // use the marshaler to get the query embedded in the "in" message
+            String query = null;
+            try {
+                query = this.fromMessageToQuery(message);
+            } catch (TransformerException te) {
+                throw new MessagingException("Error while parsing incoming message.", te);
+            }
+            // execute the query on the database and get result set
+            String result = (String)jdbcTemplate.queryForObject(query, String.class);
+            // send content in out message (depending of the MEP)
+            message.setContent(new StringSource("<result>" + result + "</result>"));
+            exchange.setMessage(message, "out");
+            channel.send(exchange);
+        }
+    }
+    
+    /**
+     * <p>
+     * Parse the given normalized message to construct the SQL query.
+     * </p>
+     * 
+     * @param message the <code>NormalizedMessage</code>.
+     * @return the SQL query.
+     * @throws MessagingException in case of parsing error.
+     */
+    protected String fromMessageToQuery(NormalizedMessage message) throws TransformerException {
+        String query = null;
+        
+        try {
+            Source content = message.getContent();
+            SourceTransformer transformer = new SourceTransformer();
+        
+            // transform the message content to a DOM document
+            Document document = transformer.toDOMDocument(content);
+            document.getDocumentElement().normalize();
+        
+            // get the query node
+            NodeList queryNode = document.getElementsByTagName("query");
+            if (queryNode == null) {
+                throw new TransformerException("Invalid message content. The message doesn't contain query tag.");
+            }
+            if (queryNode.getLength() > 1) {
+                throw new TransformerException("Invalid message content. Only one query tag is allowed.");
+            }
+        
+            // return the query
+            query = queryNode.item(0).getChildNodes().item(0).getNodeValue();
+        } catch (Exception e) {
+            throw new TransformerException(e);
+        }
+        return query;
+    }
+
+}

Propchange: servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/java/org/apache/servicemix/samples/DatabaseQueryBean.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/resources/xbean.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/resources/xbean.xml?rev=783026&view=auto
==============================================================================
--- servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/resources/xbean.xml (added)
+++ servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/resources/xbean.xml Tue Jun  9 15:04:59 2009
@@ -0,0 +1,38 @@
+<?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:bean="http://servicemix.apache.org/bean/1.0"
+       xmlns:dbb="http://servicemix.apache.org/samples/dbb">
+       
+    <bean:endpoint service="dbb" endpoint="bean">
+        <bean:bean>
+            <bean class="org.apache.servicemix.samples.DatabaseQueryBean">
+                <property name="dataSource" ref="dataSource"/>
+            </bean>
+        </bean:bean>
+    </bean:endpoint>
+    
+    <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
+        <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
+        <property name="url" value="jdbc:oracle:thin:srvfms-49:1522:V10UTF8"/>
+        <property name="username" value="test"/>
+        <property name="password" value="test"/>
+    </bean>
+
+</beans>
\ No newline at end of file

Propchange: servicemix/smx3/trunk/samples/database-bean/database-bean-su/src/main/resources/xbean.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: servicemix/smx3/trunk/samples/database-bean/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx3/trunk/samples/database-bean/pom.xml?rev=783026&view=auto
==============================================================================
--- servicemix/smx3/trunk/samples/database-bean/pom.xml (added)
+++ servicemix/smx3/trunk/samples/database-bean/pom.xml Tue Jun  9 15:04:59 2009
@@ -0,0 +1,72 @@
+<?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>samples</artifactId>
+        <version>3.3.1-SNAPSHOT</version>
+    </parent>
+    
+    <groupId>org.apache.servicemix.samples</groupId>
+    <artifactId>database-bean</artifactId>
+    <name>ServiceMix :: Samples :: Database Bean</name>
+    <packaging>pom</packaging>
+    
+    <modules>
+        <module>database-bean-su</module>
+        <module>database-bean-sa</module>
+    </modules>
+    
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-assembly-plugin</artifactId>
+                <version>2.1</version>
+                <inherited>false</inherited>
+                <executions>
+                    <execution>
+                        <id>src</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>single</goal>
+                        </goals>
+                        <configuration>
+                            <descriptors>
+                                <descriptor>src/main/assembly/src.xml</descriptor>
+                            </descriptors>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.servicemix.tooling</groupId>
+                <artifactId>jbi-maven-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+        </plugins>
+    </build>
+         
+</project>
\ No newline at end of file

Propchange: servicemix/smx3/trunk/samples/database-bean/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain