oodt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfos...@apache.org
Subject svn commit: r1128538 - in /oodt/branches/protocol: protocol-http/ protocol-sftp/ protocol-sftp/src/ protocol-sftp/src/main/ protocol-sftp/src/main/java/ protocol-sftp/src/main/java/org/ protocol-sftp/src/main/java/org/apache/ protocol-sftp/src/main/jav...
Date Sat, 28 May 2011 00:09:19 GMT
Author: bfoster
Date: Sat May 28 00:09:19 2011
New Revision: 1128538

URL: http://svn.apache.org/viewvc?rev=1128538&view=rev
Log:

- initial SFTP Protocol

---------------
OODT-194

Added:
    oodt/branches/protocol/protocol-sftp/
    oodt/branches/protocol/protocol-sftp/pom.xml   (with props)
    oodt/branches/protocol/protocol-sftp/src/
    oodt/branches/protocol/protocol-sftp/src/main/
    oodt/branches/protocol/protocol-sftp/src/main/java/
    oodt/branches/protocol/protocol-sftp/src/main/java/org/
    oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/
    oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/
    oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/
    oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/
    oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/
    oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClient.java
  (with props)
    oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClientFactory.java
  (with props)
    oodt/branches/protocol/protocol-sftp/src/main/test/
Modified:
    oodt/branches/protocol/protocol-http/pom.xml

Modified: oodt/branches/protocol/protocol-http/pom.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-http/pom.xml?rev=1128538&r1=1128537&r2=1128538&view=diff
==============================================================================
--- oodt/branches/protocol/protocol-http/pom.xml (original)
+++ oodt/branches/protocol/protocol-http/pom.xml Sat May 28 00:09:19 2011
@@ -84,6 +84,11 @@
 			<version>3.0</version>
 		</dependency>
 		<dependency>
+			<groupId>nekohtml</groupId>
+			<artifactId>nekohtml</artifactId>
+			<version>1.9.6.2</version>
+		</dependency>
+		<dependency>
 			<groupId>org.apache.tika</groupId>
 			<artifactId>tika-core</artifactId>
 			<version>0.8</version>

