Search in sources :

Example 46 with DefaultClientConfig

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

the class TestDataSourceResource method getConnectionByName.

private static IDatabaseConnection getConnectionByName(String aConnecitonName) {
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    IDatabaseConnection connection = null;
    WebResource resource = client.resource(getURL);
    try {
        connection = resource.type(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_XML).entity(aConnecitonName).get(DatabaseConnection.class);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return connection;
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) WebResource(com.sun.jersey.api.client.WebResource) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatabaseConnection(org.pentaho.database.model.DatabaseConnection) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client)

Example 47 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project cloudbreak by hortonworks.

the class YarnHttpClient method getNewWebResource.

public WebResource getNewWebResource(String url) {
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    client.addFilter(new LoggingFilter());
    return client.resource(url);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) LoggingFilter(com.sun.jersey.api.client.filter.LoggingFilter) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client)

Example 48 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project cloudbreak by hortonworks.

the class YarnHttpClient method deleteApplication.

@Override
public void deleteApplication(DeleteApplicationRequest deleteApplicationRequest) throws YarnClientException, MalformedURLException {
    // Add the application name to the URL
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH + '/' + deleteApplicationRequest.getName());
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    // Delete the application
    WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept("application/json").type("application/json").delete(ClientResponse.class);
    // Validate HTTP 204 return
    String msg;
    switch(response.getStatus()) {
        case YarnResourceConstants.HTTP_NO_CONTENT:
            msg = String.format("Successfully deleted application %s", deleteApplicationRequest.getName());
            LOGGER.debug(msg);
            break;
        case YarnResourceConstants.HTTP_NOT_FOUND:
            msg = String.format("Application %s not found, already deleted?", deleteApplicationRequest.getName());
            LOGGER.debug(msg);
            break;
        default:
            msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class));
            LOGGER.debug(msg);
            throw new YarnClientException(msg);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) YarnClientException(com.sequenceiq.cloudbreak.cloud.yarn.client.exception.YarnClientException) WebResource(com.sun.jersey.api.client.WebResource) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client) YarnEndpoint(com.sequenceiq.cloudbreak.cloud.yarn.client.api.YarnEndpoint)

Example 49 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project cloudbreak by hortonworks.

the class YarnHttpClient method validateApiEndpoint.

@Override
public void validateApiEndpoint() throws CloudbreakOrchestratorFailedException, MalformedURLException {
    YarnEndpoint dashEndpoint = new YarnEndpoint(apiEndpoint, YarnResourceConstants.APPLICATIONS_PATH);
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    WebResource webResource = client.resource(dashEndpoint.getFullEndpointUrl().toString());
    ClientResponse response = webResource.accept("application/json").type("application/json").get(ClientResponse.class);
    // Validate HTTP 200 status code
    if (response.getStatus() != YarnResourceConstants.HTTP_SUCCESS) {
        String msg = String.format("Received %d status code from url %s, reason: %s", response.getStatus(), dashEndpoint.getFullEndpointUrl().toString(), response.getEntity(String.class));
        LOGGER.debug(msg);
        throw new CloudbreakOrchestratorFailedException(msg);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) WebResource(com.sun.jersey.api.client.WebResource) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client) YarnEndpoint(com.sequenceiq.cloudbreak.orchestrator.yarn.api.YarnEndpoint)

Example 50 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project cloudbreak by hortonworks.

the class YarnHttpClient method getNewWebResource.

public WebResource getNewWebResource(String url) {
    ClientConfig clientConfig = new DefaultClientConfig();
    Client client = Client.create(clientConfig);
    return client.resource(url);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client)

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