[jboss-svn-commits] JBL Code SVN: r38301 - in labs/jbossesb/trunk/product: rosetta/src/org/jboss/internal/soa/esb/services/registry and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 13 15:12:17 EDT 2013


Author: tcunning
Date: 2013-03-13 15:12:17 -0400 (Wed, 13 Mar 2013)
New Revision: 38301

Modified:
   labs/jbossesb/trunk/product/ivy.xml
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
Log:
JBESB-3907
ESB should not be able to register duplicate EPRs for the same service/host.    Check whether the EPR we want to register already exists for the service/host before registering it.

M    product/rosetta/src/org/jboss/soa/esb/common/Environment.java
M    product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
M    product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
M    product/ivy.xml


Modified: labs/jbossesb/trunk/product/ivy.xml
===================================================================
--- labs/jbossesb/trunk/product/ivy.xml	2013-03-13 18:21:51 UTC (rev 38300)
+++ labs/jbossesb/trunk/product/ivy.xml	2013-03-13 19:12:17 UTC (rev 38301)
@@ -39,7 +39,7 @@
         <dependency org="javassist" name="javassist" rev="3.12.1.GA"/>
 
         <dependency org="org.apache.ws.scout" name="jaxr-api" rev="1.0"/>
-        <dependency org="org.apache.juddi.scout" name="scout" rev="1.2.6"/>
+        <dependency org="org.apache.juddi.scout" name="scout" rev="1.2.7"/>
         <dependency org="org.apache.camel" name="camel-core" rev="2.10.2"/>
         <dependency org="org.fusesource.commonman" name="commons-management" rev="1.0"/>
 

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java	2013-03-13 18:21:51 UTC (rev 38300)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java	2013-03-13 19:12:17 UTC (rev 38301)
@@ -54,6 +54,7 @@
 
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
+import org.apache.ws.scout.registry.infomodel.ClassificationImpl;
 import org.apache.ws.scout.registry.infomodel.SpecificationLinkImpl;
 import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
 import org.jboss.soa.esb.ConfigurationException;
@@ -81,10 +82,10 @@
 	private ClassificationScheme jbossESBScheme;
 	private static Concept jbossTModelXXX;
 	public static final String JBOSS_ESB_CATEGORY = "org.jboss.soa.esb.:category";
+	private static final boolean isV3;
     public static final String REGISTERED_BY_JBOSSESB = "Registered by JBoss ESB";
     public static final String SERVICE_DESCRIPTION = "JBoss ESB Service";
     public String orgCategory;
-    private static final boolean isV3;
 	
     public JAXRRegistryImpl() throws ConfigurationException {
         jaxrConnectionFactory = new JAXRConnectionFactory();
@@ -124,6 +125,7 @@
 		}
 		return service;
 	}
