Search in sources :

Example 6 with RestTemplate

use of org.springframework.web.client.RestTemplate in project androidannotations by androidannotations.

the class HttpMethodServiceTest method useOptionsHttpMethod.

@Test
@SuppressWarnings("unchecked")
public void useOptionsHttpMethod() {
    HttpMethodsService_ service = new HttpMethodsService_(null);
    RestTemplate restTemplate = mock(RestTemplate.class);
    ResponseEntity<Object> response = mock(ResponseEntity.class);
    when(restTemplate.exchange(Matchers.anyString(), Matchers.<HttpMethod>eq(HttpMethod.OPTIONS), Matchers.<HttpEntity<?>>any(), Matchers.<Class<Object>>any())).thenReturn(response);
    HttpHeaders headers = mock(HttpHeaders.class);
    when(response.getHeaders()).thenReturn(headers);
    service.setRestTemplate(restTemplate);
    service.options();
    verify(restTemplate).exchange(Matchers.anyString(), Matchers.<HttpMethod>eq(HttpMethod.OPTIONS), Matchers.<HttpEntity<?>>any(), Matchers.<Class<Object>>any());
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 7 with RestTemplate

use of org.springframework.web.client.RestTemplate in project androidannotations by androidannotations.

the class HttpMethodServiceTest method usePostHttpMethod.

@Test
public void usePostHttpMethod() {
    HttpMethodsService_ service = new HttpMethodsService_(null);
    RestTemplate restTemplate = mock(RestTemplate.class);
    service.setRestTemplate(restTemplate);
    service.post();
    verify(restTemplate).exchange(Matchers.anyString(), Matchers.<HttpMethod>eq(HttpMethod.POST), Matchers.<HttpEntity<?>>any(), Matchers.<Class<Object>>any());
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 8 with RestTemplate

use of org.springframework.web.client.RestTemplate in project spring-security-oauth by spring-projects.

the class OAuth2AccessTokenSupport method getRestTemplate.

protected RestOperations getRestTemplate() {
    if (restTemplate == null) {
        synchronized (this) {
            if (restTemplate == null) {
                RestTemplate restTemplate = new RestTemplate();
                restTemplate.setErrorHandler(getResponseErrorHandler());
                restTemplate.setRequestFactory(requestFactory);
                restTemplate.setInterceptors(interceptors);
                this.restTemplate = restTemplate;
            }
        }
    }
    if (messageConverters == null) {
        setMessageConverters(new RestTemplate().getMessageConverters());
    }
    return restTemplate;
}
Also used : RestTemplate(org.springframework.web.client.RestTemplate)

Example 9 with RestTemplate

use of org.springframework.web.client.RestTemplate in project h2o-2 by h2oai.

the class h2oService method PredictGBMStatus.

public String PredictGBMStatus(String src_key) {
    //http://localhost:54321/2/Inspect2.json?src_key=1111
    String status;
    String h2oUrlJobStatusEndPoint = H2O_HOST_URL + H2O_GBM_MODEL_PREDICT_STATUS_URL + "src_key=" + src_key;
    System.out.println(h2oUrlJobStatusEndPoint);
    System.out.println("@@@ Calling endpoint {} : " + h2oUrlJobStatusEndPoint);
    log.debug("@@@ Calling endpoint {}", h2oUrlJobStatusEndPoint);
    RestTemplate restTemplate = new RestTemplate();
    try {
        while (true) {
            String responseBody = restTemplate.getForObject(h2oUrlJobStatusEndPoint, String.class);
            JSONObject jsonobject = new JSONObject(responseBody);
            JSONObject response_info = (JSONObject) jsonobject.get("response_info");
            status = (String) response_info.get("status");
            log.debug("!!!!!! JOB Status  {}", status);
            if (status.equalsIgnoreCase("done")) {
                break;
            }
            //Should use futures here
            Thread.sleep(2000L);
        }
    } catch (Exception ex) {
        log.debug("!!!!!! Error Occured while getting job status  {}", ex);
        return null;
    }
    return status;
}
Also used : JSONObject(org.json.JSONObject) RestTemplate(org.springframework.web.client.RestTemplate) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) JSONException(org.json.JSONException)

Example 10 with RestTemplate

use of org.springframework.web.client.RestTemplate in project h2o-2 by h2oai.

the class h2oService method PredictGBM.

public String PredictGBM(String model, String new_data_key) {
    //http://localhost:54321/2/Predict.html?model=gbmmodelDestinationKey&data=prostate_csv.hex&prediction=predict_1
    String status;
    String inspect_status;
    String prediction_name = "Predict_GBM";
    String h2oUrlPredictEndPoint = H2O_HOST_URL + H2O_GBM_MODEL_PREDICT_URL + "model=" + model + "&data=" + new_data_key + "&prediction=" + prediction_name;
    System.out.println(h2oUrlPredictEndPoint);
    log.debug("@@@ Calling endpoint {}", h2oUrlPredictEndPoint);
    try {
        RestTemplate restTemplate = new RestTemplate();
        String responseBody = restTemplate.getForObject(h2oUrlPredictEndPoint, String.class);
        JSONObject jsonobject = new JSONObject(responseBody);
        JSONObject response_info = (JSONObject) jsonobject.get("response_info");
        status = (String) response_info.get("status");
        System.out.println("PREDICT GBM status: " + status);
        inspect_status = PredictGBMStatus(prediction_name);
    } catch (Exception ex) {
        log.debug("!!!!!! Error Occurred while getting job status  {}", ex);
        ex.printStackTrace();
        return null;
    }
    return inspect_status;
}
Also used : JSONObject(org.json.JSONObject) RestTemplate(org.springframework.web.client.RestTemplate) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) JSONException(org.json.JSONException)

Aggregations

RestTemplate (org.springframework.web.client.RestTemplate)206 Test (org.junit.Test)107 URI (java.net.URI)39 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)29 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)22 HttpComponentsClientHttpRequestFactory (org.springframework.http.client.HttpComponentsClientHttpRequestFactory)22 HttpHeaders (org.springframework.http.HttpHeaders)19 HttpEntity (org.springframework.http.HttpEntity)16 MapPropertySource (org.springframework.core.env.MapPropertySource)15 StandardEnvironment (org.springframework.core.env.StandardEnvironment)15 StringHttpMessageConverter (org.springframework.http.converter.StringHttpMessageConverter)15 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)15 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)13 IOException (java.io.IOException)12 JSONObject (org.json.JSONObject)12 Before (org.junit.Before)11 ClientHttpResponse (org.springframework.http.client.ClientHttpResponse)11 MappingJackson2HttpMessageConverter (org.springframework.http.converter.json.MappingJackson2HttpMessageConverter)11