protected void setAlternateOption(
      final URI location, ResourceOptions options, Map<String, Object> optionsByName) {
    String key = options.getOption(HttpResourceAddress.NEXT_PROTOCOL);
    String scheme = location.getScheme();
    final boolean secureScheme = "https".equals(scheme) || scheme.contains("+ssl");
    if (key != null && secureScheme) {
      key = key + " secure";
    }

    List<ResourceFactory> resourceFactories = RESOURCE_FACTORIES_BY_KEY.get(key);

    if (resourceFactories != null
        && !resourceFactories.isEmpty()
        && getResourceAddressFactory() != null) {

      // create alternate addresses

      HttpResourceAddress alternateAddress = null;
      for (ResourceFactory resourceFactory : resourceFactories) {
        alternateAddress =
            newResourceAddressWithAlternate(
                resourceFactory.createURI(location),
                getNewOptionsByName(options, optionsByName),
                alternateAddress);
      }

      // save the alternate chain into this address.
      options.setOption(ResourceAddress.ALTERNATE, alternateAddress);
    }
  }
  @Override
  protected void setOptions(
      HttpResourceAddress address, ResourceOptions options, Object qualifier) {

    super.setOptions(address, options, qualifier);

    address.setOption0(KEEP_ALIVE, options.getOption(KEEP_ALIVE));
    address.setOption0(KEEP_ALIVE_TIMEOUT, options.getOption(KEEP_ALIVE_TIMEOUT));
    address.setOption0(KEEP_ALIVE_CONNECTIONS, options.getOption(KEEP_ALIVE_CONNECTIONS));
    address.setOption0(REQUIRED_ROLES, options.getOption(REQUIRED_ROLES));
    address.setOption0(REALM_NAME, options.getOption(REALM_NAME));
    address.setOption0(REALM_AUTHORIZATION_MODE, options.getOption(REALM_AUTHORIZATION_MODE));
    address.setOption0(REALM_CHALLENGE_SCHEME, options.getOption(REALM_CHALLENGE_SCHEME));
    address.setOption0(REALM_DESCRIPTION, options.getOption(REALM_DESCRIPTION));
    address.setOption0(
        REALM_AUTHENTICATION_HEADER_NAMES, options.getOption(REALM_AUTHENTICATION_HEADER_NAMES));
    address.setOption0(
        REALM_AUTHENTICATION_PARAMETER_NAMES,
        options.getOption(REALM_AUTHENTICATION_PARAMETER_NAMES));
    address.setOption0(
        REALM_AUTHENTICATION_COOKIE_NAMES, options.getOption(REALM_AUTHENTICATION_COOKIE_NAMES));
    address.setOption0(LOGIN_CONTEXT_FACTORY, options.getOption(LOGIN_CONTEXT_FACTORY));
    address.setOption0(INJECTABLE_HEADERS, options.getOption(INJECTABLE_HEADERS));
    address.setOption0(ORIGIN_SECURITY, options.getOption(ORIGIN_SECURITY));
    address.setOption0(TEMP_DIRECTORY, options.getOption(TEMP_DIRECTORY));
    address.setOption0(GATEWAY_ORIGIN_SECURITY, options.getOption(GATEWAY_ORIGIN_SECURITY));
    address.setOption0(BALANCE_ORIGINS, options.getOption(BALANCE_ORIGINS));
    address.setOption0(AUTHENTICATION_CONNECT, options.getOption(AUTHENTICATION_CONNECT));
    address.setOption0(AUTHENTICATION_IDENTIFIER, options.getOption(AUTHENTICATION_IDENTIFIER));
    address.setOption0(ENCRYPTION_KEY_ALIAS, options.getOption(ENCRYPTION_KEY_ALIAS));
    address.setOption0(SERVICE_DOMAIN, options.getOption(SERVICE_DOMAIN));
    address.setOption0(SERVER_HEADER_ENABLED, options.getOption(SERVER_HEADER_ENABLED));
  }