servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r392284 - in /incubator/servicemix/trunk/servicemix-wsn2005: ./ src/main/java/org/apache/servicemix/wsn/component/ src/main/resources/org/ src/main/resources/org/apache/ src/main/resources/org/apache/servicemix/ src/main/resources/org/apach...
Date Fri, 07 Apr 2006 13:21:45 GMT
Author: gnodet
Date: Fri Apr  7 06:21:37 2006
New Revision: 392284

URL: http://svn.apache.org/viewcvs?rev=392284&view=rev
Log:
SM-304: expose WSDL for WS-Notification endpoints

Added:
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/resources/org/
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/resources/org/apache/
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/resources/org/apache/servicemix/
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/resources/org/apache/servicemix/wsn/
      - copied from r391748, incubator/servicemix/trunk/servicemix-wsn2005/src/main/wsdl/
Removed:
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/wsdl/
    incubator/servicemix/trunk/servicemix-wsn2005/src/test/resources/org/servicemix/
Modified:
    incubator/servicemix/trunk/servicemix-wsn2005/project.properties
    incubator/servicemix/trunk/servicemix-wsn2005/project.xml
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNComponent.java
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNEndpoint.java
    incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNLifeCycle.java
    incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java

Modified: incubator/servicemix/trunk/servicemix-wsn2005/project.properties
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/project.properties?rev=392284&r1=392283&r2=392284&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/project.properties (original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/project.properties Fri Apr  7 06:21:37 2006
@@ -23,7 +23,7 @@
 # -------------------------------------------------------------------
 lib.home=lib
 etc.home=etc
-wsdl.home=${basedir}/src/main/wsdl
+wsdl.home=${basedir}/src/main/resources/org/apache/servicemix/wsn
 
 debug=true
 verbose=false

Modified: incubator/servicemix/trunk/servicemix-wsn2005/project.xml
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/project.xml?rev=392284&r1=392283&r2=392284&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/project.xml (original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/project.xml Fri Apr  7 06:21:37 2006
@@ -43,6 +43,9 @@
       <groupId>servicemix</groupId>
       <artifactId>jsr181-api</artifactId>
       <version>${jaxws_rt_version}</version>
+      <properties>
+        <jbi.bundle>true</jbi.bundle>
+      </properties>
     </dependency>
     <dependency>
       <groupId>servicemix</groupId>
@@ -58,11 +61,17 @@
       <groupId>servicemix</groupId>
       <artifactId>jaxb-api</artifactId>
       <version>${jaxws_rt_version}</version>
+      <properties>
+        <jbi.bundle>true</jbi.bundle>
+      </properties>
     </dependency>
     <dependency>
       <groupId>servicemix</groupId>
       <artifactId>jaxb-impl</artifactId>
       <version>${jaxws_rt_version}</version>
+      <properties>
+        <jbi.bundle>true</jbi.bundle>
+      </properties>
     </dependency>
     <dependency>
       <groupId>servicemix</groupId>

Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNComponent.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNComponent.java?rev=392284&r1=392283&r2=392284&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNComponent.java
(original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNComponent.java
Fri Apr  7 06:21:37 2006
@@ -15,15 +15,31 @@
  */
 package org.apache.servicemix.wsn.component;
 
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.jms.ConnectionFactory;
+import javax.wsdl.Definition;
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
 
 import org.apache.servicemix.common.BaseComponent;
 import org.apache.servicemix.common.BaseLifeCycle;
 import org.apache.servicemix.common.BaseServiceUnitManager;
 import org.apache.servicemix.common.Deployer;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.EndpointSupport;
+import org.apache.servicemix.common.tools.wsdl.WSDLFlattener;
+import org.w3c.dom.Document;
 
 public class WSNComponent extends BaseComponent {
 
+    private WSDLFlattener flattener;
+    private Map descriptions;
+    
     @Override
 	protected BaseLifeCycle createLifeCycle() {
 		return new WSNLifeCycle(this);
@@ -42,5 +58,59 @@
 	public void setConnectionFactory(ConnectionFactory connectionFactory) {
 		((WSNLifeCycle) lifeCycle).setConnectionFactory(connectionFactory);
 	}
+
+    /* (non-Javadoc)
+     * @see org.apache.servicemix.common.BaseComponent#getServiceDescription(javax.jbi.servicedesc.ServiceEndpoint)
+     */
+    @Override
+    public Document getServiceDescription(ServiceEndpoint endpoint) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Querying service description for " + endpoint);
+        }
+        String key = EndpointSupport.getKey(endpoint);
+        Endpoint ep = this.registry.getEndpoint(key);
+        if (ep != null) {
+            QName interfaceName = ep.getInterfaceName();
+            if (interfaceName == null) {
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Could not retrieve description for endpoint " + key + "
(no interface defined)");
+                }
+                return null;
+            }
+            Document doc = getDescription(interfaceName);
+            return doc;
+        } else {
+            if (logger.isDebugEnabled()) {
+                logger.debug("No endpoint found for " + key);
+            }
+            return null;
+        }
+    }
+
+    private synchronized Document getDescription(QName interfaceName) {
+        try {
+            if (descriptions == null) {
+                descriptions = new HashMap(); 
+            }
+            Document doc = (Document) descriptions.get(interfaceName);
+            if (doc == null) {
+                if (flattener == null) {
+                    URL resource = getClass().getClassLoader().getResource("org/apache/servicemix/wsn/wsn.wsdl");
+                    WSDLReader reader = WSDLFactory.newInstance().newWSDLReader();
+                    Definition definition = reader.readWSDL(null, resource.toString());
+                    flattener = new WSDLFlattener(definition);
+                }
+                Definition flatDef = flattener.getDefinition(interfaceName);
+                doc = WSDLFactory.newInstance().newWSDLWriter().getDocument(flatDef);
+                descriptions.put(interfaceName, doc);
+            }
+            return doc;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Error retrieving endpoint description", e);
+            }
+            return null;
+        }
+    }
 	
 }

Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNEndpoint.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNEndpoint.java?rev=392284&r1=392283&r2=392284&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNEndpoint.java
Fri Apr  7 06:21:37 2006
@@ -70,21 +70,21 @@
 	@Override
 	public void activate() throws Exception {
         logger = this.serviceUnit.getComponent().getLogger();
+        WebService ws = getWebServiceAnnotation(pojo.getClass());
+        if (ws == null) {
+            throw new IllegalStateException("Unable to find WebService annotation");
+        }
+        endpointInterface = Class.forName(ws.endpointInterface());
+        jaxbContext = createJAXBContext(endpointInterface);
+        ws = getWebServiceAnnotation(endpointInterface);
+        if (ws != null) {
+            interfaceName = new QName(ws.targetNamespace(), ws.name());
+        }
         ComponentContext ctx = this.serviceUnit.getComponent().getComponentContext();
         activated = ctx.activateEndpoint(service, endpoint);
         channel = ctx.getDeliveryChannel();
-        jaxbContext = createJAXBContext();
 	}
 	
