01: /*
02: * BEGIN_HEADER - DO NOT EDIT
03: *
04: * The contents of this file are subject to the terms
05: * of the Common Development and Distribution License
06: * (the "License"). You may not use this file except
07: * in compliance with the License.
08: *
09: * You can obtain a copy of the license at
10: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
11: * See the License for the specific language governing
12: * permissions and limitations under the License.
13: *
14: * When distributing Covered Code, include this CDDL
15: * HEADER in each file and include the License file at
16: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
17: * If applicable add the following below this CDDL HEADER,
18: * with the fields enclosed by brackets "[]" replaced with
19: * your own identifying information: Portions Copyright
20: * [year] [name of copyright owner]
21: */
22:
23: /*
24: * @(#)SecureClient.java
25: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
26: *
27: * END_HEADER - DO NOT EDIT
28: */
29: /**
30: * SecureClient.java
31: *
32: * SUN PROPRIETARY/CONFIDENTIAL.
33: * This software is the proprietary information of Sun Microsystems, Inc.
34: * Use is subject to license terms.
35: *
36: * Created on November 16, 2004, 4:33 PM
37: */package com.sun.jbi.internal.security.https.jregress.client;
38:
39: import java.net.HttpURLConnection;
40: import java.net.URL;
41: import java.io.File;
42: import java.io.FileWriter;
43:
44: import com.sun.jbi.internal.security.https.jregress.Helper;
45:
46: /**
47: * This is a client which will be used to connect to the TestSecurityServlet,
48: * to test the Transport Level Security feature.
49: *
50: * @author Sun Microsystems, Inc.
51: */
52: public class SecureClient {
53:
54: /** Creates a new instance of SecureClient */
55: public SecureClient(URL url, String file) throws Exception {
56: HttpURLConnection connection = (HttpURLConnection) url
57: .openConnection();
58: setExtendedHostVerifier(connection);
59: Helper.getResponse(connection, new FileWriter(file, true));
60: }
61:
62: public static void main(String[] args) throws Exception {
63: try {
64: if (args.length != 2) {
65: System.out.println("Usage: SecureClient <url> <file>");
66: return;
67: }
68:
69: SecureClient client = new SecureClient(new URL(args[0]),
70: args[1]);
71:
72: } catch (Exception ex) {
73: //-- ex.printStackTrace();
74: throw ex;
75: }
76:
77: }
78:
79: /**
80: * Set a Hostname Verifier, this is called when hostname verification fails,
81: * Ignore the hostname mismatch as this is a test client.
82: *
83: * @param connection is the HttpURLConnection
84: */
85: private void setExtendedHostVerifier(HttpURLConnection connection) {
86: if (connection instanceof javax.net.ssl.HttpsURLConnection) {
87: ((javax.net.ssl.HttpsURLConnection) connection)
88: .setHostnameVerifier(new javax.net.ssl.HostnameVerifier() {
89: public boolean verify(String hostname,
90: javax.net.ssl.SSLSession ssn) {
91: return true;
92: }
93: });
94: }
95:
96: }
97:
98: }
|