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);
    }
  }
示例#2
0
  @Override
  protected <T extends ConnectFuture> ConnectFuture connectInternal(
      ResourceAddress connectAddress,
      IoHandler handler,
      final IoSessionInitializer<T> initializer) {
    final DefaultConnectFuture wseConnectFuture = new DefaultConnectFuture();

    // propagate connection failure, if necessary
    IoFutureListener<ConnectFuture> parentConnectListener =
        new IoFutureListener<ConnectFuture>() {
          @Override
          public void operationComplete(ConnectFuture future) {
            // fail bridge connect future if parent connect fails
            if (!future.isConnected()) {
              wseConnectFuture.setException(future.getException());
            }
          }
        };

    IoSessionInitializer<ConnectFuture> parentInitializer =
        createParentInitializer(connectAddress, handler, initializer, wseConnectFuture);

    ResourceAddress httpxeAddress = connectAddress.getTransport();

    URI createURI = appendURI(httpxeAddress.getExternalURI(), CREATE_SUFFIX);

    // default options but clear the transports so they get rebuilt by default
    ResourceOptions createOptions = ResourceOptions.FACTORY.newResourceOptions(httpxeAddress);
    createOptions.setOption(ResourceAddress.TRANSPORT, null);
    createOptions.setOption(ResourceAddress.TRANSPORT_URI, null);

    ResourceAddress createAddress =
        resourceAddressFactory.newResourceAddress(createURI, createOptions);
    BridgeConnector connector = bridgeServiceFactory.newBridgeConnector(createAddress);

    // TODO: proxy detection, append ?.ki=p on timeout
    connector
        .connect(createAddress, selectConnectHandler(createAddress), parentInitializer)
        .addListener(parentConnectListener);

    return wseConnectFuture;
  }
  @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));
  }
  @SuppressWarnings("unchecked")
  @Override
  protected void parseNamedOptions0(
      URI location, ResourceOptions options, Map<String, Object> optionsByName) {

    Boolean keepAlive = (Boolean) optionsByName.remove(KEEP_ALIVE.name());
    if (keepAlive != null) {
      options.setOption(KEEP_ALIVE, keepAlive);
    }

    Integer keepAliveTimeout = (Integer) optionsByName.remove(KEEP_ALIVE_TIMEOUT.name());
    if (keepAliveTimeout != null) {
      options.setOption(KEEP_ALIVE_TIMEOUT, keepAliveTimeout);
    }

    Integer keepAliveConnections = (Integer) optionsByName.remove(KEEP_ALIVE_CONNECTIONS.name());
    if (keepAliveConnections != null) {
      options.setOption(KEEP_ALIVE_CONNECTIONS, keepAliveConnections);
    }

    String[] requiredRoles = (String[]) optionsByName.remove(REQUIRED_ROLES.name());
    if (requiredRoles != null) {
      options.setOption(REQUIRED_ROLES, requiredRoles);
    }

    String realmName = (String) optionsByName.remove(REALM_NAME.name());
    if (realmName != null) {
      options.setOption(REALM_NAME, realmName);
    }

    String realmAuthorizationMode = (String) optionsByName.remove(REALM_AUTHORIZATION_MODE.name());
    if (realmAuthorizationMode != null) {
      options.setOption(REALM_AUTHORIZATION_MODE, realmAuthorizationMode);
    }

    String realmChallengeScheme = (String) optionsByName.remove(REALM_CHALLENGE_SCHEME.name());
    if (realmChallengeScheme != null) {
      options.setOption(REALM_CHALLENGE_SCHEME, realmChallengeScheme);
    }

    String realmDescription = (String) optionsByName.remove(REALM_DESCRIPTION.name());
    if (realmDescription != null) {
      options.setOption(REALM_DESCRIPTION, realmDescription);
    }

    String[] realmAuthenticationHeaderNames =
        (String[]) optionsByName.remove(REALM_AUTHENTICATION_HEADER_NAMES.name());
    if (realmAuthenticationHeaderNames != null) {
      options.setOption(REALM_AUTHENTICATION_HEADER_NAMES, realmAuthenticationHeaderNames);
    }

    String[] realmAuthenticationParameterNames =
        (String[]) optionsByName.remove(REALM_AUTHENTICATION_PARAMETER_NAMES.name());
    if (realmAuthenticationParameterNames != null) {
      options.setOption(REALM_AUTHENTICATION_PARAMETER_NAMES, realmAuthenticationParameterNames);
    }

    String[] realmAuthenticationCookieNames =
        (String[]) optionsByName.remove(REALM_AUTHENTICATION_COOKIE_NAMES.name());
    if (realmAuthenticationCookieNames != null) {
      options.setOption(REALM_AUTHENTICATION_COOKIE_NAMES, realmAuthenticationCookieNames);
    }

    LoginContextFactory loginContextFactory =
        (LoginContextFactory) optionsByName.remove(LOGIN_CONTEXT_FACTORY.name());
    if (loginContextFactory != null) {
      options.setOption(LOGIN_CONTEXT_FACTORY, loginContextFactory);
    }

    String authenticationConnect = (String) optionsByName.remove(AUTHENTICATION_CONNECT.name());
    if (authenticationConnect != null) {
      options.setOption(AUTHENTICATION_CONNECT, authenticationConnect);
    }

    String authenticationIdentifier =
        (String) optionsByName.remove(AUTHENTICATION_IDENTIFIER.name());
    if (authenticationIdentifier != null) {
      options.setOption(AUTHENTICATION_IDENTIFIER, authenticationIdentifier);
    }

    String encryptionKeyAlias = (String) optionsByName.remove(ENCRYPTION_KEY_ALIAS.name());
    if (encryptionKeyAlias != null) {
      options.setOption(ENCRYPTION_KEY_ALIAS, encryptionKeyAlias);
    }

    String serviceDomain = (String) optionsByName.remove(SERVICE_DOMAIN.name());
    if (serviceDomain != null) {
      options.setOption(SERVICE_DOMAIN, serviceDomain);
    }

    Set<HttpInjectableHeader> injectableHeaders =
        (Set<HttpInjectableHeader>) optionsByName.remove(INJECTABLE_HEADERS.name());
    if (injectableHeaders != null) {
      options.setOption(INJECTABLE_HEADERS, injectableHeaders);
    }

    Map<String, ? extends CrossSiteConstraintContext> acceptConstraints =
        (Map<String, ? extends CrossSiteConstraintContext>)
            optionsByName.remove(ORIGIN_SECURITY.name());
    if (acceptConstraints != null) {
      options.setOption(ORIGIN_SECURITY, new HttpOriginSecurity(acceptConstraints));
    }

    File tempDirectory = (File) optionsByName.remove(TEMP_DIRECTORY.name());
    if (tempDirectory != null) {
      options.setOption(TEMP_DIRECTORY, tempDirectory);
    }

    List<Map<URI, Map<String, CrossSiteConstraintContext>>> authorityToSetOfAcceptConstraintsByURI =
        (List<Map<URI, Map<String, CrossSiteConstraintContext>>>)
            optionsByName.remove(GATEWAY_ORIGIN_SECURITY.name());
    if (authorityToSetOfAcceptConstraintsByURI != null) {
      options.setOption(
          GATEWAY_ORIGIN_SECURITY,
          new GatewayHttpOriginSecurity(authorityToSetOfAcceptConstraintsByURI));
    }

    Collection<URI> balanceOrigin = (Collection<URI>) optionsByName.remove(BALANCE_ORIGINS.name());
    if (balanceOrigin != null) {
      options.setOption(BALANCE_ORIGINS, balanceOrigin);
    }

    Boolean serverHeaderEnabled = (Boolean) optionsByName.remove(SERVER_HEADER_ENABLED.name());
    if (serverHeaderEnabled != null) {
      options.setOption(SERVER_HEADER_ENABLED, serverHeaderEnabled);
    }
  }