Java Code Examples for com.mashape.unirest.http.Unirest#setHttpClient()
The following examples show how to use
com.mashape.unirest.http.Unirest#setHttpClient() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BasicFunctionalityTest.java From elepy with Apache License 2.0 | 6 votes |
@BeforeAll protected void setUpAll() { HttpClient httpClient = HttpClients.custom() .disableCookieManagement() .build(); Unirest.setHttpClient(httpClient); elepy = ElepySystemUnderTest.create(); elepy.addModel(Resource.class); elepy.addModel(CustomUser.class); this.configureElepy(elepy); elepy.start(); resourceCrud = elepy.getCrudFor(Resource.class); userCrud = elepy.getCrudFor(User.class); }
Example 2
Source File: CustomHttpClient.java From openvidu with Apache License 2.0 | 6 votes |
public CustomHttpClient(String url, String user, String pass) throws Exception { this.openviduUrl = url.replaceFirst("/*$", ""); this.headerAuth = "Basic " + Base64.getEncoder().encodeToString((user + ":" + pass).getBytes()); SSLContext sslContext = null; try { sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy() { public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException { return true; } }).build(); } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) { throw new Exception("Error building custom HttpClient: " + e.getMessage()); } HttpClient unsafeHttpClient = HttpClients.custom().setSSLContext(sslContext) .setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); Unirest.setHttpClient(unsafeHttpClient); }
Example 3
Source File: AppServicePacketTransport.java From swellrt with Apache License 2.0 | 6 votes |
private void httpConfig() { LOG.info("Setting up http Matrix Federation for id: " + userId); SSLContext sslcontext; try { sslcontext = SSLContexts.custom() .loadTrustMaterial(null, new TrustSelfSignedStrategy()) .build(); } catch (Exception ex) { throw new RuntimeException(ex); } CloseableHttpClient httpclient = HttpClients.custom() .setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER) .setSSLContext(sslcontext) .build(); Unirest.setHttpClient(httpclient); Unirest.setDefaultHeader("Content-Type","application/json"); }
Example 4
Source File: FiltersTest.java From elepy with Apache License 2.0 | 5 votes |
@BeforeEach void before() { elepy = ElepySystemUnderTest.create(); this.configureElepy(elepy); elepy.addModel(Product.class); elepy.start(); Unirest.setHttpClient(HttpClients.custom().disableCookieManagement().build()); }
Example 5
Source File: SecurityTest.java From elepy with Apache License 2.0 | 5 votes |
@BeforeEach void before() { elepy = ElepySystemUnderTest.create(); this.configureElepy(elepy); elepy.addModel(CustomUser.class); elepy.start(); Unirest.setHttpClient(HttpClients.custom().disableCookieManagement().build()); }
Example 6
Source File: CorrectPermissionsTest.java From elepy with Apache License 2.0 | 5 votes |
@BeforeAll void beforeAll() { elepy = ElepySystemUnderTest.create(); this.configureElepy(elepy); elepy.addModel(Password.class); elepy.start(); users = elepy.getCrudFor(User.class); passwords = elepy.getCrudFor(Password.class); Unirest.setHttpClient(HttpClients.custom().disableCookieManagement().build()); createInitialUsersViaHttp(); }
Example 7
Source File: RocketChatClient.java From rocket-chat-rest-client with MIT License | 5 votes |
/** * Trust self-signed certificates on the rocketchat server url. * @throws KeyManagementException * @throws NoSuchAlgorithmException * @throws KeyStoreException */ public void trustSelfSignedCertificates() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException { SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); Unirest.setHttpClient(httpclient); }
Example 8
Source File: TestWithProxiedEmbeddedServer.java From Bastion with GNU General Public License v3.0 | 5 votes |
@BeforeClass public static void setupProxying() { DnsResolver dnsResolver = prepareProxiedDnsResolver(); DefaultSchemePortResolver schemePortResolver = prepareSchemePortResolver(); BasicHttpClientConnectionManager connManager = prepareConnectionManager(dnsResolver, schemePortResolver); HttpClient httpClient = prepareHttpClient(connManager); originalHttpClient = (HttpClient) Options.getOption(Option.HTTPCLIENT); Unirest.setHttpClient(httpClient); }
Example 9
Source File: MockSetup.java From cloudbreak with Apache License 2.0 | 5 votes |
private void disableSSLCheck() { try { SSLContext sslcontext = SSLContexts.custom() .loadTrustMaterial(null, new TrustSelfSignedStrategy()) .build(); LayeredConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext); CloseableHttpClient httpclient = HttpClients.custom() .setSSLSocketFactory(sslsf) .build(); Unirest.setHttpClient(httpclient); } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException ignored) { throw new RuntimeException("can't create ssl settings"); } }
Example 10
Source File: RestAgentConnector.java From vicinity-gateway-api with GNU General Public License v3.0 | 4 votes |
/** * This method initialize CloseableHttpClient * */ private void initialize() { // accept snake oil boolean customClientInUse = false; if (useHttps && acceptSelfSigned) { SSLContext sslcontext = null; try { sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustSelfSignedStrategy()).build(); } catch (Exception e) { logger.warning("Exception during configuration of SSL for Agent Connector. Reverting to HTTP. " + "Exception message: " + e.getMessage()); } if (sslcontext != null) { SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext); // create request config builder RequestConfig.Builder requestBuilder = RequestConfig.custom(); requestBuilder = requestBuilder.setConnectTimeout(agentTimeout * 1000); // create client builder HttpClientBuilder clientBuilder = HttpClients.custom(); // set request configuration clientBuilder.setDefaultRequestConfig(requestBuilder.build()); clientBuilder.setSSLSocketFactory(sslsf); httpClient = clientBuilder.build(); Unirest.setHttpClient(httpClient); customClientInUse = true; } } if (!customClientInUse) { // set timeouts - we are not using custom client, we have to do it this way Unirest.setTimeouts(agentTimeout * 1000, agentTimeout * 1000); } }
Example 11
Source File: TestWithProxiedEmbeddedServer.java From Bastion with GNU General Public License v3.0 | 4 votes |
@AfterClass public static void cleanupProxying() { Unirest.setHttpClient(originalHttpClient); }