[jboss-svn-commits] JBL Code SVN: r7152 - in labs/jbossesb/trunk/product/core/services: src/org/jboss/soa/esb/services/registry tests/src/org/jboss/soa/esb/services/registry
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 26 16:48:19 EDT 2006
Author: kurt.stam at jboss.com
Date: 2006-10-26 16:48:16 -0400 (Thu, 26 Oct 2006)
New Revision: 7152
Modified:
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java
labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java
labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
Log:
Working on Registry
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java 2006-10-26 19:50:28 UTC (rev 7151)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/JAXRRegistryImpl.java 2006-10-26 20:48:16 UTC (rev 7152)
@@ -38,9 +38,6 @@
import javax.xml.registry.JAXRException;
import javax.xml.registry.JAXRResponse;
import javax.xml.registry.RegistryService;
-import javax.xml.registry.infomodel.Classification;
-import javax.xml.registry.infomodel.ClassificationScheme;
-import javax.xml.registry.infomodel.Concept;
import javax.xml.registry.infomodel.EmailAddress;
import javax.xml.registry.infomodel.Key;
import javax.xml.registry.infomodel.Organization;
@@ -93,8 +90,7 @@
Connection connection = null;
init();
try
- {
- // Create the connection, passing it the configuration properties
+ { // Create the connection, passing it the configuration properties
ConnectionFactory factory = ConnectionFactory.newInstance();
factory.setProperties(props);
connection = factory.createConnection();
@@ -164,23 +160,39 @@
connection.setCredentials(JAXRRegistryImpl.creds);
RegistryService rs = connection.getRegistryService();
BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
- BusinessQueryManager bqm = rs.getBusinessQueryManager();
+// BusinessQueryManager bqm = rs.getBusinessQueryManager();
ServiceBinding serviceBinding = blm.createServiceBinding();
- serviceBinding.setDescription(blm.createInternationalString("Binding Description"));
- serviceBinding.setAccessURI("http://www.jboss.com/services/TestService");
+ serviceBinding.setDescription(blm.createInternationalString(eprDescription));
+ //For now storing the EPR XML in the URI until I fill in the holes in scout.
+ serviceBinding.setAccessURI("<EPR XML>");
- Concept specConcept = blm.createConcept(null, "HelloConcept", "");
- String schemeName = "uddi-org:types";
- ClassificationScheme uddiOrgTypes =
- bqm.findClassificationSchemeByName(null, schemeName);
- Classification wsdlSpecClassification =
- blm.createClassification(uddiOrgTypes,
- "eprSpec", "eprSpec");
- specConcept.addClassification(wsdlSpecClassification);
- Collection<Concept> concepts = new ArrayList<Concept>();
- concepts.add(specConcept);
- blm.saveConcepts(concepts);
-
+// Concept specConcept = blm.createConcept(null, "HelloConcept", "");
+// String schemeName = "uddi-org:types";
+// ClassificationScheme uddiOrgTypes =
+// bqm.findClassificationSchemeByName(null, schemeName);
+// Classification wsdlSpecClassification =
+// blm.createClassification(uddiOrgTypes,
+// "eprSpec", "eprSpec");
+// 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);
@@ -202,28 +214,62 @@
* {@inheritDoc}
* @return collection services
*/
- public Collection<String> findAllServices()
+ public Collection<String> findAllServices() throws RegistryException
{
- Collection<String> services = new ArrayList<String>();
- return services;
+ 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 type ("transformation"
+ * Find Services based on a category ("transformation").
*
* @param serviceType
* @return collection services
*/
- public Collection<String> findServices(String category){
- Collection<String> services = new ArrayList<String>();
- return 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){
+ public Collection<EPR> findEPRs(String category, String serviceName) throws RegistryException
+ {
Collection<EPR> eprs = new ArrayList<EPR>();
+ try {
+ Service service = findService(category, serviceName);
+ Collection serviceBindings = service.getServiceBindings();
+ for (Iterator i=serviceBindings.iterator();i.hasNext();) {
+ ServiceBinding serviceBinding = (ServiceBinding) i.next();
+ @SuppressWarnings("unused")
+ String eprXML = serviceBinding.getAccessURI();
+ //TODO use the XML to generate the EPR
+ EPR epr = new EPR();
+ eprs.add(epr);
+ }
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ }
return eprs;
}
/**
@@ -325,6 +371,42 @@
}
}
/**
+ * 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
Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java 2006-10-26 19:50:28 UTC (rev 7151)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java 2006-10-26 20:48:16 UTC (rev 7152)
@@ -67,14 +67,14 @@
* Find all Services assigned to the Red Hat/JBossESB organization.
* @return Collection of Strings containing the service names.
*/
- public Collection<String> findAllServices();
+ public Collection<String> findAllServices() throws RegistryException;
/**
* Find all services that belong to the supplied category.
*
* @param category - name of the category to which the service belongs.
* @return Collection of Strings containing the service names
*/
- public Collection<String> findServices(String category);
+ public Collection<String> findServices(String category) throws RegistryException;
/**
* Finds all the EPRs that belong to a specific category and service combination.
*
@@ -82,5 +82,5 @@
* @param serviceName - name of the service to which the EPS belongs.
* @return Collection of EPRs.
*/
- public Collection<EPR> findEPRs(String category, String serviceName);
+ public Collection<EPR> findEPRs(String category, String serviceName) throws RegistryException;
}
Modified: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java 2006-10-26 19:50:28 UTC (rev 7151)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/JAXRRegistryUnitTest.java 2006-10-26 20:48:16 UTC (rev 7152)
@@ -163,7 +163,7 @@
ServiceBinding serviceBinding = (ServiceBinding) serviceBindingIter.next();
logger.log(Priority.INFO, " ServiceBinding Description: " + serviceBinding.getDescription().getValue());
logger.log(Priority.INFO, " ServiceBinding URI: " + serviceBinding.getAccessURI());
- assertEquals("http://www.jboss.com/services/TestService",serviceBinding.getAccessURI());
+ assertEquals("<EPR XML>",serviceBinding.getAccessURI());
}
}
logger.log(Priority.INFO, "-------------------------------------------------");
Modified: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java 2006-10-26 19:50:28 UTC (rev 7151)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java 2006-10-26 20:48:16 UTC (rev 7152)
@@ -21,29 +21,22 @@
*/
package org.jboss.soa.esb.services.registry;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.InputStream;
import java.sql.DriverManager;
import java.sql.Statement;
-import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Properties;
-import javax.xml.registry.BulkResponse;
-import javax.xml.registry.BusinessLifeCycleManager;
-import javax.xml.registry.BusinessQueryManager;
-import javax.xml.registry.Connection;
-import javax.xml.registry.FindQualifier;
-import javax.xml.registry.JAXRResponse;
-import javax.xml.registry.RegistryService;
-import javax.xml.registry.infomodel.Organization;
-import javax.xml.registry.infomodel.Service;
-
import junit.framework.JUnit4TestAdapter;
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.common.tests.HsqldbUtil;
import org.jboss.soa.esb.common.tests.TestUtil;
import org.jboss.soa.esb.services.util.FileUtil;
@@ -62,72 +55,69 @@
private static String mDbUrl;
private static String mDbUsername;
private static String mDbPassword;
+ private static final String SERVICE_NAME = "Kurt's Travel Agency";
+ private static final String CATEGORY = "travel";
+ private Logger logger = Logger.getLogger(this.getClass());
+
/**
- *
+ * Testing the registering of an EPR.
*/
- @SuppressWarnings("unchecked")
@Test
- public void publishAnEPR() {
-// String EPR_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-// + "<EPR>"
-// + " <wsa:Address>jms://queue</wsa:Address>"
-// + " <wsa:ReferenceProperties>"
-// + " <wsarjaddr:specification-version xmlns:wsarjaddr=\"http://schemas.arjuna.com/ws/2004/06/wsarjaddr\">1.1</wsarjaddr:specification-version>"
-// + " <wsarjaddr:destination-name xmlns:wsarjaddr=\"http://schemas.arjuna.com/ws/2004/06/wsarjaddr\">queue/A</wsarjaddr:destination-name>"
-// + " <wsarjaddr:connection-factory xmlns:wsarjaddr=\"http://schemas.arjuna.com/ws/2004/06/wsarjaddr\">ConnectionFactory</wsarjaddr:connection-factory>"
-// + " <wsarjaddr:jndi-type xmlns:wsarjaddr=\"http://schemas.arjuna.com/ws/2004/06/wsarjaddr\">jboss</wsarjaddr:jndi-type>"
-// + " <wsarjaddr:jndi-URL xmlns:wsarjaddr=\"http://schemas.arjuna.com/ws/2004/06/wsarjaddr\">localhost</wsarjaddr:jndi-URL>"
-// + " <wsarjaddr:message-selector xmlns:wsarjaddr=\"http://schemas.arjuna.com/ws/2004/06/wsarjaddr\">listener='maradona'</wsarjaddr:message-selector>"
-// + " </wsa:ReferenceProperties>"
-// + "</EPR>";
-// String serviceName="Kurt's Travel Agency";
-// String serviceURI="epr:jbossesb:version:1.0:logicalname:KurtsTravelAgency";
-
- Connection connection = JAXRRegistryImpl.getConnection();
+ public void publishEPR()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ EPR epr = new EPR();
try {
- //Logging in
- connection.setCredentials(JAXRRegistryImpl.creds);
- RegistryService rs = connection.getRegistryService();
- BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
- 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("%JBOSS%");
-// 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);
-
- System.out.println("Found " + response.getCollection().size() + " organization.");
- for (Iterator orgIter = response.getCollection().iterator(); orgIter.hasNext();)
- {
- Organization org = (Organization) orgIter.next();
- Service service = blm.createService(blm.createInternationalString("JBossESB TEST Service"));
- service.setDescription(blm.createInternationalString("Services of the ESB UDDI Registry"));
- org.addService(service);
- Collection services = new ArrayList();
- services.add(service);
- BulkResponse br=blm.saveServices(services);
- if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
- br.getCollection();
- //ServiceBinding serviceBinding =
- //service.addServiceBinding(serviceBinding);
- }
+ registry.registerEPR(CATEGORY, SERVICE_NAME, "Service for traveling",
+ epr, "Specific Service Binding for traveling");
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ /**
+ * This test will try to find all services in the "travel" category.
+ */
+ @Test
+ public void findService()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ try {
+ Collection<String> services = registry.findServices(CATEGORY);
+ for (Iterator i=services.iterator();i.hasNext();) {
+ String serviceName = (String) i.next();
+ logger.log(Priority.INFO, "Found service: " + serviceName);
+ assertEquals(CATEGORY + ":" + SERVICE_NAME, serviceName);
}
- } catch (Exception e) {
- e.printStackTrace();
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
assertTrue(false);
- } finally {
- JAXRRegistryImpl.closeConnection(connection);
}
+ }
+ /**
+ * Find the EPRs for this service.
+ */
+ @Test
+ public void findEPRs()
+ {
+ Registry registry = RegistryFactory.getRegistry();
+ try {
+ Collection<EPR> eprs = registry.findEPRs(CATEGORY, SERVICE_NAME);
+ for (Iterator i=eprs.iterator();i.hasNext();) {
+ String epr = (String) i.next();
+ logger.log(Priority.INFO, "Found epr: " + epr);
+ }
+ } catch (RegistryException re) {
+ logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+ assertTrue(false);
+ }
+ }
+ @Test
+ public void unregisterEPR()
+ {
-
-
}
-
/**
* Setup the database.
* @throws Exception
More information about the jboss-svn-commits
mailing list