httpstestsuiteservice.java.svn-base

来自「cqME :java framework for TCK test.」· SVN-BASE 代码 · 共 159 行

SVN-BASE
159
字号
/* * $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.services.httpsService;import java.io.File;import com.sun.javatest.TestEnvironment;import com.sun.javatest.Harness;import com.sun.tck.j2me.services.ServiceFault;import com.sun.tck.j2me.services.httpService.HttpTestSuiteService;/** * A class to start and stop Https server for a TestSuite. */public class HttpsTestSuiteService extends HttpTestSuiteService {             /**     * Name of JavaTest environment variable for the support server name and     * arguments.     */    public static final String HTTPS_SERVER_KEY = "SupportServer1";        /**     * Name of JavaTest environment variable for the secure protocol.     */    public static final String SECURE_PROTOCOL = "network.https.secureProtocol";        /**     * Name of JavaTest environment variable for the server certificate file     */    public static final String CERT_FILE = "network.https.certFile";        /**     * Name of JavaTest environment variable for the alias of the certificate     * used by the server     */    public static final String ALIAS = "network.https.alias";    /**     * Name of JavaTest environment variable for the keystore password.     */    public static final String STORE_PASS = "network.https.storepass";    /**     * Name of JavaTest environment variable  for the key password.     */    public static final String KEY_PASS = "network.https.keypass";    /**     * The default name for this service for registration with the service manager.     */    public static final String SERVICE_NAME="service.https";        /**     * @param harness the Harness where the service will be running      */        public HttpsTestSuiteService(Harness harness)  {        super(harness);        supportServerEnvKey = HTTPS_SERVER_KEY;    }        /**     * Get the parameters of the support server from JavaTest     * environment variables.           */        protected String[] getServerArgs(String[] supportServerEnvData) throws ServiceFault {        TestEnvironment env = getTestEnvironment();        String[] envData = null;        String[] serverArgs = new String[5];        if (supportServerEnvData.length > 1) {            serverArgs = new String[supportServerEnvData.length + 4];            System.arraycopy(supportServerEnvData, 1, serverArgs, 0, supportServerEnvData.length - 1);        }        // Protocol Name used in HTTPS        try {            envData = env.lookup(SECURE_PROTOCOL);            if (envData == null || envData.length == 0) {                throw new TestSuiteServiceFault(i18n, "ts.secureProtocolNotDefined");            }        } catch (TestEnvironment.Fault tef) {            throw new TestSuiteServiceFault(i18n, "ts.secureProtocolNotDefined");        }        serverArgs[serverArgs.length-5] = envData[0];        // location of keystore file        File certFile = null;        try {            envData = env.lookup(CERT_FILE);            if (envData == null || envData.length != 1) {                throw new TestSuiteServiceFault(i18n, "ts.secureKeystoreNotDefined");            }            certFile = new File(envData[0]);            if (!certFile.exists()) {                throw new TestSuiteServiceFault(i18n, "ts.secureKeystoreNotFound", envData[0]);            } else if(!certFile.isFile()) {                throw new TestSuiteServiceFault(i18n, "ts.secureKeystoreNotFile", envData[0]);            } else if(!certFile.canRead()) {                throw new TestSuiteServiceFault(i18n, "ts.secureKeystoreNotRead", envData[0]);            }          } catch (TestEnvironment.Fault tef) {             throw new TestSuiteServiceFault(i18n, "ts.secureKeystoreNotDefined");         }         serverArgs[serverArgs.length-4] = envData[0];         //Server Certificate Alias         try {             envData = env.lookup(ALIAS);             if (envData == null || envData.length == 0) {                 throw new TestSuiteServiceFault(i18n, "ts.secureAliasNotDefined");             }         } catch (TestEnvironment.Fault tef) {             throw new TestSuiteServiceFault(i18n, "ts.secureAliasNotDefined");         }         serverArgs[serverArgs.length-3] = envData[0];         //Keystore password         try {             envData = env.lookup(STORE_PASS);             if (envData == null || envData.length == 0) {                 throw new TestSuiteServiceFault(i18n, "ts.secureStorePassNotDefined");             }         } catch (TestEnvironment.Fault tef) {             throw new TestSuiteServiceFault(i18n, "ts.secureStorePassNotDefined");         }         serverArgs[serverArgs.length-2] = envData[0];         //Key password         try {             envData = env.lookup(KEY_PASS);             if (envData == null || envData.length == 0) {                 throw new TestSuiteServiceFault(i18n, "ts.secureKeyPassNotDefined");             }         } catch (TestEnvironment.Fault tef) {             throw new TestSuiteServiceFault(i18n, "ts.secureKeyPassNotDefined");         }         serverArgs[serverArgs.length-1] = envData[0];         return serverArgs;    }                            }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?