JBoss.orgCommunity Documentation
The HelloWorld resource adapter example shows a simple example of how to use and implement the interfaces in the Java EE Connector Architecture specification.
The HelloWorld examples exposes the HelloWorldConnection interface where developers can invoke the exposed methods.
The example shows how to build and test a resource adapter.
The build environment needs various libraries in order to being able to build and test the resource adapter. The setup is done by
cd doc/samples/helloworld cp -R ../../../lib . cp ../../../bin/ironjacamar-sjc.jar lib/
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import java.util.logging.Logger;
import javax.resource.ResourceException;
import javax.resource.spi.ActivationSpec;
import javax.resource.spi.BootstrapContext;
import javax.resource.spi.ConfigProperty;
import javax.resource.spi.Connector;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ResourceAdapterInternalException;
import javax.resource.spi.TransactionSupport;
import javax.resource.spi.endpoint.MessageEndpointFactory;
import javax.transaction.xa.XAResource;
/**
* HelloWorldResourceAdapter
*
* @version $Revision: $
*/
@Connector(
reauthenticationSupport = false,
transactionSupport = TransactionSupport.TransactionSupportLevel.NoTransaction)
public class HelloWorldResourceAdapter implements ResourceAdapter
{
/** The logger */
private static Logger log = Logger.getLogger("HelloWorldResourceAdapter");
/** Name property */
@ConfigProperty(defaultValue = "AS 7", supportsDynamicUpdates = true)
private String name;
/**
* Default constructor
*/
public HelloWorldResourceAdapter()
{
}
/**
* Set name
* @param name The value
*/
public void setName(String name)
{
this.name = name;
}
/**
* Get name
* @return The value
*/
public String getName()
{
return name;
}
/**
* This is called during the activation of a message endpoint.
*
* @param endpointFactory A message endpoint factory instance.
* @param spec An activation spec JavaBean instance.
* @throws ResourceException generic exception
*/
public void endpointActivation(MessageEndpointFactory endpointFactory,
ActivationSpec spec) throws ResourceException
{
}
/**
* This is called when a message endpoint is deactivated.
*
* @param endpointFactory A message endpoint factory instance.
* @param spec An activation spec JavaBean instance.
*/
public void endpointDeactivation(MessageEndpointFactory endpointFactory,
ActivationSpec spec)
{
}
/**
* This is called when a resource adapter instance is bootstrapped.
*
* @param ctx A bootstrap context containing references
* @throws ResourceAdapterInternalException indicates bootstrap failure.
*/
public void start(BootstrapContext ctx)
throws ResourceAdapterInternalException
{
}
/**
* This is called when a resource adapter instance is undeployed or
* during application server shutdown.
*/
public void stop()
{
}
/**
* This method is called by the application server during crash recovery.
*
* @param specs an array of ActivationSpec JavaBeans
* @throws ResourceException generic exception
* @return an array of XAResource objects
*/
public XAResource[] getXAResources(ActivationSpec[] specs)
throws ResourceException
{
return null;
}
/**
* Returns a hash code value for the object.
* @return A hash code value for this object.
*/
@Override
public int hashCode()
{
int result = 17;
if (name != null)
result += 31 * result + 7 * name.hashCode();
else
result += 31 * result + 7;
return result;
}
/**
* Indicates whether some other object is equal to this one.
* @param other The reference object with which to compare.
* @return true If this object is the same as the obj argument, false otherwise.
*/
@Override
public boolean equals(Object other)
{
if (other == null)
return false;
if (other == this)
return true;
if (!(other instanceof HelloWorldResourceAdapter))
return false;
HelloWorldResourceAdapter obj = (HelloWorldResourceAdapter)other;
boolean result = true;
if (result)
{
if (name == null)
result = obj.getName() == null;
else
result = name.equals(obj.getName());
}
return result;
}
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Set;
import java.util.logging.Logger;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionDefinition;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionFactory;
import javax.resource.spi.ResourceAdapter;
import javax.resource.spi.ResourceAdapterAssociation;
import javax.security.auth.Subject;
/**
* HelloWorldManagedConnectionFactory
*
* @version $Revision: $
*/
@ConnectionDefinition(connectionFactory = HelloWorldConnectionFactory.class,
connectionFactoryImpl = HelloWorldConnectionFactoryImpl.class,
connection = HelloWorldConnection.class,
connectionImpl = HelloWorldConnectionImpl.class)
public class HelloWorldManagedConnectionFactory
implements ManagedConnectionFactory, ResourceAdapterAssociation
{
/** The serialVersionUID */
private static final long serialVersionUID = 1L;
/** The logger */
private static Logger log = Logger.getLogger("HelloWorldManagedConnectionFactory");
/** The resource adapter */
private ResourceAdapter ra;
/** The logwriter */
private PrintWriter logwriter;
/**
* Default constructor
*/
public HelloWorldManagedConnectionFactory()
{
this.ra = null;
this.logwriter = null;
}
/**
* Creates a Connection Factory instance.
*
* @return EIS-specific Connection Factory instance or
* javax.resource.cci.ConnectionFactory instance
* @throws ResourceException Generic exception
*/
public Object createConnectionFactory() throws ResourceException
{
throw new ResourceException("This resource adapter doesn't support non-managed environments");
}
/**
* Creates a Connection Factory instance.
*
* @param cxManager ConnectionManager to be associated with created EIS
* connection factory instance
* @return EIS-specific Connection Factory instance or
* javax.resource.cci.ConnectionFactory instance
* @throws ResourceException Generic exception
*/
public Object createConnectionFactory(ConnectionManager cxManager) throws ResourceException
{
return new HelloWorldConnectionFactoryImpl(this, cxManager);
}
/**
* Creates a new physical connection to the underlying EIS resource manager.
*
* @param subject Caller's security information
* @param cxRequestInfo Additional resource adapter specific connection
* request information
* @throws ResourceException generic exception
* @return ManagedConnection instance
*/
public ManagedConnection createManagedConnection(Subject subject,
ConnectionRequestInfo cxRequestInfo)
throws ResourceException
{
return new HelloWorldManagedConnection(this);
}
/**
* Returns a matched connection from the candidate set of connections.
*
* @param connectionSet Candidate connection set
* @param subject Caller's security information
* @param cxRequestInfo Additional resource adapter specific connection request information
* @throws ResourceException generic exception
* @return ManagedConnection if resource adapter finds an acceptable match otherwise null
*/
public ManagedConnection matchManagedConnections(Set connectionSet,
Subject subject, ConnectionRequestInfo cxRequestInfo)
throws ResourceException
{
ManagedConnection result = null;
Iterator it = connectionSet.iterator();
while (result == null && it.hasNext())
{
ManagedConnection mc = (ManagedConnection)it.next();
if (mc instanceof HelloWorldManagedConnection)
{
HelloWorldManagedConnection hwmc = (HelloWorldManagedConnection)mc;
result = hwmc;
}
}
return result;
}
/**
* Get the log writer for this ManagedConnectionFactory instance.
*
* @return PrintWriter
* @throws ResourceException generic exception
*/
public PrintWriter getLogWriter() throws ResourceException
{
return logwriter;
}
/**
* Set the log writer for this ManagedConnectionFactory instance.
*
* @param out PrintWriter - an out stream for error logging and tracing
* @throws ResourceException generic exception
*/
public void setLogWriter(PrintWriter out) throws ResourceException
{
logwriter = out;
}
/**
* Get the resource adapter
*
* @return The handle
*/
public ResourceAdapter getResourceAdapter()
{
return ra;
}
/**
* Set the resource adapter
*
* @param ra The handle
*/
public void setResourceAdapter(ResourceAdapter ra)
{
this.ra = ra;
}
/**
* Returns a hash code value for the object.
* @return A hash code value for this object.
*/
@Override
public int hashCode()
{
int result = 17;
return result;
}
/**
* Indicates whether some other object is equal to this one.
* @param other The reference object with which to compare.
* @return true If this object is the same as the obj argument, false otherwise.
*/
@Override
public boolean equals(Object other)
{
if (other == null)
return false;
if (other == this)
return true;
if (!(other instanceof HelloWorldManagedConnectionFactory))
return false;
HelloWorldManagedConnectionFactory obj = (HelloWorldManagedConnectionFactory)other;
boolean result = true;
return result;
}
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;
import javax.resource.NotSupportedException;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.ConnectionEventListener;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
/**
* HelloWorldManagedConnection
*
* @version $Revision: $
*/
public class HelloWorldManagedConnection implements ManagedConnection
{
/** The logger */
private static Logger log = Logger.getLogger("HelloWorldManagedConnection");
/** MCF */
private HelloWorldManagedConnectionFactory mcf;
/** Log writer */
private PrintWriter logWriter;
/** Listeners */
private List<ConnectionEventListener> listeners;
/** Connection */
private Object connection;
/**
* default constructor
* @param mcf mcf
*/
public HelloWorldManagedConnection(HelloWorldManagedConnectionFactory mcf)
{
this.mcf = mcf;
this.logWriter = null;
this.listeners = new ArrayList<ConnectionEventListener>(1);
this.connection = null;
}
/**
* Creates a new connection handle for the underlying physical connection
* represented by the ManagedConnection instance.
*
* @param subject Security context as JAAS subject
* @param cxRequestInfo ConnectionRequestInfo instance
* @return generic Object instance representing the connection handle.
* @throws ResourceException generic exception if operation fails
*/
public Object getConnection(Subject subject,
ConnectionRequestInfo cxRequestInfo)
throws ResourceException
{
connection = new HelloWorldConnectionImpl(this, mcf);
return connection;
}
/**
* Used by the container to change the association of an
* application-level connection handle with a ManagedConneciton instance.
*
* @param connection Application-level connection handle
* @throws ResourceException generic exception if operation fails
*/
public void associateConnection(Object connection) throws ResourceException
{
this.connection = connection;
}
/**
* Application server calls this method to force any cleanup on
* the ManagedConnection instance.
*
* @throws ResourceException generic exception if operation fails
*/
public void cleanup() throws ResourceException
{
}
/**
* Destroys the physical connection to the underlying resource manager.
*
* @throws ResourceException generic exception if operation fails
*/
public void destroy() throws ResourceException
{
this.connection = null;
}
/**
* Adds a connection event listener to the ManagedConnection instance.
*
* @param listener A new ConnectionEventListener to be registered
*/
public void addConnectionEventListener(ConnectionEventListener listener)
{
if (listener == null)
throw new IllegalArgumentException("Listener is null");
listeners.add(listener);
}
/**
* Removes an already registered connection event listener
* from the ManagedConnection instance.
*
* @param listener Already registered connection event listener to be removed
*/
public void removeConnectionEventListener(ConnectionEventListener listener)
{
if (listener == null)
throw new IllegalArgumentException("Listener is null");
listeners.remove(listener);
}
/**
* Gets the log writer for this ManagedConnection instance.
*
* @return Character ourput stream associated with this
* Managed-Connection instance
* @throws ResourceException generic exception if operation fails
*/
public PrintWriter getLogWriter() throws ResourceException
{
return logWriter;
}
/**
* Sets the log writer for this ManagedConnection instance.
*
* @param out Character Output stream to be associated
* @throws ResourceException generic exception if operation fails
*/
public void setLogWriter(PrintWriter out) throws ResourceException
{
this.logWriter = out;
}
/**
* Returns an <code>javax.resource.spi.LocalTransaction</code> instance.
*
* @return LocalTransaction instance
* @throws ResourceException generic exception if operation fails
*/
public LocalTransaction getLocalTransaction() throws ResourceException
{
throw new NotSupportedException("LocalTransaction not supported");
}
/**
* Returns an <code>javax.transaction.xa.XAresource</code> instance.
*
* @return XAResource instance
* @throws ResourceException generic exception if operation fails
*/
public XAResource getXAResource() throws ResourceException
{
throw new NotSupportedException("GetXAResource not supported");
}
/**
* Gets the metadata information for this connection's underlying
* EIS resource manager instance.
*
* @return ManagedConnectionMetaData instance
* @throws ResourceException generic exception if operation fails
*/
public ManagedConnectionMetaData getMetaData() throws ResourceException
{
return new HelloWorldManagedConnectionMetaData();
}
/**
* Call helloWorld
* @param name String name
* @return String helloworld
*/
String helloWorld(String name)
{
return "Hello World, " + name + " !";
}
/**
* Close handle
* @param handle The handle
*/
void closeHandle(HelloWorldConnection handle)
{
ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
event.setConnectionHandle(handle);
for (ConnectionEventListener cel : listeners)
{
cel.connectionClosed(event);
}
}
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import java.io.Serializable;
import javax.resource.Referenceable;
import javax.resource.ResourceException;
/**
* HelloWorldConnectionFactory
*
* @version $Revision: $
*/
public interface HelloWorldConnectionFactory extends Serializable, Referenceable
{
/**
* Get connection from factory
*
* @return HelloWorldConnection instance
* @exception ResourceException Thrown if a connection can't be obtained
*/
public HelloWorldConnection getConnection() throws ResourceException;
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import javax.naming.NamingException;
import javax.naming.Reference;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;
/**
* HelloWorldConnectionFactoryImpl
*
* @version $Revision: $
*/
public class HelloWorldConnectionFactoryImpl implements HelloWorldConnectionFactory
{
/** The serialVersionUID */
private static final long serialVersionUID = 1L;
private Reference reference;
private HelloWorldManagedConnectionFactory mcf;
private ConnectionManager connectionManager;
/**
* Default constructor
* @param mcf ManagedConnectionFactory
* @param cxManager ConnectionManager
*/
public HelloWorldConnectionFactoryImpl(HelloWorldManagedConnectionFactory mcf,
ConnectionManager cxManager)
{
this.mcf = mcf;
this.connectionManager = cxManager;
}
/**
* Get connection from factory
*
* @return HelloWorldConnection instance
* @exception ResourceException Thrown if a connection can't be obtained
*/
@Override
public HelloWorldConnection getConnection() throws ResourceException
{
return (HelloWorldConnection)connectionManager.allocateConnection(mcf, null);
}
/**
* Get the Reference instance.
*
* @return Reference instance
* @exception NamingException Thrown if a reference can't be obtained
*/
@Override
public Reference getReference() throws NamingException
{
return reference;
}
/**
* Set the Reference instance.
*
* @param reference A Reference instance
*/
@Override
public void setReference(Reference reference)
{
this.reference = reference;
}
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
/**
* HelloWorldConnection
*
* @version $Revision: $
*/
public interface HelloWorldConnection
{
/**
* HelloWorld
* @return String
*/
public String helloWorld();
/**
* HelloWorld
* @param name A name
* @return String
*/
public String helloWorld(String name);
/**
* Close
*/
public void close();
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import java.util.logging.Logger;
/**
* HelloWorldConnectionImpl
*
* @version $Revision: $
*/
public class HelloWorldConnectionImpl implements HelloWorldConnection
{
/** The logger */
private static Logger log = Logger.getLogger("HelloWorldConnectionImpl");
/** ManagedConnection */
private HelloWorldManagedConnection mc;
/** ManagedConnectionFactory */
private HelloWorldManagedConnectionFactory mcf;
/**
* Default constructor
* @param mc HelloWorldManagedConnection
* @param mcf HelloWorldManagedConnectionFactory
*/
public HelloWorldConnectionImpl(HelloWorldManagedConnection mc,
HelloWorldManagedConnectionFactory mcf)
{
this.mc = mc;
this.mcf = mcf;
}
/**
* Call helloWorld
* @return String helloworld
*/
public String helloWorld()
{
return helloWorld(((HelloWorldResourceAdapter)mcf.getResourceAdapter()).getName());
}
/**
* Call helloWorld
* @param name String name
* @return String helloworld
*/
public String helloWorld(String name)
{
return mc.helloWorld(name);
}
/**
* Close
*/
public void close()
{
mc.closeHandle(this);
}
}
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import javax.resource.ResourceException;
import javax.resource.spi.ManagedConnectionMetaData;
/**
* HelloWorldManagedConnectionMetaData
*
* @version $Revision: $
*/
public class HelloWorldManagedConnectionMetaData implements ManagedConnectionMetaData
{
/**
* Default constructor
*/
public HelloWorldManagedConnectionMetaData()
{
}
/**
* Returns Product name of the underlying EIS instance connected
* through the ManagedConnection.
*
* @return Product name of the EIS instance
* @throws ResourceException Thrown if an error occurs
*/
@Override
public String getEISProductName() throws ResourceException
{
return "HelloWorld Resource Adapter";
}
/**
* Returns Product version of the underlying EIS instance connected
* through the ManagedConnection.
*
* @return Product version of the EIS instance
* @throws ResourceException Thrown if an error occurs
*/
@Override
public String getEISProductVersion() throws ResourceException
{
return "1.0";
}
/**
* Returns maximum limit on number of active concurrent connections
*
* @return Maximum limit for number of active concurrent connections
* @throws ResourceException Thrown if an error occurs
*/
@Override
public int getMaxConnections() throws ResourceException
{
return 0;
}
/**
* Returns name of the user associated with the ManagedConnection instance
*
* @return Name of the user
* @throws ResourceException Thrown if an error occurs
*/
@Override
public String getUserName() throws ResourceException
{
return null;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<ironjacamar>
<connection-definitions>
<connection-definition
class-name="org.jboss.jca.samples.helloworld.HelloWorldManagedConnectionFactory"
jndi-name="java:/eis/HelloWorld"/>
</connection-definitions>
</ironjacamar>
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.jca.samples.helloworld;
import java.util.UUID;
import java.util.logging.Logger;
import javax.annotation.Resource;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.ResourceAdapterArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* ConnectorTestCase
*
* @version $Revision: $
*/
@RunWith(Arquillian.class)
public class ConnectorTestCase
{
private static Logger log = Logger.getLogger("ConnectorTestCase");
private static String deploymentName = "ConnectorTestCase";
/**
* Define the deployment
*
* @return The deployment archive
*/
@Deployment
public static ResourceAdapterArchive createDeployment()
{
ResourceAdapterArchive raa =
ShrinkWrap.create(ResourceAdapterArchive.class, deploymentName + ".rar");
JavaArchive ja = ShrinkWrap.create(JavaArchive.class,
UUID.randomUUID().toString() + ".jar");
ja.addClasses(HelloWorldResourceAdapter.class,
HelloWorldManagedConnectionFactory.class,
HelloWorldManagedConnection.class,
HelloWorldManagedConnectionMetaData.class,
HelloWorldConnectionFactory.class,
HelloWorldConnectionFactoryImpl.class,
HelloWorldConnection.class,
HelloWorldConnectionImpl.class);
raa.addAsLibrary(ja);
raa.addAsManifestResource("META-INF/ironjacamar.xml", "ironjacamar.xml");
return raa;
}
/** resource */
@Resource(mappedName = "java:/eis/HelloWorld")
private HelloWorldConnectionFactory connectionFactory;
/**
* Test helloWorld
*
* @exception Throwable Thrown if case of an error
*/
@Test
public void testHelloWorldNoArgs() throws Throwable
{
assertNotNull(connectionFactory);
HelloWorldConnection connection = connectionFactory.getConnection();
assertNotNull(connection);
String result = connection.helloWorld();
connection.close();
}
/**
* Test helloWorld
*
* @exception Throwable Thrown if case of an error
*/
@Test
public void testHelloWorldNameString() throws Throwable
{
assertNotNull(connectionFactory);
HelloWorldConnection connection = connectionFactory.getConnection();
assertNotNull(connection);
String result = connection.helloWorld(null);
connection.close();
}
}
<!--
/*
* JBoss, Home of Professional Open Source.
* Copyright 2010, Red Hat Middleware LLC, and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY 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 along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
-->
<project name="helloworld" basedir="." default="rar">
<!-- =================================
Properties
================================= -->
<property name="build.dir" value="${basedir}/build" />
<property name="target.dir" value="${basedir}/target" />
<property name="lib.dir" value="${basedir}/lib" />
<property name="javac.debug" value="on" />
<property name="javac.deprecation" value="on" />
<property name="javac.optimize" value="off" />
<property name="junit.printsummary" value="yes" />
<property name="junit.haltonerror" value="no" />
<property name="junit.haltonfailure" value="no" />
<property name="junit.fork" value="yes" />
<property name="junit.timeout" value="60000" />
<property name="junit.jvm" value="" />
<property name="junit.jvm.options" value="-Xms128m -Xmx512m -XX:MaxPermSize=256m" />
<property name="junit.batchtest.haltonerror" value="no" />
<property name="junit.batchtest.haltonfailure" value="no" />
<property name="junit.batchtest.fork" value="yes" />
<path id="lib.path.id">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<path id="test.lib.path.id">
<fileset dir="${lib.dir}">
<include name="**/*.jar"/>
</fileset>
<fileset dir="${build.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- =================================
Target: init
================================= -->
<target name="init">
<mkdir dir="${lib.dir}" />
</target>
<!-- =================================
Target: compile
================================= -->
<target name="compile" depends="init">
<mkdir dir="${build.dir}" />
<javac srcdir="${basedir}/src/main/java"
destdir="${build.dir}"
classpathref="lib.path.id"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
optimize="${javac.optimize}">
</javac>
</target>
<!-- =================================
Target: rar
================================= -->
<target name="rar" depends="compile">
<mkdir dir="${target.dir}" />
<mkdir dir="${basedir}/src/main/resources" />
<jar destfile="${build.dir}/helloworld.jar"
basedir="${build.dir}"
includes="**/*.class"/>
<jar destfile="${target.dir}/helloworld.rar">
<fileset dir="${basedir}/src/main/resources" includes="META-INF/*"/>
<fileset dir="${build.dir}" includes="**/*.jar"/>
</jar>
</target>
<!-- =================================
Target: prepare-test
================================= -->
<target name="prepare-test" depends="init">
<mkdir dir="${build.dir}/test" />
<javac srcdir="src/test"
destdir="${build.dir}/test"
classpathref="test.lib.path.id"
debug="${javac.debug}"
deprecation="${javac.deprecation}"
optimize="${javac.optimize}">
<compilerarg value="-Xlint"/>
</javac>
<copy todir="${build.dir}/test">
<fileset dir="src/main/resources"/>
<fileset dir="src/test/resources"/>
</copy>
</target>
<!-- =================================
Target: test
================================= -->
<target name="test" depends="rar, prepare-test">
<mkdir dir="${basedir}/reports"/>
<junit dir="src/test"
printsummary="${junit.printsummary}"
haltonerror="${junit.haltonerror}"
haltonfailure="${junit.haltonfailure}"
fork="${junit.fork}"
timeout="${junit.timeout}">
<jvmarg line="${junit.jvm.options}"/>
<sysproperty key="archives.dir" value="${target.dir}"/>
<sysproperty key="reports.dir" value="${basedir}/reports"/>
<sysproperty key="java.util.logging.manager" value="org.jboss.logmanager.LogManager"/>
<sysproperty key="log4j.defaultInitOverride" value="true"/>
<sysproperty key="org.jboss.logging.Logger.pluginClass"
value="org.jboss.logging.logmanager.LoggerPluginImpl"/>
<sysproperty key="test.dir" value="${build.dir}/test"/>
<sysproperty key="xb.builder.useUnorderedSequence" value="true"/>
<classpath>
<fileset dir="${lib.dir}" includes="**/*.jar" />
<fileset dir="${build.dir}" includes="*.jar" />
<pathelement location="${build.dir}/test"/>
</classpath>
<formatter type="plain"/>
<formatter type="xml"/>
<batchtest todir="${basedir}/reports"
haltonerror="${junit.batchtest.haltonerror}"
haltonfailure="${junit.batchtest.haltonfailure}"
fork="${junit.batchtest.fork}">
<fileset dir="${build.dir}/test">
<include name="**/*TestCase.class"/>
</fileset>
</batchtest>
</junit>
</target>
<!-- =================================
Target: docs
================================= -->
<target name="docs" depends="compile">
<mkdir dir="${target.dir}/docs"/>
<javadoc packagenames="*"
sourcepath="src/main/java"
destdir="${target.dir}/docs"
classpathref="lib.path.id">
</javadoc>
</target>
<!-- =================================
Target: clean
================================= -->
<target name="clean">
<delete>
<fileset dir="${basedir}" defaultexcludes="no">
<include name="**/*~"/>
<include name="**/*.bak"/>
</fileset>
</delete>
<delete dir="${build.dir}"/>
<delete dir="${target.dir}"/>
<delete dir="${basedir}/reports"/>
</target>
<!-- =================================
Target: dist-clean
================================= -->
<target name="dist-clean" depends="init,clean">
<delete includeemptydirs="true">
<fileset dir="${lib.dir}" includes="**/*"/>
</delete>
</target>
</project>