/** * Using {@link ApacheHttpClient4Executor} and specified {@link HttpClient}. */ public RestfulClient(final URI baseUri, HttpClient client) { this(baseUri, new ApacheHttpClient4Executor(client)); }
/** * Creates a ClientExecutor for this BrooklynApi */ protected ClientExecutor getClientExecutor(Credentials credentials) { CredentialsProvider provider = new BasicCredentialsProvider(); if (credentials != null) provider.setCredentials(AuthScope.ANY, credentials); CloseableHttpClient httpClient = HttpClients.custom() .setDefaultCredentialsProvider(provider) .setDefaultRequestConfig(reqConfSupplier.get()) .setConnectionManager(connectionManagerSupplier.get()) .build(); return new ApacheHttpClient4Executor(httpClient); }
private void init(ClientExecutor executor, ResteasyProviderFactory providerFactory, URI base) { if (providerFactory == null) this.providerFactory = ResteasyProviderFactory.getInstance(); else this.providerFactory = providerFactory; if (executor == null) this.executor = new ApacheHttpClient4Executor(); else this.executor = executor; this.base = base; }
private void init(ClientExecutor executor, ResteasyProviderFactory providerFactory, URI base) { if (providerFactory == null) this.providerFactory = ResteasyProviderFactory.getInstance(); else this.providerFactory = providerFactory; if (executor == null) this.executor = new ApacheHttpClient4Executor(); else this.executor = executor; this.base = base; }
ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(); DefaultHttpClient client = (DefaultHttpClient) executor.getHttpClient(); client.addRequestInterceptor(new MyPreemptiveAuthInterceptor(), 0); ClientRequest request = new ClientRequest("http://my-url", executor);
public static ClientExecutor factory(String username, String password) throws UnauthorizedException { RestEasyPreemptiveClientExecutor f = new RestEasyPreemptiveClientExecutor(); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.addRequestInterceptor(f.new PreemptiveAuthInterceptor(username,password), 0); ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient); return clientExecutor; }
/** * Creates the client executor that will be used by RESTEasy when * making the request. */ private ClientExecutor createClientExecutor() { // TODO I think the http client is thread safe - so let's try to create just one of these DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { Locale l = getLocale(); if (l == null) { l = Locale.getDefault(); } request.addHeader("Accept-Language", l.toString()); //$NON-NLS-1$ } }); if (this.authProvider != null) { httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { authProvider.provideAuthentication(request); } }); } return new ApacheHttpClient4Executor(httpClient); }
/** * Creates the client executor that will be used by RESTEasy when * making the request. */ private ClientExecutor createClientExecutor() { // TODO I think the http client is thread safe - so let's try to create just one of these DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { Locale l = getLocale(); if (l == null) { l = Locale.getDefault(); } request.addHeader("Accept-Language", l.toString()); } }); if (this.authProvider != null) { httpClient.addRequestInterceptor(new HttpRequestInterceptor() { @Override public void process(HttpRequest request, HttpContext context) throws HttpException, IOException { authProvider.provideAuthentication(request); } }); } return new ApacheHttpClient4Executor(httpClient); }
/** * Gets the rest-service client. * * @param <T> the rest-service client implementation. * @param clazz the rest-service class. * @param url the server URL. * @param username the username. * @param password the password. * @param auth the authentication flag. * @exception Exception if the method fails. * * @return the the rest-service client instance. */ public static <T> T getClient(final Class<T> clazz, String url, boolean auth, String username, char[] password) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); if (url.startsWith(HTTPS)) { SSLSocketFactory sslSocketFactory = new SSLSocketFactory(new TrustSelfSignedStrategy(), SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); httpClient.getConnectionManager().getSchemeRegistry().register(new Scheme(HTTPS, 443, sslSocketFactory)); } if (auth) { BasicCredentialsProvider provider = new BasicCredentialsProvider(); Credentials credentials = new UsernamePasswordCredentials(username, new String(password)); provider.setCredentials(AuthScope.ANY, credentials); httpClient.setCredentialsProvider(provider); } return ProxyFactory.create(clazz, url, new ApacheHttpClient4Executor(httpClient)); }
public static ClientExecutor clientExecutor(boolean trustAll) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException { if (trustAll) { return new ApacheHttpClient4Executor(createHttpClientTrustAll()); } return ClientRequest.getDefaultExecutor(); }
tokenClient.setExecutor(new ApacheHttpClient4Executor(httpclient)); tokenClient.setRequest(tokenRequest); TokenResponse tokenResponse = tokenClient.exec();
cm.setDefaultMaxPerRoute(20); HttpClient httpClient = new DefaultHttpClient(cm); _executor = new ApacheHttpClient4Executor(httpClient);
cm.setDefaultMaxPerRoute(20); HttpClient httpClient = new DefaultHttpClient(cm); _executor = new ApacheHttpClient4Executor(httpClient);
private AuthorizationResponse requestAuthorization( final String userId, final String userSecret, final String redirectUri, List<ResponseType> responseTypes, String clientId, List<String> scopes) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { String nonce = UUID.randomUUID().toString(); String state = UUID.randomUUID().toString(); AuthorizationRequest authorizationRequest = new AuthorizationRequest( responseTypes, clientId, scopes, redirectUri, nonce); authorizationRequest.setState(state); authorizationRequest.setAuthUsername(userId); authorizationRequest.setAuthPassword(userSecret); authorizationRequest.getPrompts().add(Prompt.NONE); AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint); authorizeClient.setExecutor(new ApacheHttpClient4Executor(createHttpClientTrustAll())); authorizeClient.setRequest(authorizationRequest); authorizeClient.getHeaders().put("Sec-Token-Binding", ENCODED_TOKEN_BINDING_MESSAGE); AuthorizationResponse authorizationResponse = authorizeClient.exec(); showClient(authorizeClient); assertNotNull(authorizationResponse.getLocation(), "The location is null"); assertNotNull(authorizationResponse.getAccessToken(), "The access token is null"); assertNotNull(authorizationResponse.getState(), "The state is null"); assertNotNull(authorizationResponse.getTokenType(), "The token type is null"); assertNotNull(authorizationResponse.getExpiresIn(), "The expires in value is null"); assertNotNull(authorizationResponse.getScope(), "The scope must be null"); assertNotNull(authorizationResponse.getIdToken(), "The id token must be null"); return authorizationResponse; }
new ApacheHttpClient4Executor(createHttpClient(HostnameVerifierType.ALLOW_ALL)));
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(userId, password)); ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient); requestFactory = new ClientRequestFactory(clientExecutor, ResteasyProviderFactory.getInstance()); } else {
if (acceptUntrustedCertificate) { HttpClient httpClient = new SslDefaultHttpClient(new TrustAllTrustManager()); clientExecutor = new ApacheHttpClient4Executor(httpClient);
private RegisterResponse registerClient(final String redirectUris, final List<ResponseType> responseTypes, final List<GrantType> grantTypes, final String sectorIdentifierUri) throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException { RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris)); registerRequest.setResponseTypes(responseTypes); registerRequest.setGrantTypes(grantTypes); registerRequest.addCustomAttribute("oxAuthTrustedClient", "true"); registerRequest.setIdTokenTokenBindingCnf(JwtClaimName.TOKEN_BINDING_HASH); // token binding hash for cnf RegisterClient registerClient = new RegisterClient(registrationEndpoint); registerClient.setExecutor(new ApacheHttpClient4Executor(createHttpClientTrustAll())); registerClient.setRequest(registerRequest); RegisterResponse registerResponse = registerClient.exec(); showClient(registerClient); assertEquals(registerResponse.getStatus(), 200, "Unexpected response code: " + registerResponse.getEntity()); assertNotNull(registerResponse.getClientId()); assertNotNull(registerResponse.getClientSecret()); assertNotNull(registerResponse.getRegistrationAccessToken()); assertNotNull(registerResponse.getClientIdIssuedAt()); assertNotNull(registerResponse.getClientSecretExpiresAt()); return registerResponse; } }
CookieStore cookieStore = new BasicCookieStore(); httpClient.setCookieStore(cookieStore); ClientExecutor clientExecutor = new ApacheHttpClient4Executor(httpClient);