Search in sources :

Example 11 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project ranger by apache.

the class NiFiRegistryClient method getWebResource.

protected WebResource getWebResource() {
    final ClientConfig config = new DefaultClientConfig();
    if (sslContext != null) {
        config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, sslContext));
    }
    final Client client = Client.create(config);
    return client.resource(url);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) BaseClient(org.apache.ranger.plugin.client.BaseClient) Client(com.sun.jersey.api.client.Client) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties)

Example 12 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project pentaho-kettle by pentaho.

the class Wadl2JavaRestConnectivetyCheck method initRestService1.

/**
 * Test stand alone generated code web service connectivity
 */
private void initRestService1() throws InitializationException {
    // get information about the remote connection
    String username = "admin";
    String password = "password";
    ClientConfig clientConfig = new DefaultClientConfig();
    client = Client.create(clientConfig);
    client.addFilter(new HTTPBasicAuthFilter(username, password));
    URI baseUri = null;
    try {
        baseUri = new URI(uri + "/plugin/");
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    PentahoDiPlugin.PurRepositoryPluginApiRevision revisionService = PentahoDiPlugin.purRepositoryPluginApiRevision(client, baseUri);
    PentahoDiPlugin.PurRepositoryPluginApiRevision.PathIdVersioningConfiguration versioningConfigurationMethod = revisionService.pathIdVersioningConfiguration("foo.ktr");
    FileVersioningConfiguration fileVersioningConfiguration = versioningConfigurationMethod.getAsXml(FileVersioningConfiguration.class);
    System.out.println("Test1: " + fileVersioningConfiguration.isVersioningEnabled());
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) URISyntaxException(java.net.URISyntaxException) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) URI(java.net.URI)

Example 13 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project pentaho-kettle by pentaho.

the class RepositoryCleanupUtil method authenticateLoginCredentials.

/**
 * Use REST API to authenticate provided credentials
 *
 * @throws Exception
 */
@VisibleForTesting
void authenticateLoginCredentials() throws Exception {
    KettleClientEnvironment.init();
    if (client == null) {
        ClientConfig clientConfig = new DefaultClientConfig();
        clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
        client = Client.create(clientConfig);
        client.addFilter(new HTTPBasicAuthFilter(username, Encr.decryptPasswordOptionallyEncrypted(password)));
    }
    WebResource resource = client.resource(url + AUTHENTICATION + AdministerSecurityAction.NAME);
    String response = resource.get(String.class);
    if (!response.equals("true")) {
        throw new Exception(Messages.getInstance().getString("REPOSITORY_CLEANUP_UTIL.ERROR_0012.ACCESS_DENIED"));
    }
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) WebResource(com.sun.jersey.api.client.WebResource) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) ParseException(java.text.ParseException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 14 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project ranger by apache.

the class KmsKeyMgr method getClient.

private synchronized Client getClient() {
    Client ret = null;
    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(ClientConfig.PROPERTY_FOLLOW_REDIRECTS, true);
    ret = Client.create(cc);
    return ret;
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig)

Example 15 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project coprhd-controller by CoprHD.

the class CustomServicesRESTExecution method executeTask.

@Override
public CustomServicesTaskResult executeTask() throws Exception {
    try {
        ExecutionUtils.currentContext().logInfo("customServicesRESTExecution.startInfo", step.getId(), step.getFriendlyName());
        final Map<String, String> attrs = primitive.attributes();
        final String authType = attrs.get(CustomServicesConstants.AUTH_TYPE);
        if (StringUtils.isEmpty(authType)) {
            logger.error("Auth type cannot be undefined");
            ExecutionUtils.currentContext().logError("customServicesOperationExecution.logStatus", step.getId(), step.getFriendlyName(), "Auth type cannot be undefined");
            throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Cannot find Auth type");
        }
        final Client client = BuildRestRequest.makeClient(new DefaultClientConfig(), coordinator, authType, attrs.get(CustomServicesConstants.PROTOCOL), AnsibleHelper.getOptions(CustomServicesConstants.USER, input), AnsibleHelper.getOptions(CustomServicesConstants.PASSWORD, input));
        final Map<String, List<InputParameter>> inputKeys = primitive.input() == null ? Collections.emptyMap() : primitive.input();
        final List<InputParameter> queryParams = inputKeys.get(CustomServicesConstants.QUERY_PARAMS);
        final WebResource webResource = BuildRestRequest.makeWebResource(client, getUrl(primitive, queryParams).toString());
        final WebResource.Builder builder = BuildRestRequest.makeRequestBuilder(webResource, step, input);
        final CustomServicesConstants.RestMethods method = CustomServicesConstants.RestMethods.valueOf(attrs.get(CustomServicesConstants.METHOD));
        final CustomServicesTaskResult result;
        switch(method) {
            case PUT:
            case POST:
                final String body = RESTHelper.makePostBody(primitive.attributes().get(CustomServicesConstants.BODY), 0, input);
                result = executeRest(method, body, builder);
                break;
            default:
                result = executeRest(method, null, builder);
        }
        ExecutionUtils.currentContext().logInfo("customServicesRESTExecution.doneInfo", step.getId(), step.getFriendlyName());
        return result;
    } catch (final Exception e) {
        ExecutionUtils.currentContext().logError("customServicesRESTExecution.doneInfo", step.getId(), step.getFriendlyName() + "Custom Service Task Failed" + e);
        logger.error("Exception:", e);
        throw InternalServerErrorException.internalServerErrors.customServiceExecutionFailed("Custom Service Task Failed" + e);
    }
}
Also used : CustomServicesConstants(com.emc.storageos.primitives.CustomServicesConstants) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) WebResource(com.sun.jersey.api.client.WebResource) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) List(java.util.List) Client(com.sun.jersey.api.client.Client) CoordinatorClient(com.emc.storageos.coordinator.client.service.CoordinatorClient) InputParameter(com.emc.storageos.primitives.input.InputParameter)

Aggregations

DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)65 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)55 Client (com.sun.jersey.api.client.Client)42 WebResource (com.sun.jersey.api.client.WebResource)21 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)15 ClientResponse (com.sun.jersey.api.client.ClientResponse)14 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)9 HostnameVerifier (javax.net.ssl.HostnameVerifier)7 SSLSession (javax.net.ssl.SSLSession)7 TrustManager (javax.net.ssl.TrustManager)7 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)6 URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)6 IOException (java.io.IOException)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)5 LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)5 SecureRandom (java.security.SecureRandom)5 SSLContext (javax.net.ssl.SSLContext)5 URISyntaxException (java.net.URISyntaxException)4 ArrayList (java.util.ArrayList)4