1 /*
2 * $Header: /home/cvs/jakarta-commons/httpclient/src/test/org/apache/commons/httpclient/TestHttps.java,v 1.9 2003/02/02 11:05:19 olegk Exp $
3 * $Revision: 1.9 $
4 * $Date: 2003/02/02 11:05:19 $
5 * ====================================================================
6 *
7 * The Apache Software License, Version 1.1
8 *
9 * Copyright (c) 1999-2003 The Apache Software Foundation. All rights
10 * reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 *
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
22 * distribution.
23 *
24 * 3. The end-user documentation included with the redistribution, if
25 * any, must include the following acknowlegement:
26 * "This product includes software developed by the
27 * Apache Software Foundation (http://www.apache.org/)."
28 * Alternately, this acknowlegement may appear in the software itself,
29 * if and wherever such third-party acknowlegements normally appear.
30 *
31 * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
32 * Foundation" must not be used to endorse or promote products derived
33 * from this software without prior written permission. For written
34 * permission, please contact apache@apache.org.
35 *
36 * 5. Products derived from this software may not be called "Apache"
37 * nor may "Apache" appear in their names without prior written
38 * permission of the Apache Group.
39 *
40 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
42 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
43 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
46 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
47 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
48 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
49 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
50 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This software consists of voluntary contributions made by many
55 * individuals on behalf of the Apache Software Foundation. For more
56 * information on the Apache Software Foundation, please see
57 * <http://www.apache.org/>.
58 *
59 * [Additional notices, if required by prior licensing conditions]
60 *
61 */
62
63 package org.apache.commons.httpclient;
64
65 import junit.framework.Test;
66 import junit.framework.TestCase;
67 import junit.framework.TestSuite;
68
69 import org.apache.commons.httpclient.methods.GetMethod;
70
71 /***
72 * Simple tests for HTTPS support in HttpClient.
73 *
74 * To run this test you'll need:
75 * + a JSSE implementation installed (see README.txt)
76 * + the java.protocol.handler.pkgs system property set
77 * for your provider. e.g.:
78 * -Djava.protocol.handler.pkgs=com.sun.net.ssl.internal.www.protocol
79 * (see build.xml)
80 *
81 * @author Rodney Waldhoff
82 * @author Ortwin Gl�ck
83 * @version $Id: TestHttps.java,v 1.9 2003/02/02 11:05:19 olegk Exp $
84 */
85 public class TestHttps extends TestCase {
86
87 // ---------------------------------------------------------------- Members
88 private String _urlWithPort = null;
89 private String _urlWithoutPort = null;
90 private final String PROXY_HOST = System.getProperty("httpclient.test.proxyHost");
91 private final String PROXY_PORT = System.getProperty("httpclient.test.proxyPort");
92 private final String PROXY_USER = System.getProperty("httpclient.test.proxyUser");
93 private final String PROXY_PASS = System.getProperty("httpclient.test.proxyPass");
94
95 // ------------------------------------------------------------ Constructor
96 public TestHttps(String testName) {
97 super(testName);
98 }
99
100 // ------------------------------------------------------------------- Main
101 public static void main(String args[]) {
102 String[] testCaseName = { TestHttps.class.getName() };
103 junit.textui.TestRunner.main(testCaseName);
104 }
105
106 // ------------------------------------------------------- TestCase Methods
107 public static Test suite() {
108 return new TestSuite(TestHttps.class);
109 }
110
111 public void setUp() throws Exception {
112 _urlWithPort = "https://www.verisign.com:443/";
113 _urlWithoutPort = "https://www.verisign.com/";
114 }
115
116 public void testHttpsGet() {
117 HttpClient client = new HttpClient();
118 if (PROXY_HOST != null) {
119 if (PROXY_USER != null) {
120 HttpState state = client.getState();
121 state.setProxyCredentials(null, new UsernamePasswordCredentials(
122 PROXY_USER, PROXY_PASS));
123 }
124 client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
125 }
126 GetMethod method = new GetMethod(_urlWithPort);
127
128 try {
129 client.executeMethod(method);
130 } catch (Throwable t) {
131 t.printStackTrace();
132 fail("Exception thrown during HTTPS GET: " + t.toString());
133 }
134
135 try {
136 String data = method.getResponseBodyAsString();
137 // This enumeration musn't be empty
138 assertTrue("No data returned.", (data.length() > 0));
139 } catch (Throwable t) {
140 t.printStackTrace();
141 fail("Exception thrown while retrieving data : " + t.toString());
142 }
143 }
144
145 public void testHttpsGetNoPort() {
146 HttpClient client = new HttpClient();
147 if (PROXY_HOST != null) {
148 if (PROXY_USER != null) {
149 HttpState state = client.getState();
150 state.setProxyCredentials(null, new UsernamePasswordCredentials(
151 PROXY_USER, PROXY_PASS));
152 }
153 client.getHostConfiguration().setProxy(PROXY_HOST, Integer.parseInt(PROXY_PORT));
154 }
155 GetMethod method = new GetMethod(_urlWithoutPort);
156
157 try {
158 client.executeMethod(method);
159 } catch (Throwable t) {
160 t.printStackTrace();
161 fail("Exception thrown during HTTPS GET: " + t.toString());
162 }
163
164 try {
165 String data = method.getResponseBodyAsString();
166 // This enumeration musn't be empty
167 assertTrue("No data returned.", (data.length() > 0));
168 } catch (Throwable t) {
169 t.printStackTrace();
170 fail("Exception thrown while retrieving data : " + t.toString());
171 }
172 }
173 }
This page was automatically generated by Maven