[jboss-cvs] JBossAS SVN: r110751 - in projects/jboss-jca/trunk/rhq/src: test/java/org/jboss/jca/rhq/core and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Feb 23 06:09:52 EST 2011
Author: jeff.zhang
Date: 2011-02-23 06:09:51 -0500 (Wed, 23 Feb 2011)
New Revision: 110751
Modified:
projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/ResourceAdapterResourceDiscoveryComponent.java
projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/core/EmbeddedJcaDiscover.java
Log:
[JBJCA-500] deploy xa.rar into embedded JCA container
Modified: projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/ResourceAdapterResourceDiscoveryComponent.java
===================================================================
--- projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/ResourceAdapterResourceDiscoveryComponent.java 2011-02-23 11:04:29 UTC (rev 110750)
+++ projects/jboss-jca/trunk/rhq/src/main/java/org/jboss/jca/rhq/ra/ResourceAdapterResourceDiscoveryComponent.java 2011-02-23 11:09:51 UTC (rev 110751)
@@ -28,6 +28,8 @@
import java.util.HashSet;
import java.util.Set;
+import org.jboss.logging.Logger;
+
import org.rhq.core.pluginapi.inventory.DiscoveredResourceDetails;
import org.rhq.core.pluginapi.inventory.InvalidPluginConfigurationException;
import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
@@ -42,6 +44,9 @@
public class ResourceAdapterResourceDiscoveryComponent
implements ResourceDiscoveryComponent<ResourceAdapterResourceComponent>
{
+ /** log */
+ private static final Logger logger = Logger.getLogger(ResourceAdapterResourceDiscoveryComponent.class);
+
/**
* discoverResources
*
@@ -55,7 +60,6 @@
ResourceDiscoveryContext<ResourceAdapterResourceComponent> jcaRarResourceComponentResourceDiscoveryContext)
throws InvalidPluginConfigurationException, Exception
{
-
Set<DiscoveredResourceDetails> result = new HashSet<DiscoveredResourceDetails>();
ManagementRepository manRepo = ManagementRepositoryManager.getManagementRepository();
Modified: projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/core/EmbeddedJcaDiscover.java
===================================================================
--- projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/core/EmbeddedJcaDiscover.java 2011-02-23 11:04:29 UTC (rev 110750)
+++ projects/jboss-jca/trunk/rhq/src/test/java/org/jboss/jca/rhq/core/EmbeddedJcaDiscover.java 2011-02-23 11:09:51 UTC (rev 110751)
@@ -21,12 +21,17 @@
*/
package org.jboss.jca.rhq.core;
-import org.jboss.jca.core.api.management.Connector;
import org.jboss.jca.core.api.management.ManagementRepository;
import org.jboss.jca.embedded.Embedded;
import org.jboss.jca.embedded.EmbeddedFactory;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
import org.jboss.logging.Logger;
/**
@@ -83,11 +88,13 @@
{
embedJCA = EmbeddedFactory.create(true);
embedJCA.startup();
- logger.debug("embedded JCA container started");
+ logger.info("embedded JCA container started");
//embedJCA.deploy(EmbeddedJcaDiscover.class.getResource("h2-ds.xml"));
- //embedJCA.deploy(EmbeddedJcaDiscover.class.getResource("xa.rar"));
+ deployFile("/xa.rar");
+ logger.debug("xa.rar deployed");
+
stopped = false;
}
catch (Throwable e)
@@ -96,7 +103,73 @@
}
}
+
+ /**
+ * deploy file into container
+ *
+ * @param fileName file name
+ */
+ private void deployFile(String fileName)
+ {
+ URL url = EmbeddedJcaDiscover.class.getResource(fileName);
+ try
+ {
+ String tmpPath = System.getProperty("java.io.tmpdir");
+ File outputFile = new File(tmpPath, fileName);
+ copyURLToFile(url, outputFile);
+ URL finalURL = outputFile.toURI().toURL();
+ embedJCA.deploy(finalURL);
+ outputFile.deleteOnExit();
+ }
+ catch (Throwable e)
+ {
+ throw new IllegalStateException("Can not deploy resource: " + url, e);
+ }
+ }
+
+ /**
+ * copyURLToFile
+ * @param url URL
+ * @param outputFile File
+ * @throws Exception
+ */
+ private void copyURLToFile(URL url, File outputFile) throws Exception
+ {
+ InputStream from = null;
+ FileOutputStream to = null;
+ try
+ {
+ from = url.openStream();
+ to = new FileOutputStream(outputFile);
+ byte[] buffer = new byte[4096];
+ int bytesRead;
+ while ((bytesRead = from.read(buffer)) != -1)
+ to.write(buffer, 0, bytesRead);
+ }
+ finally
+ {
+ if (from != null)
+ try
+ {
+ from.close();
+ }
+ catch (IOException e)
+ {
+ ;
+ }
+ if (to != null)
+ try
+ {
+ to.close();
+ }
+ catch (IOException e)
+ {
+ ;
+ }
+ }
+ }
+
/**
* getManagementRepository
*
@@ -140,27 +213,4 @@
throw new IllegalStateException("Can not shutdown the Embedded JCA container", e);
}
}
-
- /**
- * getConnectorByUniqueId
- *
- * @param rarUniqueId The RAR unique ID
- * @return the Connector associated with the RAR resource with the unique id.
- */
- public Connector getConnectorByUniqueId(String rarUniqueId)
- {
- if (null == rarUniqueId)
- {
- throw new IllegalArgumentException("rar unique id can not be null.");
- }
- ManagementRepository manRepo = getManagementRepository();
- for (Connector connector : manRepo.getConnectors())
- {
- if (rarUniqueId.equals(connector.getUniqueId()))
- {
- return connector;
- }
- }
- return null;
- }
}
More information about the jboss-cvs-commits
mailing list