Search in sources :

Example 61 with DefaultClientConfig

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

the class NiFiClient 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 62 with DefaultClientConfig

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

the class RangerRESTClient method buildClient.

private Client buildClient() {
    Client client = null;
    if (mIsSSL) {
        KeyManager[] kmList = getKeyManagers();
        TrustManager[] tmList = getTrustManagers();
        SSLContext sslContext = getSSLContext(kmList, tmList);
        ClientConfig config = new DefaultClientConfig();
        // to handle List<> unmarshalling
        config.getClasses().add(JacksonJsonProvider.class);
        HostnameVerifier hv = new HostnameVerifier() {

            public boolean verify(String urlHostName, SSLSession session) {
                return session.getPeerHost().equals(urlHostName);
            }
        };
        config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hv, sslContext));
        client = Client.create(config);
    }
    if (client == null) {
        ClientConfig config = new DefaultClientConfig();
        // to handle List<> unmarshalling
        config.getClasses().add(JacksonJsonProvider.class);
        client = Client.create(config);
    }
    if (StringUtils.isNotEmpty(mUsername) && StringUtils.isNotEmpty(mPassword)) {
        client.addFilter(new HTTPBasicAuthFilter(mUsername, mPassword));
    }
    // Set Connection Timeout and ReadTime for the PolicyRefresh
    client.setConnectTimeout(mRestClientConnTimeOutMs);
    client.setReadTimeout(mRestClientReadTimeOutMs);
    return client;
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) Client(com.sun.jersey.api.client.Client) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) KeyManager(javax.net.ssl.KeyManager) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties)

Example 63 with DefaultClientConfig

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

the class ApiTestBase method createHttpClient.

/**
 * create the httpclient, returns a BalancedWebResource that can be used the same
 * way a WebResource is.
 */
protected BalancedWebResource createHttpClient(final String username, final String attribute, final String groups, List<String> hostNames) {
    BalancedWebResource lbw = new BalancedWebResource();
    for (String h : hostNames) {
        final ClientConfig config = new DefaultClientConfig();
        final Client c = Client.create(config);
        c.addFilter(new ClientFilter() {

            @Override
            public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
                ArrayList<Object> headerValue = new ArrayList<Object>();
                String userAndAttribute = username;
                if (!attribute.isEmpty()) {
                    userAndAttribute += "," + attribute;
                }
                headerValue.add(userAndAttribute + ";" + groups);
                request.getHeaders().put(NoAuthHeaderUserFilter.USER_INFO_HEADER_TAG, headerValue);
                return getNext().handle(request);
            }
        });
        lbw.addWebResource(c.resource(h));
    }
    return lbw;
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) ClientResponse(com.sun.jersey.api.client.ClientResponse) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ArrayList(java.util.ArrayList) ClientFilter(com.sun.jersey.api.client.filter.ClientFilter) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client) ClientRequest(com.sun.jersey.api.client.ClientRequest)

Example 64 with DefaultClientConfig

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

the class RepositoryPublishResourceIT method configure.

@Override
protected AppDescriptor configure() {
    ClientConfig config = new DefaultClientConfig();
    config.getClasses().add(MultiPartWriter.class);
    config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    return new WebAppDescriptor.Builder("org.pentaho.platform.web.http.api.resources").contextPath("api").addFilter(PentahoRequestContextFilter.class, "pentahoRequestContextFilter").clientConfig(config).build();
}
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)

Example 65 with DefaultClientConfig

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

the class CommandLineProcessor method initRestService.

/**
 * Used only for REST Jersey calls
 *
 * @param contextURL The Pentaho server web application base URL.
 */
private void initRestService(String contextURL) throws ParseException, KettleException, URISyntaxException {
    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    client = Client.create(clientConfig);
    client.addFilter(new HTTPBasicAuthFilter(getUsername(), getPassword()));
    client.addFilter(new SessionCookiesFilter(new CookieManager()));
    client.addFilter(new CsrfTokenFilter(new URI(contextURL + API_CSRF_TOKEN)));
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) CsrfTokenFilter(com.hitachivantara.security.web.impl.client.csrf.jaxrsv1.CsrfTokenFilter) SessionCookiesFilter(com.hitachivantara.security.web.impl.client.csrf.jaxrsv1.util.SessionCookiesFilter) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) URI(java.net.URI) CookieManager(java.net.CookieManager)

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