Added: oodt/branches/protocol/protocol-sftp/pom.xml
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/pom.xml?rev=1128538&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-sftp/pom.xml (added)
+++ oodt/branches/protocol/protocol-sftp/pom.xml Sat May 28 00:09:19 2011
@@ -0,0 +1,93 @@
+<?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. -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+	<modelVersion>4.0.0</modelVersion>
+	<parent>
+		<groupId>org.apache.oodt</groupId>
+		<artifactId>oodt-core</artifactId>
+		<version>0.3-SNAPSHOT</version>
+		<relativePath>../core/pom.xml</relativePath>
+	</parent>
+	<artifactId>cas-protocol-sftp</artifactId>
+	<name>CAS Protocol IMAPS Implementation</name>
+	<profiles>
+		<profile>
+			<id>audit</id>
+			<activation>
+				<activeByDefault>false</activeByDefault>
+			</activation>
+			<build>
+				<plugins>
+					<plugin>
+						<groupId>org.codehaus.mojo</groupId>
+						<artifactId>rat-maven-plugin</artifactId>
+						<configuration>
+							<excludes>
+								<exclude>**/resources/examples/**/*</exclude>
+							</excludes>
+						</configuration>
+						<executions>
+							<execution>
+								<phase>verify</phase>
+								<goals>
+									<goal>check</goal>
+								</goals>
+							</execution>
+						</executions>
+					</plugin>
+				</plugins>
+			</build>
+		</profile>
+	</profiles>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-assembly-plugin</artifactId>
+				<version>2.2-beta-2</version>
+				<configuration>
+					<descriptors>
+						<descriptor>src/main/assembly/assembly.xml</descriptor>
+					</descriptors>
+				</configuration>
+				<executions>
+					<execution>
+						<phase>package</phase>
+						<goals>
+							<goal>single</goal>
+						</goals>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+	<dependencies>
+		<dependency>
+			<groupId>org.apache.oodt</groupId>
+			<artifactId>cas-protocol-api</artifactId>
+			<version>${project.parent.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>com.jcraft</groupId>
+			<artifactId>jsch</artifactId>
+			<version>0.1.42</version>
+		</dependency>
+		<dependency>
+			<groupId>junit</groupId>
+			<artifactId>junit</artifactId>
+			<version>3.8.2</version>
+			<scope>test</scope>
+		</dependency>
+	</dependencies>
+</project>

Propchange: oodt/branches/protocol/protocol-sftp/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClient.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClient.java?rev=1128538&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClient.java
(added)
+++ oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClient.java
Sat May 28 00:09:19 2011
@@ -0,0 +1,172 @@
+/**
+ * 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.oodt.cas.pushpull.protocol.sftp;
+
+//OODT imports
+import org.apache.oodt.cas.pushpull.exceptions.ProtocolException;
+import org.apache.oodt.cas.pushpull.protocol.Protocol;
+import org.apache.oodt.cas.pushpull.protocol.ProtocolFile;
+import org.apache.oodt.cas.pushpull.protocol.ProtocolPath;
+
+//JSCH imports
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.SftpProgressMonitor;
+
+//JDK imports
+import java.io.File;
+import java.util.List;
+import java.util.Vector;
+
+/**
+ * 
+ * An implement of an SFTP provider based on <a
+ * href="http://www.jcraft.org">Jcraft's</a> <a
+ * href="http://www.jcraft.org/jsch/">JSCH</a> library.
+ * 
+ * @author bfoster
+ * @version $Revision$
+ */
+public class JschSftpClient extends Protocol {
+
+  private Session session;
+
+  private ChannelSftp sftpChannel;
+
+  private static final JSch jsch = new JSch();
+
+  private String host;
+
+  private boolean abort;
+
+  public JschSftpClient() {
+    super("sftp");
+    session = null;
+    sftpChannel = null;
+    host = null;
+  }
+
+  protected void chDir(ProtocolPath path) throws ProtocolException {
+    try {
+      sftpChannel.cd(path.getPathString());
+    } catch (Exception e) {
+      throw new ProtocolException("Failed to cd to " + path + " : "
+          + e.getMessage());
+    }
+  }
+
+  public void cdToRoot() throws ProtocolException {
+    try {
+      chDir(new ProtocolPath("/", true));
+    } catch (Exception e) {
+      throw new ProtocolException("Failed to cd to root : " + e.getMessage());
+    }
+  }
+
+  protected void connect(String host, final String username,
+      final String password) throws ProtocolException {
+    try {
+      System.out.println(System.getProperty("user.home") + "/.ssh/known_hosts");
+      jsch.setKnownHosts(System.getProperty("user.home") + "/.ssh/known_hosts");
+      session = jsch.getSession(username, this.getRemoteSite().getURL()
+          .getHost(), 22);
+      session.setPassword(password);
+      session.connect();
+      sftpChannel = (ChannelSftp) session.openChannel("sftp");
+      sftpChannel.connect();
+    } catch (Exception e) {
+      throw new ProtocolException("Failed to connect to host " + host + " : "
+          + e.getMessage());
+    }
+  }
+
+  public void disconnectFromServer() throws ProtocolException {
+    session.disconnect();
+  }
+
+  public void getFile(ProtocolFile file, File toLocalFile)
+      throws ProtocolException {
+    try {
+      this.abort = false;
+      SftpProgressMonitor monitor = new SftpProgressMonitor() {
+        public boolean count(long arg0) {
+          return JschSftpClient.this.abort;
+        }
+
+        public void end() {
+
+        }
+
+        public void init(int arg0, String arg1, String arg2, long arg3) {
+
+        }
+      };
+      sftpChannel.get(file.getProtocolPath().getPathString(), toLocalFile
+          .getAbsolutePath());
+    } catch (Exception e) {
+      throw new ProtocolException("Failed to download " + file + " : "
+          + e.getMessage());
+    }
+  }
+
+  public void abortCurFileTransfer() {
+    this.abort = true;
+  }
+
+  public List<ProtocolFile> listFiles() throws ProtocolException {
+    try {
+      Vector<ChannelSftp.LsEntry> sftpFiles = (Vector<ChannelSftp.LsEntry>) sftpChannel
+          .ls(sftpChannel.pwd());
+      Vector<ProtocolFile> returnFiles = new Vector<ProtocolFile>();
+      for (ChannelSftp.LsEntry sftpFile : sftpFiles) {
+        String path = this.pwd().getProtocolPath().getPathString();
+        returnFiles.add(new ProtocolFile(this.getRemoteSite(),
+            new ProtocolPath(path + "/" + sftpFile.getFilename(), sftpFile
+                .getAttrs().isDir())));
+      }
+      return returnFiles;
+    } catch (Exception e) {
+      throw new ProtocolException("Failed to get file list : " + e.getMessage());
+    }
+  }
+
+  public ProtocolFile getCurrentWorkingDir() throws ProtocolException {
+    try {
+      return new ProtocolFile(this.getRemoteSite(), new ProtocolPath(
+          sftpChannel.pwd(), true));
+    } catch (Exception e) {
+      throw new ProtocolException("Failed to pwd : " + e.getMessage());
+    }
+  }
+
+  public boolean isConnected() throws ProtocolException {
+    return session.isConnected();
+  }
+
+  @Override
+  protected boolean deleteFile(ProtocolFile file) {
+    try {
+      sftpChannel.rm(file.getProtocolPath().getPathString());
+      return true;
+    } catch (Exception e) {
+      return false;
+    }
+  }
+
+}

Propchange: oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClientFactory.java
URL: http://svn.apache.org/viewvc/oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClientFactory.java?rev=1128538&view=auto
==============================================================================
--- oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClientFactory.java
(added)
+++ oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClientFactory.java
Sat May 28 00:09:19 2011
@@ -0,0 +1,44 @@
+/**
+ * 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.oodt.cas.pushpull.protocol.sftp;
+
+//OODT imports
+import org.apache.oodt.cas.pushpull.protocol.Protocol;
+import org.apache.oodt.cas.pushpull.protocol.ProtocolFactory;
+
+/**
+ * 
+ * Creates new {@link JschSftpClient}s.
+ * 
+ * @author bfoster
+ * @author mattmann
+ * @version $Revision$
+ * 
+ */
+public class JschSftpClientFactory implements ProtocolFactory {
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.oodt.cas.pushpull.protocol.ProtocolFactory#newInstance()
+   */
+  public Protocol newInstance() {
+    return new JschSftpClient();
+  }
+
+}

Propchange: oodt/branches/protocol/protocol-sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpClientFactory.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message