You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@oodt.apache.org by ma...@apache.org on 2017/10/12 17:57:26 UTC
[02/50] [abbrv] oodt git commit: update some dependenceies
http://git-wip-us.apache.org/repos/asf/oodt/blob/78ce45e2/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java
----------------------------------------------------------------------
diff --git a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java
index 5cba7d7..44ee93a 100755
--- a/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java
+++ b/filemgr/src/main/java/org/apache/oodt/cas/filemgr/tools/SolrIndexer.java
@@ -27,6 +27,7 @@ import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
+import org.apache.http.impl.client.SystemDefaultHttpClient;
import org.apache.oodt.cas.filemgr.metadata.CoreMetKeys;
import org.apache.oodt.cas.filemgr.structs.Product;
import org.apache.oodt.cas.filemgr.structs.ProductPage;
@@ -34,14 +35,12 @@ import org.apache.oodt.cas.filemgr.structs.ProductType;
import org.apache.oodt.cas.filemgr.structs.exceptions.CatalogException;
import org.apache.oodt.cas.filemgr.structs.exceptions.ConnectionException;
import org.apache.oodt.cas.filemgr.structs.exceptions.RepositoryManagerException;
-import org.apache.oodt.cas.filemgr.system.FileManagerClient;
-import org.apache.oodt.cas.filemgr.util.RpcCommunicationFactory;
+import org.apache.oodt.cas.filemgr.system.XmlRpcFileManagerClient;
import org.apache.oodt.cas.metadata.Metadata;
import org.apache.oodt.cas.metadata.SerializableMetadata;
import org.apache.oodt.cas.metadata.util.PathUtils;
-import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
-import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer;
+import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.util.StringUtils;
@@ -74,31 +73,31 @@ public class SolrIndexer {
private final static String ACCESS_KEY = "access.key";
private final static String ACCESS_URL = "access.url";
private final static String PRODUCT_NAME = "CAS.ProductName";
+ private final HttpSolrClient server;
private IndexerConfig config = null;
- private final SolrServer server;
private String fmUrl;
private String solrUrl;
private static Logger LOG = Logger.getLogger(SolrIndexer.class.getName());
private final static SimpleDateFormat solrFormat = new SimpleDateFormat(
- "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+ "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
/**
* Constructor reads in the configuration and initiates the connection to the
* Solr instance.
- *
+ *
* @param solrUrl
* URL for the Solr instance.
* @param fmUrl
* URL for the File Manager instance.
*/
public SolrIndexer(String solrUrl, String fmUrl)
- throws InstantiationException {
+ throws InstantiationException {
InputStream input = null;
String filename;
try {
LOG.info("System property " + SOLR_INDEXER_CONFIG + " set to "
- + System.getProperty(SOLR_INDEXER_CONFIG));
+ + System.getProperty(SOLR_INDEXER_CONFIG));
filename = System.getProperty(SOLR_INDEXER_CONFIG);
if (filename != null) {
LOG.info("Reading config from " + filename);
@@ -110,7 +109,7 @@ public class SolrIndexer {
config = new IndexerConfig(input);
} catch (IOException e) {
LOG
- .severe("Could not read in configuration for indexer from classpath or file");
+ .severe("Could not read in configuration for indexer from classpath or file");
throw new InstantiationException(e.getMessage());
} finally {
if (input != null) {
@@ -133,13 +132,10 @@ public class SolrIndexer {
}
LOG.info("Using Solr: " + this.solrUrl + " FileManager: " + this.fmUrl);
+ SystemDefaultHttpClient httpClient = new SystemDefaultHttpClient();
+ server = new HttpSolrClient(this.solrUrl, httpClient);
- try {
- server = new CommonsHttpSolrServer(this.solrUrl);
- } catch (MalformedURLException e) {
- LOG.severe("Could not connect to Solr server " + this.solrUrl);
- throw new InstantiationException(e.getMessage());
- }
+// server = new SolrClient(this.solrUrl);
}
@@ -166,7 +162,7 @@ public class SolrIndexer {
/**
* This method transforms the product metadata into a Solr document.
- *
+ *
* @param metadata
* The metadata object for the product to index.
* @return Returns the SolrInputDocument containing product metadata.
@@ -174,6 +170,8 @@ public class SolrIndexer {
private SolrInputDocument getSolrDocument(Metadata metadata) {
SolrInputDocument doc = new SolrInputDocument();
// Only grab metadata which have a mapping in the indexer.properties
+ String official = "";
+
for (Object objKey : config.getMapProperties().keySet()) {
// The key in the metadata object
String key = (String) objKey;
@@ -184,19 +182,21 @@ public class SolrIndexer {
for (String value : values) {
// Add each metadata value into the
if (value != null && !config.getIgnoreValues().contains(value.trim())) {
- LOG.fine("Adding field: " + fieldName + " value: " + value);
+ official += " Key: " + key + " Value: " + value;
doc.addField(fieldName, value);
}
}
}
}
+ // LOG.info("KEYS WERE:" +official);
+
return doc;
}
/**
* This method adds a single product extracted from a metadata file to the
* Solr index.
- *
+ *
* @param file
* The file containing product metadata.
* @param delete
@@ -206,24 +206,24 @@ public class SolrIndexer {
* When an error occurs communicating with the Solr server instance.
*/
public void indexMetFile(File file, boolean delete)
- throws
- SolrServerException {
+ throws
+ SolrServerException {
LOG.info("Attempting to index product from metadata file.");
try {
SerializableMetadata metadata = new SerializableMetadata("UTF-8", false);
metadata.loadMetadataFromXmlStream(new FileInputStream(file));
metadata.addMetadata("id", metadata.getMetadata("CAS."
- + CoreMetKeys.PRODUCT_ID));
+ + CoreMetKeys.PRODUCT_ID));
metadata.addMetadata(config.getProperty(ACCESS_KEY), config
- .getProperty(ACCESS_URL)
- + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
+ .getProperty(ACCESS_URL)
+ + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
if (delete) {
server
- .deleteById(metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
+ .deleteById(metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
}
server.add(this.getSolrDocument(metadata));
LOG.info("Indexed product: "
- + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
+ + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
} catch (InstantiationException e) {
LOG.severe("Could not instantiate metadata object: " + e.getMessage());
} catch (FileNotFoundException e) {
@@ -236,7 +236,7 @@ public class SolrIndexer {
/**
* This method indexes all product types retrieved from the File Manager to
* the Solr index.
- *
+ *
* @param delete
* Flag indicating whether each product type retrieved from the File
* Manager should be deleted from the index.
@@ -246,7 +246,8 @@ public class SolrIndexer {
public void indexProductTypes(boolean delete) {
LOG.info("Indexing product types...");
try {
- FileManagerClient fmClient = RpcCommunicationFactory.createClient(new URL(this.fmUrl));
+ XmlRpcFileManagerClient fmClient = new XmlRpcFileManagerClient(new URL(
+ this.fmUrl));
LOG.info("Retrieving list of product types.");
List<ProductType> types = fmClient.getProductTypes();
for (ProductType type : types) {
@@ -255,9 +256,9 @@ public class SolrIndexer {
metadata.addMetadata("id", type.getProductTypeId());
metadata.addMetadata("CAS.ProductTypeId", type.getProductTypeId());
metadata.addMetadata("CAS.ProductTypeDescription", type
- .getDescription());
+ .getDescription());
metadata.addMetadata("CAS.ProductTypeRepositoryPath", type
- .getProductRepositoryPath());
+ .getProductRepositoryPath());
metadata.addMetadata("CAS.ProductTypeVersioner", type.getVersioner());
metadata.addMetadata("CAS.ProductTypeName", type.getName());
metadata.addMetadata("ProductType", "ProductType");
@@ -267,7 +268,7 @@ public class SolrIndexer {
server.deleteById(type.getProductTypeId());
} catch (Exception e) {
LOG.severe("Could not delete product type " + type.getName()
- + " from index: " + e.getMessage());
+ + " from index: " + e.getMessage());
}
}
try {
@@ -276,7 +277,7 @@ public class SolrIndexer {
LOG.info("Indexed product type: " + type.getName());
} catch (Exception e) {
LOG.severe("Could not index " + type.getName() + ": "
- + e.getMessage());
+ + e.getMessage());
}
} else {
LOG.info("Ignoring product type: " + type.getName());
@@ -288,15 +289,15 @@ public class SolrIndexer {
LOG.severe("Could not connect to File Manager: " + e.getMessage());
} catch (RepositoryManagerException e) {
LOG.severe("Could not retrieve product types from File Manager: "
- + e.getMessage());
+ + e.getMessage());
}
LOG.info("Finished indexing product types.");
}
-
+
/**
- * Suppresses exception that occurred with older file managers.
+ * Suppresses exception that occurred with older file managers.
*/
- private ProductPage safeFirstPage(FileManagerClient fmClient, ProductType type) {
+ private ProductPage safeFirstPage(XmlRpcFileManagerClient fmClient, ProductType type) {
ProductPage page = null;
try {
page = fmClient.getFirstPage(type);
@@ -310,7 +311,7 @@ public class SolrIndexer {
* This method indexes all products retrieved from the File Manager to the
* Solr index. Metadata from the product's associated ProductType is also
* included.
- *
+ *
* @param delete
* Flag indicating whether each product retrieved from the File
* Manager should be deleted from the index.
@@ -320,28 +321,30 @@ public class SolrIndexer {
public void indexAll(boolean delete) {
LOG.info("Indexing products...");
try {
- FileManagerClient fmClient = RpcCommunicationFactory.createClient(new URL(this.fmUrl));
+ XmlRpcFileManagerClient fmClient = new XmlRpcFileManagerClient(new URL(
+ this.fmUrl));
LOG.info("Retrieving list of product types.");
List<ProductType> types = fmClient.getProductTypes();
for (ProductType type : types) {
if (!config.getIgnoreTypes().contains(type.getName().trim())) {
+ ProductPage page = safeFirstPage(fmClient, type);
LOG.info("Paging through products for product type: "
- + type.getName());
- ProductPage page = safeFirstPage(fmClient, type);
+ + type.getName()+" Total pages are "+page.getTotalPages());
while (page != null) {
- for (Product product : page.getPageProducts()) {
+ for (Product product : page.getPageProducts()) {
try {
- this.indexProduct(product.getProductId(), fmClient
- .getMetadata(product), type.getTypeMetadata());
+ String p = product.getProductId();
+ Metadata m = fmClient.getMetadata(product);
+ this.indexProduct(p, m, type.getTypeMetadata());
} catch (Exception e) {
LOG.severe("Could not index " + product.getProductId() + ": "
- + e.getMessage());
+ + e.getLocalizedMessage());
}
}
- if (page.isLastPage()) {
- break;
- }
- page = fmClient.getNextPage(type, page);
+ if (page.getPageNum() >= page.getTotalPages() || page.isLastPage()) {
+ break;
+ }
+ page = fmClient.getNextPage(type, page);
}
}
}
@@ -352,10 +355,10 @@ public class SolrIndexer {
LOG.severe("Could not connect to File Manager: " + e.getMessage());
} catch (CatalogException e) {
LOG.severe("Could not retrieve products from File Manager: "
- + e.getMessage());
+ + e.getMessage());
} catch (RepositoryManagerException e) {
LOG.severe("Could not retrieve product types from File Manager: "
- + e.getMessage());
+ + e.getMessage());
}
}
@@ -363,38 +366,50 @@ public class SolrIndexer {
* This method adds a single product retrieved from the File Manager by its
* product identifier to the Solr index. Metadata from the ProductType is also
* included.
- *
+ *
* @param productId
* The identifier of the product (CAS.ProductId).
* @throws SolrServerException
* When an error occurs communicating with the Solr server instance.
*/
public void indexProduct(String productId)
- throws SolrServerException {
+ throws SolrServerException {
LOG.info("Attempting to index product: " + productId);
try {
- FileManagerClient fmClient = RpcCommunicationFactory.createClient(new URL(this.fmUrl));
+ XmlRpcFileManagerClient fmClient = new XmlRpcFileManagerClient(new URL(
+ this.fmUrl));
Product product = fmClient.getProductById(productId);
Metadata productMetadata = fmClient.getMetadata(product);
+ List<String> keys = productMetadata.getAllKeys();
+ String logger = "";
+ for(String k :keys){
+ logger+=" key: "+keys;
+ List<String> values = productMetadata.getAllValues(k);
+
+ for(String v : values){
+ logger+=" value: "+v + ", ";
+ }
+ }
+ LOG.info("Metadata: "+ logger);
indexProduct(product.getProductId(), productMetadata, product
- .getProductType().getTypeMetadata());
+ .getProductType().getTypeMetadata());
} catch (MalformedURLException e) {
LOG.severe("File Manager URL is malformed: " + e.getMessage());
} catch (ConnectionException e) {
LOG.severe("Could not connect to File Manager: " + e.getMessage());
} catch (CatalogException e) {
LOG.severe("Could not retrieve product from File Manager: "
- + e.getMessage());
+ + e.getMessage());
} catch (java.text.ParseException e) {
LOG.severe("Could not format date: " + e.getMessage());
}
}
-
+
/**
* This method adds a single product retrieved from the File Manager by its
* product name to the Solr index. Metadata from the ProductType is also
* included.
- *
+ *
* @param productName
* The identifier of the product (CAS.ProductId).
* @param delete
@@ -404,7 +419,7 @@ public class SolrIndexer {
* When an error occurs communicating with the Solr server instance.
*/
public void indexProductByName(String productName, boolean delete) throws SolrServerException {
-
+
LOG.info("Attempting to index product: " + productName);
try {
@@ -423,27 +438,28 @@ public class SolrIndexer {
}
}
- FileManagerClient fmClient = RpcCommunicationFactory.createClient(new URL(this.fmUrl));
+ XmlRpcFileManagerClient fmClient = new XmlRpcFileManagerClient(new URL(
+ this.fmUrl));
Product product = fmClient.getProductByName(productName);
Metadata productMetadata = fmClient.getMetadata(product);
// NOTE: delete (by id) is now false
indexProduct(product.getProductId(), productMetadata, product.getProductType().getTypeMetadata());
-
+
} catch (MalformedURLException e) {
LOG.severe("File Manager URL is malformed: " + e.getMessage());
} catch (ConnectionException e) {
LOG.severe("Could not connect to File Manager: " + e.getMessage());
} catch (CatalogException e) {
LOG.severe("Could not retrieve product from File Manager: "
- + e.getMessage());
+ + e.getMessage());
} catch (java.text.ParseException e) {
LOG.severe("Could not format date: " + e.getMessage());
}
}
private void indexProduct(String productId, Metadata productMetadata,
- Metadata typeMetadata) throws SolrServerException,
- java.text.ParseException {
+ Metadata typeMetadata) throws SolrServerException,
+ java.text.ParseException {
Metadata metadata = new Metadata();
metadata.addMetadata("id", productId);
// Add in product type metadata
@@ -469,7 +485,7 @@ public class SolrIndexer {
server.add(this.getSolrDocument(metadata));
LOG.info("Indexed product: " + productId);
} catch (IOException e) {
- LOG.severe("Could not index product: " + productId);
+ LOG.severe("Could not index product: " + productId+ "Exception:"+e.getLocalizedMessage());
}
} else {
LOG.info("Could not find metadata for product: " + productId);
@@ -478,7 +494,7 @@ public class SolrIndexer {
/**
* This method deletes a single product identified by a productID from the Solr index
- *
+ *
* @param productId
* @throws IOException
* @throws SolrServerException
@@ -490,7 +506,7 @@ public class SolrIndexer {
/**
* This method deletes a product(s) from the Solr index identified by a given name
- *
+ *
* @param productName
* @throws IOException
* @throws SolrServerException
@@ -514,16 +530,16 @@ public class SolrIndexer {
private void deleteProductFromIndex(String productId) throws IOException, SolrServerException {
server.deleteById(productId);
}
-
+
/**
* Quick helper method to do substitution on the keys specified in the config
- *
+ *
* @param metadata
* to substitute on
* @throws java.text.ParseException
*/
private void performSubstitution(Metadata metadata)
- throws java.text.ParseException {
+ throws java.text.ParseException {
// Do metadata replacement
for (String key : config.getReplacementKeys()) {
List<String> values = metadata.getAllMetadata(key);
@@ -543,10 +559,12 @@ public class SolrIndexer {
List<String> values = metadata.getAllMetadata(keyString);
if (values != null) {
List<String> newValues = new ArrayList<String>();
- SimpleDateFormat format = new SimpleDateFormat(config
- .getFormatProperties().getProperty(keyString).trim());
+
+ /* SimpleDateFormat format = new SimpleDateFormat(config
+ .getFormatProperties().getProperty(keyString).trim());*/
for (String value : values) {
- newValues.add(formatDate(format, value));
+ String d = value.trim();
+ newValues.add(d);
}
metadata.removeMetadata(keyString);
metadata.addMetadata(keyString, newValues);
@@ -556,17 +574,17 @@ public class SolrIndexer {
}
private String formatDate(SimpleDateFormat format, String value)
- throws java.text.ParseException {
+ throws java.text.ParseException {
// Ignore formating if its an ignore value
if (config.getIgnoreValues().contains(value.trim())) {
- return value;
+ return value;
}
return solrFormat.format(format.parse(value));
}
/**
* This method builds the command-line options.
- *
+ *
* @return Returns the supported Options.
*/
@SuppressWarnings("static-access")
@@ -575,31 +593,31 @@ public class SolrIndexer {
options.addOption(new Option("h", "help", false, "Print this message"));
options.addOption(new Option("o", "optimize", false,
- "Optimize the Solr index"));
+ "Optimize the Solr index"));
options.addOption(new Option("d", "delete", false,
- "Delete item before indexing"));
+ "Delete item before indexing"));
options.addOption(OptionBuilder.withArgName("Solr URL").hasArg()
- .withDescription("URL to the Solr instance").withLongOpt("solrUrl")
- .create("su"));
+ .withDescription("URL to the Solr instance").withLongOpt("solrUrl")
+ .create("su"));
options.addOption(OptionBuilder.withArgName("Filemgr URL").hasArg()
- .withDescription("URL to the File Manager").withLongOpt("fmUrl")
- .create("fmu"));
+ .withDescription("URL to the File Manager").withLongOpt("fmUrl")
+ .create("fmu"));
OptionGroup group = new OptionGroup();
Option all = new Option("a", "all", false,
- "Index all products from the File Manager");
+ "Index all products from the File Manager");
Option product = OptionBuilder.withArgName("productId").hasArg()
- .withDescription("Index the product from the File Manager")
- .withLongOpt("product").create("p");
+ .withDescription("Index the product from the File Manager")
+ .withLongOpt("product").create("p");
Option met = OptionBuilder.withArgName("file").hasArg().withDescription(
- "Index the product from a metadata file").withLongOpt("metFile")
- .create("mf");
+ "Index the product from a metadata file").withLongOpt("metFile")
+ .create("mf");
Option read = new Option("r", "read", false,
- "Index all products based on a list of product identifiers passed in");
+ "Index all products based on a list of product identifiers passed in");
Option types = new Option("t", "types", false,
- "Index all product types from the File Manager");
+ "Index all product types from the File Manager");
Option deleteAll = new Option("da", "deleteAll", false,
- "Delete all products/types from the Solr index");
+ "Delete all products/types from the Solr index");
group.addOption(all);
group.addOption(product);
@@ -614,7 +632,7 @@ public class SolrIndexer {
/**
* The main method. Execution without argument displays help message.
- *
+ *
* @param args
* Command-line arguments.
*/
@@ -633,8 +651,8 @@ public class SolrIndexer {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java " + SolrIndexer.class.getName(), options);
} else if (line.hasOption("all") || line.hasOption("product")
- || line.hasOption("metFile") || line.hasOption("read")
- || line.hasOption("types") || line.hasOption("deleteAll")) {
+ || line.hasOption("metFile") || line.hasOption("read")
+ || line.hasOption("types") || line.hasOption("deleteAll")) {
SolrIndexer indexer;
String solrUrl = null;
String fmUrl = null;
@@ -652,7 +670,7 @@ public class SolrIndexer {
indexer.indexProduct(line.getOptionValue("product"));
} else if (line.hasOption("metFile")) {
indexer.indexMetFile(new File(line.getOptionValue("metFile")), line
- .hasOption("delete"));
+ .hasOption("delete"));
} else if (line.hasOption("read")) {
for (String productId : readProductIdsFromStdin()) {
indexer.indexProduct(productId);
@@ -671,14 +689,14 @@ public class SolrIndexer {
} catch (Exception e) {
LOG.severe("An error occurred indexing: " + e.getMessage());
LOG
- .severe("If the above message is related to accessing the Solr instance, see the Application Server's log for additional information.");
+ .severe("If the above message is related to accessing the Solr instance, see the Application Server's log for additional information.");
}
}
}
/**
* This method reads product identifiers from the standard input.
- *
+ *
* @return Returns a List of product identifiers.
*/
private static List<String> readProductIdsFromStdin() {
@@ -694,12 +712,12 @@ public class SolrIndexer {
}
} catch (IOException e) {
LOG.severe("Error reading product id: line: [" + line + "]: Message: "
- + e.getMessage());
+ + e.getMessage());
} finally {
- try {
- br.close();
- } catch (Exception ignore) {
- }
+ try {
+ br.close();
+ } catch (Exception ignore) {
+ }
}
return productIds;
}
@@ -731,32 +749,32 @@ public class SolrIndexer {
String key = (String) objKey;
if (key.startsWith(PREFIX_CONFIG)) {
properties.put(key.substring(PREFIX_CONFIG.length()), props
- .getProperty(key));
+ .getProperty(key));
} else if (key.startsWith(PREFIX_MET)) {
mapProperties.put(key.substring(PREFIX_MET.length()), props
- .getProperty(key));
+ .getProperty(key));
} else if (key.startsWith(PREFIX_FORMAT)) {
formatProperties.put(key.substring(PREFIX_FORMAT.length()), props
- .getProperty(key));
+ .getProperty(key));
}
}
if (properties.getProperty(IGNORE_TYPES) != null) {
String[] values = properties.getProperty(IGNORE_TYPES).trim()
- .split(",");
- Collections.addAll(ignoreTypes, values);
+ .split(",");
+ Collections.addAll(ignoreTypes, values);
}
if (properties.getProperty(IGNORE_VALUES) != null) {
String[] values = properties.getProperty(IGNORE_VALUES).trim().split(
- ",");
- Collections.addAll(ignoreValues, values);
+ ",");
+ Collections.addAll(ignoreValues, values);
}
if (properties.getProperty(REPLACEMENT_KEYS) != null) {
String[] values = properties.getProperty(REPLACEMENT_KEYS).trim()
- .split(",");
- Collections.addAll(replacementKeys, values);
+ .split(",");
+ Collections.addAll(replacementKeys, values);
}
}
http://git-wip-us.apache.org/repos/asf/oodt/blob/78ce45e2/profile/pom.xml
----------------------------------------------------------------------
diff --git a/profile/pom.xml b/profile/pom.xml
index 3d67496..68f8fa9 100644
--- a/profile/pom.xml
+++ b/profile/pom.xml
@@ -62,9 +62,8 @@
<version>1.3</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.0-alpha1</version>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
http://git-wip-us.apache.org/repos/asf/oodt/blob/78ce45e2/protocol/http/pom.xml
----------------------------------------------------------------------
diff --git a/protocol/http/pom.xml b/protocol/http/pom.xml
index 4aaf834..19b5685 100644
--- a/protocol/http/pom.xml
+++ b/protocol/http/pom.xml
@@ -41,8 +41,8 @@
-->
<dependencies>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
http://git-wip-us.apache.org/repos/asf/oodt/blob/78ce45e2/resource/pom.xml
----------------------------------------------------------------------
diff --git a/resource/pom.xml b/resource/pom.xml
index 6ccb724..3e1bc8e 100644
--- a/resource/pom.xml
+++ b/resource/pom.xml
@@ -73,8 +73,8 @@ the License.
<artifactId>commons-dbcp</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
http://git-wip-us.apache.org/repos/asf/oodt/blob/78ce45e2/sso/pom.xml
----------------------------------------------------------------------
diff --git a/sso/pom.xml b/sso/pom.xml
index cdb59a2..82979ec 100644
--- a/sso/pom.xml
+++ b/sso/pom.xml
@@ -53,9 +53,8 @@ the License.
<version>1.3</version>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
- <version>3.0</version>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
http://git-wip-us.apache.org/repos/asf/oodt/blob/78ce45e2/sso/src/main/java/org/apache/oodt/security/sso/opensso/SSOProxy.java
----------------------------------------------------------------------
diff --git a/sso/src/main/java/org/apache/oodt/security/sso/opensso/SSOProxy.java b/sso/src/main/java/org/apache/oodt/security/sso/opensso/SSOProxy.java
index 5d77083..d0d399f 100755
--- a/sso/src/main/java/org/apache/oodt/security/sso/opensso/SSOProxy.java
+++ b/sso/src/main/java/org/apache/oodt/security/sso/opensso/SSOProxy.java
@@ -18,30 +18,37 @@
package org.apache.oodt.security.sso.opensso;
-import org.apache.commons.httpclient.HttpClient;
-import org.apache.commons.httpclient.HttpException;
-import org.apache.commons.httpclient.HttpStatus;
-import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.methods.PostMethod;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpStatus;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.BasicResponseHandler;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
- *
+ *
* A client class to the services provided by the <a
* href="https://opensso.dev.java.net/">OpenSSO</a> project. The descriptions of
* these services are <a
* href="http://developers.sun.com/identity/reference/techart/id-svcs.html"
* >here</a>.
- *
+ *
* @author mattmann
* @version $Revision$
- *
+ *
*/
public class SSOProxy implements SSOMetKeys {
@@ -54,53 +61,63 @@ public class SSOProxy implements SSOMetKeys {
private static final String IDENT_ATTR_ENDPOINT_KEY = "IDENT_ATTR_ENDPOINT";
private static final String LOG_ENDPOINT;
private static final String LOG_ENDPOINT_KEY = "LOG_ENDPOINT";
-
+
static {
- if (System.getProperty(AUTH_ENDPOINT_KEY) != null) {
- AUTH_ENDPOINT = System.getProperty(AUTH_ENDPOINT_KEY);
- } else {
- AUTH_ENDPOINT = AUTHENTICATE_ENDPOINT;
- }
- if (System.getProperty(IDENT_READ_ENDPOINT_KEY) != null) {
- IDENT_READ_ENDPOINT = System.getProperty(IDENT_READ_ENDPOINT_KEY);
- } else {
- IDENT_READ_ENDPOINT = IDENTITY_READ_ENDPOINT;
- }
- if (System.getProperty(IDENT_ATTR_ENDPOINT_KEY) != null) {
- IDENT_ATTR_ENDPOINT = System.getProperty(IDENT_ATTR_ENDPOINT_KEY);
- } else {
- IDENT_ATTR_ENDPOINT = IDENTITY_ATTRIBUTES_ENDPOINT;
- }
- if (System.getProperty(LOG_ENDPOINT_KEY) != null) {
- LOG_ENDPOINT = System.getProperty(LOG_ENDPOINT_KEY);
- } else {
- LOG_ENDPOINT = LOGOUT_ENDPOINT;
- }
-
- LOG.log(Level.INFO, AUTH_ENDPOINT_KEY + " set to " + AUTH_ENDPOINT);
- LOG.log(Level.INFO, IDENT_READ_ENDPOINT_KEY + " set to " + IDENT_READ_ENDPOINT);
- LOG.log(Level.INFO, IDENT_ATTR_ENDPOINT_KEY + " set to " + IDENT_ATTR_ENDPOINT);
- LOG.log(Level.INFO, LOG_ENDPOINT_KEY + " set to " + LOG_ENDPOINT);
+ if (System.getProperty(AUTH_ENDPOINT_KEY) != null) {
+ AUTH_ENDPOINT = System.getProperty(AUTH_ENDPOINT_KEY);
+ } else {
+ AUTH_ENDPOINT = AUTHENTICATE_ENDPOINT;
+ }
+ if (System.getProperty(IDENT_READ_ENDPOINT_KEY) != null) {
+ IDENT_READ_ENDPOINT = System.getProperty(IDENT_READ_ENDPOINT_KEY);
+ } else {
+ IDENT_READ_ENDPOINT = IDENTITY_READ_ENDPOINT;
+ }
+ if (System.getProperty(IDENT_ATTR_ENDPOINT_KEY) != null) {
+ IDENT_ATTR_ENDPOINT = System.getProperty(IDENT_ATTR_ENDPOINT_KEY);
+ } else {
+ IDENT_ATTR_ENDPOINT = IDENTITY_ATTRIBUTES_ENDPOINT;
+ }
+ if (System.getProperty(LOG_ENDPOINT_KEY) != null) {
+ LOG_ENDPOINT = System.getProperty(LOG_ENDPOINT_KEY);
+ } else {
+ LOG_ENDPOINT = LOGOUT_ENDPOINT;
+ }
+
+ LOG.log(Level.INFO, AUTH_ENDPOINT_KEY + " set to " + AUTH_ENDPOINT);
+ LOG.log(Level.INFO, IDENT_READ_ENDPOINT_KEY + " set to " + IDENT_READ_ENDPOINT);
+ LOG.log(Level.INFO, IDENT_ATTR_ENDPOINT_KEY + " set to " + IDENT_ATTR_ENDPOINT);
+ LOG.log(Level.INFO, LOG_ENDPOINT_KEY + " set to " + LOG_ENDPOINT);
}
public String authenticate(String username, String password) {
- HttpClient httpClient = new HttpClient();
- PostMethod post = new PostMethod(AUTH_ENDPOINT);
+ HttpClient httpClient = new DefaultHttpClient();
+ HttpPost post = new HttpPost(AUTH_ENDPOINT);
+ //PostMethod post = new PostMethod(AUTH_ENDPOINT);
String response;
String ssoToken = null;
- NameValuePair[] data = { new NameValuePair("username", username),
- new NameValuePair("password", password),
- new NameValuePair("uri", "realm/lmmp") };
+ NameValuePair[] data = { new BasicNameValuePair("username", username),
+ new BasicNameValuePair("password", password),
+ new BasicNameValuePair("uri", "realm/lmmp") };
- post.setRequestBody(data);
+ UrlEncodedFormEntity entity = null;
+ try {
+ entity = new UrlEncodedFormEntity(Arrays.asList(data), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ post.setEntity(entity);
try {
- httpClient.executeMethod(post);
- if (post.getStatusCode() != HttpStatus.SC_OK) {
- throw new HttpException(post.getStatusLine().toString());
+ HttpResponse response1 = httpClient.execute(post);
+ if (response1.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ throw new HttpException(response1.getStatusLine().toString());
}
- response = post.getResponseBodyAsString().trim();
+ ResponseHandler<String> handler = new BasicResponseHandler();
+
+ response = handler.handleResponse(response1);
ssoToken = response.substring(9);
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage());
@@ -112,56 +129,85 @@ public class SSOProxy implements SSOMetKeys {
}
public IdentityDetails readIdentity(String username, String token)
- throws IOException, SingleSignOnException {
- HttpClient httpClient = new HttpClient();
- PostMethod post = new PostMethod(IDENT_READ_ENDPOINT);
+ throws IOException, SingleSignOnException {
+ HttpClient httpClient = new DefaultHttpClient();
+ HttpPost post = new HttpPost(IDENT_READ_ENDPOINT);
LOG.log(Level.INFO, "Obtaining identity: username: [" + username
- + "]: token: [" + token + "]: REST url: [" + IDENT_READ_ENDPOINT
- + "]");
- NameValuePair[] data = { new NameValuePair("name", username),
- new NameValuePair("admin", token) };
+ + "]: token: [" + token + "]: REST url: [" + IDENT_READ_ENDPOINT
+ + "]");
+ NameValuePair[] data = { new BasicNameValuePair("name", username),
+ new BasicNameValuePair("admin", token) };
- post.setRequestBody(data);
+ UrlEncodedFormEntity entity = null;
+ try {
+ entity = new UrlEncodedFormEntity(Arrays.asList(data), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ post.setEntity(entity);
- httpClient.executeMethod(post);
- if (post.getStatusCode() != HttpStatus.SC_OK) {
- throw new SingleSignOnException(post.getStatusLine().toString());
+ HttpResponse response1 = httpClient.execute(post);
+ if (response1.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ throw new SingleSignOnException(response1.getStatusLine().toString());
}
- return parseIdentityDetails(post.getResponseBodyAsString().trim());
+ ResponseHandler<String> handler = new BasicResponseHandler();
+
+
+ return parseIdentityDetails(handler.handleResponse(response1).trim());
}
public UserDetails getUserAttributes(String token) throws IOException, SingleSignOnException {
- HttpClient httpClient = new HttpClient();
- PostMethod post = new PostMethod(IDENT_ATTR_ENDPOINT);
+ HttpClient httpClient = new DefaultHttpClient();
+ HttpPost post = new HttpPost(IDENT_READ_ENDPOINT);
LOG.log(Level.INFO, "Obtaining user attributes: token: [" + token
- + "]: REST url: [" + IDENT_ATTR_ENDPOINT + "]");
- NameValuePair[] data = { new NameValuePair("subjectid", token) };
+ + "]: REST url: [" + IDENT_ATTR_ENDPOINT + "]");
+ NameValuePair[] data = { new BasicNameValuePair("subjectid", token) };
+
+ UrlEncodedFormEntity entity = null;
+ try {
+ entity = new UrlEncodedFormEntity(Arrays.asList(data), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
- post.setRequestBody(data);
+ post.setEntity(entity);
- httpClient.executeMethod(post);
- if (post.getStatusCode() != HttpStatus.SC_OK) {
- throw new SingleSignOnException(post.getStatusLine().toString());
+ HttpResponse response1 = httpClient.execute(post);
+ if (response1.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ throw new SingleSignOnException(response1.getStatusLine().toString());
}
- return parseUserDetails(post.getResponseBodyAsString().trim());
+ ResponseHandler<String> handler = new BasicResponseHandler();
+
+
+ return parseUserDetails(handler.handleResponse(response1).trim());
}
public void logout(String token) {
- HttpClient httpClient = new HttpClient();
- PostMethod post = new PostMethod(LOG_ENDPOINT);
+ HttpClient httpClient = new DefaultHttpClient();
+ HttpPost post = new HttpPost(LOG_ENDPOINT);
LOG.log(Level.INFO, "Logging out: token: [" + token + "]: REST url: ["
- + LOG_ENDPOINT + "]");
- NameValuePair[] data = { new NameValuePair("subjectid", token) };
- post.setRequestBody(data);
+ + LOG_ENDPOINT + "]");
+ NameValuePair[] data = { new BasicNameValuePair("subjectid", token) };
+
+
+ UrlEncodedFormEntity entity = null;
+ try {
+ entity = new UrlEncodedFormEntity(Arrays.asList(data), "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+
+ post.setEntity(entity);
try {
- httpClient.executeMethod(post);
- if (post.getStatusCode() != HttpStatus.SC_OK) {
- throw new HttpException(post.getStatusLine().toString());
+ HttpResponse response1 = httpClient.execute(post);
+ if (response1.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
+ throw new HttpException(response1.getStatusLine().toString());
}
} catch (HttpException e) {
// TODO Auto-generated catch block
@@ -176,7 +222,7 @@ public class SSOProxy implements SSOMetKeys {
private IdentityDetails parseIdentityDetails(String serviceResponse) {
ByteArrayInputStream is = new ByteArrayInputStream(serviceResponse
- .getBytes());
+ .getBytes());
BufferedReader br = new BufferedReader(new InputStreamReader(is));
IdentityDetails details = new IdentityDetails();
String line = null, lastAttrKeyRead = null;
@@ -214,7 +260,7 @@ public class SSOProxy implements SSOMetKeys {
} catch (IOException e) {
LOG.log(Level.SEVERE, e.getMessage());
LOG.log(Level.WARNING, "Error reading service response line: [" + line
- + "]: Message: " + e.getMessage());
+ + "]: Message: " + e.getMessage());
} finally {
try {
is.close();
@@ -233,7 +279,7 @@ public class SSOProxy implements SSOMetKeys {
private UserDetails parseUserDetails(String serviceResponse) {
ByteArrayInputStream is = new ByteArrayInputStream(serviceResponse
- .getBytes());
+ .getBytes());
BufferedReader br = new BufferedReader(new InputStreamReader(is));
UserDetails details = new UserDetails();
String line = null, lastAttrKeyRead = null;
@@ -264,7 +310,7 @@ public class SSOProxy implements SSOMetKeys {
} catch (IOException e) {
LOG.log(Level.SEVERE, e.getMessage());
LOG.log(Level.WARNING, "Error reading service response line: [" + line
- + "]: Message: " + e.getMessage());
+ + "]: Message: " + e.getMessage());
} finally {
try {
is.close();
@@ -283,8 +329,8 @@ public class SSOProxy implements SSOMetKeys {
public static void main(String[] args) throws IOException, SingleSignOnException {
String usage = "SSOProxy <cmd> [args]\n\n" + "Where cmd is one of:\n"
- + "authenticate <user> <pass>\n" + "identity <user> <token>\n"
- + "attributes <token>\nlogout <token>\n";
+ + "authenticate <user> <pass>\n" + "identity <user> <token>\n"
+ + "attributes <token>\nlogout <token>\n";
if (args.length < 2 || args.length > 3) {
System.err.println(usage);
http://git-wip-us.apache.org/repos/asf/oodt/blob/78ce45e2/workflow/pom.xml
----------------------------------------------------------------------
diff --git a/workflow/pom.xml b/workflow/pom.xml
index 72fb549..1fe5189 100644
--- a/workflow/pom.xml
+++ b/workflow/pom.xml
@@ -76,8 +76,8 @@ the License.
<artifactId>commons-dbcp</artifactId>
</dependency>
<dependency>
- <groupId>commons-httpclient</groupId>
- <artifactId>commons-httpclient</artifactId>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>