+	
 	/** 
 	 * Remove an EPR from the Registry
 	 * @param category
@@ -151,6 +153,12 @@
 			JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
         }
 	}
+    
+    private String getHost() {
+    	return "esbhost:" + Configuration.getBindAddress() + ":" + Configuration.getEsbWebPort();
+    }
+    
+    
 	/** 
 	 * Publish an EPR to the Registry
 	 * @param category
@@ -174,6 +182,29 @@
 		{
 			throw new RegistryException("Null EPR argument specified") ;
 		}
+
+		String xml;
+		try {
+			xml = EPRHelper.toXMLString(epr);
+		} catch (MarshalException me) {
+            throw new RegistryException(me.getLocalizedMessage(), me);			
+		}
+        
+		// If we find something here, there's already an EPR registered, why create a dupe?
+		List<EPR> eprs;
+		try {
+			eprs = findEPRs(category, serviceName, getHost());
+			for (EPR foundEpr : eprs) {
+				if (foundEpr.equals(epr)) {
+					return;
+				}
+			}
+		} catch (RegistryException re) {
+			logger.error(re);
+		} catch (ServiceNotFoundException sfe) {
+			logger.error(sfe);
+		}
+		
 		Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
         try {
 			final Concept jbossTModel = getJBossESBTModel(connection);
@@ -189,8 +220,14 @@
             BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
             BusinessQueryManager bqm = rs.getBusinessQueryManager();
             ServiceBinding serviceBinding = blm.createServiceBinding();
-            String xml = EPRHelper.toXMLString(epr);
             serviceBinding.setAccessURI(xml);
+
+            ClassificationScheme cScheme = getClassificationScheme(bqm, blm);
+            // Add a host string as a classification
+            // so we can try to prevent stale EPR
+            Classification hostClassification = blm.createClassification(cScheme, 
+            		"host", getHost());
+            serviceBinding.addClassification(hostClassification);            
             
             ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
             SpecificationLink sl = new SpecificationLinkImpl(blm);
@@ -204,15 +241,13 @@
             serviceBindings.add(serviceBinding);
             
             service.addServiceBindings(serviceBindings);
-            ClassificationScheme cScheme = getClassificationScheme(bqm, blm);
+            
             Classification classification = blm.createClassification(cScheme, "category", category);
             service.addClassification(classification);
             
             saveRegistryObject(serviceBinding, jaxrConnectionFactory);
         } catch (JAXRException je) {
             throw new RegistryException(je.getLocalizedMessage(), je);
-        } catch (MarshalException me) {
-            throw new RegistryException(me.getLocalizedMessage(), me);
         } finally {
 			JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
         }
@@ -311,6 +346,7 @@
 		}
 		return serviceNames;
 	}
+		
 	/**
 	 * @param category
 	 * @param serviceName
@@ -363,6 +399,75 @@
 		}
 		return eprs;
 	}
+
+	/**
+	 * This version of findEPRs checks whether the serviceBinding has an ESB host ID
+	 * classification (esb + bind.address + : + web.port), and returns an EPR only if 
+	 * it can find that classification.
+	 * @param category
+	 * @param serviceName
+	 * @param esbHost
+	 * @return epr list
+	 * @throws RegistryException
+	 * @throws ServiceNotFoundException
+	 */
+	public List<EPR> findEPRs(String category, String serviceName, String esbHost) throws RegistryException, ServiceNotFoundException
+	{
+		List<EPR> eprs = new ArrayList<EPR>();
+
+		Connection connection = JAXRConnectionSingleton.getConnection(jaxrConnectionFactory);
+		try {
+			final Concept jbossTModel = getJBossESBTModel(connection);
+
+			Service service = findService(category, serviceName);
+			if (service==null){
+                throw new ServiceNotFoundException("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();
+
+				if (serviceBinding.getClassifications().size() > 0) {
+					ArrayList<Classification> classifications = new ArrayList(serviceBinding.getClassifications());
+					
+					boolean registeredFlag = false;
+					for  (Classification classification : classifications) {
+						// If the classification name is "host" and the host matches the current host
+						((ClassificationImpl)classification).setExternal(true);
+						if ((classification.getName().getValue().equals("host"))
+								&& (classification.getValue().equals(esbHost)) ) {
+							String eprXML = serviceBinding.getAccessURI();
+			                EPR epr = null;
+			                //for backwards compatibility still have the decoder if
+			                //unmarchalling fails
+			                try {
+			                    epr = EPRHelper.fromXMLString(eprXML);
+			                    eprs.add(epr);
+			                } catch (UnmarshalException unme) {
+			                    try {
+			                        eprXML = URLDecoder.decode(eprXML, "UTF-8");
+			                        epr = EPRHelper.fromXMLString(eprXML);
+			                        eprs.add(epr);
+			                    } catch (UnsupportedEncodingException ue) {
+			                        logger.error(ue.getMessage(), ue);
+			                        throw new UnmarshalException(ue.getMessage(), ue);
+			                    }
+			                }
+						}
+					}
+				}
+			}
+		} catch (JAXRException je) {
+			throw new RegistryException(je.getLocalizedMessage(), je);
+        } catch (UnmarshalException me) {
+            throw new RegistryException(me.getLocalizedMessage(), me);
+		} finally {
+			JAXRConnectionSingleton.recycleConnection(jaxrConnectionFactory, connection);
+		}
+		return eprs;
+	}
 	
 	/**
 	 * @param category

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java	2013-03-13 18:21:51 UTC (rev 38300)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Configuration.java	2013-03-13 19:12:17 UTC (rev 38301)
@@ -99,6 +99,7 @@
 			new KeyValuePair(Environment.REGISTRY_CACHE_MAX_SIZE		,getRegistryCacheMaxSize()),
 			new KeyValuePair(Environment.REGISTRY_CACHE_VALIDITY_PERIOD	,getRegistryCacheValidityPeriod()),
 			new KeyValuePair(Environment.ESB_BIND_ADDRESS ,getBindAddress()),
+			new KeyValuePair(Environment.ESB_WEB_PORT,getEsbWebPort()),
 			new KeyValuePair(Environment.RULES_CONTINUE_STATE			,getRulesContinueState()),
 			new KeyValuePair(Environment.RULES_RESOURCE_SCANNER_INTERVAL,getRulesResourceScannerInterval()),
 			new KeyValuePair(Environment.DEPLOYMENT_SCHEMA_VALIDATION	,getDeploymentSchemaValidation()),
@@ -698,6 +699,16 @@
 		return ModulePropertyManager.getPropertyManager(ModulePropertyManager.SECURITY_MODULE).getProperty(Environment.SECURITY_JBOSSAS_SECURITY_CONTEXT_OPERATIONS_CLASS);
 	}
 
+	public static String getEsbWebPort() 
+	{
+                String address = System.getProperty(Environment.ESB_WEB_PORT) ;
+                if (address == null)
+                {
+                   address = "8080" ;
+                }
+                return address ;
+	}
+
     /**
 	 * Get the bind address.
 	 * @return the bind address.
@@ -744,4 +755,4 @@
 		return ModulePropertyManager.getPropertyManager(ModulePropertyManager.SECURITY_MODULE).getProperty(Environment.BINARY_SECURITY_TOKEN_IMPLEMENTATION_CLASS,
 				"org.jboss.soa.esb.services.security.auth.ws.BinarySecurityTokenImpl");
 	}
-}
\ No newline at end of file
+}

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java	2013-03-13 18:21:51 UTC (rev 38300)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/common/Environment.java	2013-03-13 19:12:17 UTC (rev 38301)
@@ -35,6 +35,7 @@
          * Binding properties
          */
         public static final String ESB_BIND_ADDRESS = "jboss.esb.bind.address" ;
+        public static final String ESB_WEB_PORT = "org.jboss.esb.web.port";
         /**
          * Schema validation
          */



More information about the jboss-svn-commits mailing list