httpsserverinterview.java
来自「cqME :java framework for TCK test.」· Java 代码 · 共 270 行
JAVA
270 行
/* * $Id$ * * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 only, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License version 2 for more details (a copy is * included at /legal/license.txt). * * You should have received a copy of the GNU General Public License * version 2 along with this work; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa * Clara, CA 95054 or visit www.sun.com if you need additional * information or have any questions. * */package com.sun.tck.j2me.interview.network.https;import java.net.InetAddress;import java.net.UnknownHostException;import java.util.Map;import com.sun.interview.FinalQuestion;import com.sun.interview.Interview;import com.sun.interview.Question;import com.sun.tck.j2me.interview.lib.ChoiceQuestion;import com.sun.tck.j2me.interview.lib.Exporter;import com.sun.tck.j2me.interview.lib.Exporters;import com.sun.tck.j2me.interview.lib.FileQuestion;import com.sun.tck.j2me.interview.lib.IntQuestion;import com.sun.tck.j2me.interview.lib.NullQuestion;import com.sun.tck.j2me.interview.lib.StringQuestion;import com.sun.tck.j2me.interview.lib.Validators;import com.sun.tck.j2me.interview.lib.YesNoQuestion;/** * Configuration interview for the HTTPS support server. * <p> * There are two modes in which this interview operates: * <ul> * <li><tt>Default Mode</tt>: The interview assumes that httpHost and https * verbose questions have been provided by other interviews. This interview's * httpHost and verbose questions are hidden. The interview expects two * variables to be defined in the environment: <code>$httpHost</code> and * <code>$network.https.verbose</code>. </li> * <li><tt>StandAlone Mode</tt>: The interview provides its own httpHost and * verbose questions and does not rely on any variables to be present in the * environment.</li> * </ul> */public class HttpsServerInterview extends Interview { /** * Creates HttpsServerInterview instance with appropriate parent. * * @param parent * Interview's parent. */ public HttpsServerInterview(Interview parent) throws Interview.Fault { super(parent, INTERVIEW_TAG); setResourceBundle(INTERVIEW_TAG); setHelpSet("help/" + INTERVIEW_TAG); setInterviewSemantics(SEMANTICS_JT32); // use JT-3.2 semantics // create all the questions. // HTTPS Intro qHttpsIntro = new NullQuestion(this, HTTPS_INTRO_TAG); // HTTPS Protocol qHttpsProto = new ChoiceQuestion(this, HTTPS_PROTO_TAG, new String[] {null, TLS, SSL, WAP_TLS, WTLS}); qHttpsProto.setExporter(new Exporter() { public void export(Question q, Map data) { String value = qHttpsProto.getValue(); String val = null; if (TLS.equals(value)) { val = TLS; } else if (SSL.equals(value)) { val = SSL; } else if (WAP_TLS.equals(value)) { val = TLS; } else { val = WTLS; } data.put(HTTPS_PROTO_KEY, val); } }); // Optional hostname question qHttpHost = new StringQuestion(this, HTTPS_HOST_TAG); qHttpHost.setValidator(Validators.HOST_NAME); qHttpHost.setExporter(Exporters.getStringValueExporter("httpHost")); try { qHttpHost.setDefaultValue(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException uhe) { // ignore } qHttpHost.setEnabled(false); // HTTPS Port Question qHttpsPort = new IntQuestion(this, HTTPS_PORT_TAG, MIN_PORT, MAX_PORT); qHttpsPort.setDefaultValue(DEFAULT_PORT); qHttpsPort.setExporter(new Exporter() { public void export(Question q, Map data) { // export network.httpURL StringBuffer sb = new StringBuffer("https://$httpHost:"); sb.append(qHttpsPort.getValue()); sb.append("/index.html"); String url = sb.toString(); data.put(HTTPS_URL_KEY, url); // export SupportServer sb = new StringBuffer(HTTPS_SERVER); sb.append(" verbose=$" + HTTPS_VERBOSE_KEY); sb.append(" test.url="); sb.append(url); data.put("SupportServer1", sb.toString()); } }); // Optional verbose question qVerbose = new YesNoQuestion(this, HTTPS_VERBOSE_TAG); qVerbose.setExporter(Exporters.getBooleanValueExporter( HTTPS_VERBOSE_KEY)); qVerbose.setEnabled(false); qCertFile = new FileQuestion(this, CERT_FILE_TAG); qCertFile.setExporter( Exporters.getQuotedValueExporter(CERT_FILE_KEY)); qCertFile.setValidator(Validators.FILE_EXISTS); qCertAlias = new StringQuestion(this, CERT_ALIAS_TAG); qCertAlias.setExporter( Exporters.getQuotedValueExporter(CERT_ALIAS_KEY)); qCertStorePass = new StringQuestion(this, CERT_STOREPASS_TAG); qCertStorePass.setExporter( Exporters.getQuotedValueExporter(CERT_STOREPASS_KEY)); qCertKeyPass = new StringQuestion(this, CERT_KEYPASS_TAG); qCertKeyPass.setExporter( Exporters.getQuotedValueExporter(CERT_KEYPASS_KEY)); qEnd = new FinalQuestion(this); // set the links between the questions setFirstQuestion(qHttpsIntro); qHttpsIntro.linkTo(qHttpsProto); qHttpsProto.linkTo(qHttpHost); qHttpHost.linkTo(qHttpsPort); qHttpsPort.linkTo(qVerbose); qVerbose.linkTo(qCertFile); qCertFile.linkTo(qCertAlias); qCertAlias.linkTo(qCertStorePass); qCertStorePass.linkTo(qCertKeyPass); qCertKeyPass.linkTo(qEnd); } /** * Returns the supported protocols question. Clients of this interview can * use this method to obtain the question in order to customize it, * providing different protocol choices. * <p> * By default, four protocols are listed: {@link #TLS}, {@link #SSL}, * {@link #WAP_TLS WAP TLS} and {@link #WTLS}. * * @return The supported protocols question. */ public ChoiceQuestion getSupportedProtocolsQuestion() { return qHttpsProto; } /** * Sets this interview's mode. By default, httpHost and verbose questions * are hidden. Setting the standalone mode will enable those questions. * * @param mode * <code>true</code> for standalone mode, <code>false</code> * otherwise. */ public void setStandAloneMode(boolean mode) { this.standAloneMode = mode; // these questions should be visible in standalone mode. qHttpHost.setEnabled(mode); qVerbose.setEnabled(mode); } /** * Returns whether this interview is in standalone mode or not. * * @return <code>true</code> if and only if the interview is in standalone * mode. */ public boolean isStandAloneMode() { return standAloneMode; } /** * TLS Protocol. */ public static final String TLS = "TLS"; /** * SSL Protocol. */ public static final String SSL = "SSL"; /** * WAP TLS Profile and Tunneling. */ public static final String WAP_TLS = "WAP TLS Profile and Tunneling"; /** * WTLS Protocol. */ public static final String WTLS = "WTLS"; private boolean standAloneMode = false; // Keys, Tags private static final String INTERVIEW_TAG = "httpsServer"; private static final String HTTPS_INTRO_TAG = "httpsIntro"; private static final String HTTPS_HOST_TAG = "httpsHost"; private static final String HTTPS_VERBOSE_TAG = "httpsVerbose"; private static final String HTTPS_VERBOSE_KEY = "network.https.verbose"; private static final String HTTPS_URL_KEY = "network.httpsURL"; private static final String HTTPS_PORT_TAG = "httpsPort"; private static final String HTTPS_PROTO_TAG = "httpsProto"; private static final String HTTPS_PROTO_KEY = "network.https.secureProtocol"; private static final String CERT_FILE_TAG = "certFile"; private static final String CERT_FILE_KEY = "network.https.certFile"; private static final String CERT_ALIAS_KEY = "network.https.alias"; private static final String CERT_ALIAS_TAG = "certAlias"; private static final String CERT_STOREPASS_KEY = "network.https.storepass"; private static final String CERT_STOREPASS_TAG = "certStorePass"; private static final String CERT_KEYPASS_KEY = "network.https.keypass"; private static final String CERT_KEYPASS_TAG = "certKeyPass"; // All Questions private final NullQuestion qHttpsIntro; private final StringQuestion qHttpHost; private final YesNoQuestion qVerbose; private final IntQuestion qHttpsPort; private final ChoiceQuestion qHttpsProto; private final FileQuestion qCertFile; private final StringQuestion qCertAlias; private final StringQuestion qCertStorePass; private final StringQuestion qCertKeyPass; private final FinalQuestion qEnd; // Default Values, Misc constants private static final String HTTPS_SERVER = "com.sun.tck.midp.lib.MIDHttpsSupportServer"; private static final int DEFAULT_PORT = 7070; private static final int MIN_PORT = 1; private static final int MAX_PORT = 65535; private static final int SEMANTICS_JT32 = 1;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?