<commit_before>/*
 * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxauth.client.uma;

import org.gluu.oxauth.model.uma.UmaMetadata;
import org.jboss.resteasy.client.ClientExecutor;
import org.jboss.resteasy.client.ProxyFactory;

/**
 * Helper class which creates proxied UMA services
 *
 * @author <NAME>
 * @author <NAME>
 */
public class UmaClientFactory {

    private final static UmaClientFactory instance = new UmaClientFactory();

    private UmaClientFactory() {
    }

    public static UmaClientFactory instance() {
        return instance;
    }

    public UmaResourceService createResourceService(UmaMetadata metadata) {
        return ProxyFactory.create(UmaResourceService.class, metadata.getResourceRegistrationEndpoint());
    }

    public UmaResourceService createResourceService(UmaMetadata metadata, ClientExecutor clientExecutor) {
        return ProxyFactory.create(UmaResourceService.class, metadata.getResourceRegistrationEndpoint(), clientExecutor);
    }

    public UmaPermissionService createPermissionService(UmaMetadata metadata) {
        return ProxyFactory.create(UmaPermissionService.class, metadata.getPermissionEndpoint());
    }

    public UmaPermissionService createPermissionService(UmaMetadata metadata, ClientExecutor clientExecutor) {
        return ProxyFactory.create(UmaPermissionService.class, metadata.getPermissionEndpoint(), clientExecutor);
    }

    public UmaRptIntrospectionService createRptStatusService(UmaMetadata metadata) {
        return ProxyFactory.create(UmaRptIntrospectionService.class, metadata.getIntrospectionEndpoint());
    }

    public UmaRptIntrospectionService createRptStatusService(UmaMetadata metadata, ClientExecutor clientExecutor) {
        return ProxyFactory.create(UmaRptIntrospectionService.class, metadata.getIntrospectionEndpoint(), clientExecutor);
    }

    public UmaMetadataService createMetadataService(String umaMetadataUri) {
        return ProxyFactory.create(UmaMetadataService.class, umaMetadataUri);
    }

    public UmaMetadataService createMetadataService(String umaMetadataUri, ClientExecutor clientExecutor) {
        return ProxyFactory.create(UmaMetadataService.class, umaMetadataUri, clientExecutor);
    }

    public UmaScopeService createScopeService(String scopeEndpointUri) {
        return ProxyFactory.create(UmaScopeService.class, scopeEndpointUri);
    }

    public UmaTokenService createTokenService(UmaMetadata metadata) {
        return ProxyFactory.create(UmaTokenService.class, metadata.getTokenEndpoint());
    }

    public UmaTokenService createTokenService(UmaMetadata metadata, ClientExecutor clientExecutor) {
        return ProxyFactory.create(UmaTokenService.class, metadata.getTokenEndpoint(), clientExecutor);
    }

}
<commit_msg>Use ResteasyClient in UMA client instead of deprecated ProxyFactory<commit_after>/*
 * oxAuth is available under the MIT License (2008). See http://opensource.org/licenses/MIT for full text.
 *
 * Copyright (c) 2014, Gluu
 */

package org.gluu.oxauth.client.uma;

import javax.ws.rs.core.UriBuilder;

import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.gluu.oxauth.model.uma.UmaMetadata;
import org.jboss.resteasy.client.jaxrs.ClientHttpEngine;
import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
import org.jboss.resteasy.client.jaxrs.engines.ApacheHttpClient4Engine;

/**
 * Helper class which creates proxied UMA services
 *
 * @author <NAME>
 * @author <NAME>
 */
public class UmaClientFactory {

    private final static UmaClientFactory instance = new UmaClientFactory();

    private ApacheHttpClient4Engine engine;

    private UmaClientFactory() {
        this.engine = createEngine();
    }

    public static UmaClientFactory instance() {
        return instance;
    }

    public UmaResourceService createResourceService(UmaMetadata metadata) {
        return createResourceService(metadata, engine);
    }

    public UmaResourceService createResourceService(UmaMetadata metadata, ClientHttpEngine engine) {
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath(metadata.getResourceRegistrationEndpoint()));
        UmaResourceService proxy = target.proxy(UmaResourceService.class);

        return proxy;
    }

    public UmaPermissionService createPermissionService(UmaMetadata metadata) {
        return createPermissionService(metadata, engine);
    }

    public UmaPermissionService createPermissionService(UmaMetadata metadata, ClientHttpEngine engine) {
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath(metadata.getPermissionEndpoint()));
        UmaPermissionService proxy = target.proxy(UmaPermissionService.class);

        return proxy;
    }

    public UmaRptIntrospectionService createRptStatusService(UmaMetadata metadata) {
        return createRptStatusService(metadata, engine);
    }

    public UmaRptIntrospectionService createRptStatusService(UmaMetadata metadata, ClientHttpEngine engine) {
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath(metadata.getIntrospectionEndpoint()));
        UmaRptIntrospectionService proxy = target.proxy(UmaRptIntrospectionService.class);

        return proxy;
    }

    public UmaMetadataService createMetadataService(String umaMetadataUri) {
        return createMetadataService(umaMetadataUri, engine);
    }

    public UmaMetadataService createMetadataService(String umaMetadataUri, ClientHttpEngine engine) {
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath(umaMetadataUri));
        UmaMetadataService proxy = target.proxy(UmaMetadataService.class);

        return proxy;
    }

    public UmaScopeService createScopeService(String scopeEndpointUri) {
        return createScopeService(scopeEndpointUri, engine);
    }

    public UmaScopeService createScopeService(String scopeEndpointUri, ClientHttpEngine engine) {
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath(scopeEndpointUri));
        UmaScopeService proxy = target.proxy(UmaScopeService.class);

        return proxy;
    }

    public UmaTokenService createTokenService(UmaMetadata metadata) {
        return createTokenService(metadata, engine);
    }

    public UmaTokenService createTokenService(UmaMetadata metadata, ClientHttpEngine engine) {
        ResteasyClient client = new ResteasyClientBuilder().httpEngine(engine).build();
        ResteasyWebTarget target = client.target(UriBuilder.fromPath(metadata.getTokenEndpoint()));
        UmaTokenService proxy = target.proxy(UmaTokenService.class);

        return proxy;
    }
	
	private ApacheHttpClient4Engine createEngine() {
	    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
	    CloseableHttpClient httpClient = HttpClients.custom()
				.setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build())
	    		.setConnectionManager(cm).build();
	    cm.setMaxTotal(200); // Increase max total connection to 200
	    cm.setDefaultMaxPerRoute(20); // Increase default max connection per route to 20
	    ApacheHttpClient4Engine engine = new ApacheHttpClient4Engine(httpClient);
	    
	    return engine;
	}
}

{'fraction_non_alphanumeric': 0.07993535554450522, 'fraction_numerical': 0.003853804077573347, 'mean_word_length': 4.725978647686833, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3110286', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2075, 'n_words': 417}