[Bedework-commit] davutil r73 - in
trunk/davio/src/org/bedework/http/client: . dav
svnadmin at bedework.org
svnadmin at bedework.org
Tue Jul 15 00:08:59 EDT 2008
Author: douglm
Date: 2008-07-15 00:08:54 -0400 (Tue, 15 Jul 2008)
New Revision: 73
Modified:
trunk/davio/src/org/bedework/http/client/Client.java
trunk/davio/src/org/bedework/http/client/dav/DavClient.java
trunk/davio/src/org/bedework/http/client/dav/DavResp.java
Log:
Allow storing of id and encrypted password for an external calendar subscription.
Switch to use DavClient instead of HttpClient directly.
Modified: trunk/davio/src/org/bedework/http/client/Client.java
===================================================================
--- trunk/davio/src/org/bedework/http/client/Client.java 2008-07-02 04:02:09 UTC (rev 72)
+++ trunk/davio/src/org/bedework/http/client/Client.java 2008-07-15 04:08:54 UTC (rev 73)
@@ -249,4 +249,19 @@
throw new DavioException(t);
}
}
-}
\ No newline at end of file
+
+ /**
+ * Returns the header specified by the case insensitive name.
+ *
+ * @param name
+ * @return Header: Multiple instances values will be combined with a ','.
+ * @throws DavioException
+ */
+ public Header getResponseHeader(String name) throws DavioException {
+ try {
+ return method.getResponseHeader(name);
+ } catch (Throwable t) {
+ throw new DavioException(t);
+ }
+ }
+}
Modified: trunk/davio/src/org/bedework/http/client/dav/DavClient.java
===================================================================
--- trunk/davio/src/org/bedework/http/client/dav/DavClient.java 2008-07-02 04:02:09 UTC (rev 72)
+++ trunk/davio/src/org/bedework/http/client/dav/DavClient.java 2008-07-15 04:08:54 UTC (rev 73)
@@ -29,7 +29,7 @@
import java.io.InputStreamReader;
import java.io.Serializable;
import java.io.StringWriter;
-import java.net.URI;
+import org.apache.commons.httpclient.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
@@ -93,68 +93,39 @@
}
/**
- * @param host
- * @param port
+ * @param uri - an un-escaped URI
* @param timeOut - millisecs, 0 for no timeout
- * @param secure
* @param debug
* @throws DavioException
*/
- public DavClient(String host, int port, int timeOut, boolean secure,
+ public DavClient(String uri, int timeOut,
boolean debug) throws DavioException {
- if (httpManager == null) {
- httpManager = new HttpManager(DavIo.class.getName());
- }
-
HostConfiguration config = new HostConfiguration();
-
- if (secure) {
- /*
- ProtocolSocketFactory pfact = new SSLProtocolSocketFactory();
- Protocol pr = new Protocol("https", pfact, port);
- Protocol.registerProtocol( "https", pr);
- */
- Protocol trustHttps;
-
- try {
- BaseProtocolSocketFactory f = new BaseProtocolSocketFactory();
-
- warn("Trusting all certificates");
- // might as well trust the usual suspects:
- //f.addTrustMaterial(TrustMaterial.CACERTS);
- f.addTrustMaterial(TrustMaterial.TRUST_ALL);
-
- // here's where we start trusting usertrust.com's CA:
- //f.addTrustMaterial(new TrustMaterial(pemCert));
-
- trustHttps = new Protocol("https", f, 443);
- Protocol.registerProtocol("https", trustHttps);
- } catch (Throwable t) {
- throw new DavioException(t);
- }
-
- config.setHost(host, port, trustHttps);
- } else {
- config.setHost(host, port);
+ URI u;
+ try {
+ u = new URI(uri, false);
+ config.setHost(u);
+ } catch (Throwable t) {
+ throw new DavioException(t);
}
- /*
- if (secure) {
- config.setHost(new URI("https://" + host + ":" + port, false));
- } else {
- config.setHost(new URI("http://" + host + ":" + port, false));
- }
- */
- if (debug) {
- debugMsg("uri set to " + config.getHostURL());
- }
- httpManager.getParams().setConnectionTimeout(timeOut);
+ init(config.getHost(), config.getPort(), timeOut,
+ "https".equals(u.getScheme()), debug);
+ }
- client = (DavIo)httpManager.getClient(config);
+ /**
+ * @param host
+ * @param port
+ * @param timeOut - millisecs, 0 for no timeout
+ * @param secure
+ * @param debug
+ * @throws DavioException
+ */
+ public DavClient(String host, int port, int timeOut, boolean secure,
+ boolean debug) throws DavioException {
+ init(host, port, timeOut, secure, debug);
+ }
- this.debug = debug;
- }
-
/** Set the credentials. user == null for unauthenticated.
*
* @param user
@@ -170,6 +141,19 @@
}
}
+ /** Send a (simple) request to the server
+ *
+ * @param method
+ * @param url
+ * @param hdrs
+ * @return int status code
+ * @throws Throwable
+ */
+ public int sendRequest(String method, String url,
+ Header[] hdrs) throws Throwable {
+ return sendRequest(method, url, hdrs, null, null, 0, null);
+ }
+
/** Send a request to the server
*
* @param method
@@ -702,9 +686,80 @@
public String getResponseBodyAsString() throws DavioException {
return client.getResponseBodyAsString();
}
+
+ public Header getResponseHeader(String name) throws DavioException {
+ return client.getResponseHeader(name);
+ }
}
/** ===================================================================
+ * Private methods
+ * =================================================================== */
+
+ /**
+ * @param host
+ * @param port
+ * @param timeOut - millisecs, 0 for no timeout
+ * @param secure
+ * @param debug
+ * @throws DavioException
+ */
+ private void init(String host, int port, int timeOut, boolean secure,
+ boolean debug) throws DavioException {
+ if (httpManager == null) {
+ httpManager = new HttpManager(DavIo.class.getName());
+ }
+
+ HostConfiguration config = new HostConfiguration();
+
+ if (secure) {
+ /*
+ ProtocolSocketFactory pfact = new SSLProtocolSocketFactory();
+ Protocol pr = new Protocol("https", pfact, port);
+ Protocol.registerProtocol( "https", pr);
+ */
+ Protocol trustHttps;
+
+ try {
+ BaseProtocolSocketFactory f = new BaseProtocolSocketFactory();
+
+ warn("Trusting all certificates");
+ // might as well trust the usual suspects:
+ //f.addTrustMaterial(TrustMaterial.CACERTS);
+ f.addTrustMaterial(TrustMaterial.TRUST_ALL);
+
+ // here's where we start trusting usertrust.com's CA:
+ //f.addTrustMaterial(new TrustMaterial(pemCert));
+
+ trustHttps = new Protocol("https", f, 443);
+ Protocol.registerProtocol("https", trustHttps);
+ } catch (Throwable t) {
+ throw new DavioException(t);
+ }
+
+ config.setHost(host, port, trustHttps);
+ } else {
+ config.setHost(host, port);
+ }
+ /*
+ if (secure) {
+ config.setHost(new URI("https://" + host + ":" + port, false));
+ } else {
+ config.setHost(new URI("http://" + host + ":" + port, false));
+ }
+ */
+ if (debug) {
+ debugMsg("uri set to " + config.getHostURL());
+ }
+
+ httpManager.getParams().setConnectionTimeout(timeOut);
+
+ client = (DavIo)httpManager.getClient(config);
+
+ this.debug = debug;
+ }
+
+ /** ===================================================================
* Logging methods
* =================================================================== */
Modified: trunk/davio/src/org/bedework/http/client/dav/DavResp.java
===================================================================
--- trunk/davio/src/org/bedework/http/client/dav/DavResp.java 2008-07-02 04:02:09 UTC (rev 72)
+++ trunk/davio/src/org/bedework/http/client/dav/DavResp.java 2008-07-15 04:08:54 UTC (rev 73)
@@ -56,6 +56,8 @@
import org.bedework.http.client.DavioException;
+import org.apache.commons.httpclient.Header;
+
import java.io.InputStream;
/**
@@ -113,4 +115,13 @@
* @throws DavioException
*/
String getResponseBodyAsString() throws DavioException;
+
+ /**
+ * Returns the header specified by the case insensitive name.
+ *
+ * @param name
+ * @return Header: Multiple instances values will be combined with a ','.
+ * @throws DavioException
+ */
+ Header getResponseHeader(String name) throws DavioException;
}
More information about the Bedework-commit
mailing list