List of usage examples for org.springframework.web.client RestTemplate getForObject
@Override @Nullable public <T> T getForObject(URI url, Class<T> responseType) throws RestClientException
From source file:com.unito.controller.PageController.java
@RequestMapping(value = { "/logout", "/logoutapp" }, method = GET) public String logout(@AuthenticationPrincipal User customUser) { UserDetails userDetails;//w w w.j a v a 2s . c o m RestTemplate restTemplate = new RestTemplate(); LOG.info("logout"); LOG.info("ustom user = " + customUser); userDetails = userDetailsRepository.find(customUser.getUsername()); if (userDetails != null) { LOG.info("GET:" + REVOKE_URL + userDetails.getAccesstoken()); restTemplate.getForObject(REVOKE_URL + userDetails.getAccesstoken(), String.class); } else return "redirect: logoutws?googleinssuccess"; //was a problem with google session login return "redirect: logoutws"; }
From source file:com.culturedear.counterpoint.CounterpointSolution.java
private ScorePartwise doScorePartwise() { Measure curMeasure = new Measure(" "); ScorePartwise scorePartwise = new ScorePartwise(); if (notesAllVoices.size() > 0) { scorePartwise.getScoreParts().add(new ScorePart("Cantus firmus", "P1")); for (int voiceIdxA = 1; voiceIdxA < notesAllVoices.size(); voiceIdxA++) { scorePartwise.getScoreParts() .add(new ScorePart("Melody " + (voiceIdxA + 1), "P" + (voiceIdxA + 1))); }/*from ww w . j a v a 2 s . com*/ for (int voiceIdxB = 0; voiceIdxB < notesAllVoices.size(); voiceIdxB++) { Part part = new Part("P" + (voiceIdxB + 1)); scorePartwise.getParts().add(part); List<Note> notesForPart = notesAllVoices.get(voiceIdxB); // Iteratate over the notes in this part and insert Measure elements for (Note note : notesForPart) { int onset = note.getOnset(); if (onset % onsetUnitsPerMeasure == 0) { curMeasure = new Measure("" + (onset / onsetUnitsPerMeasure + 1)); part.getMeasures().add(curMeasure); } curMeasure.getNotes().add(note); } } } // Iterate over the measures for all parts, identifying the first chord in each measure boolean keepGoing = true; int measureNum = 0; while (keepGoing) { log.debug("Analyzing chord for measure " + measureNum); Note topMeasureFirstNote = null; List<Note> chordNotes = new ArrayList<>(); List<Part> parts = scorePartwise.getParts(); for (Part part : parts) { List<Measure> measures = part.getMeasures(); if (measureNum < measures.size()) { Measure measure = measures.get(measureNum); List<Note> notes = measure.getNotes(); if (notes.size() > 0) { Note firstNoteInMeasure = notes.get(0); if (measureNum == 0 && firstNoteInMeasure.getPitch().octave <= 3) { // First note in measure is below middle C, so use bass clef Clef clef = new Clef("F", 4); MeasureAttributes measureAttributes = new MeasureAttributes(clef); measure.setMeasureAttributes(measureAttributes); } if (topMeasureFirstNote == null) { topMeasureFirstNote = firstNoteInMeasure; } chordNotes.add(firstNoteInMeasure); } else { // Unexpected, as all measures should have at least one note keepGoing = false; } } else { // We've run out of measures in at least one part keepGoing = false; } } if (topMeasureFirstNote != null) { Collections.sort(chordNotes); String notesString = chordNotes.stream().map(note -> note.getPitch().toString()) .collect(Collectors.joining(" ")); // Call the Chord Analyzer service RestTemplate restTemplate = new RestTemplate(); Lyric lyric = null; try { ClientMusicChord clientMusicChord = restTemplate.getForObject( this.counterpointProperties.getAnalyzerServiceEndpoint(notesString), ClientMusicChord.class); String chordTypeStr = clientMusicChord.getChordType(); String chordNotationStr = clientMusicChord.getRoot(); if (chordTypeStr.equalsIgnoreCase("pow")) { chordNotationStr += "5"; // This is a power chord (triad with no 3) } else { chordNotationStr += " " + chordTypeStr; } // Notate as a slash chord if appropriate if (clientMusicChord.getInversion() != 0) { chordNotationStr += "/" + clientMusicChord.getBassNote(); } lyric = new Lyric(chordNotationStr); } catch (Exception e) { log.info("Caught exception when analyzing chord " + e); //lyric = new Lyric("???"); } topMeasureFirstNote.setLyric(lyric); } measureNum++; } return scorePartwise; }
From source file:com.bytebybyte.mapquest.geocoding.service.standard.MapQuestTest.java
@Test public void getGoogleMap() { String API_KEY = "AIzaSyAv9WhULXF0Ri_C19NGyV2-rCUh50nMNA4"; RestTemplate restTemplate = new RestTemplate(); String url = "https://maps.googleapis.com/maps/api/geocode/json?address=11480 Sunset Hills Road, Reston, VA 20190&key=" + API_KEY;/*from w w w.j a v a2s . c om*/ String result = restTemplate.getForObject(url, String.class); System.out.println("Result : " + result); /*HttpEntity<String> newentity = new HttpEntity<String>(headers); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, newentity, String.class); System.out.println("Response : " + response);*/ JsonElement jelement = new JsonParser().parse(result); JsonObject jobject = jelement.getAsJsonObject(); JsonArray jarray = jobject.getAsJsonArray("results"); jobject = jarray.get(0).getAsJsonObject(); System.out.println(jobject.get("geometry")); JsonElement je = new JsonParser().parse(jobject.get("geometry").toString()); JsonObject jo = je.getAsJsonObject(); jo = jo.getAsJsonObject("location"); System.out.println("Lat : " + jo.get("lat")); System.out.println("Lon : " + jo.get("lng")); }
From source file:org.starfishrespect.myconsumption.android.tasks.ConfigUpdater.java
public void refreshDB() { AsyncTask<Void, List, Void> task = new AsyncTask<Void, List, Void>() { @Override/*from w w w . j av a 2 s . c om*/ protected Void doInBackground(Void... params) { DatabaseHelper db = SingleInstance.getDatabaseHelper(); RestTemplate template = new RestTemplate(); template.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); try { String url = SingleInstance.getServerUrl() + "configs/co2"; Double co2 = template.getForObject(url, Double.class); int id = db.getIdForKey("config_co2"); KeyValueData valueData = new KeyValueData("config_co2", co2.toString()); valueData.setId(id); LOGD(TAG, "writing stat in local db: " + co2); db.getKeyValueDao().createOrUpdate(valueData); } catch (SQLException e) { LOGD(TAG, "Cannot create config co2", e); } catch (ResourceAccessException | HttpClientErrorException e) { LOGE(TAG, "Cannot access server ", e); } try { String url = SingleInstance.getServerUrl() + "configs/day"; Double day = template.getForObject(url, Double.class); int id = db.getIdForKey("config_day"); KeyValueData valueData = new KeyValueData("config_day", day.toString()); valueData.setId(id); LOGD(TAG, "writing stat in local db: " + day); db.getKeyValueDao().createOrUpdate(valueData); } catch (SQLException e) { LOGD(TAG, "Cannot create config day", e); } catch (ResourceAccessException | HttpClientErrorException e) { LOGE(TAG, "Cannot access server ", e); } try { String url = SingleInstance.getServerUrl() + "configs/night"; Double night = template.getForObject(url, Double.class); int id = db.getIdForKey("config_night"); KeyValueData valueData = new KeyValueData("config_night", night.toString()); valueData.setId(id); LOGD(TAG, "writing stat in local db: " + night); db.getKeyValueDao().createOrUpdate(valueData); } catch (SQLException e) { LOGD(TAG, "Cannot create config night", e); } catch (ResourceAccessException | HttpClientErrorException e) { LOGE(TAG, "Cannot access server ", e); } return null; } @Override protected void onPostExecute(Void aVoid) { if (configUpdateFinishedCallback != null) { configUpdateFinishedCallback.onConfigUpdateFinished(); } } }; task.execute(); }
From source file:fi.vrk.xroad.catalog.collector.actors.ListClientsRestTest.java
@Test public void testOkMessage() throws Exception { RestTemplate t = new RestTemplate(); MockRestServiceServer mockServer = MockRestServiceServer.createServer(t); mockServer.expect(requestTo(TEST_REQUEST_PATH)) .andRespond(withSuccess(VALID_LISTCLIENTS_RESPONSE, MediaType.APPLICATION_XML)); ClientList clientList = t.getForObject(TEST_REQUEST_PATH, ClientList.class); assertNotNull(clientList);/*w w w.j a v a 2 s . co m*/ assertEquals(3, clientList.getMember().size()); }
From source file:fi.vrk.xroad.catalog.collector.actors.ListClientsRestTest.java
@Test public void testBadMessage() throws Exception { RestTemplate t = new RestTemplate(); MockRestServiceServer mockServer = MockRestServiceServer.createServer(t); mockServer.expect(requestTo(TEST_REQUEST_PATH)) .andRespond(withSuccess(OUTDATED_GLOBAL_CONF, MediaType.APPLICATION_XML)); try {/*from ww w . ja v a2 s. c om*/ ClientList clientList = t.getForObject(TEST_REQUEST_PATH, ClientList.class); fail("should fail since restOperation is not returning valid ClientList"); } catch (Exception expected) { log.error("expected exception: ", expected); } }
From source file:be.roots.taconic.pricingguide.service.HubSpotServiceImpl.java
public Contact getContactFor(String hsID) throws IOException { LOGGER.info("Start getting the recent contact information based on conversion-id: " + hsID); final RestTemplate restTemplate = new RestTemplate(); RecentContacts recentContacts = null; do {/*from w w w . ja v a 2s .c o m*/ if (recentContacts == null) { // first call LOGGER.info("Initial call for recent contacts"); recentContacts = restTemplate.getForObject(apiUrl + apiKey + "&count=100", RecentContacts.class); } else { // page through the next calls LOGGER.info("Secondary call for recent contacts with timeOffset=" + recentContacts.getTimeOffset() + ", and vidOffset=" + recentContacts.getVidOffset()); recentContacts = restTemplate.getForObject(apiUrl + apiKey + "&count=100&timeOffset=" + recentContacts.getTimeOffset() + "&vidOffset=" + recentContacts.getVidOffset(), RecentContacts.class); } if (recentContacts != null && !CollectionUtils.isEmpty(recentContacts.getContacts())) { for (RecentContact contact : recentContacts.getContacts()) { if (!CollectionUtils.isEmpty(contact.getFormSubmissions())) { for (FormSubmission form : contact.getFormSubmissions()) { if (hsID.equals(form.getConversionId())) { final Contact result = getContactDetailsFor( String.format(apiContactUrl + apiKey, contact.getVid())); result.setHsId(hsID); return result; } } } } } } while (recentContacts.isHasMore()); LOGGER.info("No recent contact information found for: " + hsID); return null; }
From source file:au.org.ala.fielddata.mobile.service.FieldDataServiceClient.java
public List<Survey> downloadSurveys(FieldDataService.SurveyDownloadCallback callback) { String url = getServerUrl() + surveyUrl + ident; RestTemplate restTemplate = getRestTemplate(); restTemplate.getMessageConverters().add(new StringHttpMessageConverter()); Log.d("URL", url); UserSurveyResponse[] result = restTemplate.getForObject(url, UserSurveyResponse[].class); url = getServerUrl() + surveyDetails; List<Survey> surveys = new ArrayList<Survey>(); List<Integer> speciesIdList = new ArrayList<Integer>(); //List<Species> species = new ArrayList<Species>(); int count = 0; int total = result.length; for (UserSurveyResponse userSurvey : result) { String downloadedSurveys = jsonSurveyIds(surveys); if (callback != null) { callback.surveysDownloaded(++count, total); }/*ww w . ja v a 2 s . c om*/ Log.d("URL", String.format(url, userSurvey.id, ident, downloadedSurveys)); DownloadSurveyResponse surveyResponse = restTemplate.getForObject( String.format(url, userSurvey.id, ident, downloadedSurveys), DownloadSurveyResponse.class); Survey survey = mapSurvey(surveyResponse); surveys.add(survey); List<Integer> speciesIds = surveyResponse.details.speciesIds; if (speciesIds != null) { speciesIdList.addAll(surveyResponse.details.speciesIds); } //species.addAll(downloadSpecies(survey)); } System.out.println(speciesIdList); return surveys; }
From source file:com.provenance.cloudprovenance.connector.policy.PolicyEnforcementConnector.java
/** Method retrieves the policy response based on a response Id as a string */ @Override//from w ww . ja va 2 s. c om public String policyResponse(String serviceId, String policyResponseId) { RestTemplate restTemplate = new RestTemplate(); String restURIstructure = new String(); restURIstructure = protocol + "://" + server_add + ":" + port_no + "/" + service + "/" + resource + "/" + serviceId + "/" + policyResponseId; logger.info("Invoking URI: " + restURIstructure); String policyResponse = restTemplate.getForObject(restURIstructure, String.class); return policyResponse; }