void initiateProviderKeyStore(Provider provider) throws Exception {
   String prov = null;
   for (Provider.Service ps : provider.getServices()) {
     if (ps.getType().equals("KeyStore")) {
       prov = ps.getAlgorithm();
     }
   }
   Security.addProvider(provider);
   KeyStore ks = KeyStore.getInstance(prov, provider);
   ks.load(
       CMD_keystore.found ? new FileInputStream(CMD_keystore.getString()) : null,
       CMD_keypass.found ? CMD_keypass.getString().toCharArray() : null);
   wrap.setKeyStore(ks, CMD_keypass.getString());
   CMD_keystore.found = false;
 }
    void execute(String argv[]) throws Exception {
      decodeCommandLine(argv);

      if (CMD_proxyhost.found != CMD_proxyport.found) {
        bad(
            "Missing command: -"
                + (CMD_proxyhost.found ? CMD_proxyport.command : CMD_proxyhost.command));
      }

      wrap.setInteractiveMode(true);

      if (CMD_user_id.found || CMD_password.found) {
        if (CMD_user_id.found != CMD_password.found) {
          bad(
              "Missing command: -"
                  + (CMD_user_id.found ? CMD_password.command : CMD_user_id.command));
        }
        wrap.setUserIDPassword(CMD_user_id.getString(), CMD_password.getString());
      }

      if (CMD_proxyhost.found) {
        wrap.setProxy(CMD_proxyhost.getString(), CMD_proxyport.getInteger());
      }

      if (CMD_timeout.found) {
        wrap.setTimeout(CMD_timeout.getInteger());
      }

      if (CMD_follow_redirs.found) {
        wrap.setFollowRedirects(true);
      }

      if (CMD_badnames_ok.found) {
        wrap.allowDiffHostNames(true);
      }

      if (CMD_invalid_ok.found) {
        wrap.allowInvalidCert(true);
      }

      if (CMD_setheader.found) {
        for (String value : CMD_setheader.argvalue) {
          value = value.trim();
          int i = value.indexOf(':');
          if (i <= 0 || i == value.length() - 1) {
            bad("Misformed header argument: " + value);
          }
          wrap.setHeader(value.substring(0, i), value.substring(i + 1));
        }
      }

      if (CMD_mime_type.found) {
        wrap.setHeader("Content-Type", CMD_mime_type.getString());
      }

      if (CMD_p11lib.found) {
        String p11wrapper = "sun.security.pkcs11.SunPKCS11";
        if (CMD_addprovider.found) {
          p11wrapper = CMD_addprovider.getString();
          CMD_addprovider.found = false;
        }
        if (CMD_p11slot.found) {
          String slot = CMD_p11slot.getString();
          String slot_label = "slot";
          if (slot.charAt(0) == 'i') {
            slot_label = "slotListIndex";
            slot = slot.substring(1);
          }
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          PrintWriter pw = new PrintWriter(baos);
          pw.println(
              "name = " + new File(CMD_p11lib.getString()).getName() + "-" + slot_label + slot);
          pw.println("library = " + CMD_p11lib.getString());
          pw.println(slot_label + " = " + slot);
          pw.flush();
          pw.close();
          initiateProviderKeyStore(
              (Provider)
                  Class.forName(p11wrapper)
                      .getConstructor(InputStream.class)
                      .newInstance(new ByteArrayInputStream(baos.toByteArray())));
        } else {
          initiateProviderKeyStore(
              (Provider)
                  Class.forName(p11wrapper)
                      .getConstructor(String.class)
                      .newInstance(CMD_p11lib.getString()));
        }
      }

      if (CMD_addprovider.found) {
        initiateProviderKeyStore(
            CMD_provider_arg.found
                ? (Provider)
                    Class.forName(CMD_addprovider.getString())
                        .getConstructor(String.class)
                        .newInstance(CMD_provider_arg.getString())
                : (Provider) Class.forName(CMD_addprovider.getString()).newInstance());
      }

      if (CMD_truststore.found) {
        wrap.setTrustStore(CMD_truststore.getString(), CMD_storepass.getString());
      }

      if (CMD_keystore.found) {
        wrap.setKeyStore(CMD_keystore.getString(), CMD_keypass.getString());
      }

      if (CMD_keyalias.found) {
        wrap.setKeyAlias(CMD_keyalias.getString());
      }

      if (CMD_get_oper.found) {
        wrap.makeGetRequest(CMD_get_oper.getString());
      } else {
        wrap.makePostRequest(
            CMD_post_oper.getString(), ArrayUtil.readFile(CMD_data_file.getString()));
      }

      if (CMD_dump_certs.found) {
        System.out.println(
            "\nCertificate:\n" + new CertificateInfo(wrap.getServerCertificate()).toString());
      }

      if (CMD_dump_headers.found) {
        System.out.println(
            "\nHeaders:\n" + wrap.getResponseCode() + " " + wrap.getResponseMessage());
        LinkedHashMap<String, Vector<String>> headers = wrap.getHeaders();
        for (String key : headers.keySet()) {
          for (String value : headers.get(key)) {
            System.out.println(key + ": " + value);
          }
        }
      }

      if (CMD_dump_data.found) {
        System.out.println("\nData:\n" + wrap.getDataUTF8());
      }

      if (CMD_store_data.found) {
        ArrayUtil.writeFile(CMD_store_data.getString(), wrap.getData());
      }
    }