List of usage examples for org.springframework.http.client SimpleClientHttpRequestFactory SimpleClientHttpRequestFactory
SimpleClientHttpRequestFactory
From source file:net.oneandone.stool.Start.java
private void ping(Stage stage) throws IOException, SAXException, URISyntaxException, InterruptedException { URI uri;/*w w w .ja v a2 s .c om*/ SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(500); console.info.println("Ping'n Applications."); Thread.sleep(2000); for (String url : stage.urlMap().values()) { if (url.startsWith("http://")) { uri = new URI(url); console.verbose.println("Opening connection to " + url); try { requestFactory.createRequest(uri, HttpMethod.GET).execute(); } catch (IOException e) { console.verbose.println("Opening connection failed. " + e.getCause()); } } } }
From source file:com.jaspersoft.android.sdk.client.JsRestClient.java
public JsRestClient() { this(new RestTemplate(true), new SimpleClientHttpRequestFactory()); }
From source file:com.jaspersoft.android.sdk.client.JsRestClient.java
public JsRestClient(RestTemplate restTemplate) { this(restTemplate, new SimpleClientHttpRequestFactory()); }
From source file:org.cloudfoundry.identity.uaa.integration.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 www.ja 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 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 { } }); List<HttpMessageConverter<?>> list = new ArrayList<HttpMessageConverter<?>>(); list.add(new StringHttpMessageConverter()); list.add(new MappingJacksonHttpMessageConverter()); client.setMessageConverters(list); return client; }
From source file:cn.org.once.cstack.cli.rest.RestUtils.java
/** * /*from ww w. jav a 2 s . co m*/ * /** sendPostCommand * * @param url * @param parameters * @return * @throws ClientProtocolException */ public Map<String, Object> sendPostForUpload(String url, Map<String, Object> parameters) { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setBufferRequestBody(false); RestTemplate restTemplate = new RestTemplate(requestFactory); List<HttpMessageConverter<?>> mc = restTemplate.getMessageConverters(); mc.add(new MappingJackson2HttpMessageConverter()); restTemplate.setMessageConverters(mc); MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<String, Object>(); postParams.setAll(parameters); Map<String, Object> response = new HashMap<String, Object>(); HttpHeaders headers = new HttpHeaders(); headers.set("Content-Type", "multipart/form-data"); headers.set("Accept", "application/json"); headers.add("Cookie", "JSESSIONID=" + localContext.getCookieStore().getCookies().get(0).getValue()); HttpEntity<Object> request = new HttpEntity<Object>(postParams, headers); ResponseEntity<?> result = restTemplate.exchange(url, HttpMethod.POST, request, String.class); String body = result.getBody().toString(); MediaType contentType = result.getHeaders().getContentType(); HttpStatus statusCode = result.getStatusCode(); response.put(CONTENT_TYPE, contentType); response.put(STATUS_CODE, statusCode); response.put(BODY, body); return response; }
From source file:io.github.microcks.service.TestRunnerService.java
/** Retrieve correct test runner according given type. */ private AbstractTestRunner<HttpMethod> retrieveRunner(TestRunnerType runnerType, String serviceId) { // TODO: remove this ugly initialization later. SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory(); factory.setConnectTimeout(200);/*from w ww .ja va 2 s .c o m*/ factory.setReadTimeout(10000); switch (runnerType) { case SOAP_HTTP: SoapHttpTestRunner soapRunner = new SoapHttpTestRunner(); soapRunner.setClientHttpRequestFactory(factory); soapRunner.setResourceUrl(validationResourceUrl); return soapRunner; case OPEN_API_SCHEMA: OpenAPITestRunner openApiRunner = new OpenAPITestRunner(resourceRepository, responseRepository, false); openApiRunner.setClientHttpRequestFactory(factory); return openApiRunner; case SOAP_UI: // Handle local download of correct project file. List<ImportJob> jobs = jobRepository.findByServiceRefId(serviceId); if (jobs != null && !jobs.isEmpty()) { try { String projectFile = handleRemoteFileDownload(jobs.get(0).getRepositoryUrl()); SoapUITestStepsRunner soapUIRunner = new SoapUITestStepsRunner(projectFile); return soapUIRunner; } catch (IOException ioe) { log.error("IOException while downloading {}", jobs.get(0).getRepositoryUrl()); } } case POSTMAN: // Handle local download of correct project file. jobs = jobRepository.findByServiceRefId(serviceId); if (jobs != null && !jobs.isEmpty()) { try { String collectionFile = handleRemoteFileDownload(jobs.get(0).getRepositoryUrl()); PostmanTestStepsRunner postmanRunner = new PostmanTestStepsRunner(collectionFile); postmanRunner.setClientHttpRequestFactory(factory); postmanRunner.setTestsCallbackUrl(testsCallbackUrl); postmanRunner.setPostmanRunnerUrl(postmanRunnerUrl); return postmanRunner; } catch (IOException ioe) { log.error("IOException while downloading {}", jobs.get(0).getRepositoryUrl()); } } default: HttpTestRunner httpRunner = new HttpTestRunner(); httpRunner.setClientHttpRequestFactory(factory); return httpRunner; } }