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:gumga.framework.security.GumgaSoftwareValuesProxy.java

private RestTemplate getRestTemplate() {
    if (restTemplate == null) {
        restTemplate = new RestTemplate();
    }
    return restTemplate;
}

From source file:org.jtalks.tests.jcommune.mail.pochta.PochtaClient.java

/**
 * Get message by identifier/*w ww. j av  a  2 s.com*/
 *
 * @param id the UUID type identifier
 * @return the message
 * @throws CouldNotGetMessageException
 */
public static String getMessage(String id) {
    RestTemplate client = new RestTemplate();
    try {
        return client.getForObject(new URI(API_INBOXES_URL), String.class);
    } catch (Exception e) {
        throw new CouldNotGetMessageException(e);
    }
}

From source file:com.springsource.greenhouse.events.load.NFJSLoader.java

@Inject
public NFJSLoader(EventLoaderRepository loaderRepository) {
    this.loaderRepository = loaderRepository;
    this.restTemplate = new RestTemplate();
    this.timeSlotIdMap = new HashMap<Long, Long>();
    this.leaderIdMap = new HashMap<Long, Long>();
    this.topicSlotMap = new HashMap<Long, Long>();
}

From source file:de.hybris.platform.marketplaceintegrationbackoffice.utils.MarketplaceintegrationbackofficeHttpClientImpl.java

@Override
public boolean redirectRequest(final String requestUrl) throws IOException {

    final boolean result = true;
    final RestTemplate restTemplate = new RestTemplate();

    final java.net.URI uri = java.net.URI.create(requestUrl);
    final java.awt.Desktop dp = java.awt.Desktop.getDesktop();
    if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
        dp.browse(uri);/*from  w ww.  jav a 2 s.  c o  m*/
    }
    restTemplate.execute(requestUrl, HttpMethod.GET, new RequestCallback() {
        @Override
        public void doWithRequest(final ClientHttpRequest request) throws IOException {
            // empty block should be documented
        }
    }, new ResponseExtractor<Object>() {
        @Override
        public Object extractData(final ClientHttpResponse response) throws IOException {
            final HttpStatus statusCode = response.getStatusCode();
            LOG.debug("Response status: " + statusCode.toString());
            return response.getStatusCode();
        }
    });
    return result;
}

From source file:cz.muni.fi.mushroomhunter.restclient.MushroomUpdateSwingWorker.java

@Override
protected Integer doInBackground() throws Exception {
    DefaultTableModel model = (DefaultTableModel) restClient.getTblMushroom().getModel();
    int selectedRow = restClient.getTblMushroom().getSelectedRow();

    RestTemplate restTemplate = new RestTemplate();

    String plainCreds = RestClient.USER_NAME + ":" + RestClient.PASSWORD;
    byte[] plainCredsBytes = plainCreds.getBytes();
    byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
    String base64Creds = new String(base64CredsBytes);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    List<MediaType> mediaTypeList = new ArrayList<>();
    mediaTypeList.add(MediaType.ALL);//  w w w .  ja  v  a  2 s.co m
    headers.setAccept(mediaTypeList);

    headers.add("Authorization", "Basic " + base64Creds);

    HttpEntity request = new HttpEntity<>(headers);

    ResponseEntity<MushroomDto> responseEntity = restTemplate.exchange(
            RestClient.SERVER_URL + "pa165/rest/mushroom/" + RestClient.getMushroomIDs().get(selectedRow),
            HttpMethod.GET, request, MushroomDto.class);

    MushroomDto mushroomDto = responseEntity.getBody();

    mushroomDto.setName(restClient.getTfMushroomName().getText());

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MMMM-yyyy", new Locale("en_US"));

    //to create date object only month is used, day and year are fixed values
    String dateInString = "01-" + restClient.getComboBoxMushroomStartOfOccurence().getSelectedItem().toString()
            + "-2000";
    mushroomDto.setStartOfOccurence(formatter.parse(dateInString));

    //to create date object only month is used, day and year are fixed values
    dateInString = "01-" + restClient.getComboBoxMushroomEndOfOccurence().getSelectedItem().toString()
            + "-2000";
    mushroomDto.setEndOfOccurence(formatter.parse(dateInString));

    ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
    String json = ow.writeValueAsString(mushroomDto);
    request = new HttpEntity(json, headers);

    restTemplate.exchange(RestClient.SERVER_URL + "pa165/rest/mushroom", HttpMethod.PUT, request,
            MushroomDto.class);
    return selectedRow;
}

From source file:jetbrains.buildServer.vsoRooms.rest.impl.VSOTeamRoomsAPIConnectionImpl.java

public VSOTeamRoomsAPIConnectionImpl(@NotNull String user, @NotNull String password) {
    myUser = user;/*from  w  w w .  j a  v  a 2s .  com*/
    myPassword = password;
    myRestTemplate = new RestTemplate();
    List<HttpMessageConverter<?>> customConverters = new ArrayList<HttpMessageConverter<?>>();
    customConverters.add(new JsonTeamRoomListConverter());
    customConverters.add(new JsonTeamRoomMessageConverter());
    customConverters.add(new StringJsonConverter());
    myRestTemplate.setMessageConverters(customConverters);
}

From source file:org.kaaproject.kaa.sandbox.rest.SandboxClient.java

public SandboxClient(String host, int port) {
    restTemplate = new RestTemplate();
    ClientHttpRequestFactory requestFactory = new HttpComponentsRequestFactoryBasicAuth(
            new HttpHost(host, port, "http"));
    restTemplate.setRequestFactory(requestFactory);
    url = "http://" + host + ":" + port + "/sandbox/rest/api/";
}

From source file:com.art4ul.jcoon.bean.RestClientAnnotationBeanPostProcessor.java

public RestClientAnnotationBeanPostProcessor(List<HttpMessageConverter<?>> messageConverters) {
    this.restTemplate = new RestTemplate();
    restTemplate.setMessageConverters(messageConverters);
}

From source file:com.springinpractice.ch11.maven.PackageMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    ZkybaseClient client = new ZkybaseClient(new RestTemplate(), skybaseUrl);
    client.createPackage(new Package(module, version));
}

From source file:com.appranix.adapter.service.AdapterServiceImpl.java

@Override
public int adapterCreate() throws Exception {
    try {/* w  w  w.  j a  v a 2s.  com*/
        ObjectMapper mapper = new ObjectMapper();
        ObjectNode node = mapper.createObjectNode();
        node.put("nsPath", "/");
        node.put("ciClassName", "Component");
        node.put("ciName", "test");

        final String uri = "http://localhost:9090/adapter/rest/cm/simple/cis";

        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity<String> result = restTemplate.postForEntity(uri, node, String.class);

        Map<String, Integer> map = mapper.readValue(result.getBody(), Map.class);

        Integer id = map.get("ciId");

        return id;
    } catch (Exception e) {
        throw new Exception("Error in Write Operation");
    }
}