Revision: 13661
http://gate.svn.sourceforge.net/gate/?rev=13661&view=rev
Author: valyt
Date: 2011-04-12 13:08:07 +0000 (Tue, 12 Apr 2011)
Log Message:
-----------
Moved the Basic Authentication support into the default WebUtils implementation
(provide a null or empty username to disable it).
Modified Paths:
--------------
mimir/trunk/mimir-client/src/gate/mimir/tool/WebUtils.java
Removed Paths:
-------------
mimir/trunk/mimir-client/src/gate/mimir/tool/BasicAuthWebUtils.java
Deleted: mimir/trunk/mimir-client/src/gate/mimir/tool/BasicAuthWebUtils.java
===================================================================
--- mimir/trunk/mimir-client/src/gate/mimir/tool/BasicAuthWebUtils.java
2011-04-12 12:18:25 UTC (rev 13660)
+++ mimir/trunk/mimir-client/src/gate/mimir/tool/BasicAuthWebUtils.java
2011-04-12 13:08:07 UTC (rev 13661)
@@ -1,50 +0,0 @@
-package gate.mimir.tool;
-
-import gate.util.GateRuntimeException;
-
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.CookieHandler;
-import java.net.URL;
-import java.net.URLConnection;
-
-import javax.xml.bind.DatatypeConverter;
-
-/**
- * Extension of the standard WebUtils class that passes a fixed
- * HTTP basic authentication header with all its HTTP requests.
- */
-public class BasicAuthWebUtils extends WebUtils {
-
- private String authHeader;
-
- public BasicAuthWebUtils(String username, String password) {
- super();
- buildAuthHeader(username, password);
- }
-
- public BasicAuthWebUtils(CookieHandler cookieJar, String username, String
password) {
- super(cookieJar);
- buildAuthHeader(username, password);
- }
-
- protected void buildAuthHeader(String username, String password) {
- try {
- String userPass = username + ":" + password;
- authHeader = "Basic " +
DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
- } catch(UnsupportedEncodingException e) {
- throw new GateRuntimeException("UTF-8 encoding not supported by this
JVM!", e);
- }
- }
-
- /**
- * Open a connection to the given URL, supplying the configured
- * Authorization header.
- */
- @Override
- protected URLConnection openURLConnection(URL u) throws IOException {
- URLConnection conn = super.openURLConnection(u);
- conn.setRequestProperty("Authorization", authHeader);
- return conn;
- }
-}
Modified: mimir/trunk/mimir-client/src/gate/mimir/tool/WebUtils.java
===================================================================
--- mimir/trunk/mimir-client/src/gate/mimir/tool/WebUtils.java 2011-04-12
12:18:25 UTC (rev 13660)
+++ mimir/trunk/mimir-client/src/gate/mimir/tool/WebUtils.java 2011-04-12
13:08:07 UTC (rev 13661)
@@ -1,5 +1,7 @@
package gate.mimir.tool;
+import gate.util.GateRuntimeException;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -8,6 +10,7 @@
import java.io.OutputStream;
import java.io.Reader;
import java.io.Serializable;
+import java.io.UnsupportedEncodingException;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.HttpURLConnection;
@@ -18,6 +21,8 @@
import java.util.List;
import java.util.Map;
+import javax.xml.bind.DatatypeConverter;
+
/**
* A collection of methods that provide various utility functions for web
* applications.
@@ -26,14 +31,34 @@
private CookieHandler cookieJar;
+ private String authHeader;
+
+ public WebUtils() {
+ this(new CookieManager(), null, null);
+ }
+
public WebUtils(CookieHandler cookieJar) {
- this.cookieJar = cookieJar;
+ this(cookieJar, null, null);
}
- public WebUtils() {
- this(new CookieManager());
+ public WebUtils(String userName, String password) {
+ this(new CookieManager(), userName, password);
}
+ public WebUtils(CookieHandler cookieJar, String userName, String password) {
+ this.cookieJar = cookieJar;
+ if(userName != null && userName.length() > 0){
+ try {
+ String userPass = userName + ":" + password;
+ authHeader = "Basic " +
DatatypeConverter.printBase64Binary(userPass.getBytes("UTF-8"));
+ } catch(UnsupportedEncodingException e) {
+ throw new GateRuntimeException("UTF-8 encoding not supported by this
JVM!", e);
+ }
+ } else {
+ authHeader = null;
+ }
+ }
+
private static WebUtils staticWebUtils = null;
public static WebUtils staticWebUtils() {
@@ -94,6 +119,9 @@
throw (IOException)new IOException(
"Error converting URL " + u + " to a URI").initCause(e);
}
+ if(authHeader != null) {
+ conn.setRequestProperty("Authorization", authHeader);
+ }
return conn;
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes
not days. Key insights are discussed in the 2010 Forrester Wave Report as
part of an in-depth evaluation of disaster recovery service providers.
Forrester found the best-in-class provider in terms of services and vision.
Read this report now! http://p.sf.net/sfu/ibm-webcastpromo
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs