Example usage for org.springframework.web.client RestTemplate RestTemplate

List of usage examples for org.springframework.web.client RestTemplate RestTemplate

Introduction

In this page you can find the example usage for org.springframework.web.client RestTemplate RestTemplate.

Prototype

public RestTemplate() 

Source Link

Document

Create a new instance of the RestTemplate using default settings.

Usage

From source file:io.pivotal.receptor.client.ReceptorClient.java

public ReceptorClient(String receptorHost) {
    this(receptorHost, new RestTemplate());
}

From source file:org.n52.tamis.rest.forward.capabilities.CapabilitiesRequestForwarder.java

/**
 * {@inheritDoc} <br/>//from  w  w  w.ja  v  a2  s  .  c o m
 * <br/>
 * Delegates an incoming getCapabilities request to the WPS proxy, receives
 * the extended capabilities document and creates an instance of
 * {@link Capabilities_Tamis}
 * 
 * @param parameterValueStore
 *            must contain the URL variable
 *            {@link URL_Constants_TAMIS#SERVICE_ID_VARIABLE_NAME} to
 *            identify the WPS instance
 * @return an instance of {@link Capabilities_Tamis}
 */
public final Capabilities_Tamis forwardRequestToWpsProxy(HttpServletRequest request, Object requestBody,
        ParameterValueStore parameterValueStore) {
    // assure that the URL variable "serviceId" is existent
    initializeRequestSpecificParameters(parameterValueStore);

    String capabilities_url_wpsProxy = createTargetURL_WpsProxy(request);

    RestTemplate capabilitiesTemplate = new RestTemplate();

    // fetch extended capabilitiesDoc from WPS proxy and deserialize it into
    // shortened capabilitiesDoc
    Capabilities_Tamis capabilitiesDoc = capabilitiesTemplate.getForObject(capabilities_url_wpsProxy,
            Capabilities_Tamis.class);

    /*
     * Override the URL of  capabilitiesDoc with the base URL of the tamis WPS proxy.
     * 
     * Retrieve the base URL from the HtteServletRequest object 
     */
    String requestURL = request.getRequestURL().toString();
    //      String wpsBaseUrl_tamisProxy = requestURL.split(URL_Constants_TAMIS.TAMIS_PREFIX)[0];
    capabilitiesDoc.setUrl(requestURL);

    return capabilitiesDoc;
}

From source file:se.sawano.spring.examples.jsonxmlws.RESTControllerTestIT.java

private RestTemplate createXMLRestTemplate() throws Exception {
    ArrayList<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new Jaxb2RootElementHttpMessageConverter());
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(messageConverters);
    return restTemplate;
}

From source file:org.zalando.stups.oauth2.spring.server.TokenInfoResourceServerTokenServices.java

public TokenInfoResourceServerTokenServices(final String tokenInfoEndpointUrl,
        final AuthenticationExtractor authenticationExtractor) {
    this(tokenInfoEndpointUrl, CLIENT_ID_NOT_NEEDED, authenticationExtractor, new RestTemplate());
}

From source file:org.openbaton.nfvo.vnfm_reg.impl.sender.RestVnfmSender.java

@PostConstruct
private void init() {
    this.rest = new RestTemplate();
    this.headers = new HttpHeaders();
    headers.add("Content-Type", "application/json");
    headers.add("Accept", "*/*");
}

From source file:org.trustedanalytics.servicebroker.h2o.config.ServiceInstanceServiceConfig.java

@Bean
@Profile({ "cloud", "default" })
public H2oProvisionerRestApi h2oProvisionerRestApi(ExternalConfiguration config) {
    return new H2oProvisionerRestClient(config.getH2oProvisionerUrl(), new RestTemplate());
}

From source file:fi.csc.emrex.smp.JsonController.java

@RequestMapping("/api/emreg")
@ResponseBody//from www  .  jav  a 2 s.  c o m
public String emreg() throws URISyntaxException {
    String emreg = (String) context.getSession().getAttribute("emreg");
    if (emreg == null) {
        RestTemplate template = new RestTemplate();
        emreg = template.getForObject(new URI(emregUrl), String.class);
        context.getSession().setAttribute("emreg", emreg);
    }
    return emreg;
}

From source file:org.springframework.boot.test.web.client.TestRestTemplateTests.java

@Test
public void fromRestTemplateBuilder() {
    RestTemplateBuilder builder = mock(RestTemplateBuilder.class);
    RestTemplate delegate = new RestTemplate();
    given(builder.build()).willReturn(delegate);
    assertThat(new TestRestTemplate(builder).getRestTemplate()).isEqualTo(delegate);
}

From source file:com.uimirror.auth.otp.OTPStepDef.java

@Then("^I call the otp validation service$")
public void i_call_the_otp_validation_service() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    when(someBean.test()).thenReturn("Helooooooooo done");
    String res = new RestTemplate().postForObject("http://localhost:8080/uim/auth/api/auth/login", new Object(),
            String.class);
    System.out.println(res);//from   w w  w . j  av  a2  s . co m
    throw new PendingException();
}

From source file:org.messic.android.util.RestJSONClient.java

/**
 * Rest GET petition to the server at the url param, sending all the post parameters defiend at formData. This post
 * return an object (json marshalling) of class defined at clazz parameter. You should register a
 * {@link RestListener} in order to obtain the returned object, this is because the petition is done in an async
 * process./*from   w w w .  ja v a 2s.c o m*/
 * 
 * @param url {@link string} URL to attack
 * @param clazz Class<T/> class that you will marshall to a json object
 * @param rl {@link RestListener} listener to push the object returned
 */
public static <T> void get(final String url, final Class<T> clazz, final RestListener<T> rl) {
    final RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());

    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    // Populate the MultiValueMap being serialized and headers in an HttpEntity object to use for the request
    final HttpEntity<MultiValueMap<?, ?>> requestEntity = new HttpEntity<MultiValueMap<?, ?>>(
            new LinkedMultiValueMap<String, Object>(), requestHeaders);

    AsyncTask<Void, Void, Void> at = new AsyncTask<Void, Void, Void>() {
        @Override
        protected Void doInBackground(Void... params) {
            try {
                ResponseEntity<T> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, clazz);
                rl.response(response.getBody());
            } catch (Exception e) {
                rl.fail(e);
            }
            return null;
        }

    };

    at.execute();
}