You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by js...@apache.org on 2006/10/03 14:10:30 UTC

svn commit: r452450 - in /incubator/servicemix/trunk/servicemix-file/src: main/java/org/apache/servicemix/file/ test/java/org/apache/servicemix/file/ test/resources/

Author: jstrachan
Date: Tue Oct  3 05:10:29 2006
New Revision: 452450

URL: http://svn.apache.org/viewvc?view=rev&rev=452450
Log:
added support for dynamic endpoint resolution for the file component using a file URL

Added:
    incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java   (with props)
    incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml   (with props)
Modified:
    incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileComponent.java
    incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileEndpoint.java
    incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/SpringComponentTest.java

Modified: incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileComponent.java?view=diff&rev=452450&r1=452449&r2=452450
==============================================================================
--- incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileComponent.java (original)
+++ incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileComponent.java Tue Oct  3 05:10:29 2006
@@ -16,16 +16,66 @@
  */
 package org.apache.servicemix.file;
 
+import org.apache.activemq.util.IntrospectionSupport;
+import org.apache.activemq.util.URISupport;
 import org.apache.servicemix.common.DefaultComponent;
+import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.common.ResolvedEndpoint;
+import org.w3c.dom.DocumentFragment;
+
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+import java.io.File;
 
 /**
  * @org.apache.xbean.XBean element="component"
- *                  description="File Component"
+ * description="File Component"
  */
 public class FileComponent extends DefaultComponent {
 
+    public final static String EPR_URI = "urn:servicemix:file";
+    public final static QName EPR_SERVICE = new QName(EPR_URI, "FileComponent");
+    public final static String EPR_NAME = "epr";
+
+
     protected Class[] getEndpointClasses() {
-        return new Class[] { FileEndpoint.class };
+        return new Class[]{FileEndpoint.class};
+    }
+
+    public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
+        return ResolvedEndpoint.resolveEndpoint(epr, EPR_URI, EPR_NAME, EPR_SERVICE, "file:");
+    }
+
+    protected QName getEPRServiceName() {
+        return EPR_SERVICE;
+    }
+
+    protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception {
+        // We receive an exchange for an EPR that has not been used yet.
+        // Register a provider endpoint and restart processing.
+        FileEndpoint fileEp = new FileEndpoint(this, ep);
+
+        // TODO
+        //fileEp.setRole(MessageExchange.Role.PROVIDER);
+
+        // lets use a URL to parse the path
+        URL url = new URL(ep.getEndpointName());
+
+        Map map = URISupport.parseQuery(url.getQuery());
+        IntrospectionSupport.setProperties(fileEp, map, "file.");
+
+        String path = url.getPath();
+        if (path != null) {
+            fileEp.setDirectory(new File(path));
+        }
+        else {
+            throw new IllegalArgumentException("No path defined for URL: " + url);
+        }
+        fileEp.activate();
+        return fileEp;
     }
 
 }

Modified: incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileEndpoint.java?view=diff&rev=452450&r1=452449&r2=452450
==============================================================================
--- incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-file/src/main/java/org/apache/servicemix/file/FileEndpoint.java Tue Oct  3 05:10:29 2006
@@ -23,6 +23,7 @@
 import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.servicedesc.ServiceEndpoint;
 import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
@@ -42,6 +43,13 @@
     private String tempFileSuffix = ".xml";
     private boolean autoCreateDirectory = true;
 
