You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sm...@apache.org on 2012/11/11 15:54:30 UTC

svn commit: r1408020 - in /airavata/sandbox/grid-tools/gridftp-client: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/airavata/ src/main/java/org/apache/airavata/filetransfer/ src/main/java/org/ap...

Author: smarru
Date: Sun Nov 11 14:54:26 2012
New Revision: 1408020

URL: http://svn.apache.org/viewvc?rev=1408020&view=rev
Log:
adding gridftp client test case to address AIRAVATA-639

Added:
    airavata/sandbox/grid-tools/gridftp-client/README
    airavata/sandbox/grid-tools/gridftp-client/pom.xml
    airavata/sandbox/grid-tools/gridftp-client/src/
    airavata/sandbox/grid-tools/gridftp-client/src/main/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/ExectionContext.java
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/FileTransfer.java
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/CertificateManager.java   (with props)
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/MyProxyCredentials.java
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/SecurityContext.java
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFTPContactInfo.java
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFtp.java
    airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/ServiceConstants.java
    airavata/sandbox/grid-tools/gridftp-client/src/main/resources/
    airavata/sandbox/grid-tools/gridftp-client/src/main/resources/airavata-gridftp-client.properties
    airavata/sandbox/grid-tools/gridftp-client/test-file-transfer.sh   (with props)

Added: airavata/sandbox/grid-tools/gridftp-client/README
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/README?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/README (added)
+++ airavata/sandbox/grid-tools/gridftp-client/README Sun Nov 11 14:54:26 2012
@@ -0,0 +1,19 @@
+Apache Airavata GRAM Client - README
+Licensed under Apache License 2.0 - http://www.apache.org/licenses/LICENSE-2.0
+--------------------------------------------------------------------------------
+
+About
+=====
+Apache Airavata, a software framework to executing and managing computational jobs on 
+distributed computing resources including local clusters, supercomputers, national grids, 
+academic and commercial clouds. 
+
+The airavata-gridftp-client is a test suite to run stand alone transfers between two GridFTP end points. 
+
+
+CA Trusted Certificates
+===========================
+* The XSEDE project maintains a repo of International Grid Certificate Authorities
+* The certificate tar file can be downloaded from https://software.xsede.org/security/xsede-certs.tar.gz
+* Once the certificates are downloaded locally, the airavata-gram-client.properties has to be configured. 
+

