[jboss-svn-commits] JBL Code SVN: r7634 - in labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/services: . registry
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Nov 16 05:30:55 EST 2006
Author: b_georges
Date: 2006-11-16 05:30:53 -0500 (Thu, 16 Nov 2006)
New Revision: 7634
Added:
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/services/registry/
labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
Log:
""
Added: labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2006-11-16 10:30:00 UTC (rev 7633)
+++ labs/jbossesb/workspace/b_georges/product/core/services/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2006-11-16 10:30:53 UTC (rev 7634)
@@ -0,0 +1,634 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.internal.soa.esb.services.registry;
+
+import java.net.PasswordAuthentication;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+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;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.EmailAddress;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.PersonName;
+import javax.xml.registry.infomodel.PostalAddress;
+import javax.xml.registry.infomodel.RegistryObject;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.TelephoneNumber;
+import javax.xml.registry.infomodel.User;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
+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;
+/**
+ * Utility class for the Registry.
+ * If need be we can extract the interface from here, add a factory and have JAXR as a plugin, allowing
+ * for other RegistryAPIs.
+ *
+ * @author Kurt Stam
+ */
+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 static Organization jbossESBOrganization;
+
+ private 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());
+ 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 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(Priority.ERROR, "Could not set up a connection to the Registry. " + e.getMessage(), e);
+ }
+ return connection;
+ }
+ /**
+ * Closes the connection to the Registry
+ */
+ protected static void closeConnection(Connection connection)
+ {
+ try {
+ if (connection!=null && !connection.isClosed()) {
+ connection.close();
+ }
+ } catch (JAXRException je) {
+ logger.log(Priority.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();
+ try {
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ //Adding the category as prefix for the name
+ service = blm.createService(blm.createInternationalString(category + ":" + serviceName));
+ service.setDescription(blm.createInternationalString(serviceDescription));
+// ClassificationScheme cScheme = getClassificationScheme(blm, "uddi-org:general_keywords", "");
+// Classification classification = blm.createClassification(cScheme, "JBossESB" + category, category);
+// service.addClassification(classification);
+ organization.addService(service);
+ saveRegistryObject(service);
+ } finally {
+ closeConnection(connection);
+ }
+ return service;
+ }
+ /**
+ * Remove an EPR from the Registry
+ */
+ public void unRegisterService(String category, String serviceName) throws RegistryException{
+ try {
+ Organization organization = getJBossESBOrganization();
+ for (Iterator i=organization.getServices().iterator(); i.hasNext();) {
+ Service service = (Service) i.next();
+ if (service.getName().getValue().equals(category + ":" + serviceName)) {
+ organization.removeService(service);
+ saveRegistryObject(organization);
+ return;
+ }
+ }
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ }
+ /**
+ * Publish an EPR to the Registry
+ */
+ public void registerEPR(String category, String serviceName, String serviceDescription, EPR epr, String eprDescription)
+ throws RegistryException
+ {
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ //Find the service
+ Service service = findService(category,serviceName);
+ if (service==null) {
+ logger.log(Priority.INFO, "Service " + serviceName + " does not yet exist, creating now..");
+ service = registerService(category, serviceName, serviceDescription);
+ }
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+// BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ ServiceBinding serviceBinding = blm.createServiceBinding();
+ serviceBinding.setDescription(blm.createInternationalString(eprDescription));
+ String xml = EPRHelper.toXMLString(epr);
+ serviceBinding.setAccessURI(URLEncoder.encode(xml,"UTF-8"));
+
+// The following code would store the EPR xml as an ExtrinsicObject, but scout does not
+// have an implementation for it.
+// DataHandler repositoryItem = new DataHandler(xml,"text/xml");
+// ExtrinsicObject eo = blm.createExtrinsicObject(repositoryItem);
+// eo.setName(blm.createInternationalString("EPR"));
+// eo.setMimeType("text/xml");
+// String conceptId = "urn:oasis:names:tc:ebxml-regrep:ObjectType:RegistryObject:ExtrinsicObject:XML";
+// Concept objectTypeConcept = (Concept) bqm.getRegistryObject(conceptId);
+// ((ExtrinsicObjectImpl)eo).setObjectType(objectTypeConcept);
+
+// Concept specConcept = blm.createConcept(null, "HelloConcept", "");
+// String schemeName = "uddi-org:types";
+// ClassificationScheme uddiOrgTypes =
+// bqm.findClassificationSchemeByName(null, schemeName);
+// Classification wsdlSpecClassification =
+// blm.createClassification(uddiOrgTypes,
+// "eprSpec", xml);
+// specConcept.addClassification(wsdlSpecClassification);
+// Collection<Concept> concepts = new ArrayList<Concept>();
+// concepts.add(specConcept);
+// BulkResponse br=blm.saveConcepts(concepts);
+// Key conceptKey = null;
+// if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
+// Collection keys = br.getCollection();
+// for (Iterator i=keys.iterator();i.hasNext();){
+// conceptKey = (Key) i.next();
+// break;
+// }
+// } else {
+// throw new RegistryException("Could not save the EPR as Concept");
+// }
+// //now adding this concept to the binding
+// Concept specificationConcept = (Concept) bqm.getRegistryObject(conceptKey.getId(), LifeCycleManager.CONCEPT);
+// SpecificationLink specificationLink = blm.createSpecificationLink();
+// specificationLink.setSpecificationObject(specificationConcept);
+// serviceBinding.addSpecificationLink(specificationLink);
+
+ ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
+ serviceBindings.add(serviceBinding);
+ service.addServiceBindings(serviceBindings);
+ saveRegistryObject(serviceBinding);
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Remove an EPR from the Registry
+ */
+ public void unRegisterEPR(String category, String serviceName, EPR toBeDeletedEPR) throws RegistryException{
+ //first find the ServiceBindings for this service
+ try {
+ Service service = findService(category, serviceName);
+ Collection<ServiceBinding> serviceBindings = findServiceBindings(service);
+ for (Iterator i=serviceBindings.iterator();i.hasNext();){
+ ServiceBinding serviceBinding = (ServiceBinding) i.next();
+ String xml = URLDecoder.decode(serviceBinding.getAccessURI(), "UTF-8");
+ if (xml.equals(EPRHelper.toXMLString(toBeDeletedEPR))) {
+ service.removeServiceBinding(serviceBinding);
+ service.setProvidingOrganization(getJBossESBOrganization());
+ saveRegistryObject(service);
+ return;
+ }
+ }
+ //We should not end up here or else we did not match any EPRs
+ throw new RegistryException("No such EPR found for service with name = "
+ + serviceName + " and EPR=" + toBeDeletedEPR);
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ * @return collection services
+ */
+ public Collection<String> findAllServices() throws RegistryException
+ {
+ Collection<String> serviceNames = new ArrayList<String>();
+ try {
+ Collection services = getJBossESBOrganization().getServices();
+ for (Iterator i=services.iterator();i.hasNext();) {
+ String serviceName = ((Service)i.next()).getName().getValue();
+ serviceNames.add(serviceName);
+ }
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ return serviceNames;
+ }
+ /**
+ * Find Services based on a category ("transformation").
+ *
+ * @param serviceType
+ * @return collection services
+ */
+ public Collection<String> findServices(String category) throws RegistryException
+ {
+ Collection<String>serviceNames = new ArrayList<String>();
+ try {
+ Collection<Service>services = findServicesForCategory(category);
+ for (Iterator<Service> i=services.iterator();i.hasNext();) {
+ String serviceName = i.next().getName().getValue();
+ serviceNames.add(serviceName);
+ }
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
+ return serviceNames;
+ }
+ /**
+ *
+ * @param service
+ * @return
+ */
+ public Collection<EPR> findEPRs(String category, String serviceName) throws RegistryException
+ {
+ Collection<EPR> eprs = new ArrayList<EPR>();
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ Service service = findService(category, serviceName);
+ if (service==null){
+ throw new RegistryException("Could not find service with category=" + category + " and serviceName=" + serviceName);
+ }
+ // Get registry service and business query manager
+ Collection<ServiceBinding> serviceBindings = findServiceBindings(service);
+ //Converting them to EPRs
+ for (Iterator i=serviceBindings.iterator();i.hasNext();) {
+ ServiceBinding serviceBinding = (ServiceBinding) i.next();
+ @SuppressWarnings("unused")
+ String eprXML = URLDecoder.decode(serviceBinding.getAccessURI(),"UTF-8");
+ //TODO use the XML to generate the EPR
+ EPR epr = EPRHelper.fromXMLString(eprXML);
+ eprs.add(epr);
+ }
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ } finally {
+ closeConnection(connection);
+ }
+ return eprs;
+ }
+ /**
+ * 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 static Organization findOrganization(String organizationName) throws JAXRException
+ {
+ if (organizationName==null) {
+ organizationName="";
+ }
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ // Define find qualifiers and name patterns
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
+ Collection<String> namePatterns = new ArrayList<String>();
+ namePatterns.add("%" + organizationName + "%");
+ //Find based upon qualifier type and values
+ System.out.println("Going to query the registry for name pattern " + namePatterns);
+ BulkResponse response = bqm.findOrganizations(findQualifiers,
+ namePatterns, null, null, null, null);
+ if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
+ for (Iterator orgIter = response.getCollection().iterator(); orgIter.hasNext();)
+ {
+ Organization org = (Organization) orgIter.next();
+ logger.log(Priority.INFO, "Organization name: " + org.getName().getValue());
+ logger.log(Priority.INFO, "Description: " + org.getDescription().getValue());
+ logger.log(Priority.INFO, "Key id: " + org.getKey().getId());
+ User primaryContact = org.getPrimaryContact();
+ logger.log(Priority.INFO, "Primary Contact: " + primaryContact.getPersonName().getFullName());
+ if (orgIter.hasNext()) {
+ logger.log(Priority.ERROR, "Found " + response.getCollection().size()
+ + " Organization, while expecting only one of name " + organizationName);
+ }
+ return org;
+ }
+ }
+ return null;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ *
+ * @param category
+ * @param serviceName
+ * @return Service
+ */
+ protected static Service findService(String category, String serviceName) throws JAXRException
+ {
+ if (category==null) {
+ category="";
+ }
+ if (serviceName==null) {
+ serviceName="";
+ }
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ // Define find qualifiers and name patterns
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.AND_ALL_KEYS);
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
+ Collection<String> namePatterns = new ArrayList<String>();
+ namePatterns.add("%" + category + "%");
+ namePatterns.add("%" + serviceName + "%");
+ //Find based upon qualifier type and values
+ logger.log(Priority.DEBUG, "Going to query the registry for name pattern " + namePatterns);
+ BulkResponse response = bqm.findServices(null, findQualifiers,
+ namePatterns, null, null);
+ if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
+ for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();)
+ {
+ Service service = (Service) servIter.next();
+ logger.log(Priority.INFO, "Service name: " + service.getName().getValue());
+ if (service.getDescription()!=null) {
+ logger.log(Priority.INFO, "Description: " + service.getDescription().getValue());
+ }
+ logger.log(Priority.INFO, "Key id: " + service.getKey().getId());
+ if (servIter.hasNext()) {
+ logger.log(Priority.ERROR, "Found " + response.getCollection().size()
+ + " Services, while expecting only one by the name of "
+ + serviceName + " in category " + category);
+ }
+ return service;
+ }
+ }
+ return null;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Finds all services for a given category.
+ * @param category
+ * @param serviceName
+ * @return Service
+ */
+ @SuppressWarnings("unchecked")
+ protected static Collection<Service> findServicesForCategory(String category) throws JAXRException
+ {
+ Collection<Service> services = new ArrayList<Service>();
+ if (category==null) {
+ category="";
+ }
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ // Define find qualifiers and name patterns
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.AND_ALL_KEYS);
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
+ Collection<String> namePatterns = new ArrayList<String>();
+ namePatterns.add("%" + category + "%");
+ //Find based upon qualifier type and values
+ logger.log(Priority.DEBUG, "Going to query the registry for name pattern " + namePatterns);
+ BulkResponse response = bqm.findServices(null, findQualifiers,
+ namePatterns, null, null);
+ if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
+ services = response.getCollection();
+ }
+ return services;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Create a jbossesb organization under which we will register all our services.
+ *
+ * @param blm
+ * @return
+ * @throws JAXRException
+ */
+ protected static Organization createJBossESBOrganization()
+ throws JAXRException
+ {
+// Getting the connection to the Registry (reading config)
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ //Logging in
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ //Building organization
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ Organization organization = blm.createOrganization(blm.createInternationalString("Red Hat/JBossESB"));
+ organization.setDescription(blm.createInternationalString("Red Hat/JBoss Professional Open Source, Services for the JBossESB"));
+
+ User user = blm.createUser();
+ organization.setPrimaryContact(user);
+ PersonName personName = blm.createPersonName("JBossESB");
+ TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
+ telephoneNumber.setNumber("404 467-8555");
+ telephoneNumber.setType(null);
+ PostalAddress address = blm.createPostalAddress("3340",
+ "Peachtree Road, NE, Suite 1200", "Atlanta", "GA", "USA",
+ "30326", "");
+ Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
+ postalAddresses.add(address);
+ Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
+ 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);
+ return organization;
+ } finally {
+ closeConnection(connection);
+ }
+ }
+ /**
+ * Save Registry Object
+ */
+ protected static void saveRegistryObject(RegistryObject registryObject) throws JAXRException
+ {
+// Getting the connection to the Registry (reading config)
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ Collection<RegistryObject> registryObjects = new ArrayList<RegistryObject>();
+ BulkResponse br = null;
+ //Logging in
+ connection.setCredentials(JAXRRegistryImpl.creds);
+ RegistryService rs = connection.getRegistryService();
+ //Building organization
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ registryObjects.add(registryObject);
+ Class[] interfaces = registryObject.getClass().getInterfaces();
+ String interfaceName ="";
+ for (int i=0; i<interfaces.length; i++) {
+ interfaceName = interfaces[i].getName();
+ if (interfaceName.equals("javax.xml.registry.infomodel.Organization")) {
+ br = blm.saveOrganizations(registryObjects);
+ break;
+ } else if (interfaceName.equals("javax.xml.registry.infomodel.Service")) {
+ br = blm.saveServices(registryObjects);
+ break;
+ } else if (interfaceName.equals("javax.xml.registry.infomodel.ServiceBinding")) {
+ br = blm.saveServiceBindings(registryObjects);
+ break;
+ } else {
+ logger.log(Priority.ERROR, "Trying to save an unsupported RegistryObject");
+ throw new JAXRException("Trying to save an unsupported RegistryObject");
+ }
+ }
+ //Verify the return
+ if (br!=null && br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
+ logger.log(Priority.INFO, interfaceName + " successfully saved");
+ Collection coll = br.getCollection();
+ Iterator iter = coll.iterator();
+ while (iter.hasNext()) {
+ Key key = (Key) iter.next();
+ registryObject.setKey(key);
+ logger.log(Priority.INFO, "Saved Key=" + key.getId());
+ }
+ } else {
+ logger.log(Priority.ERROR, "Errors occurred during save.");
+ if (br!=null) {
+ Collection exceptions = br.getExceptions();
+ Iterator iter = exceptions.iterator();
+ String errors = "";
+ JAXRException je = new JAXRException("JAXRExceptions occurred during save");
+ while (iter.hasNext()) {
+ Exception e = (Exception) iter.next();
+ errors += e.getLocalizedMessage() + "\n";
+ je.setStackTrace(e.getStackTrace());
+ logger.log(Priority.ERROR, e.getLocalizedMessage(), e);
+ //if it's the last error, throw it now and set the current stacktrace
+ if (!iter.hasNext()) {
+ throw new JAXRException(errors, e);
+ }
+ }
+ throw new JAXRException("Errors occurred during save. Response status=" + br.getStatus());
+ }
+ throw new JAXRException("Errors occurred during save");
+ }
+ } finally {
+ JAXRRegistryImpl.closeConnection(connection);
+ }
+ }
+ /**
+ * finds the JBossESB Organizationa and creates one if it is not there.
+ * @return JBossESB Organization
+ * @throws JAXRException
+ */
+ private Organization getJBossESBOrganization() throws JAXRException
+ {
+ if (jbossESBOrganization==null) {
+ jbossESBOrganization = findOrganization("Red Hat/JBossESB");
+ if (jbossESBOrganization==null) {
+ jbossESBOrganization = createJBossESBOrganization();
+ }
+ }
+ return jbossESBOrganization;
+ }
+ /**
+ * Find the ServiceBindings for a given Service
+ * @param service
+ * @return
+ * @throws RegistryException
+ */
+ @SuppressWarnings("unchecked")
+ private Collection<ServiceBinding> findServiceBindings(Service service) throws RegistryException
+ {
+ Collection<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
+ Connection connection = JAXRRegistryImpl.getConnection();
+ try {
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
+ BulkResponse bulkResponse = bqm.findServiceBindings(service.getKey(),findQualifiers,null,null);
+ if (bulkResponse.getStatus()==JAXRResponse.STATUS_SUCCESS){
+ serviceBindings = bulkResponse.getCollection();
+ }
+ return serviceBindings;
+ } catch (Exception je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ } finally {
+ closeConnection(connection);
+ }
+ }
+
+}
+
+
More information about the jboss-svn-commits
mailing list