[jboss-svn-commits] JBL Code SVN: r19057 - in labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta: src/org/jboss/soa/esb/services/registry and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Mar 18 15:00:57 EDT 2008
Author: tfennelly
Date: 2008-03-18 15:00:57 -0400 (Tue, 18 Mar 2008)
New Revision: 19057
Added:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionFactory.java
Modified:
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/registry/RegistryFactory.java
labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java
Log:
http://jira.jboss.com/jira/browse/JBESB-1594
http://jira.jboss.com/jira/browse/JBESB-1439
Added: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionFactory.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionFactory.java 2008-03-18 19:00:57 UTC (rev 19057)
@@ -0,0 +1,108 @@
+/*
+ * 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-2006, JBoss Inc.
+ */
+package org.jboss.internal.soa.esb.services.registry;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.common.Configuration;
+
+import javax.xml.registry.Connection;
+import javax.xml.registry.ConnectionFactory;
+import javax.xml.registry.JAXRException;
+import java.net.PasswordAuthentication;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * JAXR Connection Factory.
+ * <p/>
+ * Extracted from the {@link JAXRRegistryImpl}.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JAXRConnectionFactory {
+
+ private static Logger logger = Logger.getLogger(JAXRConnectionFactory.class);
+
+ private Set<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
+ private Properties props = new Properties();
+
+ public JAXRConnectionFactory() {
+ props = new Properties();
+ props.setProperty("javax.xml.registry.queryManagerURL", Configuration.getRegistryQueryManageURI());
+ props.setProperty("javax.xml.registry.lifeCycleManagerURL", Configuration.getRegistryLifecycleManagerURI());
+ props.setProperty("javax.xml.registry.factoryClass", Configuration.getRegistryFactoryClass());
+ if (Configuration.getRegistrySemanticEquivalences()!=null) {
+ props.setProperty("javax.xml.registry.semanticEquivalences", Configuration.getRegistrySemanticEquivalences());
+ }
+ if (Configuration.getRegistryPostalAddressScheme()!=null) {
+ props.setProperty("javax.xml.registry.postalAddressScheme", Configuration.getRegistryPostalAddressScheme());
+ }
+ if (Configuration.getRegistrySecurityAuthenticationMethod()!=null) {
+ props.setProperty("javax.xml.registry.security.authenticationMethod", Configuration.getRegistrySecurityAuthenticationMethod());
+ }
+ if (Configuration.getRegistryUDDIMaxRows()!=null) {
+ props.setProperty("javax.xml.registry.uddi.maxRows", Configuration.getRegistryUDDIMaxRows());
+ }
+ if (Configuration.getRegistryScoutTransportClass()!=null) {
+ props.setProperty("scout.proxy.transportClass", Configuration.getRegistryScoutTransportClass());
+ }
+ String user = Configuration.getRegistryUser();
+ String password = Configuration.getRegistryPassword();
+ PasswordAuthentication passwdAuth = new PasswordAuthentication(user, password.toCharArray());
+ creds.add(passwdAuth);
+ }
+
+
+ /**
+ * Creates a connecton to a JAXR capable registy.
+ *
+ * @return Connection to a Registry using JAXR.
+ */
+ protected Connection getConnection()
+ {
+ Connection connection = null;
+ try
+ { // Create the connection, passing it the configuration properties
+ ConnectionFactory factory = ConnectionFactory.newInstance();
+ factory.setProperties(props);
+ connection = factory.createConnection();
+ connection.setCredentials(creds);
+ } catch (JAXRException e) {
+ logger.log(Level.ERROR, "Could not set up a connection to the Registry. " + e.getMessage(), e);
+ }
+ return connection;
+ }
+
+ /**
+ * Closes the connection to the Registry
+ */
+ protected void closeConnection(Connection connection)
+ {
+ try {
+ if (connection!=null && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (JAXRException je) {
+ logger.log(Level.ERROR, je.getMessage(), je);
+ }
+ }
+}
Property changes on: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRConnectionFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2008-03-18 17:48:14 UTC (rev 19056)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2008-03-18 19:00:57 UTC (rev 19057)
@@ -22,21 +22,16 @@
package org.jboss.internal.soa.esb.services.registry;
import java.io.UnsupportedEncodingException;
-import java.net.PasswordAuthentication;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
-import java.util.Properties;
-import java.util.Set;
import javax.xml.registry.BulkResponse;
import javax.xml.registry.BusinessLifeCycleManager;
import javax.xml.registry.BusinessQueryManager;
import javax.xml.registry.Connection;
-import javax.xml.registry.ConnectionFactory;
import javax.xml.registry.FindQualifier;
import javax.xml.registry.JAXRException;
import javax.xml.registry.JAXRResponse;
@@ -60,7 +55,6 @@
import org.jboss.soa.esb.MarshalException;
import org.jboss.soa.esb.UnmarshalException;
import org.jboss.soa.esb.addressing.EPR;
-import org.jboss.soa.esb.common.Configuration;
import org.jboss.soa.esb.services.registry.Registry;
import org.jboss.soa.esb.services.registry.RegistryException;
import org.jboss.soa.esb.services.registry.ServiceNotFoundException;
@@ -74,79 +68,18 @@
public class JAXRRegistryImpl implements Registry
{
private static Logger logger = Logger.getLogger(JAXRRegistryImpl.class);
- public static Set<PasswordAuthentication> creds = new HashSet<PasswordAuthentication>();
- private static Properties props = new Properties();
+ private JAXRConnectionFactory jaxrConnectionFactory = new JAXRConnectionFactory();
private static Organization jbossESBOrganization;
-
- private synchronized static void init()
- {
- props = new Properties();
- props.setProperty("javax.xml.registry.queryManagerURL", Configuration.getRegistryQueryManageURI());
- props.setProperty("javax.xml.registry.lifeCycleManagerURL", Configuration.getRegistryLifecycleManagerURI());
- props.setProperty("javax.xml.registry.factoryClass", Configuration.getRegistryFactoryClass());
- if (Configuration.getRegistrySemanticEquivalences()!=null) {
- props.setProperty("javax.xml.registry.semanticEquivalences", Configuration.getRegistrySemanticEquivalences());
- }
- if (Configuration.getRegistryPostalAddressScheme()!=null) {
- props.setProperty("javax.xml.registry.postalAddressScheme", Configuration.getRegistryPostalAddressScheme());
- }
- if (Configuration.getRegistrySecurityAuthenticationMethod()!=null) {
- props.setProperty("javax.xml.registry.security.authenticationMethod", Configuration.getRegistrySecurityAuthenticationMethod());
- }
- if (Configuration.getRegistryUDDIMaxRows()!=null) {
- props.setProperty("javax.xml.registry.uddi.maxRows", Configuration.getRegistryUDDIMaxRows());
- }
- if (Configuration.getRegistryScoutTransportClass()!=null) {
- props.setProperty("scout.proxy.transportClass", Configuration.getRegistryScoutTransportClass());
- }
- String user = Configuration.getRegistryUser();
- String password = Configuration.getRegistryPassword();
- PasswordAuthentication passwdAuth = new PasswordAuthentication(user, password.toCharArray());
- creds.add(passwdAuth);
- }
/**
- * Creates a connecton to a JAXR capable registy.
- *
- * @return Connection to a Registry using JAXR.
- */
- protected synchronized static Connection getConnection()
- {
- Connection connection = null;
- init();
- try
- { // Create the connection, passing it the configuration properties
- ConnectionFactory factory = ConnectionFactory.newInstance();
- factory.setProperties(props);
- connection = factory.createConnection();
- } catch (JAXRException e) {
- logger.log(Level.ERROR, "Could not set up a connection to the Registry. " + e.getMessage(), e);
- }
- return connection;
- }
- /**
- * Closes the connection to the Registry
- */
- protected synchronized static void closeConnection(Connection connection)
- {
- try {
- if (connection!=null && !connection.isClosed()) {
- connection.close();
- }
- } catch (JAXRException je) {
- logger.log(Level.ERROR, je.getMessage(), je);
- }
- }
- /**
* Publish an EPR to the Registry
*/
protected Service registerService(String category, String serviceName, String serviceDescription) throws JAXRException
{
Service service =null;
Organization organization = getJBossESBOrganization();
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
- connection.setCredentials(JAXRRegistryImpl.creds);
RegistryService rs = connection.getRegistryService();
BusinessQueryManager bqm = rs.getBusinessQueryManager();
BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
@@ -160,9 +93,9 @@
Classification classification = blm.createClassification(cScheme, "category", category);
service.addClassification(classification);
organization.addService(service);
- saveRegistryObject(service);
+ saveRegistryObject(service, jaxrConnectionFactory);
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
return service;
}
@@ -172,7 +105,7 @@
@SuppressWarnings("unchecked")
public void unRegisterService(String category, String serviceName) throws RegistryException, ServiceNotFoundException{
// first find the ServiceBindings for this service
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
Service service = null;
try {
service = findService(category, serviceName);
@@ -180,7 +113,6 @@
throw new ServiceNotFoundException("No such EPR found for service with name = "
+ serviceName);
}
- connection.setCredentials(JAXRRegistryImpl.creds);
RegistryService rs = connection.getRegistryService();
BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
Collection<Key> serviceKeys = new ArrayList<Key>();
@@ -189,7 +121,7 @@
} catch (JAXRException je) {
throw new RegistryException(je.getLocalizedMessage(), je);
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
}
/**
@@ -198,7 +130,7 @@
public void registerEPR(String category, String serviceName, String serviceDescription, EPR epr, String eprDescription)
throws RegistryException
{
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
//Find the service
Service service = findService(category,serviceName);
@@ -207,7 +139,6 @@
service = registerService(category, serviceName, serviceDescription);
}
- connection.setCredentials(JAXRRegistryImpl.creds);
RegistryService rs = connection.getRegistryService();
BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
BusinessQueryManager bqm = rs.getBusinessQueryManager();
@@ -226,13 +157,13 @@
Classification classification = blm.createClassification(cScheme, "category", category);
service.addClassification(classification);
- saveRegistryObject(serviceBinding);
+ saveRegistryObject(serviceBinding, jaxrConnectionFactory);
} catch (JAXRException je) {
throw new RegistryException(je.getLocalizedMessage(), je);
} catch (MarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
}
/**
@@ -240,7 +171,7 @@
*/
public void unRegisterEPR(String category, String serviceName, EPR toBeDeletedEPR) throws RegistryException, ServiceNotFoundException{
//first find the ServiceBindings for this service
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
Service service = null;
try {
service = findService(category, serviceName);
@@ -248,7 +179,6 @@
throw new ServiceNotFoundException("No such Service found for service with category= "
+ category + " and name = " + serviceName);
}
- connection.setCredentials(JAXRRegistryImpl.creds);
Collection serviceBindings = findServiceBindings(service);
service.addServiceBindings(serviceBindings);
for (Iterator i=serviceBindings.iterator();i.hasNext();){
@@ -283,7 +213,7 @@
} catch (MarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
}
@@ -308,7 +238,6 @@
/**
* Find Services based on a category ("transformation").
*
- * @param serviceType
* @return collection services
*/
public List<String> findServices(String category) throws RegistryException
@@ -327,13 +256,12 @@
}
/**
*
- * @param service
* @return
*/
public List<EPR> findEPRs(String category, String serviceName) throws RegistryException, ServiceNotFoundException
{
List<EPR> eprs = new ArrayList<EPR>();
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
Service service = findService(category, serviceName);
if (service==null){
@@ -368,19 +296,18 @@
} catch (UnmarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
return eprs;
}
/**
*
- * @param service
* @return
*/
public EPR findEPR(String category, String serviceName) throws RegistryException, ServiceNotFoundException
{
EPR epr = null;
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
Service service = findService(category, serviceName);
if (service==null){
@@ -410,22 +337,22 @@
} catch (UnmarshalException me) {
throw new RegistryException(me.getLocalizedMessage(), me);
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
return epr;
}
- /**
+
+ /**
* Find all Organizations with a name mathing the queryString parameter.
- *
+ *
* @param organizationName used to match with the name of the organization.
* @return the Organization.
*/
- protected synchronized static Organization findOrganization(String organizationName) throws JAXRException
- {
+ public static Organization findOrganization(String organizationName, JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException {
if (organizationName==null) {
organizationName="";
}
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
// Get registry service and business query manager
RegistryService rs = connection.getRegistryService();
@@ -440,7 +367,7 @@
BulkResponse response = bqm.findOrganizations(findQualifiers,
namePatterns, null, null, null, null);
if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
- for (Iterator orgIter = response.getCollection().iterator(); orgIter.hasNext();)
+ for (Iterator orgIter = response.getCollection().iterator(); orgIter.hasNext();)
{
Organization org = (Organization) orgIter.next();
logger.log(Level.DEBUG, "Organization name: " + org.getName().getValue());
@@ -449,7 +376,7 @@
User primaryContact = org.getPrimaryContact();
logger.log(Level.DEBUG, "Primary Contact: " + primaryContact.getPersonName().getFullName());
if (orgIter.hasNext()) {
- logger.log(Level.ERROR, "Found " + response.getCollection().size()
+ logger.log(Level.ERROR, "Found " + response.getCollection().size()
+ " Organization, while expecting only one of name " + organizationName);
}
return org;
@@ -457,16 +384,17 @@
}
return null;
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
}
- /**
- *
+
+ /**
+ *
* @param category
* @param serviceName
* @return Service
*/
- protected synchronized static Service findService(String category, String serviceName) throws JAXRException
+ protected Service findService(String category, String serviceName) throws JAXRException
{
if (category==null) {
category="";
@@ -474,7 +402,7 @@
if (serviceName==null) {
serviceName="";
}
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
// Get registry service and business query manager
RegistryService rs = connection.getRegistryService();
@@ -487,9 +415,9 @@
findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:category");
Collection<Classification> classifications = new ArrayList<Classification>();
- Classification classification =
- blm.createClassification(
- cScheme,
+ Classification classification =
+ blm.createClassification(
+ cScheme,
"category", category );
classifications.add(classification);
Collection<String> namePatterns = new ArrayList<String>();
@@ -499,7 +427,7 @@
BulkResponse response = bqm.findServices(null, findQualifiers,
namePatterns, classifications, null);
if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
- for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();)
+ for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();)
{
Service service = (Service) servIter.next();
logger.log(Level.DEBUG, "Service name: " + service.getName().getValue());
@@ -508,8 +436,8 @@
}
logger.log(Level.DEBUG, "Key id: " + service.getKey().getId());
if (servIter.hasNext()) {
- logger.log(Level.ERROR, "Found " + response.getCollection().size()
- + " Services, while expecting only one by the name of "
+ logger.log(Level.ERROR, "Found " + response.getCollection().size()
+ + " Services, while expecting only one by the name of "
+ serviceName + " in category " + category);
}
return service;
@@ -517,23 +445,23 @@
}
return null;
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
}
- /**
+
+ /**
* Finds all services for a given category.
* @param category
- * @param serviceName
* @return Service
*/
@SuppressWarnings("unchecked")
- protected synchronized static Collection<Service> findServicesForCategory(String category) throws JAXRException
+ protected Collection<Service> findServicesForCategory(String category) throws JAXRException
{
Collection<Service> services = new ArrayList<Service>();
if (category==null) {
category="";
}
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
// Get registry service and business query manager
RegistryService rs = connection.getRegistryService();
@@ -542,13 +470,13 @@
Collection<String> findQualifiers = new ArrayList<String>();
findQualifiers.add(FindQualifier.AND_ALL_KEYS);
findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
- ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:category");
+ ClassificationScheme cScheme = bqm.findClassificationSchemeByName(findQualifiers, "org.jboss.soa.esb.:category");
//Create classification
- Classification classification =
- blm.createClassification(
- cScheme,
+ Classification classification =
+ blm.createClassification(
+ cScheme,
"category", category );
-
+
// Define find qualifiers and name patterns
//Collection<String> findQualifiers = new ArrayList<String>();
//findQualifiers.add(FindQualifier.AND_ALL_KEYS);
@@ -564,24 +492,22 @@
}
return services;
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
}
- /**
+
+ /**
* Create a jbossesb organization under which we will register all our services.
- *
- * @param blm
+ *
* @return
* @throws JAXRException
*/
- protected synchronized static Organization createJBossESBOrganization()
- throws JAXRException
+ protected static Organization createJBossESBOrganization(JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException
{
// Getting the connection to the Registry (reading config)
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
//Logging in
- connection.setCredentials(JAXRRegistryImpl.creds);
RegistryService rs = connection.getRegistryService();
//Building organization
BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
@@ -603,43 +529,43 @@
EmailAddress emailAddress = blm
.createEmailAddress("jbossesb at jboss.com");
emailAddresses.add(emailAddress);
-
+
Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
numbers.add(telephoneNumber);
user.setPersonName(personName);
user.setPostalAddresses(postalAddresses);
user.setEmailAddresses(emailAddresses);
user.setTelephoneNumbers(numbers);
-
+
// Scout does not support this (yet), so leaving it out for now.
// ClassificationScheme cScheme = getClassificationScheme(blm,
// blm.createInternationalString("uddi-org:general_keywords"), blm.createInternationalString(""));
// Classification classification = blm.createClassification(cScheme,
// blm.createInternationalString("JBoss ESB"), blm.createInternationalString("JBESB"));
// org.addClassification(classification);
-
- saveRegistryObject(organization);
+
+ saveRegistryObject(organization, jaxrConnectionFactory);
return organization;
} finally {
- closeConnection(connection);
- }
+ jaxrConnectionFactory.closeConnection(connection);
+ }
}
- /**
+
+ /**
* Save Registry Object
*/
- protected synchronized static void saveRegistryObject(RegistryObject registryObject) throws JAXRException
+ private static void saveRegistryObject(RegistryObject registryObject, JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException
{
// Getting the connection to the Registry (reading config)
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
-
+
BulkResponse br = null;
//Logging in
- connection.setCredentials(JAXRRegistryImpl.creds);
RegistryService rs = connection.getRegistryService();
//Building organization
BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
-
+
Class[] interfaces = registryObject.getClass().getInterfaces();
String interfaceName ="";
for (int i=0; i<interfaces.length; i++) {
@@ -696,23 +622,25 @@
throw new JAXRException("Errors occurred during save");
}
} finally {
- JAXRRegistryImpl.closeConnection(connection);
- }
+ jaxrConnectionFactory.closeConnection(connection);
+ }
}
- /**
+
+ /**
* finds the JBossESB Organizationa and creates one if it is not there.
* @return JBossESB Organization
* @throws JAXRException
*/
private Organization getJBossESBOrganization() throws JAXRException
{
- jbossESBOrganization = findOrganization("Red Hat/JBossESB");
+ jbossESBOrganization = findOrganization("Red Hat/JBossESB", jaxrConnectionFactory);
if (jbossESBOrganization==null) {
- jbossESBOrganization = createJBossESBOrganization();
+ jbossESBOrganization = createJBossESBOrganization(jaxrConnectionFactory);
}
return jbossESBOrganization;
}
- /**
+
+ /**
* Find the ServiceBindings for a given Service
* @param service
* @return
@@ -722,7 +650,7 @@
private Collection<ServiceBinding> findServiceBindings(Service service) throws RegistryException
{
Collection<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
- Connection connection = JAXRRegistryImpl.getConnection();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
RegistryService rs = connection.getRegistryService();
BusinessQueryManager bqm = rs.getBusinessQueryManager();
@@ -736,10 +664,9 @@
} catch (Exception je) {
throw new RegistryException(je.getLocalizedMessage(), je);
} finally {
- closeConnection(connection);
+ jaxrConnectionFactory.closeConnection(connection);
}
}
-
}
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/registry/RegistryFactory.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/registry/RegistryFactory.java 2008-03-18 17:48:14 UTC (rev 19056)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/registry/RegistryFactory.java 2008-03-18 19:00:57 UTC (rev 19057)
@@ -44,14 +44,26 @@
}
- public static Registry getRegistry() throws RegistryException
- {
- // no synchronized block as there should be a service that initializes this
- if (singleton != null) return singleton;
- return createRegistry();
- }
+ public static Registry getRegistry() throws RegistryException {
+ // no synchronized block as there should be a service that initializes this
+ if (singleton != null) {
+ return singleton;
+ }
- public static Registry createRegistry()
+ // The factory hasn't been intialised via the RegistryService e.g.
+ // when used in tests?? Create and set the singleton...
+ synchronized(RegistryFactory.class) {
+ // Check the instance again in case a second thread was blocked on
+ // the sync - prevent it from creating the Registry again...
+ if(singleton == null) {
+ singleton = createRegistry();
+ }
+ }
+
+ return singleton;
+ }
+
+ public static Registry createRegistry()
throws RegistryException
{
Registry registry = null;
Modified: labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java 2008-03-18 17:48:14 UTC (rev 19056)
+++ labs/jbossesb/branches/JBESB_4_2_1_GA_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java 2008-03-18 19:00:57 UTC (rev 19057)
@@ -80,8 +80,9 @@
@Test
public void publishOrganization()
{
+ JAXRConnectionFactory jaxrConnectionFactory = new JAXRConnectionFactory();
try {
- Organization org = JAXRRegistryImpl.createJBossESBOrganization();
+ Organization org = JAXRRegistryImpl.createJBossESBOrganization(jaxrConnectionFactory);
logger.debug("Succesfully created organization: " + org.getName().getValue());
assertEquals("Red Hat/JBossESB", org.getName().getValue());
} catch (JAXRException je) {
@@ -92,8 +93,9 @@
@Test
public void findOrganization()
{
+ JAXRConnectionFactory jaxrConnectionFactory = new JAXRConnectionFactory();
try {
- Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB");
+ Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB", jaxrConnectionFactory);
logger.debug("Succesfully created organization: " + org.getName().getValue());
assertEquals("Red Hat/JBossESB", org.getName().getValue());
} catch (JAXRException je) {
@@ -101,7 +103,7 @@
assertTrue(false);
}
try {
- Organization org = JAXRRegistryImpl.findOrganization("Not Existing Org");
+ Organization org = JAXRRegistryImpl.findOrganization("Not Existing Org", jaxrConnectionFactory);
logger.debug("Could not find non-existing organization.");
assertEquals(null, org);
} catch (JAXRException je) {
@@ -151,8 +153,9 @@
@Test
public void findServicesForAnOrganization()
{
+ JAXRConnectionFactory jaxrConnectionFactory = new JAXRConnectionFactory();
try {
- Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB");
+ Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB", jaxrConnectionFactory);
//Listing out the services and their Bindings
logger.debug("-------------------------------------------------");
logger.debug("Organization name: " + org.getName().getValue());
@@ -187,7 +190,8 @@
*/
public void findServicesByClassification()
{
- Connection connection = JAXRRegistryImpl.getConnection();
+ JAXRConnectionFactory jaxrConnectionFactory = new JAXRConnectionFactory();
+ Connection connection = jaxrConnectionFactory.getConnection();
try {
// Get registry service and business query manager
RegistryService rs = connection.getRegistryService();
@@ -210,7 +214,9 @@
} catch (JAXRException je) {
logger.error(je);
}
- finally{}
+ finally{
+ jaxrConnectionFactory.closeConnection(connection);
+ }
}
/**
* Setup the database.
More information about the jboss-svn-commits
mailing list