List of usage examples for org.springframework.http.client SimpleClientHttpRequestFactory SimpleClientHttpRequestFactory
SimpleClientHttpRequestFactory
From source file:org.cloudfoundry.identity.uaa.test.TestAccountSetup.java
private OAuth2RestTemplate createRestTemplate(OAuth2ProtectedResourceDetails resource, AccessTokenRequest accessTokenRequest) { OAuth2ClientContext context = new DefaultOAuth2ClientContext(accessTokenRequest); OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context); client.setRequestFactory(new SimpleClientHttpRequestFactory() { @Override/*from ww w . j a v a 2 s .c o m*/ protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException { super.prepareConnection(connection, httpMethod); connection.setInstanceFollowRedirects(false); } }); client.setErrorHandler(new OAuth2ErrorHandler(client.getResource()) { // Pass errors through in response entity for status code analysis @Override public boolean hasError(ClientHttpResponse response) throws IOException { return false; } @Override public void handleError(ClientHttpResponse response) throws IOException { } }); List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>(); list.add(new StringHttpMessageConverter()); list.add(new MappingJackson2HttpMessageConverter()); client.setMessageConverters(list); return client; }
From source file:org.jboss.windup.decorator.integration.mvn.MavenCentralSHA1VersionDecorator.java
@Override public void processMeta(ZipMetadata meta) { if (!active) { return;/*from w w w. j a v a 2s . co m*/ } if (!knownArchiveProfiler.isExclusivelyKnownArchive(meta)) { return; } String sha1Hash = null; for (AbstractDecoration result : meta.getDecorations()) { if (result instanceof PomVersion) { LOG.debug("Already has version result: " + result.toString()); return; } else if (result instanceof Hash) { if (((Hash) result).getHashType() == HashType.SHA1) { sha1Hash = ((Hash) result).getHash(); } } } if (sha1Hash == null) { LOG.debug("No SHA-1 Hash found. Returning."); return; } LOG.info("No Version Found: " + meta.getRelativePath() + "; trying Maven Central"); if (LOG.isDebugEnabled()) { LOG.debug("SHA1: " + sha1Hash); } RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); try { MavenCentralSHA1VersionResponseWrapper result = restTemplate.getForObject(MAVEN_API_URL, MavenCentralSHA1VersionResponseWrapper.class, sha1Hash); if (result != null && result.getResponse() != null && result.getResponse().getNumFound() > 0) { MavenCentralSHA1VersionResponseItem rsp = result.getResponse().getDocs()[0]; String groupId = rsp.getGroupId(); String artifactId = rsp.getArtifactId(); String version = rsp.getVersion(); String url = generateUrl(groupId, artifactId, version); // pull the POM from the URL. ClientHttpRequestFactory request = new SimpleClientHttpRequestFactory(); try { ClientHttpRequest pomRequest = request.createRequest(new URI(url), HttpMethod.GET); ClientHttpResponse resp = pomRequest.execute(); String outputDir = meta.getArchiveOutputDirectory().getAbsolutePath() + File.separator + "maven-remote"; FileUtils.forceMkdir(new File(outputDir)); File outputPath = new File(outputDir + File.separator + "pom.xml"); IOUtils.copy(new InputStreamReader(resp.getBody()), new FileOutputStream(outputPath)); XmlMetadata xmlMeta = new XmlMetadata(); xmlMeta.setFilePointer(outputPath); xmlMeta.setArchiveMeta(meta); pomInterrogator.processMeta(xmlMeta); LOG.info("Fetched remote POM for: " + meta.getName()); } catch (Exception e) { LOG.error("Exception fetching remote POM: " + url + "; skipping.", e); } } else { if (LOG.isDebugEnabled()) { LOG.debug("No Version Information Found in Maven Central for: " + sha1Hash); } } } catch (Exception e) { LOG.error("Exception creating API call to Central Repo for POM: " + meta.getName() + "; skipping.", e); } }
From source file:org.rippleosi.common.service.proxies.C4HReportingRequestProxy.java
private RestTemplate restTemplate() { return new RestTemplate(new SimpleClientHttpRequestFactory()); }
From source file:org.springframework.boot.actuate.metrics.influxdb.InfluxDBGaugeWriter.java
/** * Creates a new {@code InfluxDBGaugeWriter} with the given millisecond * {@code connectTimeout} and {@code readTimeout}. * * @param connectTimeout the connect timeout in milliseconds * @param readTimeout the read timeout in milliseconds */// w ww . j a v a 2 s . c om public InfluxDBGaugeWriter(int connectTimeout, int readTimeout) { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(connectTimeout); requestFactory.setReadTimeout(readTimeout); this.restTemplate = new RestTemplate(requestFactory); }
From source file:org.springframework.boot.context.embedded.AbstractEmbeddedServletContainerFactoryTests.java
protected ClientHttpResponse getClientResponse(String url) throws IOException, URISyntaxException { SimpleClientHttpRequestFactory clientHttpRequestFactory = new SimpleClientHttpRequestFactory(); ClientHttpRequest request = clientHttpRequestFactory.createRequest(new URI(url), HttpMethod.GET); ClientHttpResponse response = request.execute(); return response; }
From source file:org.springframework.boot.devtools.remote.client.RemoteClientConfiguration.java
@Bean public ClientHttpRequestFactory clientHttpRequestFactory() { List<ClientHttpRequestInterceptor> interceptors = Arrays.asList(getSecurityInterceptor()); SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); Proxy proxy = this.properties.getRemote().getProxy(); if (proxy.getHost() != null && proxy.getPort() != null) { requestFactory.setProxy(//from www. ja v a 2s.c o m new java.net.Proxy(Type.HTTP, new InetSocketAddress(proxy.getHost(), proxy.getPort()))); } return new InterceptingClientHttpRequestFactory(requestFactory, interceptors); }
From source file:org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.java
private RestTemplate getSecureRestTemplate(ConfigClientProperties client) { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setReadTimeout((60 * 1000 * 3) + 5000); //TODO 3m5s, make configurable? RestTemplate template = new RestTemplate(requestFactory); String password = client.getPassword(); if (password != null) { template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList( new BasicAuthorizationInterceptor(client.getUsername(), password))); }//from ww w. ja v a 2 s . c o m return template; }
From source file:org.springframework.security.oauth2.client.test.OAuth2ContextSetup.java
private OAuth2RestTemplate createRestTemplate(OAuth2ProtectedResourceDetails resource, AccessTokenRequest request) {//from w ww . j ava2 s . c o m OAuth2ClientContext context = new DefaultOAuth2ClientContext(request); OAuth2RestTemplate client = new OAuth2RestTemplate(resource, context); client.setRequestFactory(new SimpleClientHttpRequestFactory() { @Override protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException { super.prepareConnection(connection, httpMethod); connection.setInstanceFollowRedirects(false); } }); client.setErrorHandler(new ResponseErrorHandler() { // Pass errors through in response entity for status code analysis public boolean hasError(ClientHttpResponse response) throws IOException { return false; } public void handleError(ClientHttpResponse response) throws IOException { } }); if (accessTokenProvider != null) { client.setAccessTokenProvider(accessTokenProvider); } return client; }
From source file:org.springframework.vault.config.ClientHttpRequestFactoryFactory.java
/** * Creates a {@link ClientHttpRequestFactory} for the given {@link ClientOptions} and * {@link SslConfiguration}./*from ww w .java2 s . c o m*/ * * @param options must not be {@literal null} * @param sslConfiguration must not be {@literal null} * @return a new {@link ClientHttpRequestFactory}. Lifecycle beans must be initialized * after obtaining. */ public static ClientHttpRequestFactory create(ClientOptions options, SslConfiguration sslConfiguration) { Assert.notNull(options, "ClientOptions must not be null"); Assert.notNull(sslConfiguration, "SslConfiguration must not be null"); try { if (HTTP_COMPONENTS_PRESENT) { return HttpComponents.usingHttpComponents(options, sslConfiguration); } if (OKHTTP3_PRESENT) { return OkHttp3.usingOkHttp3(options, sslConfiguration); } if (OKHTTP_PRESENT) { return OkHttp.usingOkHttp(options, sslConfiguration); } if (NETTY_PRESENT) { return Netty.usingNetty(options, sslConfiguration); } } catch (GeneralSecurityException e) { throw new IllegalStateException(e); } catch (IOException e) { throw new IllegalStateException(e); } if (hasSslConfiguration(sslConfiguration)) { logger.warn("VaultProperties has SSL configured but the SSL configuration " + "must be applied outside the Vault Client to use the JDK HTTP client"); } return new SimpleClientHttpRequestFactory(); }