http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/pom.xml ---------------------------------------------------------------------- diff --git a/protocol/http/pom.xml b/protocol/http/pom.xml deleted file mode 100644 index 22013f5..0000000 --- a/protocol/http/pom.xml +++ /dev/null @@ -1,105 +0,0 @@ -<?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>1.1-SNAPSHOT</version> - <relativePath>../../core/pom.xml</relativePath> - </parent> - <artifactId>cas-protocol-http</artifactId> - <name>CAS Protocol HTTP Implementation</name> - <!-- All dependencies should be listed in core/pom.xml and be ordered alphabetically by package and artifact. - Once the dependency is in the core pom, it can then be used in other modules without the version tags. - For example, within core/pom.xml: - - <dependency> - <groupId>com.amazonaws</groupId> - <artifactId>aws-java-sdk</artifactId> - <version>1.7.4</version> - </dependency> - - Elsewhere in the platform: - <dependency> - <groupId>com.amazonaws</groupId> - <artifactId>aws-java-sdk</artifactId> - </dependency> - - Where possible the same dependency version should be used across the whole platform but if required the version - can be overridden in a specific pom and should have a comment explaing why the version has been overridden - --> - <dependencies> - <dependency> - <groupId>commons-httpclient</groupId> - <artifactId>commons-httpclient</artifactId> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>nekohtml</groupId> - <artifactId>nekohtml</artifactId> - </dependency> - <dependency> - <groupId>org.apache.oodt</groupId> - <artifactId>cas-protocol-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.tika</groupId> - <artifactId>tika-parsers</artifactId> - </dependency> - </dependencies> - <build> - <resources> - <resource> - <targetPath>org/apache/oodt/cas/protocol/http</targetPath> - <directory>${basedir}/src/main/resources/policy</directory> - <includes> - <include>http-protocol-config.xml</include> - </includes> - </resource> - </resources> - </build> - <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> - <goals> - <goal>check</goal> - </goals> - <phase>verify</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project>
http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java ---------------------------------------------------------------------- diff --git a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java b/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java deleted file mode 100644 index 5e38940..0000000 --- a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpFile.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.protocol.http; - -//OODT imports -import org.apache.commons.lang.Validate; -import org.apache.oodt.cas.protocol.ProtocolFile; - -//JDK imports -import java.net.URL; - -/** - * HTTP extension of {@link ProtocolFile} - * - * @author bfoster - * @version $Revision$ - */ -public class HttpFile extends ProtocolFile { - - private static final long serialVersionUID = -7780059889413081800L; - - private URL link; - - public HttpFile(String virtualPath, boolean isDir, URL link) { - this(null, virtualPath, isDir, link); - } - - public HttpFile(HttpFile parent, String virtualPath, boolean isDir, URL link) { - super(parent, virtualPath, isDir); - Validate.notNull(link, "URL link must not be NULL"); - this.link = link; - } - - public URL getLink() { - return this.link; - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java ---------------------------------------------------------------------- diff --git a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java b/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java deleted file mode 100644 index dc0d6a8..0000000 --- a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocol.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * 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.protocol.http; - -import org.apache.oodt.cas.protocol.Protocol; -import org.apache.oodt.cas.protocol.ProtocolFile; -import org.apache.oodt.cas.protocol.auth.Authentication; -import org.apache.oodt.cas.protocol.exceptions.ProtocolException; -import org.apache.oodt.cas.protocol.http.util.HttpUtils; -import org.apache.oodt.cas.protocol.util.ProtocolFileFilter; - -//JDK imports -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.ArrayList; -import java.util.concurrent.ConcurrentHashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -/** - * - * Http Protocol communication class - * - * - * @author bfoster - * @version $Revision$ - * - */ -public class HttpProtocol implements Protocol { - - public static final int INT = 1024; - private static Map<String, List<HttpFile>> linkChildren = new ConcurrentHashMap<String, List<HttpFile>>(); - - private HttpFile parentFile; - private HttpFile currentFile; - private boolean isConnected; - - public HttpProtocol() { - isConnected = false; - } - - public void cd(ProtocolFile file) throws ProtocolException { - try { - HttpFile httpFile; - if (file instanceof HttpFile) { - httpFile = (HttpFile) file; - } else { - URL link = HttpUtils.resolveUri(currentFile.getLink().toURI(), file.getPath()).toURL(); - httpFile = new HttpFile(link.getPath(), file.isDir(), link); - } - - if (!HttpUtils - .isDirectory(httpFile.getLink(), file.getPath())) { - throw new ProtocolException(file - + " is not a directory (mime type must be text/html)"); - } - this.currentFile = httpFile; - } catch (Exception e) { - throw new ProtocolException("Failed to cd to " + file + " : " - + e.getMessage(), e); - } - } - - public void cdRoot() { - currentFile = parentFile; - } - - public void cdHome() { - cdRoot(); - } - - public void connect(String host, Authentication auth) - throws ProtocolException { - try { - URL url = new URL("http://" + host + "/"); - url.openStream().close(); - currentFile = parentFile = new HttpFile("/", true, url); - isConnected = true; - } catch (Exception e) { - throw new ProtocolException("Failed to connect to http://" + host + " : " - + e.getMessage()); - } - } - - public void close() throws ProtocolException { - currentFile = parentFile = null; - } - - public void get(ProtocolFile fromFile, File toFile) - throws ProtocolException { - - OutputStream out = null; - InputStream in = null; - try { - out = new BufferedOutputStream(new FileOutputStream(toFile)); - if (fromFile instanceof HttpFile) { - in = ((HttpFile) fromFile).getLink().openStream(); - } else { - in = HttpUtils.resolveUri(currentFile.getLink().toURI(), fromFile.getPath()).toURL().openStream(); - } - - byte[] buffer = new byte[INT]; - int numRead; - long numWritten = 0; - while ((numRead = in.read(buffer)) != -1) { - out.write(buffer, 0, numRead); - numWritten += numRead; - } - in.close(); - out.close(); - } catch (Exception e) { - throw new ProtocolException("Failed to get file '" + fromFile + "' : " - + e.getMessage(), e); - } finally { - if (in != null) { - try { - in.close(); - } catch (Exception e) { - // log failure - } - } - if (out != null) { - try { - out.close(); - } catch (Exception e) { - // log failure - } - } - } - } - - public void put(File fromFile, ProtocolFile toFile) { - //do nothing - } - - public List<ProtocolFile> ls() throws ProtocolException { - List<ProtocolFile> lsResults = new ArrayList<ProtocolFile>(); - for (HttpFile file : parseLink(currentFile)) { - lsResults.add(file); - } - return lsResults; - } - - public List<ProtocolFile> ls(ProtocolFileFilter filter) - throws ProtocolException { - List<ProtocolFile> lsResults = new ArrayList<ProtocolFile>(); - for (HttpFile file : parseLink(currentFile)) { - if (filter.accept(file)) { - lsResults.add(file); - } - } - return lsResults; - } - - public ProtocolFile pwd() throws ProtocolException { - try { - return currentFile; - } catch (Exception e) { - throw new ProtocolException("Failed to get current working directory : " - + e.getMessage()); - } - } - - public boolean connected() { - return this.isConnected; - } - - public List<HttpFile> parseLink(HttpFile file) - throws ProtocolException { - List<HttpFile> children = linkChildren.get(file.getLink() - .toString()); - if (file.isDir() && children == null) { - try { - - // Open link. - HttpURLConnection conn = HttpUtils.connect(file.getLink()); - - // If redirection took place, then change the ProtocolFile's URL. - if (HttpUtils.checkForRedirection(file.getLink(), conn.getURL())) { - file = new HttpFile(file, file.getPath(), file.isDir(), conn.getURL()); - } - - // Find links in URL. - children = new LinkedList<HttpFile>(); - children.addAll(HttpUtils.findLinks(file)); - - // Save children links found. - linkChildren.put(file.getLink().toString(), children); - - } catch (Exception e) { - throw new ProtocolException("Failed to get children links for " + file - + " : " + e.getMessage(), e); - } - } - return children; - } - - public void delete(ProtocolFile file) {} - - public static void main(String[] args) throws Exception { - String urlString = null, downloadToDir = null; - for (int i = 0; i < args.length; i++) { - if (args[i].equals("--url")) { - urlString = args[++i]; - } else if (args[i].equals("--downloadToDir")) { - downloadToDir = args[++i]; - } - } - - if (urlString == null) { - throw new Exception("Must specify a url to download: --url <url>"); - } - - URL url = new URL(urlString); - ProtocolFile urlFile = new HttpFile(url.getPath(), false, url); - File toFile = new File(downloadToDir, urlFile.getName()); - toFile = toFile.getAbsoluteFile(); - toFile.createNewFile(); - new HttpProtocol().get(urlFile, toFile); - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java ---------------------------------------------------------------------- diff --git a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java b/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java deleted file mode 100644 index 05b5bb3..0000000 --- a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/HttpProtocolFactory.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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.protocol.http; - -//OODT imports -import org.apache.oodt.cas.protocol.ProtocolFactory; - -/** - * Factory for creating {@link HttpProtocol}s - * - * @author bfoster - * @version $Revision$ - */ -public class HttpProtocolFactory implements ProtocolFactory { - - public HttpProtocol newInstance() { - return new HttpProtocol(); - } - - public String getSchema() { - return "http"; - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java ---------------------------------------------------------------------- diff --git a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java b/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java deleted file mode 100644 index 9a35934..0000000 --- a/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http/util/HttpUtils.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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.protocol.http.util; - -//JDK imports -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import java.util.Scanner; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -//APACHE imports -import org.apache.commons.lang.Validate; - -//OODT imports -import org.apache.oodt.cas.metadata.util.MimeTypeUtils; -import org.apache.oodt.cas.protocol.http.HttpFile; - -/** - * Utility methods for HTTP Protocol related tasks. - * - * @author bfoster - */ -public class HttpUtils { - - static final MimeTypeUtils MIME_TYPES = new MimeTypeUtils(); - - // Pattern looking for <a href="(group-2)"/>(group-3)</a> . . . group-1 is for either " or ' - static final Pattern XHTML_LINK_PATTERN = Pattern.compile("<\\s*a\\s+href\\s*=\\s*(['\"])(.+?)\\1\\s*>(.+?)<\\s*/\\s*a\\s*>"); - static final Pattern LAZY_LINK_PATTERN = Pattern.compile("<\\s*a\\s+href\\s*=\\s*(['\"])(.+?)\\1\\s*/\\s*>"); - - private HttpUtils() {} - - /** - * Resolves a path against given {@link URI} and creates the resolved {@link URI}. - * (i.e. base = "http://localhost" ; path = "/path/to/file" ; resolved = "http://localhost/path/to/file") - * Handles all cases: if base already has a path, if path is relative, if path is absolute. - * - * @param base The base {@link URI} which the given path will be resolved against. - * @param path The path to be resolved against the given {@link URI} - * @return resolved {@link URI}. - * @throws URISyntaxException - */ - public static URI resolveUri(URI base, String path) throws URISyntaxException { - Validate.notNull(base, "base URI must not be NULL"); - Validate.notNull(path, "resolve path must not be NULL"); - if (path.startsWith("http://")) { - return new URI(path); - } else if (path.startsWith("/")) { - return new URI(base.getScheme() + "://" + base.getHost() + path); - } else { - if (base.toString().endsWith("/")) { - return new URI(base.toString() + path); - } else { - return new URI(base.toString() + "/" + path); - } - } - } - - public static HttpURLConnection connect(URL url) throws IOException { - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.connect(); - conn.getResponseMessage(); - return conn; - } - - public static boolean checkForRedirection(URL beforeConnUrl, URL afterConnUrl) { - return !beforeConnUrl.toString().equals(afterConnUrl.toString()); - } - - public static String readUrl(HttpURLConnection conn) throws IOException { - // create URL source reader - Scanner scanner = new Scanner(conn.getInputStream()); - - // Read in link - StringBuilder sb = new StringBuilder(""); - while (scanner.hasNext()) { - sb.append(scanner.nextLine()); - } - - return sb.toString(); - } - - public static List<HttpFile> findLinks(HttpFile file) throws IOException, URISyntaxException { - Matcher matcher = XHTML_LINK_PATTERN.matcher(HttpUtils.readUrl(connect(file.getLink()))); - List<HttpFile> httpFiles = new ArrayList<HttpFile>(); - while (matcher.find()) { - String link = matcher.group(2).trim(); - String virtualPath = matcher.group(3).trim(); - URL url = resolveUri(file.getLink().toURI(), link).toURL(); - httpFiles.add(new HttpFile(file, link, isDirectory(url, virtualPath), url)); - } - matcher = LAZY_LINK_PATTERN.matcher(HttpUtils.readUrl(connect(file.getLink()))); - while (matcher.find()) { - String link = matcher.group(2).trim(); - URL url = resolveUri(file.getLink().toURI(), link).toURL(); - httpFiles.add(new HttpFile(file, link, isDirectory(url, link), url)); - } - return httpFiles; - } - - public static boolean isDirectory(URL url, String virtualPath) throws IOException { - try { - String mime = MIME_TYPES.autoResolveContentType(url.toString(), - MimeTypeUtils.readMagicHeader(url.openStream())); - return (mime.equals("text/html") && !virtualPath.endsWith(".html")); - } catch (Exception e) { - throw new IOException("URL does not exist '" + url + "'", e); - } - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/main/resources/policy/http-protocol-config.xml ---------------------------------------------------------------------- diff --git a/protocol/http/src/main/resources/policy/http-protocol-config.xml b/protocol/http/src/main/resources/policy/http-protocol-config.xml deleted file mode 100644 index 3b96e58..0000000 --- a/protocol/http/src/main/resources/policy/http-protocol-config.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?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. ---> -<!-- - - Author: bfoster - Description: ProtocolManager Configuration - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:p="http://www.springframework.org/schema/p" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - - <bean class="org.apache.oodt.cas.protocol.http.HttpProtocolFactory"/> - -</beans> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpFile.java ---------------------------------------------------------------------- diff --git a/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpFile.java b/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpFile.java deleted file mode 100644 index f0ad7b4..0000000 --- a/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpFile.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.protocol.http; - -//JUnit imports -import java.net.MalformedURLException; -import java.net.URL; - -import junit.framework.TestCase; - -/** - * Test class for {@link HttpFile}. - * - * @author bfoster - */ -public class TestHttpFile extends TestCase { - - public void testInitialState() throws MalformedURLException { - HttpFile parent = new HttpFile("/path/to", false, new URL("http://some-site")); - HttpFile file = new HttpFile(parent, "/path/to/file", false, new URL("http://some-site")); - assertNotNull(file.getLink()); - assertEquals("http://some-site", file.getLink().toString()); - assertFalse(file.isDir()); - assertFalse(file.isRelative()); - assertNotNull(file.getParent()); - assertEquals(parent, file.getParent()); - } - - public void testNullCase() throws MalformedURLException { - try { - new HttpFile(null, false, new URL("http://some-site")); - fail("Should have thrown an IllegalArgumentException"); - } catch (IllegalArgumentException ignored) {} - try { - new HttpFile("/path/to/file", false, null); - fail("Should have thrown an IllegalArgumentException"); - } catch (IllegalArgumentException ignored) {} - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java ---------------------------------------------------------------------- diff --git a/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java b/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java deleted file mode 100644 index 05a7c4f..0000000 --- a/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/TestHttpProtocol.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * 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.protocol.http; - -//JUnit imports -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.List; -import java.util.Scanner; - -import org.apache.commons.io.FileUtils; -import org.apache.oodt.cas.protocol.ProtocolFile; -import org.apache.oodt.cas.protocol.auth.NoAuthentication; -import org.apache.oodt.cas.protocol.exceptions.ProtocolException; -import org.apache.oodt.cas.protocol.http.util.HttpUtils; - -import junit.framework.TestCase; - -/** - * Test class for {@link HttpProtocol}. - * - * @author bfoster - */ -public class TestHttpProtocol extends TestCase { - - public void testConnection() throws InstantiationException, ProtocolException { - HttpProtocol httpProtocol = new HttpProtocol(); - assertFalse(httpProtocol.connected()); - httpProtocol.connect("svn.apache.org", new NoAuthentication()); - assertTrue(httpProtocol.connected()); - } - - public void testLSandCD() throws ProtocolException, InstantiationException { - HttpProtocol httpProtocol = new HttpProtocol(); - httpProtocol.connect("svn.apache.org", new NoAuthentication()); - assertTrue(httpProtocol.connected()); - httpProtocol.cd(new ProtocolFile("repos/asf/oodt/trunk/protocol/http/src/main/java/org/apache/oodt/cas/protocol/http", true)); - List<ProtocolFile> files = httpProtocol.ls(); - boolean foundFile = false; - for (ProtocolFile file : files) { - if (file.getName().equals("HttpProtocol.java")) { - foundFile = true; - break; - } - } - assertTrue(foundFile); - } - - public void testPWD() throws ProtocolException { - HttpProtocol httpProtocol = new HttpProtocol(); - httpProtocol.connect("svn.apache.org", new NoAuthentication()); - assertTrue(httpProtocol.connected()); - ProtocolFile gotoDir = new ProtocolFile(httpProtocol.pwd(), - "repos/asf/oodt/trunk/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http", true); - httpProtocol.cd(gotoDir); - ProtocolFile currentDir = httpProtocol.pwd(); - System.out.println(gotoDir.getAbsoluteFile()); - System.out.println(currentDir.getAbsoluteFile()); - assertEquals(gotoDir, currentDir); - } - - public void testGET() throws ProtocolException, IOException { - HttpProtocol httpProtocol = new HttpProtocol(); - httpProtocol.connect("svn.apache.org", new NoAuthentication()); - assertTrue(httpProtocol.connected()); - httpProtocol.cd(new ProtocolFile("repos/asf/oodt/trunk/protocol/http/src/test/java/org/apache/oodt/cas" - + "/protocol/http", true)); - File bogus = File.createTempFile("bogus", "bogus"); - File tmpDir = new File(bogus.getParentFile(), "TestHttpProtocol"); - bogus.delete(); - tmpDir.mkdirs(); - File toFile = new File(tmpDir, "TestHttpProtocol.java"); - httpProtocol.get(new ProtocolFile("TestHttpProtocol.java", false), toFile); - assertTrue(toFile.exists()); - assertNotSame(0, toFile.length()); - - String fileContent = ""; - Scanner scanner = new Scanner(toFile); - while(scanner.hasNextLine()) { - fileContent += scanner.nextLine(); - } - assertEquals(fileContent, HttpUtils.readUrl(HttpUtils.connect(new URL("http://svn.apache.org/repos/asf/oodt/" - + "trunk/protocol/http/src/test/java/org/" - + "apache/oodt/cas/protocol/http/" - + "TestHttpProtocol.java")))); - FileUtils.forceDelete(tmpDir); - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java ---------------------------------------------------------------------- diff --git a/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java b/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java deleted file mode 100644 index a6a16dc..0000000 --- a/protocol/http/src/test/java/org/apache/oodt/cas/protocol/http/util/TestHttpUtils.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * 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.protocol.http.util; - -//JDK imports -import java.io.IOException; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.List; -import java.util.regex.Matcher; - -//OODT imports -import org.apache.oodt.cas.protocol.http.HttpFile; - -//JUnits imports -import junit.framework.TestCase; - -/** - * Test class for {@link HttpUtils}. - * - * @author bfoster - */ -public class TestHttpUtils extends TestCase { - - private static final String APACHE_SVN_SITE = "http://svn.apache.org"; - - private static final String PROTOCOL_HTTP_SVN_LOC = "/repos/asf/oodt/trunk/protocol/http"; - private static final String PARENT_URL_OF_THIS_TEST = PROTOCOL_HTTP_SVN_LOC + - "/src/test/java/org/apache/oodt/cas/protocol/http/util"; - private static final String URL_OF_THIS_TEST = PARENT_URL_OF_THIS_TEST + "/TestHttpUtils.java"; - - public void testResolveUri() throws URISyntaxException { - URI baseUri = new URI("http://localhost/base/directory/"); - - // Test absolute resolve. - URI resolvedAbsoluteUri = HttpUtils.resolveUri(baseUri, "/path/to/file"); - assertEquals("http://localhost/path/to/file", resolvedAbsoluteUri.toString()); - - // Test relative resolve. - URI resolvedRelativeUri = HttpUtils.resolveUri(baseUri, "path/to/file"); - assertEquals("http://localhost/base/directory/path/to/file", resolvedRelativeUri.toString()); - - // Test relative with base not ending in / - baseUri = new URI("http://localhost/base/directory"); - assertEquals("http://localhost/base/directory/path/to/file", resolvedRelativeUri.toString()); - } - - public void testConnectUrl() throws IOException { - HttpURLConnection conn = HttpUtils.connect(new URL(APACHE_SVN_SITE + URL_OF_THIS_TEST)); - assertNotSame(0, conn.getDate()); - String urlText = HttpUtils.readUrl(conn); - assertTrue(urlText.contains("public class TestHttpUtils extends TestCase {")); - conn.disconnect(); - } - - public void testRedirector() throws MalformedURLException { - URL url = new URL("http://localhost:80"); - URL redirectedURL = new URL("http://localhost:8080"); - assertFalse(HttpUtils.checkForRedirection(url, url)); - assertTrue(HttpUtils.checkForRedirection(url, redirectedURL)); - } - - public void testXhtmlLinkPattern() { - // SUCCESS cases - Matcher matcher = HttpUtils.XHTML_LINK_PATTERN.matcher("<a href=\"http://localhost\">localhost</a>"); - assertTrue(matcher.find()); - assertEquals("\"", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - assertEquals("localhost", matcher.group(3).trim()); - - matcher = HttpUtils.XHTML_LINK_PATTERN.matcher("<a href='http://localhost'>localhost</a>"); - assertTrue(matcher.find()); - assertEquals("'", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - assertEquals("localhost", matcher.group(3).trim()); - - matcher = HttpUtils.XHTML_LINK_PATTERN.matcher("< a href = \" http://localhost \" > localhost < / a >"); - assertTrue(matcher.find()); - assertEquals("\"", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - assertEquals("localhost", matcher.group(3).trim()); - - matcher = HttpUtils.XHTML_LINK_PATTERN.matcher("< a href = ' http://localhost ' > localhost < / a >"); - assertTrue(matcher.find()); - assertEquals("'", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - assertEquals("localhost", matcher.group(3).trim()); - - //Should not find case: open with " end with ' - matcher = HttpUtils.XHTML_LINK_PATTERN.matcher("<a href=\"http://localhost\'>localhost</a>"); - assertFalse(matcher.find()); - - //Should not find case: open with ' end with " - matcher = HttpUtils.XHTML_LINK_PATTERN.matcher("<a href=\'http://localhost\">localhost</a>"); - assertFalse(matcher.find()); - - //Should not find case: lazy link pattern - matcher = HttpUtils.XHTML_LINK_PATTERN.matcher("<a href=\"http://localhost\"/>"); - assertFalse(matcher.find()); - } - - public void testLazyLinkPattern() { - Matcher matcher = HttpUtils.LAZY_LINK_PATTERN.matcher("<a href=\"http://localhost\"/>"); - assertTrue(matcher.find()); - assertEquals("\"", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - - matcher = HttpUtils.LAZY_LINK_PATTERN.matcher("<a href='http://localhost'/>"); - assertTrue(matcher.find()); - assertEquals("'", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - - matcher = HttpUtils.LAZY_LINK_PATTERN.matcher("< a href = \" http://localhost \" / >"); - assertTrue(matcher.find()); - assertEquals("\"", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - - matcher = HttpUtils.LAZY_LINK_PATTERN.matcher("< a href = ' http://localhost ' / >"); - assertTrue(matcher.find()); - assertEquals("'", matcher.group(1).trim()); - assertEquals("http://localhost", matcher.group(2).trim()); - - //Should not find case: open with " end with ' - matcher = HttpUtils.LAZY_LINK_PATTERN.matcher("<a href=\"http://localhost\'/>"); - assertFalse(matcher.find()); - - //Should not find case: open with ' end with " - matcher = HttpUtils.LAZY_LINK_PATTERN.matcher("<a href=\'http://localhost\"/>"); - assertFalse(matcher.find()); - - //Should not find case: xhtml link pattern - matcher = HttpUtils.LAZY_LINK_PATTERN.matcher("<a href='http://localhost'>localhost</a>"); - assertFalse(matcher.find()); - } - - public void testFindLinks() throws IOException, URISyntaxException { - URL url = new URL(APACHE_SVN_SITE + PARENT_URL_OF_THIS_TEST); - HttpFile parent = new HttpFile(PARENT_URL_OF_THIS_TEST, true, url); - HttpURLConnection conn = HttpUtils.connect(url); - List<HttpFile> httpFiles = HttpUtils.findLinks(parent); - boolean foundThisTest = false; - for (HttpFile httpFile : httpFiles) { - if (httpFile.getName().equals("TestHttpUtils.java")) { - foundThisTest = true; - break; - } - } - assertTrue(foundThisTest); - } - - public void testIsDirectory() throws IOException { - assertTrue(HttpUtils.isDirectory(new URL(APACHE_SVN_SITE + PARENT_URL_OF_THIS_TEST), "")); - assertFalse(HttpUtils.isDirectory(new URL(APACHE_SVN_SITE + URL_OF_THIS_TEST), "")); - assertTrue(HttpUtils.isDirectory(new URL(APACHE_SVN_SITE), "")); - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/imaps/.gitignore ---------------------------------------------------------------------- diff --git a/protocol/imaps/.gitignore b/protocol/imaps/.gitignore deleted file mode 100644 index b54523f..0000000 --- a/protocol/imaps/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/maven-eclipse.xml http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/imaps/pom.xml ---------------------------------------------------------------------- diff --git a/protocol/imaps/pom.xml b/protocol/imaps/pom.xml deleted file mode 100644 index 9e54a1f..0000000 --- a/protocol/imaps/pom.xml +++ /dev/null @@ -1,114 +0,0 @@ -<?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>1.1-SNAPSHOT</version> - <relativePath>../../core/pom.xml</relativePath> - </parent> - <artifactId>cas-protocol-imaps</artifactId> - <name>CAS Protocol IMAPS Implementation</name> - <!-- All dependencies should be listed in core/pom.xml and be ordered alphabetically by package and artifact. - Once the dependency is in the core pom, it can then be used in other modules without the version tags. - For example, within core/pom.xml: - - <dependency> - <groupId>com.amazonaws</groupId> - <artifactId>aws-java-sdk</artifactId> - <version>1.7.4</version> - </dependency> - - Elsewhere in the platform: - <dependency> - <groupId>com.amazonaws</groupId> - <artifactId>aws-java-sdk</artifactId> - </dependency> - - Where possible the same dependency version should be used across the whole platform but if required the version - can be overridden in a specific pom and should have a comment explaing why the version has been overridden - --> - <dependencies> - <dependency> - <groupId>com.icegreen</groupId> - <artifactId>greenmail</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.geronimo.javamail</groupId> - <artifactId>geronimo-javamail_1.4_mail</artifactId> - </dependency> - <dependency> - <groupId>org.apache.geronimo.specs</groupId> - <artifactId>geronimo-activation_1.1_spec</artifactId> - </dependency> - <dependency> - <groupId>org.apache.oodt</groupId> - <artifactId>cas-protocol-api</artifactId> - </dependency> - <dependency> - <groupId>org.apache.tika</groupId> - <artifactId>tika-parsers</artifactId> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-simple</artifactId> - </dependency> - </dependencies> - <build> - <resources> - <resource> - <targetPath>org/apache/oodt/cas/protocol/imaps</targetPath> - <directory>${basedir}/src/main/resources/policy</directory> - <includes> - <include>imaps-protocol-config.xml</include> - </includes> - </resource> - </resources> - </build> - <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> - <goals> - <goal>check</goal> - </goals> - <phase>verify</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocol.java ---------------------------------------------------------------------- diff --git a/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocol.java b/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocol.java deleted file mode 100644 index ce47398..0000000 --- a/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocol.java +++ /dev/null @@ -1,385 +0,0 @@ -/* - * 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.protocol.imaps; - -//JDK imports -import org.apache.oodt.cas.protocol.Protocol; -import org.apache.oodt.cas.protocol.ProtocolFile; -import org.apache.oodt.cas.protocol.auth.Authentication; -import org.apache.oodt.cas.protocol.exceptions.ProtocolException; -import org.apache.oodt.cas.protocol.util.ProtocolFileFilter; -import org.apache.tika.exception.TikaException; -import org.apache.tika.metadata.Metadata; -import org.apache.tika.parser.html.HtmlParser; -import org.apache.tika.sax.BodyContentHandler; -import org.apache.tika.sax.TextContentHandler; - -import org.xml.sax.SAXException; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import javax.mail.Address; -import javax.mail.Flags; -import javax.mail.Folder; -import javax.mail.Header; -import javax.mail.Message; -import javax.mail.MessagingException; -import javax.mail.Multipart; -import javax.mail.Part; -import javax.mail.Session; -import javax.mail.Store; - - -/** - * IMAP Secure {@link Protocol} implementation - * - * @author bfoster - * @version $Revision$ - */ -public class ImapsProtocol implements Protocol { - - static Store store; - - static Folder currentFolder; - - static Folder homeFolder; - - static int port = 993; - - static Session session; - - static int openCalls = 0; - - static int connectCalls = 0; - - public synchronized void cd(ProtocolFile file) throws ProtocolException { - try { - String remotePath = file.getPath(); - if (remotePath.startsWith("/")) { - remotePath = remotePath.substring(1); - } - if (remotePath.trim().equals("")) { - homeFolder = currentFolder = store.getDefaultFolder(); - } else { - homeFolder = currentFolder = store.getFolder(remotePath); - } - } catch (Exception e) { - throw new ProtocolException("Failed to change directory to '" - + file + "' : " + e.getMessage(), e); - } - } - - public synchronized void cdRoot() throws ProtocolException { - try { - cd(new ProtocolFile("/", true)); - } catch (Exception e) { - throw new ProtocolException("Failed to cd to root : " + e.getMessage(), e); - } - } - - public synchronized void cdHome() throws ProtocolException { - try { - cd(new ProtocolFile("", true)); - } catch (Exception e) { - throw new ProtocolException("Failed to cd to home : " + e.getMessage(), e); - } - } - - public synchronized void connect(String host, Authentication auth) - throws ProtocolException { - try { - if (store == null) { - store = (session = Session.getInstance(System.getProperties())) - .getStore("imaps"); - store.connect(host, port, auth.getUser(), auth.getPass()); - currentFolder = store.getDefaultFolder(); - } - this.incrementConnections(); - } catch (Exception e) { - throw new ProtocolException("Failed to connected to IMAPS server " + host - + " with username " + auth.getUser() + " : " + e.getMessage(), e); - } - } - - public synchronized void close() throws ProtocolException { - decrementConnections(); - if (connectCalls <= 0) { - try { - store.close(); - } catch (Exception e) { - throw new ProtocolException("Failed to close connection : " + e.getMessage(), e); - } finally { - store = null; - } - } - } - - private synchronized void incrementConnections() { - connectCalls++; - } - - private synchronized void decrementConnections() { - if (connectCalls > 0) { - connectCalls--; - } - } - - public synchronized void get(ProtocolFile fromFile, File toFile) - throws ProtocolException { - try { - openFolder(currentFolder); - Message[] messages = currentFolder.getMessages(); - for (Message message : messages) { - if (this.getMessageName(message).equals(fromFile.getName())) { - writeMessageToLocalFile(message, toFile); - break; - } - } - } catch (Exception e) { - throw new ProtocolException("Failed to download " + fromFile + " to " - + toFile + " : " + e.getMessage(), e); - } finally { - try { - closeFolder(currentFolder); - } catch (Exception ignored) { - } - } - } - - public synchronized void put(File fromFile, ProtocolFile toFile) { - //do nothing; - } - - private void writeMessageToLocalFile(Message message, File toLocalFile) - throws MessagingException, IOException, SAXException, - TikaException { - PrintStream ps = new PrintStream(new FileOutputStream(toLocalFile)); - - ps.print("From:"); - Address[] senders = message.getFrom(); - for (Address address : senders) { - ps.print(" " + address.toString()); - } - - ps.print("\nTo:"); - Set<Address> recipients = new LinkedHashSet<Address>(Arrays.asList(message - .getAllRecipients())); - for (Address address : recipients) { - ps.print(" " + address.toString()); - } - - ps.println("\nSubject: " + message.getSubject()); - - ps.println("----- ~ Message ~ -----"); - String content = this.getContentFromHTML(message); - if (content.equals("")) { - content = this.getContentFromPlainText(message); - } - ps.println(content); - - ps.close(); - } - - public synchronized boolean connected() { - return store.isConnected(); - } - - public List<ProtocolFile> ls() throws ProtocolException { - LinkedList<ProtocolFile> currentFilesForCurrentFolder = new LinkedList<ProtocolFile>(); - try { - openFolder(currentFolder); - if (!currentFolder.getFullName().equals( - store.getDefaultFolder().getFullName())) { - Message[] messages = currentFolder.getMessages(); - for (Message message : messages) { - currentFilesForCurrentFolder.add(new ProtocolFile(this.pwd().getPath() - + "/" + this.getMessageName(message), false)); - } - } - // changedDir = false; - } catch (Exception e) { - if (!currentFolder.getFullName().equals("")) { - throw new ProtocolException("Failed to ls : " + e.getMessage(), e); - } - } finally { - try { - closeFolder(currentFolder); - } catch (Exception ignored) { - } - } - // } - return currentFilesForCurrentFolder; - } - - public List<ProtocolFile> ls(ProtocolFileFilter filter) - throws ProtocolException { - LinkedList<ProtocolFile> currentFilesForCurrentFolder = new LinkedList<ProtocolFile>(); - try { - openFolder(currentFolder); - if (!currentFolder.getFullName().equals( - store.getDefaultFolder().getFullName())) { - Message[] messages = currentFolder.getMessages(); - for (Message message : messages) { - ProtocolFile pFile = new ProtocolFile(this.pwd().getPath() - + "/" + this.getMessageName(message), false); - if (filter.accept(pFile)) { - currentFilesForCurrentFolder.add(pFile); - } - } - } - } catch (Exception e) { - if (!currentFolder.getFullName().equals("")) { - throw new ProtocolException("Failed to ls : " + e.getMessage(), e); - } - } finally { - try { - closeFolder(currentFolder); - } catch (Exception ignored) { - } - } - return currentFilesForCurrentFolder; - } - - public synchronized ProtocolFile pwd() - throws ProtocolException { - try { - String pwd = currentFolder.getFullName(); - if (!pwd.equals("") && !pwd.startsWith("/")) { - pwd = "/" + pwd; - } - return new ProtocolFile(pwd, true); - } catch (Exception e) { - throw new ProtocolException("Failed to pwd : " + e.getMessage(), e); - } - } - - private String getMessageName(Message msg) throws MessagingException { - Enumeration headers = msg.getAllHeaders(); - while (headers.hasMoreElements()) { - Header header = (Header) headers.nextElement(); - if (header.getName().toLowerCase().equals("message-id")) { - String stringHeader = header.getValue(); - stringHeader = stringHeader.replace("<", ""); - return stringHeader.substring(0, stringHeader.indexOf("@")); - } - } - return null; - } - - private String getContentFromPlainText(Part p) throws MessagingException, - IOException { - StringBuilder content = new StringBuilder(""); - if (p.isMimeType("text/plain")) { - content.append((String) p.getContent()); - } else if (p.isMimeType("multipart/*")) { - Multipart mp = (Multipart) p.getContent(); - int count = mp.getCount(); - for (int i = 0; i < count; i++) { - content.append(getContentFromPlainText(mp.getBodyPart(i))); - } - } else { - Object obj = p.getContent(); - if (obj instanceof Part) { - content.append(getContentFromPlainText((Part) p.getContent())); - } - } - return content.toString().replaceAll(" \\r\\n", "").replaceAll(" \\n", ""); - } - - private String getContentFromHTML(Part p) throws MessagingException, - IOException, SAXException, TikaException { - StringBuilder content = new StringBuilder(""); - if (p.isMimeType("multipart/*")) { - Multipart mp = (Multipart) p.getContent(); - int count = mp.getCount(); - for (int i = 0; i < count; i++) { - content.append(getContentFromHTML(mp.getBodyPart(i))); - } - } else if (p.isMimeType("text/html")) { - HtmlParser parser = new HtmlParser(); - Metadata met = new Metadata(); - TextContentHandler handler = new TextContentHandler( - new BodyContentHandler()); - parser.parse(new ByteArrayInputStream(((String) p.getContent()) - .getBytes()), handler, met); - content.append(handler.toString()); - } else { - Object obj = p.getContent(); - if (obj instanceof Part) { - content.append(getContentFromHTML((Part) p.getContent())); - } - } - return content.toString(); - } - - private synchronized void openFolder(Folder folder) throws ProtocolException { - if (!folder.isOpen()) { - try { - folder.open(Folder.READ_WRITE); - } catch (Exception e) { - try { - folder.open(Folder.READ_ONLY); - } catch (Exception e2) { - throw new ProtocolException("Failed to open folder : " - + e.getMessage() + " : " + e2.getMessage()); - } - } - } - openCalls++; - } - - private synchronized void closeFolder(Folder folder) { - if (openCalls > 0) { - openCalls--; - } - - if (openCalls <= 0) { - try { - folder.close(true); - } catch (Exception ignored) { - } - } - } - - public synchronized void delete(ProtocolFile file) throws ProtocolException { - try { - openFolder(currentFolder); - Message[] messages = currentFolder.getMessages(); - for (Message message : messages) { - if (this.getMessageName(message).equals(file.getName())) { - message.setFlag(Flags.Flag.DELETED, true); - break; - } - } - } catch (Exception e) { - throw new ProtocolException("Failed to delete file '" + file + "' : " + e.getMessage(), e); - } finally { - closeFolder(currentFolder); - } - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocolFactory.java ---------------------------------------------------------------------- diff --git a/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocolFactory.java b/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocolFactory.java deleted file mode 100644 index b3a83b9..0000000 --- a/protocol/imaps/src/main/java/org/apache/oodt/cas/protocol/imaps/ImapsProtocolFactory.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.protocol.imaps; - -//OODT imports -import org.apache.oodt.cas.protocol.ProtocolFactory; - -/** - * Factory for creating {@link ImapsProtocol}s. - * - * @author bfoster - * @version $Revision$ - */ -public class ImapsProtocolFactory implements ProtocolFactory { - - private ImapsProtocol imapsClient; - - public ImapsProtocol newInstance() { - if (this.imapsClient == null) { - this.imapsClient = new ImapsProtocol(); - } - return this.imapsClient; - } - - public String getSchema() { - return "imaps"; - } - -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/imaps/src/main/resources/policy/imaps-protocol-config.xml ---------------------------------------------------------------------- diff --git a/protocol/imaps/src/main/resources/policy/imaps-protocol-config.xml b/protocol/imaps/src/main/resources/policy/imaps-protocol-config.xml deleted file mode 100644 index da206b4..0000000 --- a/protocol/imaps/src/main/resources/policy/imaps-protocol-config.xml +++ /dev/null @@ -1,31 +0,0 @@ -<?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. ---> -<!-- - - Author: bfoster - Description: ProtocolManager Configuration - ---> -<beans xmlns="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:p="http://www.springframework.org/schema/p" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - - <bean class="org.apache.oodt.cas.protocol.imaps.ImapsProtocolFactory"/> - -</beans> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/imaps/src/test/java/org/apache/oodt/cas/protocol/imaps/TestImapsProtocol.java ---------------------------------------------------------------------- diff --git a/protocol/imaps/src/test/java/org/apache/oodt/cas/protocol/imaps/TestImapsProtocol.java b/protocol/imaps/src/test/java/org/apache/oodt/cas/protocol/imaps/TestImapsProtocol.java deleted file mode 100644 index f2b78b3..0000000 --- a/protocol/imaps/src/test/java/org/apache/oodt/cas/protocol/imaps/TestImapsProtocol.java +++ /dev/null @@ -1,112 +0,0 @@ -/* - * 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.protocol.imaps; - -//JDK imports -import java.io.File; -import java.io.IOException; -import java.util.List; - -//Apache imports -import org.apache.commons.io.FileUtils; - -//OODT imports -import org.apache.oodt.cas.protocol.ProtocolFile; -import org.apache.oodt.cas.protocol.auth.BasicAuthentication; -import org.apache.oodt.cas.protocol.exceptions.ProtocolException; - -//GreenMail imports -import com.icegreen.greenmail.util.DummySSLSocketFactory; -import com.icegreen.greenmail.util.GreenMail; -import com.icegreen.greenmail.util.GreenMailUtil; - -//JUnit imports -import junit.framework.TestCase; - -/** - * Test class for {@link ImapsProtocol}. - * - * @author bfoster - */ -public class TestImapsProtocol extends TestCase { - - private GreenMail gMail; - private ImapsProtocol imapsProtocol; - - @Override - public void setUp() { - System.setProperty("mail.imaps.socketFactory.class", DummySSLSocketFactory.class.getCanonicalName()); - System.setProperty("mail.imaps.socketFactory.fallback", "false"); - gMail = new GreenMail(); - gMail.setUser("[email protected]", "password"); - gMail.start(); - ImapsProtocol.port = gMail.getImaps().getPort(); - imapsProtocol = new ImapsProtocol(); - try { - imapsProtocol.connect("localhost", new BasicAuthentication("[email protected]", "password")); - } catch (ProtocolException e) { - fail("Failed to connect to GreenMail IMAPS server : " + e.getMessage()); - } - assertEquals(1, ImapsProtocol.connectCalls); - } - - @Override - public void tearDown() { - gMail.stop(); - try { - imapsProtocol.close(); - } catch (Exception ignored) {} - assertEquals(0, ImapsProtocol.connectCalls); - } - - public void testCDAndPWD() throws ProtocolException { - assertEquals("", imapsProtocol.pwd().getPath()); - imapsProtocol.cd(new ProtocolFile("INBOX", true)); - assertEquals("/INBOX", imapsProtocol.pwd().getPath()); - } - - public void testLSandGET() throws ProtocolException, IOException { - GreenMailUtil.sendTextEmailSecureTest("[email protected]", "[email protected]", "Test Subject", "Test Body"); - imapsProtocol.cd(new ProtocolFile("INBOX", true)); - List<ProtocolFile> emails = imapsProtocol.ls(); - assertEquals(1, emails.size()); - File bogusFile = File.createTempFile("bogus", "bogus"); - File tmpDir = new File(bogusFile.getParentFile(), "TestImapsProtocol"); - bogusFile.delete(); - tmpDir.mkdirs(); - - File email = new File(tmpDir, "test-email"); - imapsProtocol.get(emails.get(0), email); - String[] splitEmail = FileUtils.readFileToString(email, "UTF-8").split("\n"); - assertEquals("From: [email protected]", splitEmail[0]); - assertEquals("To: [email protected]", splitEmail[1]); - assertEquals("Subject: Test Subject", splitEmail[2]); - // 3 is divider text (i.e. ----- ~ Message ~ -----) - assertEquals("Test Body", splitEmail[4]); - tmpDir.delete(); - } - - public void testDelete() throws ProtocolException { - GreenMailUtil.sendTextEmailSecureTest("[email protected]", "[email protected]", "Test Subject", "Test Body"); - imapsProtocol.cd(new ProtocolFile("INBOX", true)); - List<ProtocolFile> emails = imapsProtocol.ls(); - assertEquals(1, emails.size()); - imapsProtocol.delete(emails.get(0)); - emails = imapsProtocol.ls(); - assertEquals(0, emails.size()); - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/sftp/.gitignore ---------------------------------------------------------------------- diff --git a/protocol/sftp/.gitignore b/protocol/sftp/.gitignore deleted file mode 100644 index b54523f..0000000 --- a/protocol/sftp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/maven-eclipse.xml http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/sftp/pom.xml ---------------------------------------------------------------------- diff --git a/protocol/sftp/pom.xml b/protocol/sftp/pom.xml deleted file mode 100644 index 71ab9df..0000000 --- a/protocol/sftp/pom.xml +++ /dev/null @@ -1,140 +0,0 @@ -<?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>1.1-SNAPSHOT</version> - <relativePath>../../core/pom.xml</relativePath> - </parent> - <artifactId>cas-protocol-sftp</artifactId> - <name>CAS Protocol SFTP Implementation</name> - <!-- All dependencies should be listed in core/pom.xml and be ordered alphabetically by package and artifact. - Once the dependency is in the core pom, it can then be used in other modules without the version tags. - For example, within core/pom.xml: - - <dependency> - <groupId>com.amazonaws</groupId> - <artifactId>aws-java-sdk</artifactId> - <version>1.7.4</version> - </dependency> - - Elsewhere in the platform: - <dependency> - <groupId>com.amazonaws</groupId> - <artifactId>aws-java-sdk</artifactId> - </dependency> - - Where possible the same dependency version should be used across the whole platform but if required the version - can be overridden in a specific pom and should have a comment explaing why the version has been overridden - --> - <dependencies> - <dependency> - <groupId>com.jcraft</groupId> - <artifactId>jsch</artifactId> - <version>0.1.42</version> - </dependency> - <dependency> - <groupId>commons-io</groupId> - <artifactId>commons-io</artifactId> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <version>1.0.3</version> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>3.8.2</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.mina</groupId> - <artifactId>mina-core</artifactId> - <version>2.0.4</version> - </dependency> - <dependency> - <groupId>org.apache.oodt</groupId> - <artifactId>cas-protocol-api</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-all</artifactId> - <version>1.3</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>1.9.5</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>sshtools</groupId> - <artifactId>j2ssh-core</artifactId> - <version>0.2.9</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>sshtools</groupId> - <artifactId>j2ssh-daemon</artifactId> - <version>0.2.9</version> - <scope>test</scope> - </dependency> - - </dependencies> - <build> - <resources> - <resource> - <targetPath>org/apache/oodt/cas/protocol/sftp</targetPath> - <directory>${basedir}/src/main/resources/policy</directory> - <includes> - <include>sftp-protocol-config.xml</include> - </includes> - </resource> - </resources> - </build> - <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> - <numUnapprovedLicenses>3</numUnapprovedLicenses> - </configuration> - <executions> - <execution> - <goals> - <goal>check</goal> - </goals> - <phase>verify</phase> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> -</project> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java ---------------------------------------------------------------------- diff --git a/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java b/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java deleted file mode 100644 index 1ddbe45..0000000 --- a/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocol.java +++ /dev/null @@ -1,211 +0,0 @@ -/* - * 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.protocol.sftp; - -//OODT imports -import org.apache.oodt.cas.protocol.auth.Authentication; -import org.apache.oodt.cas.protocol.exceptions.ProtocolException; -import org.apache.oodt.cas.protocol.sftp.auth.HostKeyAuthentication; -import org.apache.oodt.cas.protocol.util.ProtocolFileFilter; -import org.apache.oodt.cas.protocol.Protocol; -import org.apache.oodt.cas.protocol.ProtocolFile; - -//JSCH imports -import com.jcraft.jsch.ChannelSftp; -import com.jcraft.jsch.JSch; -import com.jcraft.jsch.Session; -import com.jcraft.jsch.UserInfo; - -//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 JschSftpProtocol implements Protocol { - - public static final int PORT = 22; - private Session session; - - private ChannelSftp sftpChannel; - - private ProtocolFile homeDir; - - private int port; - - private static final JSch jsch = new JSch(); - - public JschSftpProtocol() { - this(PORT); - } - - public JschSftpProtocol(int port) { - session = null; - sftpChannel = null; - this.port = port; - } - - public void cd(ProtocolFile file) throws ProtocolException { - try { - sftpChannel.cd(file.getPath()); - } catch (Exception e) { - throw new ProtocolException("Failed to cd to " + file + " : " - + e.getMessage()); - } - } - - public void cdRoot() throws ProtocolException { - cd(new ProtocolFile(ProtocolFile.SEPARATOR, true)); - } - - public void cdHome() throws ProtocolException { - cd(homeDir); - } - - public void connect(String host, final Authentication auth) throws ProtocolException { - try { - if (auth instanceof HostKeyAuthentication) { - jsch.setKnownHosts(((HostKeyAuthentication) auth).getHostKeyFile()); - } else { - jsch.setKnownHosts(System.getProperty("user.home") + "/.ssh/known_hosts"); - } - session = jsch.getSession(auth.getUser(), host, this.port); - session.setUserInfo(new UserInfo() { - public String getPassphrase() { - return (auth instanceof HostKeyAuthentication) ? ((HostKeyAuthentication) auth) - .getPassphrase() : null; - } - public String getPassword() { - return auth.getPass(); - } - public boolean promptPassphrase(String arg0) { - return (auth instanceof HostKeyAuthentication && ((HostKeyAuthentication) auth) - .getPassphrase() != null); - } - public boolean promptPassword(String arg0) { - return true; - } - public boolean promptYesNo(String arg0) { - return false; - } - public void showMessage(String arg0) {} - }); - session.connect(); - sftpChannel = (ChannelSftp) session.openChannel("sftp"); - sftpChannel.connect(); - homeDir = pwd(); - } catch (Exception e) { - throw new ProtocolException("Failed to connect to host " + host + " : " - + e.getMessage(), e); - } - } - - public void close() throws ProtocolException { - session.disconnect(); - } - - public void get(ProtocolFile fromFile, File toFile) - throws ProtocolException { - try { - sftpChannel.get(fromFile.getPath(), toFile - .getAbsolutePath()); - } catch (Exception e) { - throw new ProtocolException("Failed to download " + fromFile + " : " - + e.getMessage()); - } - } - - public void put(File fromFile, ProtocolFile toFile) throws ProtocolException { - try { - sftpChannel.put(fromFile.getAbsolutePath(), toFile.getPath()); - } catch (Exception e) { - throw new ProtocolException("Failed to put file '" + fromFile + "' : " + e.getMessage(), e); - } - } - - public List<ProtocolFile> ls() 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().getPath(); - returnFiles.add(new ProtocolFile(path + "/" + sftpFile.getFilename(), sftpFile - .getAttrs().isDir())); - } - return returnFiles; - } catch (Exception e) { - throw new ProtocolException("Failed to get file list : " + e.getMessage()); - } - } - - public List<ProtocolFile> ls(ProtocolFileFilter filter) - 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().getPath(); - ProtocolFile pFile = new ProtocolFile(path + "/" + sftpFile.getFilename(), sftpFile - .getAttrs().isDir()); - if (filter.accept(pFile)) { - returnFiles.add(pFile); - } - } - return returnFiles; - } catch (Exception e) { - throw new ProtocolException("Failed to get file list : " + e.getMessage()); - } - } - - public ProtocolFile pwd() throws ProtocolException { - try { - return new ProtocolFile(sftpChannel.pwd(), true); - } catch (Exception e) { - throw new ProtocolException("Failed to pwd : " + e.getMessage()); - } - } - - public boolean connected() { - return session.isConnected(); - } - - public void delete(ProtocolFile file) throws ProtocolException { - try { - if (file.isDir()) { - sftpChannel.rmdir(file.getPath()); - } else { - sftpChannel.rm(file.getPath()); - } - } catch (Exception e) { - throw new ProtocolException("Failed to download file '" + file + "' : " + e.getMessage(), e); - } - } - - public JschSftpProtocol createJschSftpProtocol(int port){ - return new JschSftpProtocol(port); - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java ---------------------------------------------------------------------- diff --git a/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java b/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java deleted file mode 100644 index c36829a..0000000 --- a/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/JschSftpProtocolFactory.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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.protocol.sftp; - -//OODT imports -import org.apache.oodt.cas.protocol.ProtocolFactory; - -/** - * Creates new {@link JschSftpProtocol}s. - * - * @author bfoster - * @author mattmann - * @version $Revision$ - */ -public class JschSftpProtocolFactory implements ProtocolFactory { - - private int port = -1; - - public JschSftpProtocol newInstance() { - if (port > 0) { - return new JschSftpProtocol(port); - } else { - return new JschSftpProtocol(); - } - } - - public String getSchema() { - return "sftp"; - } - - public void setPort(int port) { - this.port = port; - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java ---------------------------------------------------------------------- diff --git a/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java b/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java deleted file mode 100644 index 0384734..0000000 --- a/protocol/sftp/src/main/java/org/apache/oodt/cas/protocol/sftp/auth/HostKeyAuthentication.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.protocol.sftp.auth; - -//OODT imports -import org.apache.oodt.cas.protocol.auth.BasicAuthentication; - -/** - * {@link Authentication} implementation allowing a SSH host key file to be specified. - * - * @author bfoster - */ -public class HostKeyAuthentication extends BasicAuthentication { - - private String hostKeyFile; - private String passphrase; - - public HostKeyAuthentication(String user, String pass, String hostKeyFile) { - this(user, pass, hostKeyFile, null); - } - - public HostKeyAuthentication(String user, String pass, String hostKeyFile, String passphrase) { - super(user, pass); - this.hostKeyFile = hostKeyFile; - this.passphrase = passphrase; - } - - public String getHostKeyFile() { - return hostKeyFile; - } - - public String getPassphrase() { - return passphrase; - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/sftp/src/main/resources/policy/sftp-protocol-config.xml ---------------------------------------------------------------------- diff --git a/protocol/sftp/src/main/resources/policy/sftp-protocol-config.xml b/protocol/sftp/src/main/resources/policy/sftp-protocol-config.xml deleted file mode 100644 index de44a3f..0000000 --- a/protocol/sftp/src/main/resources/policy/sftp-protocol-config.xml +++ /dev/null @@ -1,23 +0,0 @@ -<?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="http://www.springframework.org/schema/beans" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:p="http://www.springframework.org/schema/p" - xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"> - - <bean class="org.apache.oodt.cas.protocol.sftp.JschSftpProtocolFactory"/> - -</beans> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/protocol/sftp/src/test/java/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java ---------------------------------------------------------------------- diff --git a/protocol/sftp/src/test/java/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java b/protocol/sftp/src/test/java/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java deleted file mode 100644 index 61da8ec..0000000 --- a/protocol/sftp/src/test/java/org/apache/oodt/cas/protocol/sftp/DummyAuthenticationProvider.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.protocol.sftp; - -//JDK imports -import java.io.File; -import java.io.IOException; - -//Apache imports -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -//SshTools imports -import com.sshtools.daemon.platform.NativeAuthenticationProvider; -import com.sshtools.daemon.platform.PasswordChangeException; - -/** - * This authentication provider provides no authentication at all, and just lets - * anybody in so you should never use it! - * - * It is really just for testing. - */ -public class DummyAuthenticationProvider extends NativeAuthenticationProvider { - - Log log = LogFactory.getLog(DummyAuthenticationProvider.class); - - public DummyAuthenticationProvider() { - log.error("DummyAuthenticationProvider is in use. This is only for testing."); - } - - @Override - public boolean changePassword(String username, String oldpassword, - String newpassword) { - return false; - } - - @Override - public String getHomeDirectory(String username) throws IOException { - return new File("src/test/resources").getAbsolutePath(); - } - - @Override - public void logoffUser() throws IOException { - - } - - @Override - public boolean logonUser(String username, String password) - throws PasswordChangeException, IOException { - return true; - } - - @Override - public boolean logonUser(String username) throws IOException { - return true; - } -}