+
+    public FileEndpoint() {
+    }
+
+    public FileEndpoint(FileComponent component, ServiceEndpoint endpoint) {
+        super(component, endpoint);
+    }
 
     public void validate() throws DeploymentException {
         super.validate();

Added: incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java?view=auto&rev=452450
==============================================================================
--- incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java (added)
+++ incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java Tue Oct  3 05:10:29 2006
@@ -0,0 +1,79 @@
+/**
+ *
+ * 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.file;
+
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.resolver.URIResolver;
+import org.apache.servicemix.tck.SpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.DocumentFragment;
+
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import java.net.URL;
+
+public class DynamicEndpointtTest extends SpringTestSupport {
+    protected String dynamicURI = "file:target/dynamicEndpoint?file.tempFilePrefix=dynamicEp-";
+
+
+    public void testSendingToDynamicEndpoint() throws Exception {
+        // lets check the path is parsable first
+        URL url = new URL(dynamicURI);
+        String path = url.getPath();
+        assertEquals("target/dynamicEndpoint", path);
+
+
+        // now lets make a request on this endpoint
+        DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+
+        DocumentFragment epr = URIResolver.createWSAEPR(dynamicURI);
+        ServiceEndpoint se = client.getContext().resolveEndpointReference(epr);
+        assertNotNull("We should find a service endpoint!", se);
+
+        InOnly exchange = client.createInOnlyExchange();
+        exchange.setEndpoint(se);
+        exchange.getInMessage().setContent(new StringSource("<hello>world</hello>"));
+        client.sendSync(exchange);
+
+        assertExchangeWorked(exchange);
+    }
+
+    protected void assertExchangeWorked(MessageExchange me) throws Exception {
+        if (me.getStatus() == ExchangeStatus.ERROR) {
+            if (me.getError() != null) {
+                throw me.getError();
+            }
+            else {
+                fail("Received ERROR status");
+            }
+        }
+        else if (me.getFault() != null) {
+            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+        }
+    }
+
+    protected AbstractXmlApplicationContext createBeanFactory() {
+        return new ClassPathXmlApplicationContext("spring-no-endpoints.xml");
+    }
+
+}

Propchange: incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/DynamicEndpointtTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/SpringComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/SpringComponentTest.java?view=diff&rev=452450&r1=452449&r2=452450
==============================================================================
--- incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/SpringComponentTest.java (original)
+++ incubator/servicemix/trunk/servicemix-file/src/test/java/org/apache/servicemix/file/SpringComponentTest.java Tue Oct  3 05:10:29 2006
@@ -20,26 +20,36 @@
 import javax.jbi.messaging.InOut;
 import javax.jbi.messaging.InOnly;
 import javax.jbi.messaging.NormalizedMessage;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
 import javax.xml.namespace.QName;
 
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.apache.servicemix.jbi.resolver.URIResolver;
 import org.apache.servicemix.tck.SpringTestSupport;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.w3c.dom.DocumentFragment;
 
 public class SpringComponentTest extends SpringTestSupport {
 
-    public void test() throws Exception {
+    public void testSendingToStaticEndpoint() throws Exception {
         DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
         InOnly me = client.createInOnlyExchange();
         me.setService(new QName("urn:test", "service"));
         NormalizedMessage message = me.getInMessage();
+
         message.setProperty("name", "cheese");
         message.setContent(new StringSource("<hello>world</hello>"));
 
         client.sendSync(me);
+        assertExchangeWorked(me);
+    }
+
+
+    protected void assertExchangeWorked(MessageExchange me) throws Exception {
         if (me.getStatus() == ExchangeStatus.ERROR) {
             if (me.getError() != null) {
                 throw me.getError();
@@ -50,7 +60,7 @@
             fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
         }
     }
-    
+
     protected AbstractXmlApplicationContext createBeanFactory() {
         return new ClassPathXmlApplicationContext("spring.xml");
     }

Added: incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml?view=auto&rev=452450
==============================================================================
--- incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml (added)
+++ incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml Tue Oct  3 05:10:29 2006
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns:sm="http://servicemix.apache.org/config/1.0" 
+	     xmlns:file="http://servicemix.apache.org/file/1.0"
+       xmlns:test="urn:test">
+
+  <sm:container id="jbi" embedded="true" createMBeanServer="false">
+    
+    <sm:activationSpecs>
+
+      <sm:activationSpec>
+      	<sm:component>
+            <file:component/>
+        </sm:component>
+      </sm:activationSpec>
+
+    </sm:activationSpecs>
+  </sm:container>
+
+</beans>

Propchange: incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: incubator/servicemix/trunk/servicemix-file/src/test/resources/spring-no-endpoints.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml