servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r468606 - in /incubator/servicemix/trunk/servicemix-ftp/src: main/java/org/apache/servicemix/ftp/ test/java/org/apache/servicemix/ftp/ test/resources/
Date Sat, 28 Oct 2006 01:18:35 GMT
Author: gnodet
Date: Fri Oct 27 18:18:35 2006
New Revision: 468606

URL: http://svn.apache.org/viewvc?view=rev&rev=468606
Log:
Handle URI for FTP endpoints / FTP resolved endpoints

Modified:
    incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpComponent.java
    incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpEndpoint.java
    incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/DynamicEndpointTest.java
    incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/SpringComponentTest.java
    incubator/servicemix/trunk/servicemix-ftp/src/test/resources/spring.xml

Modified: incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpComponent.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpComponent.java?view=diff&rev=468606&r1=468605&r2=468606
==============================================================================
--- incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpComponent.java
(original)
+++ incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpComponent.java
Fri Oct 27 18:18:35 2006
@@ -18,11 +18,14 @@
 
 import java.net.URI;
 import java.util.List;
+import java.util.Map;
 
 import javax.jbi.servicedesc.ServiceEndpoint;
 
 import org.apache.servicemix.common.DefaultComponent;
 import org.apache.servicemix.common.Endpoint;
+import org.apache.servicemix.jbi.util.IntrospectionSupport;
+import org.apache.servicemix.jbi.util.URISupport;
 
 /**
  * An FTP based component
@@ -52,13 +55,11 @@
 
     protected Endpoint getResolvedEPR(ServiceEndpoint ep) throws Exception {
         FtpEndpoint ftpEndpoint = new FtpEndpoint(this, ep);
-
-        // TODO
-        //ftpEp.setRole(MessageExchange.Role.PROVIDER);
-
         URI uri = new URI(ep.getEndpointName());
-
+        Map map = URISupport.parseQuery(uri.getQuery());
+        IntrospectionSupport.setProperties(ftpEndpoint, map);
         ftpEndpoint.setUri(uri);
+        ftpEndpoint.validate();
         ftpEndpoint.activate();
         return ftpEndpoint;
     }

Modified: incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpEndpoint.java?view=diff&rev=468606&r1=468605&r2=468606
==============================================================================
--- incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpEndpoint.java
(original)
+++ incubator/servicemix/trunk/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpEndpoint.java
Fri Oct 27 18:18:35 2006
@@ -22,6 +22,7 @@
 import org.apache.servicemix.components.util.DefaultFileMarshaler;
 import org.apache.servicemix.components.util.FileMarshaler;
 
+import javax.jbi.management.DeploymentException;
 import javax.jbi.messaging.MessageExchange;
 import javax.jbi.messaging.NormalizedMessage;
 import javax.jbi.servicedesc.ServiceEndpoint;
@@ -41,6 +42,7 @@
     private FileMarshaler marshaler = new DefaultFileMarshaler();
     private String uniqueFileName = "ServiceMix";
     private boolean overwrite = false;
+    private URI uri;
 
     public FtpEndpoint() {
     }
@@ -48,12 +50,22 @@
     public FtpEndpoint(FtpComponent component, ServiceEndpoint endpoint) {
         super(component, endpoint);
     }
+    
+    public void validate() throws DeploymentException {
+        super.validate();
+        if (uri == null && (getClientPool() == null || getClientPool().getHost()
== null)) {
+            throw new DeploymentException("Property uri or clientPool.host must be configured");
+        }
+        if (uri != null && getClientPool() != null && getClientPool().getHost()
!= null) {
+            throw new DeploymentException("Properties uri and clientPool.host can not be
configured at the same time");
+        }
+    }
 
     /**
      * Configures the endpoint from a URI
      */
     public void setUri(URI uri) {
-        // TODO
+        this.uri = uri;
     }
 
 
@@ -62,6 +74,17 @@
         if (clientPool == null) {
             clientPool = createClientPool();
         }
+        if (uri != null) {
+            clientPool.setHost(uri.getHost());
+            clientPool.setPort(uri.getPort());
+            if (uri.getUserInfo() != null) {
+                String[] infos = uri.getUserInfo().split(":");
+                clientPool.setUsername(infos[0]);
+                if (infos.length > 1) {
+                    clientPool.setPassword(infos[1]);
+                }
+            }
+        }
     }
 
     // Properties
@@ -111,6 +134,10 @@
         OutputStream out = null;
         try {
             client = (FTPClient) getClientPool().borrowClient();
+            // Change to the directory specified by the URI path if any
+            if (uri != null && uri.getPath() != null) {
+                client.changeWorkingDirectory(uri.getPath());
+            }
 
             String name = marshaler.getOutputName(exchange, message);
             if (name == null) {
@@ -150,9 +177,10 @@
         }
     }
 
-    protected FTPClientPool createClientPool() {
-        FTPClientPool answer = new FTPClientPool();
-        return answer;
+    protected FTPClientPool createClientPool() throws Exception {
+        FTPClientPool pool = new FTPClientPool();
+        pool.afterPropertiesSet();
+        return pool;
     }
 
     protected void returnClient(SocketClient client) {

Modified: incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/DynamicEndpointTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/DynamicEndpointTest.java?view=diff&rev=468606&r1=468605&r2=468606
==============================================================================
--- incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/DynamicEndpointTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/DynamicEndpointTest.java
Fri Oct 27 18:18:35 2006
@@ -16,29 +16,31 @@
  */
 package org.apache.servicemix.ftp;
 
+import javax.jbi.messaging.ExchangeStatus;
+import javax.jbi.messaging.InOnly;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+
 import org.apache.servicemix.client.DefaultServiceMixClient;
 import org.apache.servicemix.client.ServiceMixClient;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.tck.SpringTestSupport;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 
-import javax.jbi.messaging.ExchangeStatus;
-import javax.jbi.messaging.InOnly;
-import javax.jbi.messaging.MessageExchange;
-import javax.jbi.servicedesc.ServiceEndpoint;
-
 public class DynamicEndpointTest extends SpringTestSupport {
 
     public void testSendingToDynamicEndpoint() throws Exception {
         ServiceMixClient client = new DefaultServiceMixClient(jbi);
 
-        ServiceEndpoint se = client.resolveEndpointReference("ftp://host/path");
+        ServiceEndpoint se = client.resolveEndpointReference("ftp://servicemix:rocks@localhost/smx/test");
         assertNotNull("We should find a service endpoint!", se);
 
         InOnly exchange = client.createInOnlyExchange();
         exchange.setEndpoint(se);
+        exchange.getInMessage().setProperty(DefaultFileMarshaler.FILE_NAME_PROPERTY, "test.xml");
         exchange.getInMessage().setContent(new StringSource("<hello>world</hello>"));
         client.sendSync(exchange);
 

Modified: incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/SpringComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/SpringComponentTest.java?view=diff&rev=468606&r1=468605&r2=468606
==============================================================================
--- incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/SpringComponentTest.java
(original)
+++ incubator/servicemix/trunk/servicemix-ftp/src/test/java/org/apache/servicemix/ftp/SpringComponentTest.java
Fri Oct 27 18:18:35 2006
@@ -18,6 +18,7 @@
 
 import org.apache.servicemix.tck.SpringTestSupport;
 import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.components.util.DefaultFileMarshaler;
 import org.apache.servicemix.jbi.jaxp.StringSource;
 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
@@ -37,7 +38,7 @@
         me.setService(new QName("urn:test", "service"));
         NormalizedMessage message = me.getInMessage();
 
-        message.setProperty("name", "cheese");
+        message.setProperty(DefaultFileMarshaler.FILE_NAME_PROPERTY, "test2.xml");
         message.setContent(new StringSource("<hello>world</hello>"));
 
         client.sendSync(me);

Modified: incubator/servicemix/trunk/servicemix-ftp/src/test/resources/spring.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-ftp/src/test/resources/spring.xml?view=diff&rev=468606&r1=468605&r2=468606
==============================================================================
--- incubator/servicemix/trunk/servicemix-ftp/src/test/resources/spring.xml (original)
+++ incubator/servicemix/trunk/servicemix-ftp/src/test/resources/spring.xml Fri Oct 27 18:18:35
2006
@@ -29,7 +29,7 @@
       	<sm:component>
             <ftp:component>
             	<ftp:endpoints>
-            		<ftp:endpoint service="test:service" endpoint="endpoint" uri="ftp://host/foo/bar"/>
+            		<ftp:endpoint service="test:service" endpoint="endpoint" uri="ftp://servicemix:rocks@localhost/smx/test"/>
             	</ftp:endpoints>
             </ftp:component>
         </sm:component>



Mime
View raw message