List of usage examples for org.springframework.web.util UriComponentsBuilder queryParam
@Override
public UriComponentsBuilder queryParam(String name, @Nullable Collection<?> values)
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically updates a key-value pair in etcd. * //from www . j a v a 2 s . co m * @param key * the key * @param value * the value * @param ttl * the time-to-live * @param prevIndex * the modified index of the key * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndSwap(String key, String value, int ttl, int prevIndex) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("ttl", ttl == -1 ? "" : ttl); builder.queryParam("prevIndex", prevIndex); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("value", value); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically updates a key-value pair in etcd. * /*from ww w . j a va 2 s.co m*/ * @param key * the key * @param value * the value * @param ttl * the time-to-live * @param prevValue * the previous value of the key * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndSwap(String key, String value, int ttl, String prevValue) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("ttl", ttl == -1 ? "" : ttl); builder.queryParam("prevValue", prevValue); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("value", value); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:org.zalando.boot.etcd.EtcdClient.java
/** * Atomically creates or updates a key-value pair in etcd. * //from w w w . j ava2s . co m * @param key * the key * @param value * the value * @param ttl * the time-to-live * @param prevExist * <code>true</code> if the existing node should be updated, * <code>false</code> of the node should be created * @return the response from etcd with the node * @throws EtcdException * in case etcd returned an error */ public EtcdResponse compareAndSwap(final String key, final String value, int ttl, boolean prevExist) throws EtcdException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(KEYSPACE); builder.pathSegment(key); builder.queryParam("ttl", ttl == -1 ? "" : ttl); builder.queryParam("prevExist", prevExist); MultiValueMap<String, String> payload = new LinkedMultiValueMap<>(1); payload.set("value", value); return execute(builder, HttpMethod.PUT, payload, EtcdResponse.class); }
From source file:org.springframework.data.rest.webmvc.jpa.JpaWebTests.java
/** * Checks, that the server only returns the properties contained in the projection requested. * //from w w w . j ava 2 s. c o m * @see OrderSummary * @see DATAREST-221 */ @Test public void returnsProjectionIfRequested() throws Exception { Link orders = client.discoverUnique("orders"); MockHttpServletResponse response = client.request(orders); Link orderLink = assertContentLinkWithRel("self", response, true).expand(); UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(orderLink.getHref()); String uri = builder.queryParam("projection", "summary").build().toUriString(); response = mvc.perform(get(uri)). // andExpect(status().isOk()). // andExpect(jsonPath("$.price", is(2.5))).// andReturn().getResponse(); assertJsonPathDoesntExist("$.lineItems", response); }
From source file:org.openmhealth.shim.withings.WithingsShim.java
URI createWithingsRequestUri(ShimDataRequest shimDataRequest, String userid, WithingsDataType withingsDataType) { MultiValueMap<String, String> dateTimeMap = new LinkedMultiValueMap<>(); if (withingsDataType.usesUnixEpochSecondsDate || isPartnerAccessActivityMeasure(withingsDataType)) { //the partner access endpoints for activity also use epoch secs dateTimeMap.add("startdate", String.valueOf(shimDataRequest.getStartDateTime().toEpochSecond())); dateTimeMap.add("enddate", String.valueOf(shimDataRequest.getEndDateTime().plusDays(1).toEpochSecond())); } else {// w w w .ja va 2s . c om dateTimeMap.add("startdateymd", shimDataRequest.getStartDateTime().toLocalDate().toString()); dateTimeMap.add("enddateymd", shimDataRequest.getEndDateTime().toLocalDate().toString()); } UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(DATA_URL) .pathSegment(withingsDataType.getEndpoint()); String measureParameter; if (isPartnerAccessActivityMeasure(withingsDataType)) { // partner level access allows greater detail around activity, but uses a different endpoint measureParameter = PARTNER_ACCESS_ACTIVITY_ENDPOINT; } else { measureParameter = withingsDataType.getMeasureParameter(); } uriComponentsBuilder.queryParam("action", measureParameter).queryParam("userid", userid) .queryParams(dateTimeMap); // if it's a body measure if (Objects.equals(withingsDataType.getMeasureParameter(), "getmeas")) { /* The Withings API allows us to query for single body measures, which we take advantage of to reduce unnecessary data transfer. However, since blood pressure is represented as two separate measures, namely a diastolic and a systolic measure, when the measure type is blood pressure we ask for all measures and then filter out the ones we don't care about. */ if (withingsDataType != WithingsDataType.BLOOD_PRESSURE) { WithingsBodyMeasureType measureType = WithingsBodyMeasureType.valueOf(withingsDataType.name()); uriComponentsBuilder.queryParam("meastype", measureType.getMagicNumber()); } uriComponentsBuilder.queryParam("category", 1); //filter out goal datapoints } UriComponents uriComponents = uriComponentsBuilder.build(); return uriComponents.toUri(); }
From source file:edu.purdue.cybercenter.dm.web.GlobusControllerTest.java
@Test @Ignore//from www.j a va 2 s. c o m public void shouldBeAbleToRunWorkflowWithGlobusTransfer() throws Exception { useTestWorkspace("brouder_sylvie"); login("george.washington", "1234"); /* * upload the test workflow */ MockMultipartFile mockMultipartFile = new MockMultipartFile(WORKFLOW_ZIP_FILE, new FileInputStream(WORKFLOW_FILES_DIR + WORKFLOW_ZIP_FILE)); MockMultipartHttpServletRequestBuilder mockMultipartHttpServletRequestBuilder = (MockMultipartHttpServletRequestBuilder) fileUpload( "/workflows/import").accept(MediaType.ALL).session(httpSession); mockMultipartHttpServletRequestBuilder.file(mockMultipartFile); ResultActions resultActions = mockMvc.perform(mockMultipartHttpServletRequestBuilder); resultActions.andExpect(status().isCreated()); String content = extractTextarea(resultActions.andReturn().getResponse().getContentAsString()); Map<String, Object> workflow = Helper.deserialize(content, Map.class); assertNotNull("workflow is null", workflow); Integer workflowId = (Integer) workflow.get("id"); /* * create a project and an experiment to associate the job for the workflow with * while doing that, make sure we save all the IDs associated to post it with the job */ MockHttpServletRequestBuilder mockHttpServletRequestBuilder = post("/projects") .content("{\"description\":\"This is a project\",\"name\":\"Project 1\"}") .accept(MediaType.APPLICATION_JSON).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isCreated()); content = resultActions.andReturn().getResponse().getContentAsString(); Map<String, Object> map = Helper.deserialize(content, Map.class); Integer projectId = (Integer) map.get("id"); mockHttpServletRequestBuilder = post("/experiments") .content("{\"projectId\":{\"$ref\":\"/projects/" + projectId + "\"},\"name\":\"Experiment 1\",\"description\":\"This is an experiment\"}") .accept(MediaType.APPLICATION_JSON).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isCreated()); content = resultActions.andReturn().getResponse().getContentAsString(); map = Helper.deserialize(content, Map.class); Integer experimentId = (Integer) map.get("id"); /* * create a job associated with the project, experiment and workflow we just created */ mockHttpServletRequestBuilder = post("/jobs").param("projectId", projectId.toString()) .param("experimentId", experimentId.toString()).param("workflowId", workflowId.toString()) .param("name", "Just a job").accept(MediaType.TEXT_HTML).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); /* * forwarded to job/submit/jobId */ String forwardedUrl = resultActions.andReturn().getResponse().getForwardedUrl(); mockHttpServletRequestBuilder = post(forwardedUrl).accept(MediaType.TEXT_HTML_VALUE).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); /* * redirected to jobs/task/jobId */ String redirectedUrl = resultActions.andReturn().getResponse().getRedirectedUrl(); mockHttpServletRequestBuilder = get(redirectedUrl).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); /* * we're at UT1 in the workflow */ String jobId = redirectedUrl.substring(redirectedUrl.lastIndexOf('/') + 1); TaskEntity task = (TaskEntity) resultActions.andReturn().getModelAndView().getModel().get("task"); String taskId = task.getId(); String templateId = "305b0f27-e829-424e-84eb-7a8a9ed93e28"; String templateVersion = "db719406-f665-45cb-a8fb-985b6082b654"; // For buttton 1 UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString("/globus/browseFile"); uriBuilder.queryParam("jobId", jobId); uriBuilder.queryParam("alias", templateId + ".browsefile1"); uriBuilder.queryParam("multiple", false); System.out.println(uriBuilder.build(true).toUriString()); mockHttpServletRequestBuilder = get(uriBuilder.build(true).toUriString()).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); redirectedUrl = resultActions.andReturn().getResponse().getContentAsString(); System.out.println("Redirected to: " + redirectedUrl); uriBuilder = UriComponentsBuilder.fromUriString("https://www.globus.org/service/graph/goauth/authorize"); uriBuilder.queryParam("response_type", "code"); //uriBuilder.queryParam("redirect_uri", "code"); uriBuilder.queryParam("client_id", username); URL url = new URL(uriBuilder.build(true).toUriString()); HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); String userpass = username + ":" + password; String basicAuth = "Basic " + new String(Base64.encodeBase64(userpass.getBytes())); connection.setRequestProperty("Authorization", basicAuth); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "application/json"); String res = IOUtils.toString(connection.getInputStream()); Map<String, Object> responseMap = Helper.deserialize(res, Map.class); String code = (String) responseMap.get("code"); uriBuilder = UriComponentsBuilder.fromUriString("/globus/loginCallback"); uriBuilder.queryParam("jobId", Integer.parseInt(jobId)); uriBuilder.queryParam("alias", templateId + ".browsefile1"); uriBuilder.queryParam("multiple", false); String uri = uriBuilder.build(true).toUriString() + "&code=" + code; mockHttpServletRequestBuilder = get(uri).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().is3xxRedirection()); redirectedUrl = resultActions.andReturn().getResponse().getRedirectedUrl(); System.out.println("Redirected to: " + redirectedUrl); // For Button 2 uriBuilder = UriComponentsBuilder.fromUriString("/globus/browseFile"); uriBuilder.queryParam("jobId", jobId); uriBuilder.queryParam("alias", templateId + ".browsefile2"); uriBuilder.queryParam("multiple", true); System.out.println(uriBuilder.build(true).toUriString()); mockHttpServletRequestBuilder = get(uriBuilder.build(true).toUriString()).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); redirectedUrl = resultActions.andReturn().getResponse().getContentAsString(); System.out.println("Redirected to: " + redirectedUrl); uriBuilder = UriComponentsBuilder.fromUriString("https://www.globus.org/service/graph/goauth/authorize"); uriBuilder.queryParam("response_type", "code"); uriBuilder.queryParam("client_id", username); url = new URL(uriBuilder.build(true).toUriString()); connection = (HttpsURLConnection) url.openConnection(); userpass = username + ":" + password; basicAuth = "Basic " + new String(Base64.encodeBase64(userpass.getBytes())); connection.setRequestProperty("Authorization", basicAuth); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "application/json"); res = IOUtils.toString(connection.getInputStream()); responseMap = Helper.deserialize(res, Map.class); code = (String) responseMap.get("code"); // For button 2 uriBuilder = UriComponentsBuilder.fromUriString("/globus/loginCallback"); uriBuilder.queryParam("jobId", Integer.parseInt(jobId)); uriBuilder.queryParam("alias", templateId + ".browsefile2"); uriBuilder.queryParam("multiple", true); uri = uriBuilder.build(true).toUriString() + "&code=" + code; mockHttpServletRequestBuilder = get(uri).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().is3xxRedirection()); redirectedUrl = resultActions.andReturn().getResponse().getRedirectedUrl(); System.out.println("Redirected to: " + redirectedUrl); // Getting accessToken only from one button String accessToken = ""; String[] urlParts = redirectedUrl.split("&"); for (String urlPart : urlParts) { if (urlPart.contains("accessToken")) { String[] accessTokenPair = urlPart.split("="); accessToken = accessTokenPair[1]; break; } } //Button 1 uriBuilder = UriComponentsBuilder.fromUriString("/globus/fileSelectCallback"); uriBuilder.queryParam(URLEncoder.encode("file[0]", "UTF-8"), FILE_TO_UPLOAD_1); uriBuilder.queryParam("jobId", jobId); uriBuilder.queryParam("alias", templateId + ".browsefile1"); uriBuilder.queryParam("accessToken", accessToken);//URLEncoder.encode(accessToken,"UTF-8") uriBuilder.queryParam("path", URLEncoder.encode("/~/remote_endpoint/", "UTF-8")); uri = uriBuilder.build(true).toUriString(); uri = URLDecoder.decode(uri); uri = uri + "&endpoint=" + URLEncoder.encode(endpoint, "UTF-8"); mockHttpServletRequestBuilder = get(uri).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); //Button 2 uriBuilder = UriComponentsBuilder.fromUriString("/globus/fileSelectCallback"); uriBuilder.queryParam(URLEncoder.encode("file[0]", "UTF-8"), FILE_TO_UPLOAD_1); uriBuilder.queryParam(URLEncoder.encode("file[1]", "UTF-8"), FILE_TO_UPLOAD_2); uriBuilder.queryParam("jobId", jobId); uriBuilder.queryParam("alias", templateId + ".browsefile2"); uriBuilder.queryParam("accessToken", accessToken);//URLEncoder.encode(accessToken,"UTF-8") uriBuilder.queryParam("path", URLEncoder.encode("/~/remote_endpoint/", "UTF-8")); uri = uriBuilder.build(true).toUriString(); uri = URLDecoder.decode(uri); uri = uri + "&endpoint=" + URLEncoder.encode(endpoint, "UTF-8"); mockHttpServletRequestBuilder = get(uri).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); //For getting Storage Files (an abstract button called browsefile3) uriBuilder = UriComponentsBuilder.fromUriString("/globus/browseFile"); uriBuilder.queryParam("jobId", jobId); uriBuilder.queryParam("alias", templateId + ".browsefile3"); uriBuilder.queryParam("multiple", true); uriBuilder.queryParam("storageFile", "StorageFile:1");// This file has to be present in the storage file record and in memory System.out.println(uriBuilder.build(true).toUriString()); mockHttpServletRequestBuilder = get(uriBuilder.build(true).toUriString()).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); redirectedUrl = resultActions.andReturn().getResponse().getContentAsString(); System.out.println("Redirected to: " + redirectedUrl); //FileSelect uriBuilder = UriComponentsBuilder.fromUriString("/globus/fileSelectCallback"); uriBuilder.queryParam("fileId", 1); uriBuilder.queryParam(URLEncoder.encode("folder[0]", "UTF-8"), "remote_endpoint/"); uriBuilder.queryParam("jobId", jobId); uriBuilder.queryParam("alias", templateId + ".browsefile3"); uriBuilder.queryParam("accessToken", accessToken);//URLEncoder.encode(accessToken,"UTF-8") uriBuilder.queryParam("path", URLEncoder.encode("/~/", "UTF-8")); uri = uriBuilder.build(true).toUriString(); uri = URLDecoder.decode(uri, "UTF-8"); uri = uri + "&endpoint=" + URLEncoder.encode(endpoint, "UTF-8"); mockHttpServletRequestBuilder = get(uri).session(httpSession); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); String multipartBoundary = "------WebKitFormBoundary3xeGH8uP6GWtBfd1"; MultiPartFileContentBuilder multiPartFileContentBuilder = new MultiPartFileContentBuilder( multipartBoundary); multiPartFileContentBuilder.addField("autoGenerated", "true"); multiPartFileContentBuilder.addField("jobId", jobId); multiPartFileContentBuilder.addField("taskId", taskId); multiPartFileContentBuilder.addField("jsonToServer", "{}"); multiPartFileContentBuilder.addField("isIframe", "true"); multiPartFileContentBuilder.addField("experimentId", ""); multiPartFileContentBuilder.addField("projectId", ""); multiPartFileContentBuilder .addField(templateId + ".name({%22_template_version:%22" + templateVersion + "%22})", ""); multiPartFileContentBuilder .addField(templateId + ".browsefile1({%22_template_version:%22" + templateVersion + "%22})", ""); multiPartFileContentBuilder .addField(templateId + ".browsefile2({%22_template_version:%22" + templateVersion + "%22})", ""); String taskContent = multiPartFileContentBuilder.build(); // /rest/objectus post call mockHttpServletRequestBuilder = (MockMultipartHttpServletRequestBuilder) fileUpload("/rest/objectus/") .param("jobId", jobId).param("taskId", taskId).param(templateId + ".name", "") .param(templateId + ".browsefile1", "").param(templateId + ".browsefile2", "") .param("jsonToServer", "{}").accept(MediaType.ALL).session(httpSession); mockHttpServletRequestBuilder.content(taskContent); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().isOk()); multipartBoundary = "------WebKitFormBoundarybiQtLhfKnPwaMgsR"; multiPartFileContentBuilder = new MultiPartFileContentBuilder(multipartBoundary); multiPartFileContentBuilder.addField("jobId", jobId); multiPartFileContentBuilder.addField("taskId", taskId); multiPartFileContentBuilder.addField("jsonToServer", "{}"); taskContent = multiPartFileContentBuilder.build(); // /jobs/task post call mockHttpServletRequestBuilder = (MockMultipartHttpServletRequestBuilder) fileUpload("/jobs/task") .param("jobId", jobId).param("taskId", taskId).param("ignoreFormData", "true") .param("jsonToServer", "{}").accept(MediaType.ALL).session(httpSession); mockHttpServletRequestBuilder.content(taskContent); resultActions = mockMvc.perform(mockHttpServletRequestBuilder); resultActions.andExpect(status().is3xxRedirection()); redirectedUrl = resultActions.andReturn().getResponse().getRedirectedUrl(); System.out.println("Redirected to: " + redirectedUrl); deleteDatasetEntries(templateId); }
From source file:org.cloudfoundry.identity.uaa.oauth.UaaAuthorizationEndpoint.java
private String getSuccessfulRedirect(AuthorizationRequest authorizationRequest, String authorizationCode) { if (authorizationCode == null) { throw new IllegalStateException("No authorization code found in the current request scope."); }//from w ww . j a va2 s .c o m UriComponentsBuilder template = UriComponentsBuilder.fromUriString(authorizationRequest.getRedirectUri()); template.queryParam("code", encode(authorizationCode)); String state = authorizationRequest.getState(); if (state != null) { template.queryParam("state", encode(state)); } return template.build(true).toUriString(); }
From source file:com.playhaven.android.req.PlayHavenRequest.java
protected void addV4Signature(UriComponentsBuilder builder, SharedPreferences pref, String nonce) throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException { String ids = null;/*www.j a v a 2 s . co m*/ if (ktsid == null) { ids = concat(":", getString(pref, DeviceId), getString(pref, Token), nonce); } else { ids = concat(":", getString(pref, DeviceId), ktsid, getString(pref, Token), nonce); } builder.queryParam("sig4", createHmac(pref, ids, true)); }
From source file:com.orange.ngsi2.client.Ngsi2Client.java
private void addGeoQueryParams(UriComponentsBuilder builder, GeoQuery geoQuery) { if (geoQuery != null) { StringBuilder georel = new StringBuilder(geoQuery.getRelation().name()); if (geoQuery.getRelation() == GeoQuery.Relation.near) { georel.append(';').append(geoQuery.getModifier()); georel.append(':').append(geoQuery.getDistance()); }/* www . j a v a2s .com*/ builder.queryParam("georel", georel.toString()); builder.queryParam("geometry", geoQuery.getGeometry()); builder.queryParam("coords", geoQuery.getCoordinates().stream().map(Coordinate::toString).collect(Collectors.joining(";"))); } }
From source file:org.openmhealth.shim.ihealth.IHealthShim.java
@Override protected ResponseEntity<ShimDataResponse> getData(OAuth2RestOperations restTemplate, ShimDataRequest shimDataRequest) throws ShimException { final IHealthDataTypes dataType; try {/*from w w w .j a v a 2s .co m*/ dataType = valueOf(shimDataRequest.getDataTypeKey().trim().toUpperCase()); } catch (NullPointerException | IllegalArgumentException e) { throw new ShimException("Null or Invalid data type parameter: " + shimDataRequest.getDataTypeKey() + " in shimDataRequest, cannot retrieve data."); } OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime startDate = shimDataRequest.getStartDateTime() == null ? now.minusDays(1) : shimDataRequest.getStartDateTime(); OffsetDateTime endDate = shimDataRequest.getEndDateTime() == null ? now.plusDays(1) : shimDataRequest.getEndDateTime(); /* The physical activity point handles start and end datetimes differently than the other endpoints. It requires use to include the range until the beginning of the next day. */ if (dataType == PHYSICAL_ACTIVITY) { endDate = endDate.plusDays(1); } // SC and SV values are client-based keys that are unique to each endpoint within a project String scValue = getScValue(); List<String> svValues = getSvValues(dataType); List<JsonNode> responseEntities = newArrayList(); int i = 0; // We iterate because one of the measures (Heart rate) comes from multiple endpoints, so we submit // requests to each of these endpoints, map the responses separately and then combine them for (String endPoint : dataType.getEndPoint()) { UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(API_URL); // Need to use a dummy userId if we haven't authenticated yet. This is the case where we are using // getData to trigger Spring to conduct the OAuth exchange String userId = "uk"; if (shimDataRequest.getAccessParameters() != null) { OAuth2AccessToken token = SerializationUtils .deserialize(shimDataRequest.getAccessParameters().getSerializedToken()); userId = Preconditions.checkNotNull((String) token.getAdditionalInformation().get("UserID")); uriBuilder.queryParam("access_token", token.getValue()); } uriBuilder.path("/user/").path(userId + "/").path(endPoint) .queryParam("client_id", restTemplate.getResource().getClientId()) .queryParam("client_secret", restTemplate.getResource().getClientSecret()) .queryParam("start_time", startDate.toEpochSecond()) .queryParam("end_time", endDate.toEpochSecond()).queryParam("locale", "default") .queryParam("sc", scValue).queryParam("sv", svValues.get(i)); ResponseEntity<JsonNode> responseEntity; try { URI url = uriBuilder.build().encode().toUri(); responseEntity = restTemplate.getForEntity(url, JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException e) { // FIXME figure out how to handle this logger.error("A request for iHealth data failed.", e); throw e; } if (shimDataRequest.getNormalize()) { IHealthDataPointMapper mapper; switch (dataType) { case PHYSICAL_ACTIVITY: mapper = new IHealthPhysicalActivityDataPointMapper(); break; case BLOOD_GLUCOSE: mapper = new IHealthBloodGlucoseDataPointMapper(); break; case BLOOD_PRESSURE: mapper = new IHealthBloodPressureDataPointMapper(); break; case BODY_WEIGHT: mapper = new IHealthBodyWeightDataPointMapper(); break; case BODY_MASS_INDEX: mapper = new IHealthBodyMassIndexDataPointMapper(); break; case STEP_COUNT: mapper = new IHealthStepCountDataPointMapper(); break; case SLEEP_DURATION: mapper = new IHealthSleepDurationDataPointMapper(); break; case HEART_RATE: // there are two different mappers for heart rate because the data can come from two endpoints if (endPoint == "bp.json") { mapper = new IHealthBloodPressureEndpointHeartRateDataPointMapper(); break; } else if (endPoint == "spo2.json") { mapper = new IHealthBloodOxygenEndpointHeartRateDataPointMapper(); break; } case OXYGEN_SATURATION: mapper = new IHealthOxygenSaturationDataPointMapper(); break; default: throw new UnsupportedOperationException(); } responseEntities.addAll(mapper.asDataPoints(singletonList(responseEntity.getBody()))); } else { responseEntities.add(responseEntity.getBody()); } i++; } return ResponseEntity.ok().body(ShimDataResponse.result(SHIM_KEY, responseEntities)); }