-	protected JAXBContext createJAXBContext() throws Exception {
-		WebService ws = getWebServiceAnnotation();
-		if (ws == null) {
-			throw new IllegalStateException("Unable to find WebService annotation");
-		}
-		endpointInterface = Class.forName(ws.endpointInterface());
-        return createJAXBContext(endpointInterface);
-	}
-    
     public static JAXBContext createJAXBContext(Class interfaceClass) throws JAXBException
{
         List<Class> classes = new ArrayList<Class>();
         classes.add(JbiFault.class);
@@ -186,7 +186,7 @@
 	}
 	
 	protected Method getWebServiceMethod(QName interfaceName, QName operation) throws Exception
{
-		WebService ws = getWebServiceAnnotation();
+		WebService ws = getWebServiceAnnotation(pojo.getClass());
 		if (ws == null) {
 			throw new IllegalStateException("Unable to find WebService annotation");
 		}
@@ -201,8 +201,8 @@
 	}
 
 	@SuppressWarnings("unchecked")
-	protected WebService getWebServiceAnnotation() {
-		for (Class cl = pojo.getClass(); cl != null; cl = cl.getSuperclass()) {
+	protected WebService getWebServiceAnnotation(Class clazz) {
+		for (Class cl = clazz; cl != null; cl = cl.getSuperclass()) {
 			WebService ws = (WebService) cl.getAnnotation(WebService.class);
 			if (ws != null) {
 				return ws;

Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNLifeCycle.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNLifeCycle.java?rev=392284&r1=392283&r2=392284&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNLifeCycle.java
(original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/main/java/org/apache/servicemix/wsn/component/WSNLifeCycle.java
Fri Apr  7 06:21:37 2006
@@ -118,29 +118,25 @@
 	public class WSNEndpointManager implements EndpointManager {
 
 		public Object register(String address, Object service) throws EndpointRegistrationException
{
-			component.getRegistry().unregisterServiceUnit(serviceUnit);
 			try {
 				WSNEndpoint endpoint = new WSNEndpoint(address, service);
 				endpoint.setServiceUnit(serviceUnit);
-				endpoint.activate();
 				serviceUnit.addEndpoint(endpoint);
+                component.getRegistry().registerEndpoint(endpoint);
+                endpoint.activate();
 				return endpoint;
 			} catch (Exception e) {
 				throw new EndpointRegistrationException("Unable to activate endpoint", e);
-			} finally {
-				component.getRegistry().registerServiceUnit(serviceUnit);
 			}
 		}
 
 		public void unregister(Object endpoint) throws EndpointRegistrationException {
-			component.getRegistry().unregisterServiceUnit(serviceUnit);
 			try {
+                serviceUnit.getEndpoints().remove(endpoint);
+                component.getRegistry().unregisterEndpoint((WSNEndpoint) endpoint);
 				((WSNEndpoint) endpoint).deactivate();
 			} catch (Exception e) {
 				throw new EndpointRegistrationException("Unable to activate endpoint", e);
-			} finally {
-				serviceUnit.getEndpoints().remove(endpoint);
-				component.getRegistry().registerServiceUnit(serviceUnit);
 			}
 		}
 

Modified: incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java
URL: http://svn.apache.org/viewcvs/incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java?rev=392284&r1=392283&r2=392284&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-wsn2005/src/test/java/org/apache/servicemix/wsn/component/WSNComponentTest.java
Fri Apr  7 06:21:37 2006
@@ -27,6 +27,7 @@
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.MessagingException;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.bind.JAXBContext;
 import javax.xml.namespace.QName;
 import javax.xml.parsers.DocumentBuilder;
@@ -103,6 +104,13 @@
 			jmsBroker.stop();
 		}
 	}
+    
+    public void testWSDL() throws Exception {
+        ServiceEndpoint[] ses = jbi.getRegistry().getEndpointsForInterface(
+                new QName("http://docs.oasis-open.org/wsn/brw-2", "NotificationBroker"));
+        assertNotNull(ses);
+        assertEquals(1, ses.length);
+    }
 	
 	public void testInvalidSubscribription() throws Exception {
 		try {



Mime
View raw message