http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/test/java/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java ---------------------------------------------------------------------- diff --git a/catalog/src/test/java/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java b/catalog/src/test/java/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java deleted file mode 100644 index 3c6d283..0000000 --- a/catalog/src/test/java/org/apache/oodt/cas/catalog/system/impl/TestCatalogServiceLocal.java +++ /dev/null @@ -1,204 +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.catalog.system.impl; - -//JDK imports - -import org.apache.commons.io.FileUtils; -import org.apache.oodt.cas.catalog.exception.CatalogServiceException; -import org.apache.oodt.cas.catalog.mapping.InMemoryIngestMapperFactory; -import org.apache.oodt.cas.catalog.metadata.TransactionalMetadata; -import org.apache.oodt.cas.catalog.page.Page; -import org.apache.oodt.cas.catalog.page.PageInfo; -import org.apache.oodt.cas.catalog.page.QueryPager; -import org.apache.oodt.cas.catalog.page.TransactionReceipt; -import org.apache.oodt.cas.catalog.query.QueryExpression; -import org.apache.oodt.cas.catalog.query.parser.ParseException; -import org.apache.oodt.cas.catalog.query.parser.QueryParser; -import org.apache.oodt.cas.catalog.query.parser.TokenMgrError; -import org.apache.oodt.cas.catalog.repository.MemoryBasedCatalogRepositoryFactory; -import org.apache.oodt.cas.catalog.struct.impl.index.DataSourceIndexFactory; -import org.apache.oodt.cas.catalog.struct.impl.index.InMemoryIndexFactory; -import org.apache.oodt.cas.catalog.struct.impl.transaction.UuidTransactionIdFactory; -import org.apache.oodt.cas.catalog.system.CatalogFactory; -import org.apache.oodt.cas.metadata.Metadata; - -import java.io.File; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Vector; -import java.util.logging.Level; -import java.util.logging.Logger; - -import junit.framework.TestCase; - -//OODT imports - -/** - * - * @author bfoster - * @version $Revision$ - * - */ -public class TestCatalogServiceLocal extends TestCase { - - private CatalogServiceLocal cs; - private File testDir; - private static Logger LOG = Logger.getLogger(TestCatalogServiceLocal.class.getName()); - public void setUp() { - try { - File tempFile = File.createTempFile("foo", "bar"); - tempFile.deleteOnExit(); - testDir = new File(tempFile.getParentFile(), "cas-catalog"); - - CatalogServiceLocalFactory factory = new CatalogServiceLocalFactory(); - factory - .setCatalogRepositoryFactory(new MemoryBasedCatalogRepositoryFactory()); - factory.setIngestMapperFactory(this - .getOracleIngestMapperFactory(testDir.getAbsolutePath() + "/mapper")); - factory.setOneCatalogFailsAllFail(true); - factory.setSimplifyQueries(true); - factory.setPluginStorageDir("/dev/null"); - factory.setRestrictIngestPermissions(false); - factory.setRestrictQueryPermissions(false); - factory.setTransactionIdFactory(UuidTransactionIdFactory.class - .getCanonicalName()); - cs = factory.createCatalogService(); - - CatalogFactory catalogFactory = new CatalogFactory(); - catalogFactory.setCatalogId("TestCatalog1"); - catalogFactory.setDictionaryFactories(null); - catalogFactory - .setIndexFactory(getInMemoryDSFactory(testDir.getAbsolutePath() + "/index/1/")); - catalogFactory.setRestrictIngestPermissions(false); - catalogFactory.setRestrictQueryPermissions(false); - cs.addCatalog(catalogFactory.createCatalog()); - catalogFactory.setCatalogId("TestCatalog2"); - catalogFactory - .setIndexFactory(getInMemoryDSFactory(testDir.getAbsolutePath() + "/index/2/")); - cs.addCatalog(catalogFactory.createCatalog()); - }catch (Exception e) { - LOG.log(Level.SEVERE, e.getMessage()); - TestCase.fail(e.getMessage()); - } - } - - public void tearDown() { - try { - FileUtils.forceDelete(this.testDir); - } catch (IOException e) { - LOG.log(Level.SEVERE, e.getMessage()); - TestCase.fail(e.getMessage()); - } - } - - public void testDataSourceCatalogIngestQueryAndDelete() - throws CatalogServiceException, ParseException, TokenMgrError { - // test ingest - Metadata m = new Metadata(); - m.addMetadata("testkey1", "testval1"); - TransactionReceipt tr = cs.ingest(m); - Vector<TransactionReceipt> receipts = new Vector<TransactionReceipt>(); - receipts.add(tr); - List<TransactionalMetadata> metadatas = cs.getMetadata(receipts); - assertEquals(metadatas.size(), 1); - Metadata ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - // test ingest update - m.replaceMetadata( - CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, tr.getTransactionId().toString()); - m.replaceMetadata(CatalogServiceLocal.ENABLE_UPDATE_MET_KEY, "true"); - tr = cs.ingest(m); - receipts = new Vector<TransactionReceipt>(); - receipts.add(tr); - metadatas = cs.getMetadata(receipts); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - // test query using querypager - QueryExpression qe = QueryParser - .parseQueryExpression("testkey1 == 'testval1'"); - QueryPager pager = cs.query(qe); - metadatas = cs.getNextPage(pager); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - // test query using std paging - qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'"); - Page page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe); - metadatas = cs.getMetadata(page); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 2); - - // test query using std paging with catalog restriction - qe = QueryParser.parseQueryExpression("testkey1 == 'testval1'"); - page = cs.getPage(new PageInfo(20, PageInfo.FIRST_PAGE), qe, - Collections.singleton("TestCatalog1")); - metadatas = cs.getMetadata(page); - assertEquals(metadatas.size(), 1); - ingestedMetadata = metadatas.get(0).getMetadata(); - assertEquals(ingestedMetadata.getMetadata("testkey1"), "testval1"); - assertEquals(ingestedMetadata.getAllMetadata("testkey1").size(), 1); - - // test delete - m = new Metadata(); - m.addMetadata(CatalogServiceLocal.CATALOG_SERVICE_TRANSACTION_ID_MET_KEY, tr.getTransactionId().toString()); - cs.delete(m); - assertEquals(cs.getMetadata(Collections.singletonList(tr)).size(), 0); - } - - private InMemoryIngestMapperFactory getOracleIngestMapperFactory( - String tmpDirPath) { - String user = "sa"; - String pass = ""; - String driver = "org.hsqldb.jdbcDriver"; - String url = "jdbc:hsqldb:file:" + tmpDirPath + ";shutdown=true"; - - InMemoryIngestMapperFactory factory = new InMemoryIngestMapperFactory(); - factory.setDriver(driver); - factory.setJdbcUrl(url); - factory.setPass(pass); - factory.setUser(user); - factory.setTablesFile(this.getClass().getResource("/test-mapper-cat.sql").getPath()); - return factory; - } - - private DataSourceIndexFactory getInMemoryDSFactory(String tmpDirPath) { - String user = "sa"; - String pass = ""; - String driver = "org.hsqldb.jdbcDriver"; - String url = "jdbc:hsqldb:file:" + tmpDirPath + ";shutdown=true"; - - InMemoryIndexFactory indexFactory = new InMemoryIndexFactory(); - indexFactory.setDriver(driver); - indexFactory.setJdbcUrl(url); - indexFactory.setPass(pass); - indexFactory.setUser(user); - indexFactory.setTablesFile(this.getClass().getResource("/test-index-cat.sql").getPath()); - return indexFactory; - } - -}
http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/test/resources/test-index-cat.sql ---------------------------------------------------------------------- diff --git a/catalog/src/test/resources/test-index-cat.sql b/catalog/src/test/resources/test-index-cat.sql deleted file mode 100644 index fbbd46e..0000000 --- a/catalog/src/test/resources/test-index-cat.sql +++ /dev/null @@ -1,32 +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. - -DROP TABLE transactions IF EXISTS; -DROP TABLE transaction_terms IF EXISTS; - -CREATE TABLE transactions -( - transaction_id varchar(256) NOT NULL, - transaction_date varchar(256) NOT NULL -); - -CREATE TABLE transaction_terms -( - transaction_id varchar(256) NOT NULL, - bucket_name varchar(256) NOT NULL, - term_name varchar(256) NOT NULL, - term_value varchar(1000) NOT NULL -); - http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/catalog/src/test/resources/test-mapper-cat.sql ---------------------------------------------------------------------- diff --git a/catalog/src/test/resources/test-mapper-cat.sql b/catalog/src/test/resources/test-mapper-cat.sql deleted file mode 100644 index 571a36e..0000000 --- a/catalog/src/test/resources/test-mapper-cat.sql +++ /dev/null @@ -1,26 +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. - -DROP TABLE CatalogServiceMapper IF EXISTS; - -CREATE TABLE CatalogServiceMapper ( - CAT_SERV_TRANS_ID VARCHAR(255) NOT NULL , - CAT_SERV_TRANS_FACTORY VARCHAR(255) NOT NULL , - CAT_TRANS_ID VARCHAR(255) NOT NULL , - CAT_TRANS_FACTORY VARCHAR(255) NOT NULL , - CAT_TRANS_DATE VARCHAR(255) NOT NULL , - CATALOG_ID VARCHAR(255) NOT NULL -); - http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/docker/Dockerfile ---------------------------------------------------------------------- diff --git a/docker/Dockerfile b/docker/Dockerfile deleted file mode 100644 index 3180f57..0000000 --- a/docker/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM ubuntu:latest -MAINTAINER Tom Barber - -ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/ - -RUN apt-get update -RUN apt-get install -y openjdk-8-jre-headless openjdk-8-jre maven curl -#RUN sudo apt-get install maven2 -WORKDIR /usr/src - -RUN curl -s http://svn.apache.org/repos/asf/oodt/trunk/mvn/archetypes/radix/src/main/resources/bin/radix | bash -RUN mv oodt oodt-src; cd oodt-src; mvn package -RUN mkdir /usr/src/oodt; tar -xvf /usr/src/oodt-src/distribution/target/oodt-distribution-0.1-bin.tar.gz -C /usr/src/oodt - -EXPOSE 8080 -EXPOSE 9000 -EXPOSE 2001 -EXPOSE 9001 -EXPOSE 9200 -EXPOSE 9002 - -CMD cd /usr/src/oodt/bin/ && ./oodt start && tail -f /usr/src/oodt/tomcat/logs/catalina.out http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/pom.xml ---------------------------------------------------------------------- diff --git a/grid/pom.xml b/grid/pom.xml deleted file mode 100644 index 59a355d..0000000 --- a/grid/pom.xml +++ /dev/null @@ -1,138 +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.txt 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>web-grid</artifactId> - <packaging>war</packaging> - <name>OODT Web Grid</name> - <description>The OODT grid services (product and profile services) use CORBA or - RMI as their underlying network transport. However, limitations - of CORBA and RMI make them inappropriate for large-scale - deployments. For one, both are procedural mechanisms, providing a - remote interface that resembles a method call. This makes - streaming of data from a service impossible, because there are - limitations to the sizes of data structures that can be passed - over a remote method call. Instead, repeated calls must be made - to retrieve each block of a product, making transfer speeds - horribly slow compared to HTTP or FTP. (Block-based retrieval of - profiles was never implemented, resulting in out of memory - conditions for large profile results, which is another problem.) - Second, both CORBA and RMI rely on a central name registry. The - registry makes an object independent of its network location, - enabling a client to call it by name (looking up its last known - location in the registry). However, this requires that server - objects be able to make outbound network calls to the registry - (through any outbound firewall), and that the registry accept - those registrations (through any inbound firewall). This required - administrative action at institutions hosting server objects and - at the institution hosting the registry. Often, these firewall - exceptions would change without notice as system adminstrators - changed at each location (apparently firewall exceptions are - poorly documented everywhere). Further, in the two major - deployments of OODT (PDS and EDRN), server objects have almost - never moved, nullifying any benefit of the registry. This - project, OODT Web Grid Services, avoids the prolems of CORBA and - RMI by using HTTP as the transport mechanism for products and - profiles. Further, it provides a password-protected mechanism to - add new sets of product and profile query handlers, enabling - seamless activation of additional capabilities.</description> - <!-- 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>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.jena</groupId> - <artifactId>apache-jena-libs</artifactId> - <type>pom</type> - </dependency> - <dependency> - <groupId>org.apache.oodt</groupId> - <artifactId>oodt-commons</artifactId> - </dependency> - <dependency> - <groupId>org.apache.oodt</groupId> - <artifactId>oodt-product</artifactId> - </dependency> - <dependency> - <groupId>org.apache.oodt</groupId> - <artifactId>oodt-profile</artifactId> - </dependency> - <dependency> - <groupId>org.apache.oodt</groupId> - <artifactId>oodt-xmlquery</artifactId> - </dependency> - <dependency> - <groupId>xalan</groupId> - <artifactId>xalan</artifactId> - </dependency> - <dependency> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> - </dependency> - </dependencies> - <build> - <plugins> - <plugin> - <artifactId>maven-war-plugin</artifactId> - <version>2.5</version> - <configuration> - <webResources /> - <warSourceDirectory>src/main/webapp</warSourceDirectory> - </configuration> - </plugin> - </plugins> - </build> - <scm> - <!--<connection>scm:svn:https://svn.apache.org/repos/asf/oodt/trunk/grid</connection> - <developerConnection>scm:svn:https://svn.apache.org/repos/asf/oodt/trunk/grid</developerConnection> - <url>http://svn.apache.org/viewvc/oodt/trunk/grid</url>--> - <tag>0.13-SNAPSHOT</tag> - </scm> -</project> http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/AuthenticationRequiredException.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/AuthenticationRequiredException.java b/grid/src/main/java/org/apache/oodt/grid/AuthenticationRequiredException.java deleted file mode 100755 index 3c152b8..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/AuthenticationRequiredException.java +++ /dev/null @@ -1,30 +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.grid; - -/** - * Exception thrown to indicate that authentication is required to continue. - */ -public class AuthenticationRequiredException extends Exception { - /** - * Creates a new <code>AuthenticationRequiredException</code> instance. - */ - public AuthenticationRequiredException() { - super("Authentication required"); - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/ConfigBean.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/ConfigBean.java b/grid/src/main/java/org/apache/oodt/grid/ConfigBean.java deleted file mode 100755 index ef4ca62..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/ConfigBean.java +++ /dev/null @@ -1,177 +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.grid; - -import java.io.Serializable; -import java.util.List; -import java.util.Properties; - -/** - * Bean containing login status for and configuration info. - */ -public class ConfigBean implements Serializable { - /** - * Return true is administrator is authenticated. - * - * @return True if authentic, false otherwise. - */ - public boolean isAuthentic() { - return authentic; - } - - /** - * Set whether the administrator's been authenticated. - * - * @param authentic - * True if authentic, false otherwise. - */ - void setAuthentic(boolean authentic) { - this.authentic = authentic; - } - - /** - * Get any message to display. This should never be null. - * - * @return A message to display - */ - public String getMessage() { - return message; - } - - /** - * Set the message to display. - * - * @param message - * Message to display. - */ - public void setMessage(String message) { - if (message == null) { - throw new IllegalArgumentException("message cannot be null"); - } - this.message = message; - } - - /** - * Get the configuration of web-grid. - * - * @return a <code>Configuration</code> value. - * @throws AuthenticationRequiredException - * if the administrator's not authenticated. - */ - public Configuration getConfiguration() - throws AuthenticationRequiredException { - checkAuthenticity(); - return configuration; - } - - /** - * Tell if HTTPS is required to access the web-grid configuration. - * - * @return True if HTTPS is required to access the web-grid configuration. - * @throws AuthenticationRequiredException - * if the administrator's not authenticated. - */ - public boolean isHttpsRequired() throws AuthenticationRequiredException { - checkAuthenticity(); - return configuration.isHTTPSrequired(); - } - - /** - * Tell if admin access can come only from the localhost. - * - * @return True if admin access can come only from the localhost. - * @throws AuthenticationRequiredException - * if the administrator's not authenticated. - */ - public boolean isLocalhostRequired() throws AuthenticationRequiredException { - checkAuthenticity(); - return configuration.isLocalhostRequired(); - } - - /** - * Get the list of {@link ProductServer}s that have been installed in this - * container. - * - * @return a <code>List</code> of {@link ProductServer}s. - * @throws AuthenticationRequiredException - * if the administrator's not authenticated. - */ - public List getProductServers() throws AuthenticationRequiredException { - checkAuthenticity(); - return configuration.getProductServers(); - } - - /** - * Get the list of {@link ProfileServer}s that have been installed in this - * container. - * - * @return a <code>List</code> of {@link ProfileServer}s. - * @throws AuthenticationRequiredException - * if the administrator's not authenticated. - */ - public List getProfileServers() throws AuthenticationRequiredException { - checkAuthenticity(); - return configuration.getProfileServers(); - } - - /** - * Set the configuration this bean will use. - * - * @param configuration - * a <code>Configuration</code> value. - */ - void setConfiguration(Configuration configuration) { - this.configuration = configuration; - } - - /** - * Get the properties defined for this container. - * - * @return a <code>Properties</code> value. - * @throws AuthenticationRequiredException - * if the administrator's not authenticated. - */ - public Properties getProperties() throws AuthenticationRequiredException { - checkAuthenticity(); - return configuration.getProperties(); - } - - /** - * Check if the administrator is authentic. This method does nothing if the - * administrator is authentic, but throws an exception if not. - * - * @throws AuthenticationRequiredException - * if the administrator's not authenticated. - */ - private void checkAuthenticity() throws AuthenticationRequiredException { - if (isAuthentic() && configuration != null) { - return; - } - message = ""; - throw new AuthenticationRequiredException(); - } - - /** True if administrator is authentic. */ - private boolean authentic; - - /** Any message to display. */ - private String message = ""; - - /** The configuration for this container. */ - private transient Configuration configuration; -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/ConfigServlet.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/ConfigServlet.java b/grid/src/main/java/org/apache/oodt/grid/ConfigServlet.java deleted file mode 100755 index 8a5b0a3..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/ConfigServlet.java +++ /dev/null @@ -1,309 +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.grid; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Controller servlet for making changes to configuration. - */ -public class ConfigServlet extends GridServlet { - /** - * Handle updates to a configuration by saving them and directing back to the - * config page. - * - * @param req - * a <code>HttpServletRequest</code> value. - * @param res - * a <code>HttpServletResponse</code> value. - * @throws ServletException - * if an error occurs. - * @throws IOException - * if an error occurs. - */ - public void doPost(HttpServletRequest req, HttpServletResponse res) - throws ServletException, IOException { - Configuration config = getConfiguration(); // Get the singleton - // configuration - if (!approveAccess(config, req, res)) { - return; // Check if the user can access this page - } - - ConfigBean cb = getConfigBean(req); // Get the bean - cb.setMessage(""); // Clear out any message - if (!cb.isAuthentic()) { - throw new ServletException(new AuthenticationRequiredException()); - } - boolean needSave = false; // Assume no changes for now - - String newPass = req.getParameter("password"); // See if she wants to change - // password - if (newPass != null && newPass.length() > 0) { // Got a password, and it's - // not empty? - config.setPassword(newPass.getBytes()); // Yes, set its bytes - needSave = true; // We need to save - } - - boolean https = config.isHTTPSrequired(); // Are we currently using https? - String httpsParam = req.getParameter("https"); // Get her https param - boolean newHttps = httpsParam != null && "on".equals(httpsParam); // See if - // she - // wants - // to use - // https - // or not - if (https != newHttps) { // Different? - config.setHTTPSrequired(newHttps); // Yes, set the new state - needSave = true; // We need to save - } - - boolean local = config.isLocalhostRequired(); // Are we requiring localhost? - String localhostParam = req.getParameter("localhost"); // Get her localhost - // param - boolean newLocal = localhostParam != null && "on".equals(localhostParam); // See - // if - // she - // wants - // to - // require - // localhost - if (local != newLocal) { // Different? - config.setLocalhostRequired(newLocal); // Yes, set the new state - needSave = true; // We need to save - } - - String newKey = req.getParameter("newkey"); // See if she's got a new - // property - if (newKey != null && newKey.length() > 0) { // And make sure it's nonempty - String newVal = req.getParameter("newval"); // Got one, get its value - if (newVal == null) { - newVal = ""; // Make sure it's at least an empty string - } - config.getProperties().setProperty(newKey, newVal); // Set the new - // property - needSave = true; // We need to save - } - - needSave |= updateProperties(config.getProperties(), // Make any updates to - // existing property - req.getParameterMap()); // values, and see note if we need to save - try { - needSave |= updateServers(config, req.getParameterMap(), 'd'); // Same - // goes for - // product - // servers - needSave |= updateServers(config, req.getParameterMap(), 'm'); // And - // profile - // servers - needSave |= updateCodeBases(config, req.getParameterMap()); // And for - // code bases - } catch (MalformedURLException ex) { // Make sure code base URLs are OK - cb.setMessage("Code bases must be valid URLs (" // Not OK? - + ex.getMessage() + "); no changes made"); // Let user know via a - // message - req.getRequestDispatcher("config.jsp").forward(req, res); // And make no - // changes until - // she fixes it - return; - } - - if (needSave) { // Do we need to save? - config.save(); // Then do it already! - cb.setMessage("Changes saved."); // And let the user know - } else { - cb.setMessage("No changes made."); // Oh, no changes were made, let user - // know - } - req.getRequestDispatcher("config.jsp").forward(req, res); // Back to the - // config page - } - - /** - * Update changes to the code bases. - * - * @param config - * a <code>Configuration</code> value. - * @param params - * a <code>Map</code> value. - * @return True if changes need to be saved. - * @throws MalformedURLException - * if an error occurs. - */ - private boolean updateCodeBases(Configuration config, Map params) - throws MalformedURLException { - boolean needSave = false; // Assume no change - List codeBases = config.getCodeBases(); // Get the current code bases - - List toRemove = new ArrayList(); // Hold indexes of code bases to remove - for (Object o : params.entrySet()) { // For each - // parameter - Map.Entry entry = (Map.Entry) o; // Get its entry - String key = (String) entry.getKey(); // And its name - String value = ((String[]) entry.getValue())[0]; // And its zeroth value - if (key.startsWith("delcb-") && "on".equals(value)) { // If it's checked - Integer index = Integer.valueOf(key.substring(6)); // Parse out the index - toRemove.add(index); // Add it to the list - } - } - if (!toRemove.isEmpty()) { // And if we have any indexes - Collections.sort(toRemove); // Sort 'em and put 'em in reverse ... - Collections.reverse(toRemove); // ... order so we can safely remove them - for (Object aToRemove : toRemove) { // For each index - // to remove - int index = (Integer) aToRemove; // Get the index value - codeBases.remove(index); // And buh-bye. - } - needSave = true; // Definitely need to save changes now - } - - String[] newCBs = (String[]) params.get("newcb"); // Was there a new code - // base specified? - if (newCBs != null && newCBs.length == 1) { // And was there exactly one - // value? - String newCB = newCBs[0]; // Get that exactly one value - if (newCB != null && newCB.length() > 0) { // Is it nonnull and nonempty? - URL newURL = new URL(newCB); // Treat is as an URL - codeBases.add(newURL); // Add it to the list - needSave = true; // Ad we gotta save - } - } - return needSave; - } - - /** - * Update the list of product/profile servers based on request parameters. - * - * @param config - * System configuration - * @param params - * Request parameters. - * @param type - * <code>d</code> (data) if product servers, <code>m</code> - * (metadata) if profile servers - * @return True if any changes were made, false if no changes were made - */ - private boolean updateServers(Configuration config, Map params, char type) { - List servers = type == 'd' ? config.getProductServers() : config - .getProfileServers(); - boolean needSave = false; // Assume no changes for now - - List toRemove = new ArrayList(); // Start with empty list of indexes to - // remove - for (Object o : params.entrySet()) { // Go - // through - // each - // parameter - Map.Entry entry = (Map.Entry) o; // Get its key/value - String name = (String) entry.getKey(); // The key is a String - if (name.startsWith(type + "rm-")) { // Is it an "drm-" or "mrm-"? - Integer index = Integer.valueOf(name.substring(4)); // Yes, get it sindex - toRemove.add(index); // Add it to the list - } - } - - if (!toRemove.isEmpty()) { // Got any to remove? - Collections.sort(toRemove); // We need to go through them in reverse ord- - Collections.reverse(toRemove); // -er, so that removals don't shift - // indexes - for (Object aToRemove : toRemove) { // For each index - int index = (Integer) aToRemove; // Get its int value - servers.remove(index); // and buh-bye - } - needSave = true; // Gotta save after all that, whew. - } - - if (params.containsKey(type + "-newcn")) { // Adding a new server? - String[] newClasses = (String[]) params.get(type + "-newcn"); // And the - // new class - // name - if (newClasses != null && newClasses.length == 1) { // Are present and - // there's only one of - // each - String newClass = newClasses[0]; // Get the new class - if (newClass != null && newClass.length() > 0) { // And nonempty - Server server; - if (type == 'd') // If it's data - { - server = new ProductServer(config, newClass); // It's a product - } -// server - else - // otherwise it's metadata - { - server = new ProfileServer(config, newClass); // Which is a profile - } - // server - servers.add(server); // Add it to the set of servers - needSave = true; // And after all this, we need to save! - } - } - } - - return needSave; - } - - /** - * Update properties based on request parameters. - * - * @param props - * <code>Properties</code> to update - * @param params - * Request parameters - * @return True if changes need to be saved, false otherwise - */ - private boolean updateProperties(Properties props, Map params) { - boolean needSave = false; // Assume no save for now - for (Object o : params.entrySet()) { // Go - // through - // each - // request - // parameter - Map.Entry entry = (Map.Entry) o; // Get the key/value - String name = (String) entry.getKey(); // Key is always a string - String newValue = ((String[]) entry.getValue())[0]; // Value is String[], - // get the zeroth - if (name.startsWith("val-")) { // If the param is "val-" - String key = name.substring(4); // Then find the key - if (props.containsKey(key)) { // If that key exists - String value = props.getProperty(key); // Find its value - if (value == null || !value.equals(newValue)) {// Are they different? - props.setProperty(key, newValue); // Yes, set the new value - needSave = true; // And we need to save - } - } - } else if (name.startsWith("del-")) { // If the param is "del-" - String key = name.substring(4); // Then find the key - if (props.containsKey(key)) { // If that key exists - props.remove(key); // Then remove its mapping - needSave = true; // And we need to save - } - } - } - return needSave; - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/Configuration.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/Configuration.java b/grid/src/main/java/org/apache/oodt/grid/Configuration.java deleted file mode 100755 index ed82943..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/Configuration.java +++ /dev/null @@ -1,463 +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.grid; - -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.Serializable; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerConfigurationException; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.w3c.dom.Text; -import org.xml.sax.SAXException; - -import org.apache.oodt.commons.util.Base64; - -/** - * web-grid configuration. This holds all the runtime configuration of profile servers, - * product servers, properties, and other settings for the web-grid container. - * - */ -public class Configuration implements Serializable { - /** - * Creates a new <code>Configuration</code> instance. - * - * @param file File containing the serialized configuration. - * @throws IOException if an I/O error occurs. - * @throws SAXException if the file can't be parsed. - */ - public Configuration(File file) throws IOException, SAXException { - this.file = file; - if (file.isFile() && file.length() > 0) { - parse(file); - } - } - - /** - * Convert the configuration to XML. - * - * @param owner Owning document. - * @return XML representation of this configuration. - */ - public Node toXML(Document owner) { - Element elem = owner.createElement("configuration"); // <configuration> - elem.setAttribute("xmlns", NS); // Set default namespace - elem.setAttribute("https", httpsRequired? "true" : "false"); // Add https attribute - elem.setAttribute("localhost", localhostRequired? "true" : "false"); // Add localhost attribute - - if (password != null && password.length > 0) // If we have a password - { - elem.setAttribute("password", encode(password)); // Add passowrd attribute - } - - for (Object productServer : productServers) { // For each product server - ProductServer ps = (ProductServer) productServer; // Get the product server - elem.appendChild(ps.toXML(owner)); // And add it under <configuration> - } - - for (Object profileServer : profileServers) { // For each profile server - ProfileServer ps = (ProfileServer) profileServer; // Get the profile server - elem.appendChild(ps.toXML(owner)); // And add it under the <configuration> - } - - if (!codeBases.isEmpty()) { // Got any code bases? - Element cbs = owner.createElement("codeBases"); // Boo yah. Make a parent for 'em - elem.appendChild(cbs); // Add parent - for (Object codeBase : codeBases) { // Then, for each code base - URL url = (URL) codeBase; // Get the URL to it - Element cb = owner.createElement("codeBase"); // And make a <codeBase> for it - cb.setAttribute("url", url.toString()); // And an "url" attribute - cbs.appendChild(cb); // Add it - } - } - - if (!properties.isEmpty()) { // If we have any properties> - Element props = owner.createElement("properties"); // Add <properties> under <configuration> - props.setAttribute("xml:space", "preserve"); // And make sure space is properly preserved - elem.appendChild(props); // Add the space attribute - for (Map.Entry<Object, Object> objectObjectEntry : properties.entrySet()) { // For each property - Map.Entry entry = - (Map.Entry) objectObjectEntry; // Get the property key/value pair - String key = (String) entry.getKey(); // Key is always a String - String value = (String) entry.getValue(); // So is the value - Element prop = owner.createElement("property"); // Create a <property> element - props.appendChild(prop); // Add it under the <properties> - prop.setAttribute("key", key); // Set the key as an attribute - Text text = owner.createTextNode(value); // Make text to hold the value - prop.appendChild(text); // Add it under the <property> - } - } - return elem; - } - - /** - * Get the properties. - * - * @return a <code>Properties</code> value. - */ - public Properties getProperties() { - return properties; - } - - /** - * Is localhost access required for the configuration? - * - * @return True if the configuration must be accessed from the localhost, false otherwise. - */ - public boolean isLocalhostRequired() { - return localhostRequired; - } - - /** - * Is https access required for the configuration? - * - * @return True if the configuration must be accessed via https, false if http is OK. - */ - public boolean isHTTPSrequired() { - return httpsRequired; - } - - /** - * Set if https is required to access the configuration. - * - * @param required True if the configuration must be accessed via https, false if http is OK. - */ - public void setHTTPSrequired(boolean required) { - httpsRequired = required; - } - - /** - * Set if localhost is required to access the configuration. - * - * @param required True if the configuration must be accessed from the localhost, false otherwise. - */ - public void setLocalhostRequired(boolean required) { - localhostRequired = required; - } - - /** - * Return the code bases. - * - * @return a <code>List</code> of {@link URL}s. - */ - public List getCodeBases() { - return codeBases; - } - - /** - * Get the product servers. - * - * @return a <code>List</code> of {@link ProductServer}s. - */ - public List getProductServers() { - return productServers; - } - - /** - * Get the profile servers. - * - * @return a <code>List</code> of {@link ProfileServer}s. - */ - public List getProfileServers() { - return profileServers; - } - - /** - * Get the administrator password. - * - * @return Administrator password. - */ - public byte[] getPassword() { - return password; - } - - /** - * Set the administrator password. - * - * @param password Administrator password. - */ - public void setPassword(byte[] password) { - if (password == null) { - throw new IllegalArgumentException("Non-null passwords not allowed"); - } - this.password = password; - } - - /** - * Save the configuration. - * - * @throws IOException if an I/O error occurs. - */ - public synchronized void save() throws IOException { - BufferedWriter writer = null; // Start w/no writer - try { // Then try ... - writer = new BufferedWriter(new FileWriter(file)); // Create a writer - Document doc; // As for the doc... - synchronized (DOCUMENT_BUILDER) { // Using the document builder... - doc = DOCUMENT_BUILDER.newDocument(); // Create an empty document - } - Node root = toXML(doc); // Convert this config to XML - doc.appendChild(root); // Add it to the doc - DOMSource source = new DOMSource(doc); // Use the source Luke - StreamResult result = new StreamResult(writer); // And serialize it to the writer - TRANSFORMER.transform(source, result); // Serialize - } catch (TransformerException ex) { - throw new IllegalStateException("Unexpected TransformerException: " + ex.getMessage()); - } finally { - if (writer != null) { - try { // And if we got a writer, try ... - writer.close(); // to close it - } catch (IOException ignore) { - } // Ignoring any error - } - } - } - - /** - * Parse a serialized configuration document. - * - * @param file File to parse - * @throws IOException if an I/O error occurs. - * @throws SAXException if a parse error occurs. - */ - private void parse(File file) throws IOException, SAXException { - Document doc; // Start with a doc ... - synchronized (DOCUMENT_BUILDER) { // And using the DOCUMENT_BUILDER - doc = DOCUMENT_BUILDER.parse(file); // Try to parse the file - } - Element root = doc.getDocumentElement(); // Assume the root element is <configuration> - - String httpsAttr = root.getAttribute("https"); // Get the https attribute - httpsRequired = httpsAttr != null && "true".equals(httpsAttr); // See if it's "true" - - String localhostAttr = root.getAttribute("localhost"); // Get the localhost attribute - localhostRequired = localhostAttr != null && "true".equals(localhostAttr); // See if it's "true" - - String passwordAttr = root.getAttribute("password"); // Get the password attribute - if (passwordAttr != null && passwordAttr.length() > 0) // If it's there, and non-empty - { - password = decode(passwordAttr); // Then decode it - } - - NodeList children = root.getChildNodes(); // Get the child nodes - for (int i = 0; i < children.getLength(); ++i) { // For each child node - Node child = children.item(i); // Get the child - if (child.getNodeType() == Node.ELEMENT_NODE) { // An element? - if ("server".equals(child.getNodeName())) { // A <server>? - Server server = Server.create(this, (Element) child); // Create the correct server - - // Keep these in separate sets? - if (server instanceof ProductServer) // Is a product server? - { - productServers.add(server); // Add to product servers - } else if (server instanceof ProfileServer) // Is a profile server? - { - profileServers.add(server); // Add to profile servers - } else { - throw new IllegalArgumentException("Unexpected server type " + server + " in " + file); - } - } else if ("properties".equals(child.getNodeName())) { // Is it a <properties>? - NodeList props = child.getChildNodes(); // Get its children - for (int j = 0; j < props.getLength(); ++j) { // For each child - Node node = props.item(j); // Get the chld - if (node.getNodeType() == Node.ELEMENT_NODE // And element? - && "property".equals(node.getNodeName())) { // And it's <property>? - Element propNode = (Element) node; // Great, use it as an element - String key = propNode.getAttribute("key"); // Get its key attribute - if (key == null || key.length() == 0) // Make sure it's there - { - throw new SAXException("Required 'key' attribute missing from " - + "<property> element"); - } - properties.setProperty(key, text(propNode)); // And set it - } - } - } else if ("codeBases".equals(child.getNodeName())) { // And yadda - NodeList cbs = child.getChildNodes(); // yadda - for (int j = 0; j < cbs.getLength(); ++j) { // yadda. - Node node = cbs.item(j); - if (node.getNodeType() == Node.ELEMENT_NODE - && "codeBase".equals(node.getNodeName())) { - Element cbNode = (Element) node; - String u = cbNode.getAttribute("url"); - if (u == null || u.length() == 0) { - throw new SAXException("Required 'url' attribute missing from " - + "<codeBase> element"); - } - try { - codeBases.add(new URL(u)); - } catch (MalformedURLException ex) { - throw new SAXException("url attribute " + u + " isn't a valid URL"); - } - } - } - } - } - } - } - - /** - * Encode a password. This just hides it so it's not plain text, but it's just as - * easy to decode it if you have a base-64 decoder handy. - * - * @param password a <code>byte[]</code> value. - * @return a <code>String</code> value. - */ - static String encode(byte[] password) { - return new String(Base64.encode(password)); - } - - /** - * Decode a password. - * - * @param password a <code>String</code> value. - * @return a <code>byte[]</code> value. - */ - static byte[] decode(String password) { - return Base64.decode(password.getBytes()); - } - - /** - * Get the text under an XML node. - * - * @param node a <code>Node</code> value. - * @return a <code>String</code> value. - */ - private static String text(Node node) { - StringBuffer b = new StringBuffer(); - text0(node, b); - return b.toString(); - } - - /** - * Get the text from an XML node into a StringBuffer. - * - * @param node a <code>Node</code> value. - * @param b a <code>StringBuffer</code> value. - */ - private static void text0(Node node, StringBuffer b) { - NodeList children = node.getChildNodes(); - for (int i = 0; i < children.getLength(); ++i) { - text0(children.item(i), b); - } - short type = node.getNodeType(); - if (type == Node.CDATA_SECTION_NODE || type == Node.TEXT_NODE) { - b.append(node.getNodeValue()); - } - } - - public boolean equals(Object obj) { - if (obj == this) { - return true; - } - if (obj instanceof Configuration) { - Configuration rhs = (Configuration) obj; - return codeBases.equals(rhs.codeBases) && productServers.equals(rhs.productServers) - && profileServers.equals(rhs.profileServers) && Arrays.equals(password, rhs.password) - && httpsRequired == rhs.httpsRequired && localhostRequired == rhs.localhostRequired - && properties.equals(rhs.properties); - } - return false; - } - - public int hashCode() { - return codeBases.hashCode() ^ productServers.hashCode() ^ profileServers.hashCode(); - } - - /** List of {@link URL}s to code bases. */ - private List codeBases = new ArrayList(); - - /** List of {@link ProductServer}s. */ - private List productServers = new ArrayList(); - - /** List of {@link ProfileServer}s. */ - private List profileServers = new ArrayList(); - - /** Admin password. */ - private byte[] password = DEFAULT_PASSWORD; - - /** True if https is requried. */ - private boolean httpsRequired; - - /** True if localhost access is required. */ - private boolean localhostRequired; - - /** Properties to set. */ - private Properties properties = new Properties(); - - /** Where to save the file. */ - private transient File file; - - /** Default password. */ - static final byte[] DEFAULT_PASSWORD = { (byte)'h', (byte)'a', (byte)'n', (byte)'a', (byte)'l', (byte)'e', (byte)'i' }; - - /** XML namespace */ - public static final String NS = "http://oodt.jpl.nasa.gov/web-grid/ns/"; - - /** Sole document builder we'll need. */ - private static final DocumentBuilder DOCUMENT_BUILDER; - - /** Sole transfomer we'll need. */ - private static final Transformer TRANSFORMER; - - static { - try { - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setNamespaceAware(true); - documentBuilderFactory.setValidating(false); - documentBuilderFactory.setIgnoringElementContentWhitespace(false); - documentBuilderFactory.setExpandEntityReferences(true); - documentBuilderFactory.setIgnoringComments(true); - documentBuilderFactory.setCoalescing(true); - DOCUMENT_BUILDER = documentBuilderFactory.newDocumentBuilder(); - - TransformerFactory transformerFactory = TransformerFactory.newInstance(); - TRANSFORMER = transformerFactory.newTransformer(); - TRANSFORMER.setOutputProperty(OutputKeys.METHOD, "xml"); - TRANSFORMER.setOutputProperty(OutputKeys.VERSION, "1.0"); - TRANSFORMER.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - TRANSFORMER.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); - TRANSFORMER.setOutputProperty(OutputKeys.INDENT, "yes"); - TRANSFORMER.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); - } catch (ParserConfigurationException ex) { - throw new IllegalStateException("Cannot create document builder"); - } catch (TransformerConfigurationException ex) { - throw new IllegalStateException("Cannot create transformer"); - } - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/GridServlet.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/GridServlet.java b/grid/src/main/java/org/apache/oodt/grid/GridServlet.java deleted file mode 100755 index 8f5ccdd..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/GridServlet.java +++ /dev/null @@ -1,126 +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.grid; - -import java.io.File; -import java.io.IOException; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import org.xml.sax.SAXException; - -/** - * Grid servlet is an abstract servlet that provides basic behavior (configuration access) - * for grid servlets. - */ -public abstract class GridServlet extends HttpServlet { - /** - * By default, grid servlets are POST only, so GETs get you the welcome page. - * - * @param req a <code>HttpServletRequest</code> value. - * @param res a <code>HttpServletResponse</code> value. - * @throws IOException if an error occurs. - * @throws ServletException if an error occurs. - */ - public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { - req.getRequestDispatcher("index.html").forward(req, res); - } - - /** - * Get the configuration. - * - * @return a <code>Configuration</code> value. - * @throws ServletException if an error occurs. - * @throws IOException if an error occurs. - */ - protected Configuration getConfiguration() throws ServletException, IOException { - if (configuration != null) { - return configuration; - } - String path = getServletContext().getInitParameter("org.apache.oodt.grid.GridServlet.config"); - if (path == null) { - path = getServletContext().getRealPath("/WEB-INF/config.xml"); - } - if (path == null) { - throw new ServletException("The config.xml file can't be accessed. Are we running from a war file!??!"); - } - File file = new File(path); - Configuration c; - try { - c = new Configuration(file); - } catch (SAXException ex) { - throw new ServletException("Cannot parse config.xml file", ex); - } - synchronized (GridServlet.class) { - while (configuration == null) { - configuration = c; - } - } - return configuration; - } - - /** - * Get the config bean. - * - * @param req a <code>HttpServletRequest</code> value. - * @return a <code>ConfigBean</code> value. - * @throws ServletException if an error occurs. - * @throws IOException if an error occurs. - */ - protected ConfigBean getConfigBean(HttpServletRequest req) throws ServletException, IOException { - HttpSession session = req.getSession(/*create*/true); - ConfigBean cb = (ConfigBean) session.getAttribute("cb"); - if (cb == null) { - cb = new ConfigBean(); - session.setAttribute("cb", cb); - } - Configuration config = getConfiguration(); - cb.setConfiguration(config); - return cb; - } - - /** - * Check if administrative access is allowed. This examines the request scheme - * (http, ftp, https, etc.) and sees if https is required by the configuration. - * It also checks the remote host and sees if localhost access is required. - * - * @param config a <code>Configuration</code> value. - * @param req a <code>HttpServletRequest</code> value. - * @param res a <code>HttpServletResponse</code> value. - * @return True if access is approved, false otherwise. - * @throws IOException if an error occurs. - */ - protected boolean approveAccess(Configuration config, HttpServletRequest req, HttpServletResponse res) throws IOException { - if (config.isHTTPSrequired() && !"https".equals(req.getScheme())) { - res.sendError(HttpServletResponse.SC_FORBIDDEN, "https required"); - return false; - } - - if (config.isLocalhostRequired() && !Utility.isLocalhost(req.getRemoteHost())) { - res.sendError(HttpServletResponse.SC_FORBIDDEN, "localhost access only"); - return false; - } - - return true; - } - - /** Singleton configuration. */ - private static volatile Configuration configuration; -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/LoginServlet.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/LoginServlet.java b/grid/src/main/java/org/apache/oodt/grid/LoginServlet.java deleted file mode 100755 index 01e186a..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/LoginServlet.java +++ /dev/null @@ -1,65 +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.grid; - -import java.io.IOException; -import java.util.Arrays; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Controller servlet that authenticates the administrator password. - * - */ -public class LoginServlet extends GridServlet { - /** - * Handle authentication from an administrator. - * - * @param req a <code>HttpServletRequest</code> value. - * @param res a <code>HttpServletResponse</code> value. - * @throws ServletException if an error occurs. - * @throws IOException if an error occurs. - */ - public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - Configuration config = getConfiguration(); // Get configuration - if (!approveAccess(config, req, res)) { - return; // Do https, localhost checking first - } - - ConfigBean cb = getConfigBean(req); // Get bean - if (cb.isAuthentic()) { // Already authentic? - req.getRequestDispatcher("config.jsp").forward(req, res); // Back to the config page with you! - return; - } - - String password = req.getParameter("password"); // Get submitted password - if (password == null) { - password = ""; // If none, use an empty string - } - byte[] bytes = password.getBytes(); // Get the bytes - if (!Arrays.equals(config.getPassword(), bytes)) { // Compare to stored password bytes - cb.setMessage("Password incorrect"); // Not equal! Set message. - throw new ServletException(new AuthenticationRequiredException()); - } else { - cb.setMessage(""); // Equal, clear message - cb.setAuthentic(true); // You are now authenticated - req.getRequestDispatcher("config.jsp").forward(req, res); // To the config page with you! - } - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/ProductQueryServlet.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/ProductQueryServlet.java b/grid/src/main/java/org/apache/oodt/grid/ProductQueryServlet.java deleted file mode 100755 index 20408af..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/ProductQueryServlet.java +++ /dev/null @@ -1,226 +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.grid; - -import org.apache.oodt.product.HttpRedirectException; -import org.apache.oodt.product.LargeProductQueryHandler; -import org.apache.oodt.product.ProductException; -import org.apache.oodt.product.QueryHandler; -import org.apache.oodt.product.Retriever; -import org.apache.oodt.xmlquery.LargeResult; -import org.apache.oodt.xmlquery.Result; -import org.apache.oodt.xmlquery.XMLQuery; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - - -/** - * Product query servlet handles product queries. It always returns the first matching - * product, if any. If no handler can provide a product, it returns 404 Not Found. If - * there are no query handlers, it returns 404 Not Found. - * - */ -public class ProductQueryServlet extends QueryServlet { - - public static final int INT = 512; - - /** {@inheritDoc} */ - protected List getServers(Configuration config) { - return config.getProductServers(); - } - - /** {@inheritDoc} */ - protected void handleQuery(XMLQuery query, List handlers, HttpServletRequest req, HttpServletResponse res) - throws IOException { - if (handlers.isEmpty()) { - res.sendError(HttpServletResponse.SC_NOT_FOUND, "no query handlers available to handle query"); - return; - } - - try { // OK, let's try - for (Object handler1 : handlers) { // Try each query handler - QueryHandler handler = (QueryHandler) handler1; // Get the query handler - query = handler.query(query); // Give it the query - if (!query.getResults().isEmpty()) { // Did it give any result? - Result result = (Result) query.getResults().get(0); // Yes, get the result - deliverResult(handler, result, res); // And deliver it - return; // Done! - } - } - } catch (ProductException ex) { - if (ex instanceof HttpRedirectException) { - HttpRedirectException hre = (HttpRedirectException) ex; - res.sendRedirect(hre.getLocation()); - } else { - res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage()); - } - return; - } - - res.sendError(HttpServletResponse.SC_NOT_FOUND, "no matching products from any query handler"); - } - - /** - * Deliver a result. This streams the product data. - * - * @param handler Which handler produced the result. - * @param result The result. - * @param res The HTTP response to which to send the result data. - * @throws IOException if an error occurs. - */ - private void deliverResult(QueryHandler handler, Result result, HttpServletResponse res) throws IOException { - characterize(handler, result, res); // First, describe it using HTTP headers - if (result instanceof LargeResult) { // Is it a large result? - LargeResult lr = (LargeResult) result; // Yes, this is gonna take some special work - LargeProductQueryHandler lpqh = (LargeProductQueryHandler) handler; // First treat 'em as large - ProductRetriever retriever = new ProductRetriever(lpqh); // Large ones need a retriever - lr.setRetriever(retriever); // Set the retriever - } - BufferedInputStream in = null; // Start with no input stream - try { // Then try ... - in = new BufferedInputStream(result.getInputStream()); // To open the input stream - byte[] buf = new byte[INT]; // And a byte buffer for data - int num; // And a place to count data - while ((num = in.read(buf)) != -1) // While we read - { - res.getOutputStream().write(buf, 0, num); // We write - } - res.getOutputStream().flush(); // Flush to commit response - } finally { // And finally - if (in != null) { - try { // If we opened it - in.close(); // Close it - } catch (IOException ignore) { - } // Ignoring any error during closing - } - } // Because come on, it's just closing! - } // For fsck's sake! - - /** - * Characterize a result by using HTTP headers. - * - * @param result Result to characterize. - * @param res HTTP response to set headers in. - */ - private void characterize(QueryHandler handler, Result result, HttpServletResponse res) { - String contentType = result.getMimeType(); // Grab the content type - res.setContentType(contentType); // Set it - long size = result.getSize(); // Grab the size - if (size >= 0) { - res.addHeader("Content-Length", String.valueOf(size)); // Don't use setContentLength(int) - } - if (!displayable(contentType)) // Finally, if a browser can't show it - { - this.suggestFilename(handler, result, res); // Then suggest a save-as filename - } - } - - /** - * Tell if a result is displayable. This compares its MIME type to a list of MIME - * types commonly displayble by browsers. - * - * @param contentType MIME type. - * @return a <code>boolean</code> value. - */ - protected static boolean displayable(String contentType) { - for (String DISPLAYABLE_TYPE : DISPLAYABLE_TYPES) { - if (DISPLAYABLE_TYPE.equals(contentType)) { - return true; // Does it match? - } - } - return false; // None of 'em do, it's not displayable - } - - /** - * We can suggest a filename (if the client happens to be a browser) using a - * content-disposition header. - * - * @param res a <code>HttpServletResponse</code> value. - */ - protected void suggestFilename(QueryHandler handler, Result result, HttpServletResponse res) { - - String resource = result.getResourceID(); - if (resource == null || resource.length() == 0) { - resource = "product.dat"; - } - - // suggest some names based on resource mime type - String contentType = res.getContentType(); - - // "zip" mime types - if (contentType!=null) { - if (contentType.equals("application/x-compressed") || - contentType.equals("application/x-zip-compressed") || - contentType.equals("application/zip") || - contentType.equals("multipart/x-zip") ) { - - // resource = resource.replaceAll("\\..+",".zip"); // replace extension with .zip - resource = "products_" + resource + ".zip"; - } - } - - // set "Content-disposition" header - res.addHeader("Content-disposition", "attachment; filename=\"" + resource + "\""); - - } - - /** - * MIME types commonly displayable by browsers. - */ - private static final String[] DISPLAYABLE_TYPES = { - "text/plain", "text/richtext", "text/enriched", "text/tab-separated-values", "text/html", "text/xml", "text/rtf", - "message/rfc822", "message/partial", "message/external-body", "message/news", "message/http", - "message/delivery-status", "message/disposition-notification", "message/s-http", "application/rtf", - "application/pdf", "image/jpeg", "image/gif", "image/tiff", "image/png", "audio/basic", "audio/32kadpcm", - "audio/mpeg", "video/mpeg", "video/quicktime" - }; - - /** - * Retriever that retrieves product data over a method call boundary to a large - * product query handler. - */ - private static class ProductRetriever implements Retriever { - /** - * Creates a new <code>ProductRetriever</code> instance. - * - * @param handler a <code>LargeProductQueryHandler</code> value. - */ - public ProductRetriever(LargeProductQueryHandler handler) { - this.handler = handler; - } - - /** {@inheritDoc} */ - public byte[] retrieveChunk(String id, long offset, int len) throws ProductException { - return handler.retrieveChunk(id, offset, len); - } - - /** {@inheritDoc} */ - public void close(String id) { - handler.close(id); - } - - /** Handler to use. */ - private LargeProductQueryHandler handler; - } -} - http://git-wip-us.apache.org/repos/asf/oodt/blob/098cc4fa/grid/src/main/java/org/apache/oodt/grid/ProductServer.java ---------------------------------------------------------------------- diff --git a/grid/src/main/java/org/apache/oodt/grid/ProductServer.java b/grid/src/main/java/org/apache/oodt/grid/ProductServer.java deleted file mode 100755 index ad16ff4..0000000 --- a/grid/src/main/java/org/apache/oodt/grid/ProductServer.java +++ /dev/null @@ -1,65 +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.grid; - -import org.apache.oodt.product.QueryHandler; - -/** - * A product server. - * - */ -public class ProductServer extends Server { - /** - * Creates a new <code>ProductServer</code> instance. - * - * @param configuration System configuration. - * @param className Class name of query handler. - */ - public ProductServer(Configuration configuration, String className) { - super (configuration, className); - } - - /** {@inheritDoc} */ - protected String getType() { - return "product"; - } - - public int hashCode() { - return super.hashCode() ^ 0xaaaaaaaa; - } - - public boolean equals(Object obj) { - return super.equals(obj) && obj instanceof ProductServer; - } - - public String toString() { - return "ProductServer[" + super.toString() + "]"; - } - - /** - * Create a query handler from this server. - * - * @return a <code>QueryHandler</code> value. - * @throws ClassNotFoundException if the class can't be found. - * @throws InstantiationException if the handler can't be instantiated. - * @throws IllegalAccessException if the handler has no public constructor. - */ - public QueryHandler createQueryHandler() throws ClassNotFoundException, InstantiationException, IllegalAccessException { - return (QueryHandler) createHandler(); - } -}
