[Httpunit-commit] CVS: httpunit/src/com/meterware/httpunit GetMethodWebRequest.java,1.3,1.4 PostMeth
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2000-09-28 18:27:42
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv13592/src/com/meterware/httpunit Modified Files: GetMethodWebRequest.java PostMethodWebRequest.java WebConversation.java WebRequest.java Log Message: Added https support Index: GetMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/GetMethodWebRequest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- GetMethodWebRequest.java 2000/09/15 16:38:44 1.3 +++ GetMethodWebRequest.java 2000/09/28 18:27:39 1.4 @@ -44,15 +44,6 @@ } - public URL getURL() throws MalformedURLException { - if (hasNoParameters()) { - return new URL( getURLBase(), getURLString() ); - } else { - return new URL( getURLBase(), getURLString() + "?" + getParameterString() ); - } - } - - //--------------------------------------- package members --------------------------------------------- @@ -61,6 +52,18 @@ **/ GetMethodWebRequest( URL urlBase, String urlString, WebForm sourceForm ) { super( urlBase, urlString, sourceForm ); + } + + +//------------------------------------- protected members --------------------------------------------- + + + protected String getURLString() { + if (hasNoParameters()) { + return super.getURLString(); + } else { + return super.getURLString() + "?" + getParameterString(); + } } Index: PostMethodWebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/PostMethodWebRequest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- PostMethodWebRequest.java 2000/09/15 16:38:44 1.4 +++ PostMethodWebRequest.java 2000/09/28 18:27:39 1.5 @@ -43,11 +43,6 @@ //---------------------------------- WebRequest methods -------------------------------- - public URL getURL() throws MalformedURLException { - return new URL( getURLBase(), getURLString() ); - } - - protected void completeRequest( URLConnection connection ) throws IOException { connection.setDoInput( true ); connection.setDoOutput( true ); Index: WebConversation.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebConversation.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- WebConversation.java 2000/09/27 18:04:04 1.9 +++ WebConversation.java 2000/09/28 18:27:39 1.10 @@ -200,12 +200,6 @@ RedirectWebRequest( WebRequest baseRequest, String relativeURL ) throws MalformedURLException { super( baseRequest, relativeURL ); - } - - - public URL getURL() throws MalformedURLException { - return new URL( getURLBase(), getURLString() ); - } - + } } Index: WebRequest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/httpunit/WebRequest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- WebRequest.java 2000/09/15 16:38:44 1.5 +++ WebRequest.java 2000/09/28 18:27:39 1.6 @@ -3,6 +3,9 @@ import java.io.*; import java.net.*; import java.util.*; +import java.lang.reflect.*; +import java.security.Provider; +import java.security.Security; /** * A request sent to a web server. @@ -66,8 +69,10 @@ /** * Returns the final URL associated with this web request. **/ - abstract - public URL getURL() throws MalformedURLException; + public URL getURL() throws MalformedURLException { + if (getURLBase() == null) validateProtocol( getURLString() ); + return new URL( getURLBase(), getURLString() ); + } @@ -121,7 +126,6 @@ } - final protected String getURLString() { return _urlString; } @@ -151,12 +155,16 @@ //--------------------------------------- private members ------------------------------------ + private final static String PROTOCOL_HANDLER_PKGS = "java.protocol.handler.pkgs"; + private URL _urlBase; private String _urlString; private Hashtable _parameters = new Hashtable(); private WebForm _sourceForm; + private boolean _httpsProtocolSupportEnabled; + private void appendParameters( StringBuffer sb, String name, String[] values, boolean moreToCome ) { for (int i = 0; i < values.length; i++) { appendParameter( sb, name, values[i], (i < values.length-1 || moreToCome ) ); @@ -197,7 +205,80 @@ } + private void validateProtocol( String urlString ) { + String protocol = urlString.substring( 0, urlString.indexOf( ':' ) ); + if (protocol.length() == 0) { + throw new RuntimeException( "No protocol specified in URL '" + urlString + "'" ); + } else if (protocol.equalsIgnoreCase( "http" )) { + return; + } else if (protocol.equalsIgnoreCase( "https" )) { + validateHttpsProtocolSupport(); + } + } + + + void validateHttpsProtocolSupport() { + if (!_httpsProtocolSupportEnabled) { + verifyHttpsSupport(); + _httpsProtocolSupportEnabled = true; + } + } + + + private static void listProviders() { + Provider[] list = Security.getProviders(); + for (int i = 0; i < list.length; i++) { + System.out.println( "provider" + i + "=" + list[i] ); + } + } + + + private static boolean hasSSLProvider() { + Provider[] list = Security.getProviders(); + for (int i = 0; i < list.length; i++) { + if (list[i].getClass().getName().equals( SunJSSE_PROVIDER_CLASS )) return true; + } + return false; + } + + private static String SunJSSE_PROVIDER_CLASS = "com.sun.net.ssl.internal.ssl.Provider"; + private static RuntimeException _httpsProblem; + + + static void verifyHttpsSupport() { + if (System.getProperty( "java.version" ).startsWith( "1.1" )) { + throw new RuntimeException( "https support requires Java 2" ); + } else if (System.getProperty( PROTOCOL_HANDLER_PKGS ) == null) { + try { + Class.forName( "com.sun.net.ssl.HttpsURLConnection" ); + Method setMethod = System.class.getMethod( "setProperty", new Class[] { String.class, String.class } ); + setMethod.invoke( null, new String[] { PROTOCOL_HANDLER_PKGS, "com.sun.net.ssl.internal.www.protocol" } ); + if (!hasSSLProvider()) { + throw new RuntimeException( "https support not enabled. Please edit <java-home>/lib/security/java.security to add the line: " + + "security.provider.2=com.sun.net.ssl.internal.ssl.Provider" ); + } + } catch (ClassNotFoundException e) { + throw new RuntimeException( "https support requires the Java Secure Sockets Extension. See http://java.sun.com/products/jsse/install.html" ); + } catch (Throwable e) { + throw new RuntimeException( "Unable to enable https support. Make sure that you have installed JSSE " + + "as described in http://java.sun.com/products/jsse/install.html: " + e ); + } + } + } + + + // this does not work for some reason + static void unusedSetProviderDynamically() throws ClassNotFoundException, InstantiationException, IllegalAccessException { + Security.addProvider( (Provider) Class.forName( SunJSSE_PROVIDER_CLASS ).newInstance() ); + } + + } + + + + + //================================ exception class NoSuchParameterException ========================================= |