You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ge...@apache.org on 2011/03/21 19:56:30 UTC

svn commit: r1083900 - in /servicemix/smx4/nmr/trunk: ./ jbi/runtime/ jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/ jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/ nmr/api/src/main/java/org/apache/servicemix/nmr/api/ser...

Author: gertv
Date: Mon Mar 21 18:56:30 2011
New Revision: 1083900

URL: http://svn.apache.org/viewvc?rev=1083900&view=rev
Log:
SMX4NMR-260: JBI's ComponentContext.resolveEndpointReference does not work with ServiceMix 4

Added:
    servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/EndpointReferenceTest.java
Modified:
    servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
    servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java
    servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/service/ServiceHelper.java
    servicemix/smx4/nmr/trunk/pom.xml

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml?rev=1083900&r1=1083899&r2=1083900&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/pom.xml Mon Mar 21 18:56:30 2011
@@ -57,10 +57,20 @@
         </dependency>
         <dependency>
             <groupId>org.apache.servicemix</groupId>
+            <artifactId>servicemix-bean</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix</groupId>
             <artifactId>servicemix-eip</artifactId>
             <scope>test</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.servicemix</groupId>
+            <artifactId>servicemix-file</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
             <scope>provided</scope>

Modified: servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java?rev=1083900&r1=1083899&r2=1083900&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/main/java/org/apache/servicemix/jbi/runtime/impl/AbstractComponentContext.java Mon Mar 21 18:56:30 2011
@@ -36,6 +36,7 @@ import javax.management.ObjectName;
 import javax.naming.InitialContext;
 import javax.xml.namespace.QName;
 
+import org.apache.servicemix.jbi.runtime.ComponentRegistry;
 import org.apache.servicemix.jbi.runtime.ComponentWrapper;
 import org.apache.servicemix.jbi.runtime.impl.utils.DOMUtil;
 import org.apache.servicemix.jbi.runtime.impl.utils.URIResolver;
@@ -43,6 +44,7 @@ import org.apache.servicemix.jbi.runtime
 import org.apache.servicemix.nmr.api.Endpoint;
 import org.apache.servicemix.nmr.api.NMR;
 import org.apache.servicemix.nmr.api.internal.InternalEndpoint;
+import org.apache.servicemix.nmr.api.service.ServiceHelper;
 import org.apache.servicemix.nmr.management.Nameable;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Document;
@@ -281,6 +283,15 @@ public abstract class AbstractComponentC
         for (ComponentWrapper component : componentRegistry.getServices()) {
             ServiceEndpoint se = component.getComponent().resolveEndpointReference(epr);
             if (se != null) {
+                Map<String, ?> target = componentRegistry.getProperties(component);
+                componentRegistry.getNmr().getWireRegistry().register(
+                    ServiceHelper.createWire(
+                            ServiceHelper.createMap(Endpoint.ENDPOINT_NAME, se.getEndpointName(),
+                                                    Endpoint.SERVICE_NAME, se.getServiceName().toString()),
+                            ServiceHelper.createMap(ComponentRegistry.NAME, target.get(ComponentRegistry.NAME).toString(),
+                                                    ComponentRegistry.TYPE, target.get(ComponentRegistry.TYPE).toString())
+                    )
+                );
                 return se;
             }
         }

Added: servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/EndpointReferenceTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/EndpointReferenceTest.java?rev=1083900&view=auto
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/EndpointReferenceTest.java (added)
+++ servicemix/smx4/nmr/trunk/jbi/runtime/src/test/java/org/apache/servicemix/jbi/runtime/EndpointReferenceTest.java Mon Mar 21 18:56:30 2011
@@ -0,0 +1,131 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.jbi.runtime;
+
+import junit.framework.TestCase;
+import org.apache.servicemix.bean.BeanComponent;
+import org.apache.servicemix.bean.BeanEndpoint;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
+import org.apache.servicemix.file.FileComponent;
+import org.apache.servicemix.jbi.listener.MessageExchangeListener;
+import org.apache.servicemix.jbi.runtime.impl.ComponentRegistryImpl;
+import org.apache.servicemix.nmr.api.service.ServiceHelper;
+import org.apache.servicemix.nmr.core.ServiceMix;
+import org.apache.servicemix.nmr.core.util.StringSource;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+
+import javax.annotation.Resource;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.*;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import java.io.File;
+import java.util.UUID;
+
+/**
+ * Test case to ensure sending to endpoint resolved by
+ * {@link ComponentContext#resolveEndpointReference(org.w3c.dom.DocumentFragment)} works
+ */
+public class EndpointReferenceTest extends TestCase {
+
+    private static final File DIRECTORY = new File("target");
+
+    private static final QName SENDER = new QName("urn:test", "sender");
+    private static final String ENDPOINT = "endpoint";
+
+    public void testSendToEPR() throws Exception {
+        ServiceMix smx = new ServiceMix();
+        smx.init();
+
+        ComponentRegistryImpl reg = new ComponentRegistryImpl();
+        reg.setNmr(smx);
+
+        BeanComponent bean = new BeanComponent();
+        SenderBean sender = new SenderBean();
+        BeanEndpoint endpoint = new BeanEndpoint();
+        endpoint.setService(SENDER);
+        endpoint.setEndpoint(ENDPOINT);
+        endpoint.setBean(sender);
+        bean.addEndpoint(endpoint);
+        reg.register(new SimpleComponentWrapper(bean),
+                ServiceHelper.createMap(ComponentRegistry.NAME, "servicemix-bean",
+                                        ComponentRegistry.TYPE, "service-engine"));
+        bean.getLifeCycle().start();
+
+        FileComponent file = new FileComponent();
+        reg.register(new SimpleComponentWrapper(file),
+                ServiceHelper.createMap(ComponentRegistry.NAME, "servicemix-file",
+                                        ComponentRegistry.TYPE, "binding-component"));
+        file.getLifeCycle().start();
+
+        String filename = UUID.randomUUID().toString();
+        MessageExchange exchange = sender.send(filename);
+        assertEquals("MessageExchange should have finished successfully",
+                     ExchangeStatus.DONE, exchange.getStatus());
+        assertTrue("File should have been created",
+                   new File(DIRECTORY, filename).exists());
+
+    }
+
+    /*
+     * Bean to allow testing with servicemix-bean
+     */
+    private static final class SenderBean implements MessageExchangeListener {
+
+        @Resource
+        private DeliveryChannel channel;
+
+        @Resource
+        private ComponentContext context;
+
+        public MessageExchange send(String filename) throws Exception {
+            ServiceEndpoint endpoint = context.resolveEndpointReference(createEndpointReference(DIRECTORY.toURI().toString()));
+
+            MessageExchange exchange = channel.createExchangeFactory().createInOnlyExchange();
+            exchange.setEndpoint(endpoint);
+
+            NormalizedMessage in = exchange.createMessage();
+            in.setContent(new StringSource("<hello/>"));
+            in.setProperty(DefaultFileMarshaler.FILE_NAME_PROPERTY, filename);
+            exchange.setMessage(in,  "in");
+
+            channel.sendSync(exchange);
+
+            return exchange;
+        }
+
+        public void onMessageExchange(MessageExchange messageExchange) throws MessagingException {
+            // ignore this -- we're only sending InOnly so nothing to do here
+        }
+
+        private DocumentFragment createEndpointReference(String uri) throws ParserConfigurationException {
+            Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+            DocumentFragment result = document.createDocumentFragment();
+            Element reference = document.createElementNS("http://www.w3.org/2005/08/addressing", "EndpointReference");
+            Element address = document.createElementNS("http://www.w3.org/2005/08/addressing", "Address");
+            address.setTextContent(uri);
+            reference.appendChild(address);
+            result.appendChild(reference);
+            return result;
+        }
+    }
+
+}

Modified: servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/service/ServiceHelper.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/service/ServiceHelper.java?rev=1083900&r1=1083899&r2=1083900&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/service/ServiceHelper.java (original)
+++ servicemix/smx4/nmr/trunk/nmr/api/src/main/java/org/apache/servicemix/nmr/api/service/ServiceHelper.java Mon Mar 21 18:56:30 2011
@@ -92,7 +92,7 @@ public final class ServiceHelper {
      * @param to the target for the wire
      * @return the wire object
      */
-    public static Wire createWire(final Map<String, ?> from, final Map<String, Object> to) {
+    public static Wire createWire(final Map<String, ?> from, final Map<String, ?> to) {
         return new Wire() {
             public Map<String, ?> getFrom() {
                 return from;

Modified: servicemix/smx4/nmr/trunk/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/pom.xml?rev=1083900&r1=1083899&r2=1083900&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/pom.xml (original)
+++ servicemix/smx4/nmr/trunk/pom.xml Mon Mar 21 18:56:30 2011
@@ -292,6 +292,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.servicemix</groupId>
+            <artifactId>servicemix-bean</artifactId>
+            <version>${servicemix.components.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix</groupId>
             <artifactId>servicemix-eip</artifactId>
             <version>${servicemix-eip.version}</version>
         </dependency>
@@ -311,6 +316,11 @@
         </dependency>
         <dependency>
             <groupId>org.apache.servicemix</groupId>
+            <artifactId>servicemix-file</artifactId>
+            <version>${servicemix.components.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.servicemix</groupId>
             <artifactId>servicemix-jsr181</artifactId>
             <version>${servicemix-jsr181.version}</version>
             <type>zip</type>
@@ -374,7 +384,7 @@
             <artifactId>camel-core</artifactId>
             <version>${camel.version}</version>
         </dependency>
-        
+
         <!-- Geronimo -->
         <dependency>
             <groupId>org.apache.geronimo.specs</groupId>