Revision: 13765
http://gate.svn.sourceforge.net/gate/?rev=13765&view=rev
Author: ian_roberts
Date: 2011-04-26 16:40:57 +0000 (Tue, 26 Apr 2011)
Log Message:
-----------
Added support for HTTP basic authentication to the GCP MimirOutputHandler.
Modified Paths:
--------------
gcp/trunk/src/gate/cloud/io/mimir/MimirOutputHandler.java
gcp/trunk/test/data/batch-test-0001.xml
Modified: gcp/trunk/src/gate/cloud/io/mimir/MimirOutputHandler.java
===================================================================
--- gcp/trunk/src/gate/cloud/io/mimir/MimirOutputHandler.java 2011-04-26
15:39:25 UTC (rev 13764)
+++ gcp/trunk/src/gate/cloud/io/mimir/MimirOutputHandler.java 2011-04-26
16:40:57 UTC (rev 13765)
@@ -15,6 +15,7 @@
import gate.cloud.io.AbstractOutputHandler;
import gate.cloud.io.OutputHandler;
import gate.mimir.index.MimirConnector;
+import gate.mimir.tool.WebUtils;
import gate.util.GateException;
import java.io.IOException;
@@ -48,6 +49,11 @@
private String uriFeature;
/**
+ * The {@link MimirConnector} used to send documents to Mímir.
+ */
+ private MimirConnector mimirConnector;
+
+ /**
* Parameter name for the index URL parameter (for which the value should be
* the URL of the Mímir index).
*/
@@ -67,6 +73,24 @@
*/
public static final String PARAM_URI_FEATURE = "uriFeature";
+ /**
+ * Username parameter name. If this parameter is set it is used as the HTTP
+ * basic authentication username when connecting to Mímir. If not
+ * set, no authentication header will be sent (unless you have installed a
+ * system-wide <code>java.net.Authenticator</code>). Note that this
+ * connector supports only a single username/password pair, so when posting
+ * documents to a federated index <i>all</i> indexes in the federation must
+ * accept the same credentials.
+ */
+ public static final String PARAM_USERNAME = "username";
+
+ /**
+ * Password parameter name. If this parameter is set it is used as the HTTP
+ * basic authentication password when connecting to Mímir. This
+ * parameter is only used if {@link #PARAM_USERNAME} is also set.
+ */
+ public static final String PARAM_PASSWORD = "password";
+
public void config(Map<String, String> configData) throws IOException,
GateException {
String indexUrlStr = configData.get(PARAM_INDEX_URL);
@@ -84,6 +108,18 @@
namespace = configData.get(PARAM_NAMESPACE);
if(namespace == null) namespace = "";
uriFeature = configData.get(PARAM_URI_FEATURE);
+
+ WebUtils webUtils = null;
+ if(configData.get(PARAM_USERNAME) == null) {
+ // no authentication
+ webUtils = new WebUtils();
+ } else {
+ // use username and password
+ webUtils = new WebUtils(configData.get(PARAM_USERNAME),
+ configData.get(PARAM_PASSWORD));
+ }
+
+ mimirConnector = new MimirConnector(webUtils);
}
public void ouputDocument(Document document, String documentId)
@@ -99,8 +135,6 @@
else {
uri = namespace + document.getName();
}
- MimirConnector.defaultConnector().sendToMimir(document, uri, indexUrl);
+ mimirConnector.sendToMimir(document, uri, indexUrl);
}
-
-
}
Modified: gcp/trunk/test/data/batch-test-0001.xml
===================================================================
--- gcp/trunk/test/data/batch-test-0001.xml 2011-04-26 15:39:25 UTC (rev
13764)
+++ gcp/trunk/test/data/batch-test-0001.xml 2011-04-26 16:40:57 UTC (rev
13765)
@@ -59,10 +59,14 @@
<!-- Send documents to a Mimir indexing server. This output handler always
sends the whole document to the server - annotationSet elements are
- ignored. -->
+ ignored. The username and password attributes are optional - if
+ specified they will be used as credentials for HTTP basic authentication
+ when contacting the Mimir server. -->
<!--
<output indexUrl="http://mimir.example.com/cloud-index-001"
namespace="urn:gatecloud.net:"
+ username="manager"
+ password="changeme"
class="gate.cloud.io.mimir.MimirOutputHandler" />
-->
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today. Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs