[jboss-svn-commits] JBL Code SVN: r10660 - in labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq: src and 4 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Mar 30 16:53:57 EDT 2007
Author: kurt.stam at jboss.com
Date: 2007-03-30 16:53:57 -0400 (Fri, 30 Mar 2007)
New Revision: 10660
Added:
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/README.txt
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/pom.xml
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQContext.java
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQInitialContextFactory.java
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQUtil.java
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/DestinationInfo.java
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/NameParserImpl.java
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/DatasourceTest.java
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/QueueTest.java
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/resources/
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/resources/oracle-aq.properties
Modified:
labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/
Log:
Working on OracleAQ JNDI-Context plugin.
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq
___________________________________________________________________
Name: svn:ignore
+ target
bin
.project
.classpath
.gpd.pom.xml
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/README.txt
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/README.txt (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/README.txt 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,9 @@
+
+To be able to compile this plugin you will need 2 proprietary libraries from Oracle: aqapi13.jar and ojbc14.jar,
+and a libray containing javax.jms. Here we have picked the jboss-messaging-client.jar
+
+Try installing them to your local maven repository using the following commands:
+
+mvn install:install-file -DgroupId=oracle -DartifactId=aqapi -Dversion=13 -Dpackaging=jar -Dfile=aqapi13.jar
+mvn install:install-file -DgroupId=oracle -DartifactId=ojdbc -Dversion=14 -Dpackaging=jar -Dfile=ojdbc14.jar
+mvn install:install-file -DgroupId=jboss-messaging-client -DartifactId=jboss-messaging-client -Dversion=1.2 -Dpackaging=jar -Dfile=jboss-messaging-client.jar
\ No newline at end of file
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/pom.xml
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/pom.xml (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/pom.xml 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,80 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.soa.esb</groupId>
+ <artifactId>org.jboss.soa.esb.oracle.aq</artifactId>
+ <version>4.2</version>
+ <description>
+ Plugin to add JNDI capability to Oracle AQ
+ </description>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <archive>
+ <addMavenDescriptor>false</addMavenDescriptor>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-clean-plugin</artifactId>
+ <version>2.1</version>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${basedir}/output</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>oracle</groupId>
+ <artifactId>aqapi</artifactId>
+ <version>13</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>oracle</groupId>
+ <artifactId>ojdbc</artifactId>
+ <version>14</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <version>1.0.4</version>
+ </dependency>
+ <dependency>
+ <groupId>jboss-messaging-client</groupId>
+ <artifactId>jboss-messaging-client</artifactId>
+ <version>1.2</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.1</version>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/pom.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQContext.java
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQContext.java (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQContext.java 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,435 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007,
+ *
+ */
+package org.jboss.soa.esb.oracle.aq;
+
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.naming.Binding;
+import javax.naming.CompositeName;
+import javax.naming.Context;
+import javax.naming.LinkRef;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.NotContextException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.Reference;
+import javax.naming.spi.NamingManager;
+
+/**
+ * A read-only Context
+ * <p/>
+ * This version assumes it and all its subcontext are read-only and any attempt
+ * to modify (e.g. through bind) will result in an OperationNotSupportedException.
+ * Each Context in the tree builds a cache of the entries in all sub-contexts
+ * to optimise the performance of lookup.
+ * </p>
+ * <p>This implementation is intended to optimise the performance of lookup(String)
+ * to about the level of a HashMap get. It has been observed that the scheme
+ * resolution phase performed by the JVM takes considerably longer, so for
+ * optimum performance lookups should be coded like:</p>
+ * <code>
+ * Context componentContext = (Context)new InitialContext().lookup("java:comp");
+ * String envEntry = (String) componentContext.lookup("env/myEntry");
+ * String envEntry2 = (String) componentContext.lookup("env/myEntry2");
+ * </code>
+ *
+ * @author David Fry <dfry at redhat.com>
+ * @author Kurt Stam <kurt.stam at jboss.com>
+ */
+public class AQContext implements Context, Serializable {
+ private static final long serialVersionUID = -5754338187296859149L;
+ protected static final NameParser nameParser = new NameParserImpl();
+ /** environment for this context */
+ protected final Hashtable<String,Object> environment;
+ /** bindings at my level */
+ protected final Map<String,Object> bindings;
+ /** all bindings under me */
+ protected final Map<String,Object> treeBindings;
+
+ private boolean frozen = false;
+ private String nameInNamespace = "";
+ public static final String SEPARATOR = "/";
+
+ public AQContext() {
+ this.environment = new Hashtable<String,Object>();
+ this.bindings = new HashMap<String,Object>();
+ this.treeBindings = new HashMap<String,Object>();
+ }
+
+ @SuppressWarnings("unchecked")
+ public AQContext(Hashtable<?,?> environment)
+ {
+ if (environment == null) {
+ this.environment = new Hashtable<String,Object>();
+ } else {
+ this.environment = (Hashtable<String,Object>)environment;
+ }
+ this.bindings = new HashMap<String,Object>();
+ this.treeBindings = new HashMap<String,Object>();
+ }
+
+ @SuppressWarnings("unchecked")
+ public AQContext(Hashtable<?,?> environment, Map bindings)
+ {
+ if (environment == null) {
+ this.environment = new Hashtable<String,Object>();
+ } else {
+ this.environment = (Hashtable<String,Object>)environment;
+ }
+ this.bindings = new HashMap<String,Object>();
+ this.treeBindings = new HashMap<String,Object>();
+ frozen = true;
+ }
+
+ public AQContext(Hashtable<String,Object> environment, Map bindings, String nameInNamespace) {
+ this(environment, bindings);
+ this.nameInNamespace = nameInNamespace;
+ }
+
+ protected AQContext(AQContext clone, Hashtable<String,Object> environment) {
+ this.bindings = clone.bindings;
+ this.treeBindings = clone.treeBindings;
+ this.environment = environment;
+ }
+
+ protected AQContext(AQContext clone, Hashtable<String,Object> environment, String nameInNamespace) {
+ this(clone, environment);
+ this.nameInNamespace = nameInNamespace;
+ }
+
+ public void freeze() {
+ frozen = true;
+ }
+
+ boolean isFrozen() {
+ return frozen;
+ }
+
+ /**
+ * internalBind is intended for use only during setup or possibly by suitably synchronized superclasses.
+ * It binds every possible lookup into a map in each context. To do this, each context
+ * strips off one name segment and if necessary creates a new context for it. Then it asks that context
+ * to bind the remaining name. It returns a map containing all the bindings from the next context, plus
+ * the context it just created (if it in fact created it). (the names are suitably extended by the segment
+ * originally lopped off).
+ *
+ * @param name
+ * @param value
+ * @return
+ * @throws javax.naming.NamingException
+ */
+ protected Map<String, Object> internalBind(String name, Object value) throws NamingException {
+ assert name != null && name.length() > 0;
+ assert !frozen;
+
+ Map<String,Object> newBindings = new HashMap<String,Object>();
+ int pos = name.indexOf('/');
+ if (pos == -1) {
+ if (treeBindings.put(name, value) != null) {
+ throw new NamingException("Something already bound at " + name);
+ }
+ bindings.put(name, value);
+ newBindings.put(name, value);
+ }
+ else {
+ String segment = name.substring(0, pos);
+ assert segment != null;
+ assert !segment.equals("");
+ Object o = treeBindings.get(segment);
+ if (o == null) {
+ o = newContext();
+ treeBindings.put(segment, o);
+ bindings.put(segment, o);
+ newBindings.put(segment, o);
+ }
+ else if (!(o instanceof AQContext)) {
+ throw new NamingException("Something already bound where a subcontext should go");
+ }
+ AQContext readOnlyContext = (AQContext) o;
+ String remainder = name.substring(pos + 1);
+ Map<String, Object> subBindings = readOnlyContext.internalBind(remainder, value);
+ for (Iterator iterator = subBindings.entrySet().iterator(); iterator.hasNext();) {
+ Map.Entry entry = (Map.Entry) iterator.next();
+ String subName = segment + "/" + (String) entry.getKey();
+ Object bound = entry.getValue();
+ treeBindings.put(subName, bound);
+ newBindings.put(subName, bound);
+ }
+ }
+ return newBindings;
+ }
+
+ protected AQContext newContext() {
+ return new AQContext();
+ }
+
+ public Object addToEnvironment(String propName, Object propVal) throws NamingException {
+ return environment.put(propName, propVal);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Hashtable<String,Object> getEnvironment() throws NamingException {
+ return (Hashtable<String,Object>) environment.clone();
+ }
+
+ public Object removeFromEnvironment(String propName) throws NamingException {
+ return environment.remove(propName);
+ }
+
+ public Object lookup(String name) throws NamingException {
+ if (name.length() == 0) {
+ return this;
+ }
+ Object result = treeBindings.get(name);
+ if (result == null) {
+ result = bindings.get(name);
+ }
+ if (result == null) {
+ int pos = name.indexOf(':');
+ if (pos > 0) {
+ String scheme = name.substring(0, pos);
+ Context ctx = NamingManager.getURLContext(scheme, environment);
+ if (ctx == null) {
+ throw new NamingException("scheme " + scheme + " not recognized");
+ }
+ return ctx.lookup(name);
+ }
+ else {
+ // Split out the first name of the path
+ // and look for it in the bindings map.
+ CompositeName path = new CompositeName(name);
+
+ if (path.size() == 0) {
+ return this;
+ }
+ else {
+ String first = path.get(0);
+ Object obj = bindings.get(first);
+ if (obj == null) {
+ throw new NameNotFoundException(name);
+ }
+ else if (obj instanceof AQContext && path.size() > 1) {
+ AQContext subContext = (AQContext) obj;
+ obj = subContext.lookup(path.getSuffix(1));
+ }
+ return obj;
+ }
+ }
+ }
+ if (result instanceof LinkRef) {
+ LinkRef ref = (LinkRef) result;
+ result = lookup(ref.getLinkName());
+ }
+ if (result instanceof Reference) {
+ try {
+ result = NamingManager.getObjectInstance(result, null, null, this.environment);
+ }
+ catch (NamingException e) {
+ throw e;
+ }
+ catch (Exception e) {
+ throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
+ }
+ }
+ if (result instanceof AQContext) {
+ String prefix = getNameInNamespace();
+ if (prefix.length() > 0) {
+ prefix = prefix + SEPARATOR;
+ }
+ result = new AQContext((AQContext) result, environment, prefix + name);
+ }
+ return result;
+ }
+
+ public Object lookup(Name name) throws NamingException {
+ return lookup(name.toString());
+ }
+
+ public Object lookupLink(String name) throws NamingException {
+ return lookup(name);
+ }
+
+ public Name composeName(Name name, Name prefix) throws NamingException {
+ Name result = (Name) prefix.clone();
+ result.addAll(name);
+ return result;
+ }
+
+ public String composeName(String name, String prefix) throws NamingException {
+ CompositeName result = new CompositeName(prefix);
+ result.addAll(new CompositeName(name));
+ return result.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
+ Object o = lookup(name);
+ if (o == this) {
+ return (NamingEnumeration<NameClassPair>)new ListEnumeration();
+ }
+ else if (o instanceof AQContext) {
+ return ((AQContext) o).list("");
+ }
+ else {
+ throw new NotContextException();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public NamingEnumeration<Binding> listBindings(String name) throws NamingException {
+ Object o = lookup(name);
+ if (o == this) {
+ return (NamingEnumeration<Binding>)new ListBindingEnumeration();
+ }
+ else if (o instanceof AQContext) {
+ return ((AQContext) o).listBindings("");
+ }
+ else {
+ throw new NotContextException();
+ }
+ }
+
+ public Object lookupLink(Name name) throws NamingException {
+ return lookupLink(name.toString());
+ }
+
+ public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
+ return list(name.toString());
+ }
+
+ public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
+ return listBindings(name.toString());
+ }
+
+ public void bind(Name name, Object obj) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void bind(String name, Object obj) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void close() throws NamingException {
+ // ignore
+ }
+
+ public AQContext createSubcontext(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public AQContext createSubcontext(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void destroySubcontext(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void destroySubcontext(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public String getNameInNamespace() throws NamingException {
+ return nameInNamespace;
+ }
+
+ public NameParser getNameParser(Name name) throws NamingException {
+ return nameParser;
+ }
+
+ public NameParser getNameParser(String name) throws NamingException {
+ return nameParser;
+ }
+
+ public void rebind(Name name, Object obj) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void rebind(String name, Object obj) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void rename(Name oldName, Name newName) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void rename(String oldName, String newName) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void unbind(Name name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ public void unbind(String name) throws NamingException {
+ throw new OperationNotSupportedException();
+ }
+
+ private abstract class LocalNamingEnumeration<T> implements NamingEnumeration<T> {
+ private Iterator i = bindings.entrySet().iterator();
+
+ public boolean hasMore() throws NamingException {
+ return i.hasNext();
+ }
+
+ public boolean hasMoreElements() {
+ return i.hasNext();
+ }
+
+ protected Map.Entry getNext() {
+ return (Map.Entry) i.next();
+ }
+
+ public void close() throws NamingException {
+ }
+ }
+
+ private class ListEnumeration<T> extends LocalNamingEnumeration {
+ public NameClassPair next() throws NamingException {
+ return nextElement();
+ }
+
+ public NameClassPair nextElement() {
+ Map.Entry entry = getNext();
+ return new NameClassPair((String) entry.getKey(), entry.getValue().getClass().getName());
+ }
+ }
+
+ private class ListBindingEnumeration<T> extends LocalNamingEnumeration {
+ public NameClassPair next() throws NamingException {
+ return nextElement();
+ }
+
+ public NameClassPair nextElement() {
+ Map.Entry entry = getNext();
+ return new Binding((String) entry.getKey(), entry.getValue());
+ }
+ }
+}
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQContext.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQInitialContextFactory.java
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQInitialContextFactory.java (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQInitialContextFactory.java 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,248 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007,
+ * @author David Fry <dfry at redhat.com>
+ * @author Kurt Stam <kurt.stam at jboss.com>
+ *
+ */
+package org.jboss.soa.esb.oracle.aq;
+
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.jms.TopicConnection;
+import javax.jms.TopicConnectionFactory;
+import javax.jms.XAConnectionFactory;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.spi.InitialContextFactory;
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import oracle.jms.AQjmsFactory;
+import oracle.jms.AQjmsSession;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+public class AQInitialContextFactory implements InitialContextFactory {
+ /** The Oracle Queue connection factory name */
+ public static final String QUEUE_CONNECTION_FACTORY = "QueueConnectionFactory";
+ /** The Oracle Topic connection factory name */
+ public static final String TOPIC_CONNECTION_FACTORY = "TopicConnectionFactory";
+ /** The Oracle Connection factory name */
+ public static final String CONNECTION_FACTORY = "ConnectionFactory";
+ /** The Oracle XA Connection factory name */
+ public static final String XA_CONNECTION_FACTORY = "XAConnectionFactory";
+
+ public static final String DB_DATASOURCE = "db.datasource";
+ public static final String DB_USER = "db.user";
+ public static final String DB_PASSWD = "db.password";
+ public static final String DB_SERVER = "db.server";
+ public static final String DB_INSTANCE = "db.instance";
+ public static final String DB_PORT = "db.port";
+ public static final String DB_SCHEMA = "db.schema";
+ public static final String DB_DRIVER = "db.driver";
+
+ protected static Log log = LogFactory
+ .getLog(AQInitialContextFactory.class);
+
+ protected Hashtable props;
+
+ protected String dbuser;
+
+ protected String dbpass;
+
+ protected String aqServerName;
+
+ protected String aqServerDBInst;
+
+ protected String aqServerPort;
+
+ protected String aqDBDriver;
+
+ protected String aqSchemaName;
+
+ protected int aqServerPortNumber = 1521;
+
+
+ private void createDestinationContext(Map<String, Object> data) throws RuntimeException {
+
+ // lookup and cache the queues
+ QueueConnectionFactory queueFactory;
+ QueueConnection queueConnection = null;
+ TopicConnectionFactory topicFactory;
+ TopicConnection topicConnection = null;
+ AQjmsSession session = null;
+ try {
+ // create a datasource to use - datasources can keep the
+ // username/password for later use
+ DataSource ds = null;
+ XADataSource xaDs = null;
+ try {
+ ds = AQUtil.getSQLDataSource(
+ aqServerName, aqServerDBInst, aqServerPortNumber, aqDBDriver, dbuser,
+ dbpass);
+ xaDs = AQUtil.getXASQLDataSource(aqServerName, aqServerDBInst, aqServerPortNumber, aqDBDriver, dbuser,
+ dbpass);
+ } catch (SQLException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+
+ XAConnectionFactory factory = AQjmsFactory.getXAConnectionFactory(xaDs);
+ data.put(XA_CONNECTION_FACTORY, factory);
+
+ // create the connection factory
+ ConnectionFactory connectionFactory = AQjmsFactory.getConnectionFactory(ds);
+ data.put(CONNECTION_FACTORY, connectionFactory);
+
+ // create the queue connection factory
+ queueFactory = AQjmsFactory.getQueueConnectionFactory(ds);
+ data.put(QUEUE_CONNECTION_FACTORY, queueFactory);
+ queueConnection = queueFactory.createQueueConnection();
+ session = (AQjmsSession) queueConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+
+ // create the topic connection factory
+ topicFactory = AQjmsFactory.getTopicConnectionFactory(ds);
+ data.put(TOPIC_CONNECTION_FACTORY, topicFactory);
+ topicConnection = topicFactory.createTopicConnection();
+ session = (AQjmsSession) topicConnection.createTopicSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ List<DestinationInfo> list = AQUtil.getDestinationInfoList(ds, aqSchemaName);
+ // for each queue
+ Iterator<DestinationInfo> iter = list.iterator();
+ while (iter.hasNext()) {
+ DestinationInfo di = iter.next();
+ if(log.isDebugEnabled()) log.debug("Loading Destination: " + di);
+ // register normal queue
+ registerDestination(data, session, di);
+ }
+ } catch (JMSException e) {
+ log.error("JMSException exception", e);
+ throw new RuntimeException("JMSException exception", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ if (queueConnection != null)
+ queueConnection.close();
+ if (topicConnection != null)
+ topicConnection.close();
+ } catch (JMSException e) {
+ log.error("JMSEx while cleaning up", e);
+ }
+ }
+ }
+
+ private void registerDestination(Map<String, Object> data, AQjmsSession session, DestinationInfo di) {
+ if (di == null) {
+ log.warn("Warning: registerDestination called with null DestinationInfo.");
+ return;
+ }
+
+ Destination destination = null;
+ try {
+ if (di.isMultipleSubscribers()) {
+ destination = session.getTopic(di.getOwner(), di.getQueueName());
+ } else {
+ destination = session.getQueue(di.getOwner(), di.getQueueName());
+ }
+
+ // place in context
+ data.put(di.getQueueName(), destination);
+ // data.put(QUEUE_PREFIX + aqQueueName, destination);
+ } catch (JMSException e) {
+ // we want to eat any exceptions associated with looking up
+ // the queues from the database
+ log.warn("Warning. Error while looking up destination: " + e);
+ }
+ }
+
+ public void init() {
+
+ dbuser = "kurt";
+ dbpass = "kurt";
+ aqServerName = "barentz";
+ aqServerDBInst = "OSC";
+ aqServerPort = "1521";
+ aqDBDriver = "thin";
+ aqSchemaName = "kurt";
+ try {
+ aqServerPortNumber = Integer.parseInt(aqServerPort);
+ } catch (Exception e) {
+ log.error("caught exception converting port", e);
+ }
+ }
+
+ @SuppressWarnings("unused")
+ public Context getInitialContext(Hashtable<?,?> environment) throws NamingException {
+ Map<String, Object> data = new ConcurrentHashMap<String, Object>();
+ if (environment!=null) {
+ //TODO read the properties
+ }
+ init();
+ createDestinationContext(data);
+ return new AQContext(environment, data);
+ }
+
+
+ public void setAqDBDriver(String aqDBDriver) {
+ this.aqDBDriver = aqDBDriver;
+ }
+
+ public void setAqSchemaName(String aqSchemaName) {
+ this.aqSchemaName = aqSchemaName;
+ }
+
+ public void setAqServerDBInst(String aqServerDBInst) {
+ this.aqServerDBInst = aqServerDBInst;
+ }
+
+ public void setAqServerName(String aqServerName) {
+ this.aqServerName = aqServerName;
+ }
+
+ public void setAqServerPort(String aqServerPort) {
+ this.aqServerPort = aqServerPort;
+ }
+
+ public void setAqServerPortNumber(int aqServerPortNumber) {
+ this.aqServerPortNumber = aqServerPortNumber;
+ }
+
+ public void setDbpass(String dbpass) {
+ this.dbpass = dbpass;
+ }
+
+ public void setDbuser(String dbuser) {
+ this.dbuser = dbuser;
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQInitialContextFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQUtil.java
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQUtil.java (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQUtil.java 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,179 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007,
+ * @author David Fry <dfry at redhat.com>
+ * @author Kurt Stam <kurt.stam at jboss.com>
+ *
+ */
+package org.jboss.soa.esb.oracle.aq;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.sql.DataSource;
+import javax.sql.XADataSource;
+
+import oracle.jdbc.pool.OracleDataSource;
+import oracle.jdbc.xa.client.OracleXADataSource;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ *
+ *
+ */
+public class AQUtil {
+ public static Log log = LogFactory.getLog(AQUtil.class);
+ private static final String NORMAL_QUEUE_TYPE = "NORMAL_QUEUE";
+ private static final String EXCEPTION_QUEUE_TYPE = "EXCEPTION_QUEUE";
+ private static final String QUEUE_RECIPIENTS_STRING = "SINGLE";
+ private static final String TOPIC_RECIPIENTS_STRING = "MULTIPLE";
+ private static final String GET_QUEUES_SQL = "SELECT allq.OWNER as owner, allq.NAME as name, allq.QUEUE_TYPE as queue_type, allqt.RECIPIENTS as recipients" +
+ " from SYS.ALL_QUEUES allq, SYS.ALL_QUEUE_TABLES allqt " +
+ " where allq.QUEUE_TABLE = allqt.QUEUE_TABLE order by name asc";
+ private static final String GET_QUEUES_PSQL = "SELECT allq.OWNER as owner, allq.NAME as name, allq.QUEUE_TYPE as queue_type, allqt.RECIPIENTS as recipients" +
+ " from SYS.ALL_QUEUES allq, SYS.ALL_QUEUE_TABLES allqt " +
+ " where allq.QUEUE_TABLE = allqt.QUEUE_TABLE and upper(allq.OWNER) in (?) order by name asc";
+
+
+ public static DataSource getSQLDataSource(String serverName,
+ String dbInstance, int portNo, String driverName)
+ throws SQLException {
+
+ OracleDataSource ds = new OracleDataSource();
+ ds.setDatabaseName(dbInstance);
+ ds.setDriverType(driverName);
+ ds.setServerName(serverName);
+ ds.setPortNumber(portNo);
+ ds.setNetworkProtocol("tcp");
+ return (DataSource) ds;
+
+ }
+
+ public static XADataSource getXADataSource(String serverName,
+ String dbInstance, int portNo, String driverName)
+ throws SQLException {
+ OracleXADataSource ds = new OracleXADataSource();
+ ds.setDatabaseName(dbInstance);
+ ds.setDriverType(driverName);
+ ds.setServerName(serverName);
+ ds.setPortNumber(portNo);
+ ds.setNetworkProtocol("tcp");
+ return (XADataSource) ds;
+ }
+
+ public static DataSource getSQLDataSource(String serverName,
+ String dbInstance, int portNo, String driverName,
+ String username, String password)
+ throws SQLException {
+
+ OracleDataSource ds = new OracleDataSource();
+ ds.setDatabaseName(dbInstance);
+ ds.setDriverType(driverName);
+ ds.setServerName(serverName);
+ ds.setPortNumber(portNo);
+ ds.setNetworkProtocol("tcp");
+ ds.setUser(username);
+ ds.setPassword(password);
+ return ds;
+ }
+
+ public static XADataSource getXASQLDataSource(String serverName,
+ String dbInstance, int portNo, String driverName,
+ String username, String password)
+ throws SQLException {
+
+ OracleXADataSource ds = new OracleXADataSource();
+ ds.setDatabaseName(dbInstance);
+ ds.setDriverType(driverName);
+ ds.setServerName(serverName);
+ ds.setPortNumber(portNo);
+ ds.setNetworkProtocol("tcp");
+ ds.setUser(username);
+ ds.setPassword(password);
+ return ds;
+ }
+
+ public static List<DestinationInfo> getDestinationInfoList(DataSource ds, String commaSeperatedQueueOwnerList) {
+ ArrayList<DestinationInfo> list = new ArrayList<DestinationInfo>();
+ Connection connection = null;
+ PreparedStatement statement = null;
+ ResultSet rs = null;
+ try {
+ connection = ds.getConnection();
+ rs = null;
+ if(commaSeperatedQueueOwnerList!=null) {
+ statement = connection.prepareStatement(AQUtil.GET_QUEUES_PSQL);
+ statement.setString(1, commaSeperatedQueueOwnerList.toUpperCase());
+
+ }
+ else {
+ statement = connection.prepareStatement(AQUtil.GET_QUEUES_SQL);
+ }
+ rs = statement.executeQuery();
+ while(rs.next()) {
+ DestinationInfo info = AQUtil.createDestInfo(rs);
+ if(info!=null)list.add(info);
+ }
+ } catch (SQLException e) {
+ log.error("caught sqlexception", e);
+ } finally {
+ if(statement!=null)
+ try {
+ statement.close();
+ } catch (SQLException e) {
+ if(log.isDebugEnabled()) log.debug("sqlexception while closing prepared statement", e);
+ }
+ if(connection!=null)
+ try {
+ connection.close();
+ } catch (SQLException e) {
+ if(log.isDebugEnabled()) log.debug("sqlexception while closing connection", e);
+ }
+ }
+ return list;
+ }
+ private static DestinationInfo createDestInfo(ResultSet rs) throws SQLException {
+ DestinationInfo info = null;
+ boolean exceptionDestination = false;
+ boolean topic = false;
+ String queueType = rs.getString("queue_type");
+ String recipients = rs.getString("recipients");
+ if(queueType.equalsIgnoreCase(AQUtil.NORMAL_QUEUE_TYPE)) exceptionDestination = false;
+ else if(queueType.equalsIgnoreCase(AQUtil.EXCEPTION_QUEUE_TYPE)) exceptionDestination = true;
+ else {
+ if(log.isDebugEnabled()) log.debug("ignoring unknown queue type:" + queueType);
+ return null;
+ }
+ if(recipients.equalsIgnoreCase(AQUtil.QUEUE_RECIPIENTS_STRING)) topic = false;
+ else if(recipients.equalsIgnoreCase(AQUtil.TOPIC_RECIPIENTS_STRING)) topic = true;
+ else {
+ if(log.isDebugEnabled()) log.debug("ignoring unknown recipients type:" + recipients);
+ return null;
+ }
+ info = new DestinationInfo(rs.getString("owner"), rs.getString("name"), exceptionDestination, topic);
+ return info;
+ }
+
+
+}
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/AQUtil.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/DestinationInfo.java
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/DestinationInfo.java (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/DestinationInfo.java 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007,
+ * @author David Fry <dfry at redhat.com>
+ * @author Kurt Stam <kurt.stam at jboss.com>
+ *
+ */
+package org.jboss.soa.esb.oracle.aq;
+
+/**
+ *
+ * @author David Fry <dfry at redhat.com>
+ * @author Kurt Stam <kurt.stam at jboss.com>
+ */
+public class DestinationInfo {
+
+ String owner;
+
+ String queueName;
+
+ boolean exceptionDestination;
+
+ boolean multipleSubscribers;
+
+ public DestinationInfo(String owner, String queueName, boolean exceptionDestination, boolean multipleSubscribers) {
+ super();
+ this.owner = owner;
+ this.queueName = queueName;
+ this.exceptionDestination = exceptionDestination;
+ this.multipleSubscribers = multipleSubscribers;
+ }
+
+ public String getQueueName() {
+ return queueName;
+ }
+
+ public void setQueueName(String queueName) {
+ this.queueName = queueName;
+ }
+
+ public boolean isExceptionDestination() {
+ return exceptionDestination;
+ }
+
+ public void setExceptionDestination(boolean exception) {
+ this.exceptionDestination = exception;
+ }
+
+ public boolean isMultipleSubscribers() {
+ return multipleSubscribers;
+ }
+
+ public void setMultipleSubscribers(boolean multipleSubscribers) {
+ this.multipleSubscribers = multipleSubscribers;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public void setOwner(String owner) {
+ this.owner = owner;
+ }
+
+}
+
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/DestinationInfo.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/NameParserImpl.java
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/NameParserImpl.java (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/NameParserImpl.java 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2007,
+ * @author David Fry <dfry at redhat.com>
+ * @author Kurt Stam <kurt.stam at jboss.com>
+ *
+ */
+package org.jboss.soa.esb.oracle.aq;
+
+import javax.naming.CompositeName;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
+
+public class NameParserImpl implements NameParser {
+
+ public Name parse(String name) throws NamingException {
+ return new CompositeName(name);
+ }
+
+}
\ No newline at end of file
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/main/java/org/jboss/soa/esb/oracle/aq/NameParserImpl.java
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test (from rev 10581, labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/test)
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/DatasourceTest.java
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/DatasourceTest.java (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/DatasourceTest.java 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,109 @@
+/**
+ *
+ */
+package org.jboss.soa.esb.oracle.aq;
+
+
+import java.io.FileInputStream;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.sql.DataSource;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+
+
+import oracle.jms.AQjmsFactory;
+import oracle.jms.AQjmsSession;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author kstam
+ *
+ */
+public class DatasourceTest
+{
+ private final static String Q_NAME = "q.name";
+ private String user, password, server, instance, schema, driver, portStr, qName;
+ private int port;
+ /**
+ * Tests for completeness of the properties needed ro make a db connection.
+ *
+ */
+ @Test
+ public void checkPropertiesInFile()
+ {
+ System.out.println("user=" + user + ", password=" + password + ", server=" + server
+ + ", port=" + portStr + ", qName=" + qName
+ + ", instance=" + instance + " schema=" + schema + ", driver=" + driver);
+ assertNotNull(user);
+ assertNotNull(password);
+ assertNotNull(server);
+ assertNotNull(portStr);
+ assertFalse(port==0);
+ assertNotNull(instance);
+ assertNotNull(schema);
+ assertNotNull(driver);
+ assertNotNull(qName);
+ }
+ /**
+ * Tries to make a database connection to Oracle using the properties in the
+ * oracle-aq.properties file.
+ *
+ */
+ @Test
+ public void createDsConnection()
+ {
+ DataSource ds = null;
+ System.out.println("Building our db connection");
+ try {
+ ds = AQUtil.getSQLDataSource(server, instance, port, driver, user, password);
+ Connection connection = ds.getConnection();
+ CallableStatement statement = connection.prepareCall("Select * from DUAL");
+ statement.execute();
+ connection.close();
+ } catch (Throwable e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ @Before
+ public void readProperyFile() {
+ try {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream("src/test/resources/oracle-aq.properties"));
+ if (properties.containsKey(AQInitialContextFactory.DB_DATASOURCE)) {
+ String datasourceName = properties.getProperty(AQInitialContextFactory.DB_DATASOURCE);
+ System.out.println("Found datasource name: " + datasourceName);
+ System.err.println("We can't use a Datasource in JUnit.");
+ assertTrue(false);
+ } else {
+ user = properties.getProperty(AQInitialContextFactory.DB_USER);
+ password = properties.getProperty(AQInitialContextFactory.DB_PASSWD);
+ server = properties.getProperty(AQInitialContextFactory.DB_SERVER);
+ instance = properties.getProperty(AQInitialContextFactory.DB_INSTANCE);
+ schema = properties.getProperty(AQInitialContextFactory.DB_SCHEMA);
+ driver = properties.getProperty(AQInitialContextFactory.DB_DRIVER);
+ portStr = properties.getProperty(AQInitialContextFactory.DB_PORT);
+ port = Integer.valueOf(portStr);
+ qName = properties.getProperty(Q_NAME);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+}
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/DatasourceTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/QueueTest.java
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/QueueTest.java (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/QueueTest.java 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,158 @@
+/**
+ *
+ */
+package org.jboss.soa.esb.oracle.aq;
+
+
+import java.io.FileInputStream;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.jms.QueueConnection;
+import javax.jms.QueueConnectionFactory;
+import javax.jms.Session;
+import javax.sql.DataSource;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+
+
+import oracle.jms.AQjmsFactory;
+import oracle.jms.AQjmsSession;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author kstam
+ *
+ */
+public class QueueTest
+{
+ private final static String Q_NAME = "q.name";
+ private String user, password, server, instance, schema, driver, portStr, qName;
+ private int port;
+ /**
+ * Tests for completeness of the properties needed ro make a db connection.
+ *
+ */
+ @Test
+ public void checkPropertiesInFile()
+ {
+ System.out.println("user=" + user + ", password=" + password + ", server=" + server
+ + ", port=" + portStr + ", qName=" + qName
+ + ", instance=" + instance + " schema=" + schema + ", driver=" + driver);
+ assertNotNull(user);
+ assertNotNull(password);
+ assertNotNull(server);
+ assertNotNull(portStr);
+ assertFalse(port==0);
+ assertNotNull(instance);
+ assertNotNull(schema);
+ assertNotNull(driver);
+ assertNotNull(qName);
+ }
+
+ /**
+ * Tries to make a queueConnection to Oracle using the properties in the
+ * oracle-aq.properties file.
+ *
+ */
+ @Test
+ public void createQueueConnection()
+ {
+ DataSource ds = null;
+ System.out.println("Building our own db connection");
+ try {
+ ds = AQUtil.getSQLDataSource(server, instance, port, driver, user, password);
+ QueueConnectionFactory queueFactory = AQjmsFactory.getQueueConnectionFactory(ds);
+ QueueConnection queueConnection = queueFactory.createQueueConnection();
+ assertNotNull(queueConnection);
+ Session session = (AQjmsSession) queueConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ assertNotNull(session);
+ session.close();
+ queueConnection.close();
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ /**
+ * Tries to locate the specified Q in Oracle using the properties in the
+ * oracle-aq.properties file.
+ *
+ */
+ @Test
+ public void findGivenQueue()
+ {
+ boolean foundQueue=false;
+ DataSource ds = null;
+ System.out.println("Building our own db connection");
+ try {
+ ds = AQUtil.getSQLDataSource(server, instance, port, driver, user, password);
+ QueueConnectionFactory queueFactory = AQjmsFactory.getQueueConnectionFactory(ds);
+ QueueConnection queueConnection = queueFactory.createQueueConnection();
+ assertNotNull(queueConnection);
+ Session session = (AQjmsSession) queueConnection.createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ assertNotNull(session);
+
+ List<DestinationInfo> list = AQUtil.getDestinationInfoList(ds, schema);
+ // for each queue
+ Iterator<DestinationInfo> iter = list.iterator();
+ while (iter.hasNext()) {
+ DestinationInfo di = iter.next();
+ System.out.println("Found Destination: " + di.getQueueName());
+ // register normal queue
+ if (di.getQueueName().equalsIgnoreCase(qName)) {
+ System.out.println("Matched up Queue: " + di.getQueueName() + " with " + qName);
+ foundQueue=true;
+ }
+ }
+
+ session.close();
+ queueConnection.close();
+ assertTrue(foundQueue);
+
+ } catch (Throwable e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+ @Before
+ public void readProperyFile() {
+ try {
+ Properties properties = new Properties();
+ properties.load(new FileInputStream("src/test/resources/oracle-aq.properties"));
+ if (properties.containsKey(AQInitialContextFactory.DB_DATASOURCE)) {
+ String datasourceName = properties.getProperty(AQInitialContextFactory.DB_DATASOURCE);
+ System.out.println("Found datasource name: " + datasourceName);
+ System.err.println("We can't use a Datasource in JUnit.");
+ assertTrue(false);
+ } else {
+ user = properties.getProperty(AQInitialContextFactory.DB_USER);
+ password = properties.getProperty(AQInitialContextFactory.DB_PASSWD);
+ server = properties.getProperty(AQInitialContextFactory.DB_SERVER);
+ instance = properties.getProperty(AQInitialContextFactory.DB_INSTANCE);
+ schema = properties.getProperty(AQInitialContextFactory.DB_SCHEMA);
+ driver = properties.getProperty(AQInitialContextFactory.DB_DRIVER);
+ portStr = properties.getProperty(AQInitialContextFactory.DB_PORT);
+ port = Integer.valueOf(portStr);
+ qName = properties.getProperty(Q_NAME);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ }
+
+
+}
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/java/org/jboss/soa/esb/oracle/aq/QueueTest.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/resources/oracle-aq.properties
===================================================================
--- labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/resources/oracle-aq.properties (rev 0)
+++ labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/resources/oracle-aq.properties 2007-03-30 20:53:57 UTC (rev 10660)
@@ -0,0 +1,10 @@
+#db.datasource=oracleDS
+db.user =kurt
+db.password =kurt
+db.server =barentz
+db.instance =OSC
+db.schema =kurt
+db.port =1521
+db.driver =thin
+
+q.name =KURTQ
Property changes on: labs/jbossesb/trunk/plugins/org.jboss.soa.esb.oracle.aq/src/test/resources/oracle-aq.properties
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
More information about the jboss-svn-commits
mailing list