Added: airavata/sandbox/grid-tools/gridftp-client/pom.xml
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/pom.xml?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/pom.xml (added)
+++ airavata/sandbox/grid-tools/gridftp-client/pom.xml Sun Nov 11 14:54:26 2012
@@ -0,0 +1,122 @@
+<?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">
+	<!-- the version of maven's project object model -->
+
+	<modelVersion>4.0.0</modelVersion>
+	<groupId>org.apache.airavata</groupId>
+	<artifactId>airavata-gridftp-client</artifactId>
+	<name>Airavata GridFTP Client</name>
+	<description>Standalone test client to experiment and test GridFTP .</description>
+	<version>0.1-SNAPSHOT</version>
+	<packaging>jar</packaging>
+
+	<repositories>
+		<repository>
+			<name>ogce.m2.all</name>
+			<id>ogce.m2.all</id>
+			<url>http://community.ucs.indiana.edu:9090/archiva/repository/ogce.m2.all</url>
+		</repository>
+	</repositories>
+
+
+	<dependencies>
+
+		<dependency>
+			<groupId>cog-jglobus</groupId>
+			<artifactId>cog-jglobus</artifactId>
+			<version>1.8.0_1</version>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>puretls</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>cryptix32</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>jce-jdk13</artifactId>
+			<version>131</version>
+			<type>jar</type>
+		</dependency>
+
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>cryptix-asn1</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+		<dependency>
+			<groupId>cog-4_1_6_rc2</groupId>
+			<artifactId>commons-digester</artifactId>
+			<type>jar</type>
+			<version>cog-4_1_6</version>
+		</dependency>
+
+		<dependency>
+			<groupId>commons-logging</groupId>
+			<artifactId>commons-logging</artifactId>
+			<version>1.0.4</version>
+		</dependency>
+		<dependency>
+			<groupId>log4j</groupId>
+			<artifactId>log4j</artifactId>
+			<version>1.2.13</version>
+		</dependency>
+
+
+	</dependencies>
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.5</source>
+					<target>1.5</target>
+				</configuration>
+			</plugin>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-dependency-plugin</artifactId>
+				<executions>
+					<execution>
+						<id>copy-dependencies</id>
+						<phase>package</phase>
+						<goals>
+							<goal>copy-dependencies</goal>
+						</goals>
+						<configuration>
+							<outputDirectory>target/lib</outputDirectory>
+							<overWriteReleases>false</overWriteReleases>
+							<overWriteSnapshots>true</overWriteSnapshots>
+						</configuration>
+					</execution>
+				</executions>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>
+

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/ExectionContext.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/ExectionContext.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/ExectionContext.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/ExectionContext.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,162 @@
+/*
+ *
+ * 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.airavata.filetransfer;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.apache.airavata.filetransfer.utils.ServiceConstants;
+
+public class ExectionContext {
+
+    private String testingHost;
+    
+    private String lonestarGridFTP;
+    private String rangerGridFTP;
+    private String trestlesGridFTP;
+    
+    private String gridFTPServerSource;
+    private String sourcedataLocation;
+    private String gridFTPServerDest;
+    private String destdataLocation;
+
+    public static final String PROPERTY_FILE = "airavata-gridftp-client.properties";
+
+    public ExectionContext() throws IOException {
+        loadConfigration();
+    }
+
+    private void loadConfigration() throws IOException {
+        ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+        InputStream propertyStream = classLoader.getResourceAsStream(PROPERTY_FILE);
+
+        Properties properties = new Properties();
+        if (propertyStream != null) {
+            properties.load(propertyStream);
+            
+            String testinghost = properties.getProperty(ServiceConstants.TESTINGHOST);
+            
+            String lonestargridftp = properties.getProperty(ServiceConstants.LONESTARGRIDFTPEPR);
+            String rangergridftp = properties.getProperty(ServiceConstants.RANGERGRIDFTPEPR);
+            String trestlesgridftp = properties.getProperty(ServiceConstants.TRESTLESGRIDFTPEPR);
+
+            String gridFTPServerSource = properties.getProperty(ServiceConstants.GRIDFTPSERVERSOURCE);
+            String gridFTPSourcePath = properties.getProperty(ServiceConstants.GRIDFTPSOURCEPATH);
+            String gridFTPServerDest = properties.getProperty(ServiceConstants.GRIDFTPSERVERDEST);
+            String gridFTPDestPath = properties.getProperty(ServiceConstants.GRIDFTPDESTPATH);
+
+            if (testinghost != null) {
+                this.testingHost = testinghost;
+            }
+            
+            if (lonestargridftp != null) {
+                this.lonestarGridFTP = lonestargridftp;
+            }
+            if (rangergridftp != null) {
+                this.rangerGridFTP= rangergridftp;
+            }
+            if (trestlesgridftp != null) {
+                this.trestlesGridFTP = trestlesgridftp;
+            }
+            
+            if (gridFTPServerSource != null && !gridFTPServerSource.isEmpty()) {
+                this.gridFTPServerSource = gridFTPServerSource;
+            }
+            if (gridFTPSourcePath != null && !gridFTPSourcePath.isEmpty()) {
+                this.sourcedataLocation = gridFTPSourcePath;
+            }
+            if (gridFTPServerDest != null && !gridFTPServerDest.isEmpty()) {
+                this.gridFTPServerDest = gridFTPServerDest;
+            }
+            if (gridFTPDestPath != null && !gridFTPDestPath.isEmpty()) {
+                this.destdataLocation = gridFTPDestPath;
+            }
+
+        }
+    }
+
+    public String getTestingHost() {
+        return testingHost;
+    }
+
+    public void setTestingHost(String testingHost) {
+        this.testingHost = testingHost;
+    }
+
+    public String getLonestarGridFTP() {
+        return lonestarGridFTP;
+    }
+
+    public void setLonestarGridFTP(String lonestarGridFTP) {
+        this.lonestarGridFTP = lonestarGridFTP;
+    }
+
+    public String getRangerGridFTP() {
+        return rangerGridFTP;
+    }
+
+    public void setRangerGridFTP(String rangerGridFTP) {
+        this.rangerGridFTP = rangerGridFTP;
+    }
+
+    public String getTrestlesGridFTP() {
+        return trestlesGridFTP;
+    }
+
+    public void setTrestlesGridFTP(String trestlesGridFTP) {
+        this.trestlesGridFTP = trestlesGridFTP;
+    }
+
+    public String getGridFTPServerSource() {
+        return gridFTPServerSource;
+    }
+
+    public void setGridFTPServerSource(String gridFTPServerSource) {
+        this.gridFTPServerSource = gridFTPServerSource;
+    }
+
+    public String getSourcedataLocation() {
+        return sourcedataLocation;
+    }
+
+    public void setSourcedataLocation(String sourcedataLocation) {
+        this.sourcedataLocation = sourcedataLocation;
+    }
+
+    public String getGridFTPServerDest() {
+        return gridFTPServerDest;
+    }
+
+    public void setGridFTPServerDest(String gridFTPServerDest) {
+        this.gridFTPServerDest = gridFTPServerDest;
+    }
+
+    public String getDestdataLocation() {
+        return destdataLocation;
+    }
+
+    public void setDestdataLocation(String destdataLocation) {
+        this.destdataLocation = destdataLocation;
+    }
+}

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/FileTransfer.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/FileTransfer.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/FileTransfer.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/FileTransfer.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,83 @@
+/*
+ *
+ * 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.airavata.filetransfer;
+
+import java.net.URI;
+
+import org.apache.airavata.filetransfer.security.SecurityContext;
+import org.apache.airavata.filetransfer.utils.GridFtp;
+import org.apache.log4j.BasicConfigurator;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.ietf.jgss.GSSCredential;
+
+public class FileTransfer {
+
+    public void makeDir(GSSCredential gssCred, URI destURI) throws Exception {
+        GridFtp ftp = new GridFtp();
+        ftp.makeDir(destURI, gssCred);
+    }
+
+    public void transferData(GSSCredential gssCred, URI srcURI, URI destURI) throws Exception {
+        GridFtp ftp = new GridFtp();
+        ftp.transfer(srcURI, destURI, gssCred, true);
+    }
+
+    public void transferData(GSSCredential gssCred, String sourceERP, String remoteSrcFile, String targetERP,
+            String remoteDestFile) throws Exception {
+        GridFtp ftp = new GridFtp();
+        URI srcURI = GridFtp.createGsiftpURI(sourceERP, remoteSrcFile);
+        URI destURI = GridFtp.createGsiftpURI(targetERP, remoteDestFile);
+        ftp.transfer(srcURI, destURI, gssCred, true);
+    }
+
+    public static void main(String[] args) {
+        try {
+            BasicConfigurator.configure();
+            Logger logger = Logger.getLogger("GridFTPClient");
+            Level lev = Level.toLevel("DEBUG");
+            logger.setLevel(lev);
+            SecurityContext context = new SecurityContext();
+            context.login();
+            ExectionContext contextExectionContext = new ExectionContext();
+            FileTransfer fileTransfer = new FileTransfer();
+
+            String sourceERP = contextExectionContext.getGridFTPServerSource();
+            String remoteSrcFile = contextExectionContext.getSourcedataLocation();
+            String targeterp = contextExectionContext.getGridFTPServerDest();
+            String remoteDestFile = contextExectionContext.getDestdataLocation();
+            URI srcURI = GridFtp.createGsiftpURI(sourceERP, remoteSrcFile);
+            URI destURI = GridFtp.createGsiftpURI(targeterp, remoteDestFile);
+            URI dirLocation = GridFtp.createGsiftpURI(targeterp,
+                    remoteDestFile.substring(0, remoteDestFile.lastIndexOf("/")));
+            GSSCredential gssCredential = context.getGssCredential();
+            System.out.println(dirLocation);
+            fileTransfer.makeDir(gssCredential, dirLocation);
+            fileTransfer.transferData(gssCredential, srcURI, destURI);
+
+        } catch (Exception e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+
+    }
+}
\ No newline at end of file

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/CertificateManager.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/CertificateManager.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/CertificateManager.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/CertificateManager.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,89 @@
+/*
+ *
+ * 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.airavata.filetransfer.security;
+
+import java.io.InputStream;
+import java.security.GeneralSecurityException;
+import java.security.cert.X509Certificate;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.globus.gsi.CertUtil;
+import org.globus.util.ClassLoaderUtils;
+
+public class CertificateManager {
+
+    private static X509Certificate[] trustedCertificates;
+
+    /**
+     * Load CA certificates from a file included in the XBaya jar.
+     * 
+     * @return The trusted certificates.
+     */
+    public static X509Certificate[] getTrustedCertificate(String certificate) {
+        if (trustedCertificates != null) {
+            return trustedCertificates;
+        }
+
+        List<X509Certificate> extremeTrustedCertificates = getTrustedCertificates(certificate);
+
+        List<X509Certificate> allTrustedCertificates = new ArrayList<X509Certificate>();
+        allTrustedCertificates.addAll(extremeTrustedCertificates);
+
+        trustedCertificates = allTrustedCertificates.toArray(new X509Certificate[allTrustedCertificates.size()]);
+        return trustedCertificates;
+    }
+
+    private static List<X509Certificate> getTrustedCertificates(String pass) {
+        // ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); //**
+        // InputStream stream = classLoader.getResourceAsStream(pass); //**
+        InputStream stream = ClassLoaderUtils.getResourceAsStream(pass); // **
+        if (stream == null) {
+            throw new RuntimeException("Failed to get InputStream to " + pass);
+        }
+        return readTrustedCertificates(stream);
+    }
+
+    /**
+     * @param stream
+     * @return List of X509Certificate
+     */
+    public static List<X509Certificate> readTrustedCertificates(InputStream stream) {
+        ArrayList<X509Certificate> certificates = new ArrayList<X509Certificate>();
+        while (true) {
+            X509Certificate certificate;
+            try {
+                certificate = CertUtil.loadCertificate(stream);
+                // certificate = CertificateLoadUtil.loadCertificate(stream); //**
+            } catch (GeneralSecurityException e) {
+                String message = "Certificates are invalid";
+                throw new RuntimeException(message, e);
+            }
+            if (certificate == null) {
+                break;
+            }
+            certificates.add(certificate);
+        }
+        return certificates;
+    }
+
+}

Propchange: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/CertificateManager.java
------------------------------------------------------------------------------
    svn:executable = *

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/MyProxyCredentials.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/MyProxyCredentials.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/MyProxyCredentials.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/MyProxyCredentials.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,318 @@
+/*
+ *
+ * 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.airavata.filetransfer.security;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.Serializable;
+import java.security.cert.X509Certificate;
+
+import org.apache.log4j.Logger;
+import org.globus.gsi.GlobusCredential;
+import org.globus.gsi.TrustedCertificates;
+import org.globus.gsi.gssapi.GlobusGSSCredentialImpl;
+import org.globus.myproxy.MyProxy;
+import org.ietf.jgss.GSSCredential;
+
+public class MyProxyCredentials implements Serializable {
+
+    private static final long serialVersionUID = -2471014486509046212L;
+    protected String myproxyHostname;
+    protected String myproxyUserName;
+    protected String myproxyPassword;
+    protected int myproxyPortNumber;
+    protected GSSCredential gssCredential;
+    protected String portalUserName;
+    private String hostcertsKeyFile;
+    private String trustedCertsFile;
+
+    protected int myproxyLifeTime = 14400;
+    final static int SECS_PER_MIN = 60;
+    final static int SECS_PER_HOUR = 3600;
+
+    private boolean initialized = false;
+    private boolean user = true;
+    protected X509Certificate[] trustedCertificates;
+
+    private static final Logger log = Logger.getLogger(MyProxyCredentials.class);
+
+    public MyProxyCredentials() {
+        // default constructor
+    }
+
+    public MyProxyCredentials(String myproxyServer, int myproxyPort, String myproxyUsername, String myproxyPassphrase,
+            int myproxyLifetime) {
+        this.myproxyHostname = myproxyServer;
+        this.myproxyPortNumber = myproxyPort;
+        this.myproxyUserName = myproxyUsername;
+        this.myproxyPassword = myproxyPassphrase;
+        this.myproxyLifeTime = myproxyLifetime;
+
+    }
+
+    public GSSCredential getGssCredential() throws Exception {
+        FileInputStream fis = null;
+        try {
+            if (hostcertsKeyFile != null && !user) {
+                fis = new FileInputStream(hostcertsKeyFile);
+                // X509Credential globusCred = new X509Credential(fis); //**
+                GlobusCredential globusCred = new GlobusCredential(fis);
+                this.gssCredential = new GlobusGSSCredentialImpl(globusCred, GSSCredential.INITIATE_AND_ACCEPT);
+
+            } else {
+                this.gssCredential = getDefaultProxy();
+            }
+            if (gssCredential != null) {
+                return gssCredential;
+            }
+        } catch (Exception e) {
+            log.error("Failed to load proxy credential from ProxyManager");
+            e.printStackTrace();
+            throw e;
+        } finally {
+            if (fis != null) {
+                fis.close();
+            }
+        }
+
+        // then we will try the MyProxy
+        if (getMyproxyUserName() != null && getMyproxyPassword() != null) {
+            gssCredential = renewProxy();
+        }
+        return gssCredential;
+    }
+
+    public GSSCredential getDefaultProxy() throws Exception {
+        init();
+        MyProxy myproxy = new MyProxy(this.myproxyHostname, this.myproxyPortNumber);
+        log.info("USER=" + this.myproxyUserName + ",PASS=" + this.myproxyPassword + ",TIME=" + this.myproxyLifeTime);
+        return myproxy.get(this.myproxyUserName, this.myproxyPassword, this.myproxyLifeTime);
+    }
+
+    private void init() {
+        if (trustedCertsFile != null) {
+            if (new File(trustedCertsFile).isDirectory()) {
+                TrustedCertificates certificates = TrustedCertificates.load(trustedCertsFile);
+                TrustedCertificates.setDefaultTrustedCertificates(certificates);
+            } else {
+                this.trustedCertificates = CertificateManager.getTrustedCertificate(trustedCertsFile);
+
+                TrustedCertificates certificatesArray = new TrustedCertificates(this.trustedCertificates);
+                TrustedCertificates.setDefaultTrustedCertificates(certificatesArray);
+            }
+        }
+    }
+
+    public GSSCredential renewProxy() throws Exception {
+        init();
+
+        FileOutputStream fout = null;
+        try {
+            String proxyloc = null;
+            MyProxy myproxy = new MyProxy(myproxyHostname, myproxyPortNumber);
+            int lifeHours = myproxyLifeTime * SECS_PER_HOUR;
+            GSSCredential proxy = myproxy.get(myproxyUserName, myproxyPassword, lifeHours);
+
+            GlobusCredential globusCred = null; // **
+            // X509Credential globusCred = null; //**
+            if (proxy instanceof GlobusGSSCredentialImpl) {
+                globusCred = ((GlobusGSSCredentialImpl) proxy).getGlobusCredential();// **
+                // globusCred = ((GlobusGSSCredentialImpl) proxy).getX509Credential();//**
+                log.info("got proxy from myproxy for " + myproxyUserName + " with " + myproxyLifeTime + " lifetime.");
+                String uid = myproxyUserName;
+                if (proxyloc == null) {
+                    log.info("uid: " + uid);
+                    proxyloc = "/tmp/x509up_u" + uid;
+                }
+                File proxyfile = new File(proxyloc);
+                log.info("proxy location: " + proxyfile.getAbsolutePath());
+                if (proxyfile.exists() == false) {
+                    String dirpath = proxyloc.substring(0, proxyloc.lastIndexOf('/'));
+                    File dir = new File(dirpath);
+                    if (dir.exists() == false) {
+                        dir.mkdirs();
+                        log.info("new directory " + dirpath + " is created.");
+                    }
+                    proxyfile.createNewFile();
+                    log.info("new proxy file " + proxyloc + " is created.");
+                }
+                fout = new FileOutputStream(proxyfile);
+                globusCred.save(fout);
+                String osName = System.getProperty("os.name");
+                if (!osName.contains("Windows")) {
+                    Runtime.getRuntime().exec("/bin/chmod 600 " + proxyloc);
+                }
+                log.info("Proxy file renewed to " + proxyloc + " for the user " + myproxyUserName + " with "
+                        + myproxyLifeTime + " lifetime.");
+
+            }
+            return proxy;
+        } catch (Exception e) {
+            throw new Exception(e);
+        } finally {
+            if (fout != null) {
+                fout.close();
+            }
+        }
+    }
+
+    /**
+     * @return the myproxyHostname
+     */
+    public String getMyproxyHostname() {
+        return myproxyHostname;
+    }
+
+    /**
+     * @param myproxyHostname
+     *            the myproxyHostname to set
+     */
+    public void setMyproxyHostname(String myproxyHostname) {
+        this.myproxyHostname = myproxyHostname;
+    }
+
+    /**
+     * @return the myproxyUserName
+     */
+    public String getMyproxyUserName() {
+        return myproxyUserName;
+    }
+
+    /**
+     * @param myproxyUserName
+     *            the myproxyUserName to set
+     */
+    public void setMyproxyUserName(String myproxyUserName) {
+        this.myproxyUserName = myproxyUserName;
+    }
+
+    /**
+     * @return the myproxyPassword
+     */
+    public String getMyproxyPassword() {
+        return myproxyPassword;
+    }
+
+    /**
+     * @param myproxyPassword
+     *            the myproxyPassword to set
+     */
+    public void setMyproxyPassword(String myproxyPassword) {
+        this.myproxyPassword = myproxyPassword;
+    }
+
+    /**
+     * @return the myproxyLifeTime
+     */
+    public int getMyproxyLifeTime() {
+        return myproxyLifeTime;
+    }
+
+    /**
+     * @param myproxyLifeTime
+     *            the myproxyLifeTime to set
+     */
+    public void setMyproxyLifeTime(int myproxyLifeTime) {
+        this.myproxyLifeTime = myproxyLifeTime;
+    }
+
+    /**
+     * @return the myproxyPortNumber
+     */
+    public int getMyproxyPortNumber() {
+        return myproxyPortNumber;
+    }
+
+    /**
+     * @param myproxyPortNumber
+     *            the myproxyPortNumber to set
+     */
+    public void setMyproxyPortNumber(int myproxyPortNumber) {
+        this.myproxyPortNumber = myproxyPortNumber;
+    }
+
+    /**
+     * @return the portalUserName
+     */
+    public String getPortalUserName() {
+        return portalUserName;
+    }
+
+    /**
+     * @param portalUserName
+     *            the portalUserName to set
+     */
+    public void setPortalUserName(String portalUserName) {
+        this.portalUserName = portalUserName;
+    }
+
+    /**
+     * Returns the initialized.
+     * 
+     * @return The initialized
+     */
+    public boolean isInitialized() {
+        return this.initialized;
+    }
+
+    /**
+     * Sets initialized.
+     * 
+     * @param initialized
+     *            The initialized to set.
+     */
+    public void setInitialized(boolean initialized) {
+        this.initialized = initialized;
+    }
+
+    /**
+     * @param hostcertsKeyFile
+     *            the hostcertsKeyFile to set
+     */
+    public void setHostcertsKeyFile(String hostcertsKeyFile) {
+        this.hostcertsKeyFile = hostcertsKeyFile;
+    }
+
+    /**
+     * @return the hostcertsKeyFile
+     */
+    public String getHostcertsKeyFile() {
+        return hostcertsKeyFile;
+    }
+
+    /**
+     * @param trustedCertsFile
+     *            the trustedCertsFile to set
+     */
+    public void setTrustedCertsFile(String trustedCertsFile) {
+        this.trustedCertsFile = trustedCertsFile;
+    }
+
+    /**
+     * @return the trustedCertsFile
+     */
+    public String getTrustedCertsFile() {
+        return trustedCertsFile;
+    }
+
+}

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/SecurityContext.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/SecurityContext.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/SecurityContext.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/security/SecurityContext.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,183 @@
+/*
+ *
+ * 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.airavata.filetransfer.security;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Properties;
+
+import org.apache.airavata.filetransfer.utils.ServiceConstants;
+import org.apache.log4j.Logger;
+import org.globus.myproxy.MyProxy;
+import org.ietf.jgss.GSSCredential;
+
+public class SecurityContext {
+
+    public static final String GRIDFTPCLIENT_PROPERTY = "airavata-gridftp-client.properties";
+    private Properties properties;
+    protected GSSCredential gssCredential;
+
+    private MyProxyCredentials credentials;
+    private static final Logger log = Logger.getLogger(SecurityContext.class);
+
+    /**
+     * 
+     * Constructs a ApplicationGlobalContext.
+     * 
+     * @throws GfacGUIException
+     */
+
+    public SecurityContext() throws Exception {
+        log.setLevel(org.apache.log4j.Level.INFO);
+        loadConfiguration();
+
+    }
+
+    public static void main(String[] args) {
+        try {
+            SecurityContext context = new SecurityContext();
+            context.login();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 
+     * @throws GfacException
+     */
+    public void login() throws Exception {
+        gssCredential = credentials.getGssCredential();
+    }
+
+    public static String getProperty(String name) {
+        try {
+            SecurityContext context = new SecurityContext();
+            return context.getProperties().getProperty(name);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return null;
+        }
+
+    }
+
+    /**
+     * Load the configration file
+     * 
+     * @throws GfacException
+     */
+    private void loadConfiguration() throws Exception {
+        try {
+            if (properties == null) {
+                ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+                URL propertyFile = classLoader.getResource(GRIDFTPCLIENT_PROPERTY);
+
+                if (propertyFile != null) {
+                    File tempFile = new File(propertyFile.getFile());
+                } else {
+                    throw new Exception(" Not able to locate " + GRIDFTPCLIENT_PROPERTY);
+                }
+                InputStream propertyStream = classLoader.getResourceAsStream(GRIDFTPCLIENT_PROPERTY);
+                properties = new Properties();
+                if (credentials == null) {
+                    this.credentials = new MyProxyCredentials();
+                }
+                if (propertyStream != null) {
+                    properties.load(propertyStream);
+                    String myproxyServerTmp = properties.getProperty(ServiceConstants.MYPROXY_SERVER);
+                    if (myproxyServerTmp != null) {
+                        this.credentials.setMyproxyHostname(myproxyServerTmp.trim());
+                    }
+                    String myproxyPortTemp = properties.getProperty(ServiceConstants.MYPROXY_PORT);
+                    if (myproxyPortTemp != null && myproxyPortTemp.trim().length() > 0) {
+                        this.credentials.setMyproxyPortNumber(Integer.parseInt(myproxyPortTemp.trim()));
+                    } else {
+                        this.credentials.setMyproxyPortNumber(MyProxy.DEFAULT_PORT);
+                    }
+                    String myproxyuser = properties.getProperty(ServiceConstants.MYPROXY_USERNAME);
+                    if (myproxyuser != null) {
+                        this.credentials.setMyproxyUserName(myproxyuser);
+                    }
+                    String myproxypass = properties.getProperty(ServiceConstants.MYPROXY_PASSWD);
+                    if (myproxypass != null) {
+                        this.credentials.setMyproxyPassword(myproxypass);
+                    }
+                    String myproxytime = properties.getProperty(ServiceConstants.MYPROXY_LIFETIME);
+                    if (myproxytime != null) {
+                        this.credentials.setMyproxyLifeTime(Integer.parseInt(myproxytime));
+                    }
+                    this.credentials.setHostcertsKeyFile(properties.getProperty(ServiceConstants.HOSTCERTS_KEY_FILE));
+                    this.credentials.setTrustedCertsFile(properties.getProperty(ServiceConstants.TRUSTED_CERTS_FILE));
+                }
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            log.error(e.getLocalizedMessage());
+            throw new Exception(e);
+        }
+
+    }
+
+    /**
+     * @return the properties
+     */
+    public Properties getProperties() {
+        return properties;
+    }
+
+    /**
+     * @param properties
+     *            the properties to set
+     */
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
+
+    /**
+     * Returns the gssCredential.
+     * 
+     * @return The gssCredential
+     */
+    public GSSCredential getGssCredential() {
+        return this.gssCredential;
+    }
+
+    /**
+     * Sets gssCredential.
+     * 
+     * @param gssCredential
+     *            The gssCredential to set.
+     */
+    public void setGssCredential(GSSCredential gssCredential) {
+        this.gssCredential = gssCredential;
+    }
+
+    public MyProxyCredentials getCredentials() {
+        return credentials;
+    }
+
+    public void setCredentials(MyProxyCredentials credentials) {
+        this.credentials = credentials;
+    }
+}

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFTPContactInfo.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFTPContactInfo.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFTPContactInfo.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFTPContactInfo.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,61 @@
+/*
+ *
+ * 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.airavata.filetransfer.utils;
+
+/**
+ * Class represents GridFTP Endpoint
+ * 
+ */
+public class GridFTPContactInfo {
+    public static final int DEFAULT_GSI_FTP_PORT = 2811;
+    public String hostName;
+    public int port;
+
+    public GridFTPContactInfo(String hostName, int port) {
+        if (port <= 0 || port == 80) {
+            port = DEFAULT_GSI_FTP_PORT;
+        }
+        this.hostName = hostName;
+        this.port = port;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof GridFTPContactInfo) {
+            return hostName.equals(((GridFTPContactInfo) obj).hostName) && port == ((GridFTPContactInfo) obj).port;
+        } else {
+            return false;
+        }
+    }
+
+    @Override
+    public int hashCode() {
+        return hostName.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        StringBuffer buf = new StringBuffer();
+        buf.append(hostName).append(":").append(port);
+        return buf.toString();
+    }
+}

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFtp.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFtp.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFtp.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/GridFtp.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,394 @@
+/*
+ *
+ * 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.airavata.filetransfer.utils;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.apache.log4j.Logger;
+import org.globus.ftp.DataChannelAuthentication;
+import org.globus.ftp.DataSourceStream;
+import org.globus.ftp.GridFTPClient;
+import org.globus.ftp.HostPort;
+import org.globus.ftp.Marker;
+import org.globus.ftp.MarkerListener;
+import org.globus.ftp.Session;
+import org.globus.ftp.exception.ClientException;
+import org.globus.ftp.exception.ServerException;
+import org.globus.gsi.gssapi.auth.HostAuthorization;
+import org.ietf.jgss.GSSCredential;
+
+/**
+ * GridFTP tools
+ */
+public class GridFtp {
+
+    public static final String GSIFTP_SCHEME = "gsiftp";
+    private static final Logger log = Logger.getLogger(GridFtp.class);
+
+    /**
+     * Make directory at remote location
+     * 
+     * @param destURI
+     * @param gssCred
+     * @throws ServerException
+     * @throws IOException
+     */
+    public void makeDir(URI destURI, GSSCredential gssCred) throws Exception {
+        GridFTPClient destClient = null;
+        GridFTPContactInfo destHost = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+        try {
+
+            String destPath = destURI.getPath();
+            log.info(("Creating Directory = " + destHost + "=" + destPath));
+
+            destClient = new GridFTPClient(destHost.hostName, destHost.port);
+
+            int tryCount = 0;
+            while (true) {
+                try {
+                    destClient.setAuthorization(new HostAuthorization("host"));
+                    destClient.authenticate(gssCred);
+                    destClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+                    if (!destClient.exists(destPath)) {
+                        destClient.makeDir(destPath);
+                    }
+                    break;
+                } catch (ServerException e) {
+                    tryCount++;
+                    if (tryCount >= 3) {
+                        throw new Exception(e.getMessage(), e);
+                    }
+                    Thread.sleep(10000);
+                } catch (IOException e) {
+                    tryCount++;
+                    if (tryCount >= 3) {
+                        throw new Exception(e.getMessage(), e);
+                    }
+                    Thread.sleep(10000);
+                }
+            }
+        } catch (ServerException e) {
+            throw new Exception("Cannot Create GridFTP Client to:" + destHost.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot Create GridFTP Client to:" + destHost.toString(), e);
+        } catch (InterruptedException e) {
+            throw new Exception("Internal Error cannot sleep", e);
+        } finally {
+            if (destClient != null) {
+                try {
+                    destClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Upload file from stream
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @throws GfacException
+     */
+    public void updateFile(URI destURI, GSSCredential gsCredential, InputStream io) throws Exception {
+        GridFTPClient ftpClient = null;
+        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+
+        try {
+
+            String remoteFile = destURI.getPath();
+            log.info("The remote file is " + remoteFile);
+
+            log.info("Setup GridFTP Client");
+
+            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+            ftpClient.setAuthorization(new HostAuthorization("host"));
+            ftpClient.authenticate(gsCredential);
+            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+            log.info("Uploading file");
+
+            ftpClient.put(remoteFile, new DataSourceStream(io), new MarkerListener() {
+                public void markerArrived(Marker marker) {
+                }
+            });
+
+            log.info("Upload file to:" + remoteFile + " is done");
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } finally {
+            if (ftpClient != null) {
+                try {
+                    ftpClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Upload file to remote location
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @throws GfacException
+     */
+    public void updateFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception {
+        GridFTPClient ftpClient = null;
+        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+        try {
+
+            String remoteFile = destURI.getPath();
+
+            log.info("The local temp file is " + localFile);
+            log.info("the remote file is " + remoteFile);
+
+            log.info("Setup GridFTP Client");
+
+            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+            ftpClient.setAuthorization(new HostAuthorization("host"));
+            ftpClient.authenticate(gsCredential);
+            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+            log.info("Uploading file");
+
+            ftpClient.put(localFile, remoteFile, false);
+
+            log.info("Upload file to:" + remoteFile + " is done");
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot upload file to GridFTP:" + contactInfo.toString(), e);
+        } finally {
+            if (ftpClient != null) {
+                try {
+                    ftpClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Download File from remote location
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @throws GfacException
+     */
+    public void downloadFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception {
+        GridFTPClient ftpClient = null;
+        GridFTPContactInfo contactInfo = new GridFTPContactInfo(destURI.getHost(), destURI.getPort());
+        try {
+            String remoteFile = destURI.getPath();
+
+            log.info("The local temp file is " + localFile);
+            log.info("the remote file is " + remoteFile);
+
+            log.info("Setup GridFTP Client");
+
+            ftpClient = new GridFTPClient(contactInfo.hostName, contactInfo.port);
+            ftpClient.setAuthorization(new HostAuthorization("host"));
+            ftpClient.authenticate(gsCredential);
+            ftpClient.setDataChannelAuthentication(DataChannelAuthentication.SELF);
+
+            log.info("Downloading file");
+
+            ftpClient.get(remoteFile, localFile);
+
+            log.info("Download file to:" + remoteFile + " is done");
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot download file from GridFTP:" + contactInfo.toString(), e);
+        } finally {
+            if (ftpClient != null) {
+                try {
+                    ftpClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Stream remote file
+     * 
+     * @param destURI
+     * @param gsCredential
+     * @param localFile
+     * @return
+     * @throws GfacException
+     */
+    public String readRemoteFile(URI destURI, GSSCredential gsCredential, File localFile) throws Exception {
+        BufferedReader instream = null;
+        File localTempfile = null;
+        try {
+
+            if (localFile == null) {
+                localTempfile = File.createTempFile("stderr", "err");
+            } else {
+                localTempfile = localFile;
+            }
+
+            log.info("Loca temporary file:" + localTempfile);
+
+            downloadFile(destURI, gsCredential, localTempfile);
+
+            instream = new BufferedReader(new FileReader(localTempfile));
+            StringBuffer buff = new StringBuffer();
+            String temp = null;
+            while ((temp = instream.readLine()) != null) {
+                buff.append(temp);
+                buff.append(System.getProperty("line.separator"));
+            }
+
+            log.info("finish read file:" + localTempfile);
+
+            return buff.toString();
+        } catch (FileNotFoundException e) {
+            throw new Exception("Cannot read localfile file:" + localTempfile, e);
+        } catch (IOException e) {
+            throw new Exception("Cannot read localfile file:" + localTempfile, e);
+        } finally {
+            if (instream != null) {
+                try {
+                    instream.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection");
+                }
+            }
+        }
+    }
+
+    /**
+     * Transfer data from one GridFTp Endpoint to another GridFTP Endpoint
+     * 
+     * @param srchost
+     * @param desthost
+     * @param gssCred
+     * @param srcActive
+     * @throws ServerException
+     * @throws ClientException
+     * @throws IOException
+     */
+    public void transfer(URI srchost, URI desthost, GSSCredential gssCred, boolean srcActive) throws Exception {
+        GridFTPClient destClient = null;
+        GridFTPClient srcClient = null;
+
+        try {
+            destClient = new GridFTPClient(desthost.getHost(), desthost.getPort());
+            destClient.setAuthorization(new HostAuthorization("host"));
+            destClient.authenticate(gssCred);
+            destClient.setType(Session.TYPE_IMAGE);
+
+            srcClient = new GridFTPClient(srchost.getHost(), srchost.getPort());
+            srcClient.setAuthorization(new HostAuthorization("host"));
+            srcClient.authenticate(gssCred);
+            srcClient.setType(Session.TYPE_IMAGE);
+
+            if (srcActive) {
+                log.info("Set src active");
+                HostPort hp = destClient.setPassive();
+                srcClient.setActive(hp);
+            } else {
+                log.info("Set dst active");
+                HostPort hp = srcClient.setPassive();
+                destClient.setActive(hp);
+            }
+
+            log.info("Start transfer file from GridFTP:" + srchost.toString() + " to " + desthost.toString());
+
+            /**
+             * Transfer a file. The transfer() function blocks until the transfer is complete.
+             */
+            srcClient.transfer(srchost.getPath(), destClient, desthost.getPath(), false, null);
+            if (srcClient.getSize(srchost.getPath()) == destClient.getSize(desthost.getPath())) {
+                log.info("CHECK SUM OK");
+            } else {
+                log.info("****CHECK SUM FAILED****");
+            }
+
+        } catch (ServerException e) {
+            throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+                    + desthost.toString(), e);
+        } catch (IOException e) {
+            throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+                    + desthost.toString(), e);
+        } catch (ClientException e) {
+            throw new Exception("Cannot transfer file from GridFTP:" + srchost.toString() + " to "
+                    + desthost.toString(), e);
+        } finally {
+            if (destClient != null) {
+                try {
+                    destClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection at Desitnation:" + desthost.toString());
+                }
+            }
+            if (srcClient != null) {
+                try {
+                    srcClient.close();
+                } catch (Exception e) {
+                    log.info("Cannot close GridFTP client connection at Source:" + srchost.toString());
+                }
+            }
+        }
+    }
+
+    public static URI createGsiftpURI(String host, String localPath) throws URISyntaxException {
+        StringBuffer buf = new StringBuffer();
+        if (!host.startsWith("gsiftp://"))
+            buf.append("gsiftp://");
+        buf.append(host);
+        if (!host.endsWith("/"))
+            buf.append("/");
+        buf.append(localPath);
+        return new URI(buf.toString());
+    }
+}

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/ServiceConstants.java
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/ServiceConstants.java?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/ServiceConstants.java (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/java/org/apache/airavata/filetransfer/utils/ServiceConstants.java Sun Nov 11 14:54:26 2012
@@ -0,0 +1,45 @@
+/*
+ *
+ * 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.airavata.filetransfer.utils;
+
+public class ServiceConstants {
+
+	public static final String MYPROXY_SERVER = "myproxyServer";
+	public static final String MYPROXY_PORT = "myproxyPort";
+	public static final String MYPROXY_LIFETIME = "myproxy_lifetime";
+	public static final String MYPROXY_USERNAME = "myproxyUserName";
+	public static final String MYPROXY_PASSWD = "myproxyPasswd";
+	public static final String TRUSTED_CERTS_FILE = "trustedCertsFile";
+	public static final String HOSTCERTS_KEY_FILE = "hostcertsKeyFile";
+
+	public static final String TESTINGHOST = "testing.host";
+	
+    public static final String LONESTARGRIDFTPEPR = "lonestar.gridftp.endpoint";
+    public static final String RANGERGRIDFTPEPR = "ranger.gridftp.endpoint";
+    public static final String TRESTLESGRIDFTPEPR = "trestles.gridftp.endpoint";
+	
+	public static final String GRIDFTPSERVERSOURCE = "gridftpserverSource";
+	public static final String GRIDFTPSOURCEPATH = "gridftpSourcePath";
+	public static final String GRIDFTPSERVERDEST = "gridftpserverDest";
+	public static final String GRIDFTPDESTPATH = "gridftpDestPath";
+
+}

Added: airavata/sandbox/grid-tools/gridftp-client/src/main/resources/airavata-gridftp-client.properties
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/src/main/resources/airavata-gridftp-client.properties?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/src/main/resources/airavata-gridftp-client.properties (added)
+++ airavata/sandbox/grid-tools/gridftp-client/src/main/resources/airavata-gridftp-client.properties Sun Nov 11 14:54:26 2012
@@ -0,0 +1,26 @@
+trustedCertsFile=./certificates/
+myproxyServer=myproxy.teragrid.org
+myproxy_lifetime=17280000
+myproxyUserName=
+myproxyPasswd=
+myproxyPort=7512
+
+
+testing.host=trestles
+#testing.host=ranger
+#testing.host=lonestar
+
+## TACC Lonestar         
+lonestar.gridftp.endpoint=gsiftp://gridftp1.ls4.tacc.utexas.edu:2811/
+
+## TACC Ranger        
+ranger.gridftp.endpoint=gsiftp://gridftp.ranger.tacc.teragrid.org:2811/
+
+## SDSC Trestles        
+trestles.gridftp.endpoint=gsiftp://trestles.sdsc.edu:2811/
+
+gridftpserverSource=gsiftp://gridftp.ranger.tacc.teragrid.org:2811/
+gridftpSourcePath=/share/home/01437/ogce/file-transfer-tests/source/test-binary.file
+#/oasis/projects/nsf/sds128/ogce/file-transfer-tests/source/sample_wrfout.netcdf
+gridftpserverDest=gsiftp://trestles.sdsc.edu:2811/
+gridftpDestPath=/oasis/projects/nsf/sds128/ogce/file-transfer-tests/dest/test-binary.file
\ No newline at end of file

Added: airavata/sandbox/grid-tools/gridftp-client/test-file-transfer.sh
URL: http://svn.apache.org/viewvc/airavata/sandbox/grid-tools/gridftp-client/test-file-transfer.sh?rev=1408020&view=auto
==============================================================================
--- airavata/sandbox/grid-tools/gridftp-client/test-file-transfer.sh (added)
+++ airavata/sandbox/grid-tools/gridftp-client/test-file-transfer.sh Sun Nov 11 14:54:26 2012
@@ -0,0 +1,12 @@
+#!/bin/sh
+
+for i in target/lib/*.jar
+do
+  CLASSPATH=$CLASSPATH:$i
+done
+
+CLASSPATH=$CLASSPATH:target/airavata-gridftp-client-0.1-SNAPSHOT.jar:./config
+
+echo $CLASSPATH
+
+java -classpath $CLASSPATH org.apache.airavata.filetransfer.FileTransfer $*

Propchange: airavata/sandbox/grid-tools/gridftp-client/test-file-transfer.sh
------------------------------------------------------------------------------
    svn:executable = *