Search in sources :

Example 1 with Builder

use of org.asynchttpclient.Realm.Builder in project camel by apache.

the class AhcComponent method createEndpoint.

@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
    String addressUri = createAddressUri(uri, remaining);
    // Do not set the HTTP URI because we still have all of the Camel internal
    // parameters in the URI at this point.
    AhcEndpoint endpoint = createAhcEndpoint(uri, this, null);
    setEndpointHeaderFilterStrategy(endpoint);
    endpoint.setClient(getClient());
    endpoint.setClientConfig(getClientConfig());
    endpoint.setBinding(getBinding());
    endpoint.setSslContextParameters(getSslContextParameters());
    setProperties(endpoint, parameters);
    if (IntrospectionSupport.hasProperties(parameters, CLIENT_CONFIG_PREFIX)) {
        DefaultAsyncHttpClientConfig.Builder builder = endpoint.getClientConfig() == null ? new DefaultAsyncHttpClientConfig.Builder() : AhcComponent.cloneConfig(endpoint.getClientConfig());
        if (endpoint.getClient() != null) {
            LOG.warn("The user explicitly set an AsyncHttpClient instance on the component or " + "endpoint, but this endpoint URI contains client configuration parameters.  " + "Are you sure that this is what was intended?  The AsyncHttpClient will be used" + " and the URI parameters will be ignored.");
        } else if (endpoint.getClientConfig() != null) {
            LOG.warn("The user explicitly set an AsyncHttpClientConfig instance on the component or " + "endpoint, but this endpoint URI contains client configuration parameters.  " + "Are you sure that this is what was intended?  The URI parameters will be applied" + " to a clone of the supplied AsyncHttpClientConfig in order to prevent unintended modification" + " of the explicitly configured AsyncHttpClientConfig.  That is, the URI parameters override the" + " settings on the explicitly configured AsyncHttpClientConfig for this endpoint.");
        }
        // special for realm builder
        Builder realmBuilder = null;
        if (IntrospectionSupport.hasProperties(parameters, CLIENT_REALM_CONFIG_PREFIX)) {
            // set and validate additional parameters on client config
            Map<String, Object> realmParams = IntrospectionSupport.extractProperties(parameters, CLIENT_REALM_CONFIG_PREFIX);
            // copy the parameters for the endpoint to have
            endpoint.setClientConfigRealmOptions(new LinkedHashMap<>(realmParams));
            Object principal = realmParams.remove("principal");
            Object password = realmParams.remove("password");
            if (ObjectHelper.isEmpty(principal)) {
                throw new IllegalArgumentException(CLIENT_REALM_CONFIG_PREFIX + ".principal must be configured");
            }
            if (password == null) {
                password = "";
            }
            realmBuilder = new Realm.Builder(principal.toString(), password.toString());
            setProperties(realmBuilder, realmParams);
            validateParameters(uri, realmParams, null);
        }
        // set and validate additional parameters on client config
        Map<String, Object> clientParams = IntrospectionSupport.extractProperties(parameters, CLIENT_CONFIG_PREFIX);
        // copy the parameters for the endpoint to have
        endpoint.setClientConfigOptions(new LinkedHashMap<>(clientParams));
        setProperties(builder, clientParams);
        validateParameters(uri, clientParams, null);
        if (realmBuilder != null) {
            builder.setRealm(realmBuilder.build());
        }
        endpoint.setClientConfig(builder.build());
    }
    // restructure uri to be based on the parameters left as we dont want to include the Camel internal options
    addressUri = UnsafeUriCharactersEncoder.encodeHttpURI(addressUri);
    URI httpUri = URISupport.createRemainingURI(new URI(addressUri), parameters);
    endpoint.setHttpUri(httpUri);
    return endpoint;
}
Also used : Builder(org.asynchttpclient.Realm.Builder) DefaultAsyncHttpClientConfig(org.asynchttpclient.DefaultAsyncHttpClientConfig) Builder(org.asynchttpclient.Realm.Builder) Realm(org.asynchttpclient.Realm) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 DefaultAsyncHttpClientConfig (org.asynchttpclient.DefaultAsyncHttpClientConfig)1 Realm (org.asynchttpclient.Realm)1 Builder (org.asynchttpclient.Realm.Builder)1