List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers)
From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java
@Override public URI triggerDataLoad(final InstanceConfig config, final String dataId) throws ResponseStatusException { Preconditions.checkArgument(config != null); Preconditions.checkArgument(StringUtils.isNotBlank(dataId)); final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(), config.getUsername(), config.getPassword()); final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(), TRIGGER_PATH, Collections.emptyList()); final HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.TEXT_PLAIN); final HttpEntity<String> httpEntity = new HttpEntity<>(dataId, headers); final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, String.class); final HttpStatus status = response.getStatusCode(); if (status.equals(HttpStatus.CREATED)) { return response.getHeaders().getLocation(); } else {/*from www .j ava 2s. c o m*/ throw new ResponseStatusException( "HttpStatus " + status.toString() + " response received. Load trigger creation failed."); } }
From source file:org.trustedanalytics.h2oscoringengine.publisher.steps.AppBitsUploadingStep.java
private HttpEntity<ByteArrayResource> prepareDataRequestPart(Path dataPath) throws IOException { ByteArrayResource data = prepareData(dataPath); HttpHeaders headers = HttpCommunication.zipHeaders(); return new HttpEntity<>(data, headers); }
From source file:org.projecthdata.weight.service.SyncService.java
@Override protected void onHandleIntent(Intent intent) { Connection<HData> connection = connectionRepository.getPrimaryConnection(HData.class); this.prefs.edit().putString(Constants.PREF_SYNC_STATE, SyncState.WORKING.toString()).commit(); //get all readings that are not synced try {//from www . ja v a 2s .co m Dao<WeightReading, Integer> dao = ormManager.getDatabaseHelper().getWeightDao(); //TODO: query the database instead of iterating over the whole table String url = this.prefs.getString(Constants.PREF_EHR_URL, ""); Uri uri = Uri.parse(url); uri = uri.buildUpon().appendPath("vitalsigns").appendPath("bodyweight").build(); RestTemplate template = connection.getApi().getRootOperations().getRestTemplate(); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_XML); for (WeightReading reading : dao) { if (!reading.isSynched()) { Result result = new Result(); //date and time result.setResultDateTime(new DateTime(reading.getDateTime().getTime()).toString(dateFormatter)); //narrative result.setNarrative(NARRATIVE); //result id result.setResultId(UUID.randomUUID().toString()); //result type code result.getResultType().setCode(CODE); //result type code system result.getResultType().setCodeSystem(CODE_SYSTEM); //status code result.setResultStatusCode(RESULT_STATUS_CODE); //value result.setResultValue(reading.getResultValue().toString()); //value unit result.setResultValueUnit(UNITS); try { HttpEntity<Result> requestEntity = new HttpEntity<Result>(result, requestHeaders); template.exchange(uri.toString(), HttpMethod.POST, requestEntity, String.class); } catch (RestClientException e) { // TODO Auto-generated catch block e.printStackTrace(); } reading.setSynched(true); dao.update(reading); } } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } this.prefs.edit().putString(Constants.PREF_SYNC_STATE, SyncState.READY.toString()).commit(); }
From source file:com.art4ul.jcoon.context.RestClientContext.java
public HttpEntity createHttpEntity() { Object postData;/*from w w w . j a va2s. c o m*/ if (body != null) { postData = body; } else { postData = httpBodyParams; } return this.httpEntity = new HttpEntity(postData, getHttpHeaders()); }
From source file:com.embedler.moon.graphql.boot.sample.test.GenericTodoSchemaParserTest.java
@Test public void restUnsupportedOperationErrorTest() throws IOException { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON_UTF8); GraphQLServerRequest qlQuery = new GraphQLServerRequest("{viewer{ id }}"); HttpEntity<GraphQLServerRequest> httpEntity = new HttpEntity<>(qlQuery, headers); ResponseEntity<GraphQLServerResult> responseEntity = restTemplate.exchange( "http://localhost:" + port + "/graphql", HttpMethod.PUT, httpEntity, GraphQLServerResult.class); GraphQLServerResult result = responseEntity.getBody(); Assert.assertFalse(CollectionUtils.isEmpty(result.getErrors())); LOGGER.info(objectMapper.writeValueAsString(result)); }
From source file:gateway.controller.util.GatewayUtil.java
/** * Sends a Job Request to the Job Manager. This will generate a Job Id and return it once the Job Manager has * indexed the Job into its database./*from w w w . jav a 2 s .c o m*/ * * @param request * The Job Request * @return The Job Id */ public String sendJobRequest(PiazzaJobRequest request, String jobId) throws PiazzaJobException { try { // Generate a Job Id if (jobId == null) { jobId = getUuid(); } // Send the message to Job Manager HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<PiazzaJobRequest> entity = new HttpEntity<PiazzaJobRequest>(request, headers); ResponseEntity<PiazzaResponse> jobResponse = restTemplate.postForEntity( String.format("%s/%s?jobId=%s", JOBMANAGER_URL, "requestJob", jobId), entity, PiazzaResponse.class); // Check if the response was an error. if (jobResponse.getBody() instanceof ErrorResponse) { throw new PiazzaJobException(((ErrorResponse) jobResponse.getBody()).message); } // Return the Job Id from the response. return ((JobResponse) jobResponse.getBody()).data.getJobId(); } catch (Exception exception) { String error = String.format("Error with Job Manager when Requesting New Piazza Job: %s", exception.getMessage()); LOGGER.error(error, exception); throw new PiazzaJobException(error); } }
From source file:org.asqatasun.websnapshot.webapp.controller.IndexController.java
/** * * @param errorMessage// w ww. j a v a 2 s. c om * @param headers * @return an auto-generated image that handles the error message */ private HttpEntity<byte[]> createErrorMessage(String errorMessage, HttpHeaders headers, int width, int height) throws IOException { return new HttpEntity<byte[]>(ConvertImage.createThumbnailFromErrorMessage(errorMessage, width, height), headers); }
From source file:org.cloudfoundry.identity.uaa.integration.PasswordChangeEndpointIntegrationTests.java
@Test @OAuth2ContextConfiguration(OAuth2ContextConfiguration.ClientCredentials.class) public void testChangePasswordSucceeds() throws Exception { PasswordChangeRequest change = new PasswordChangeRequest(); change.setPassword("newpassword"); HttpHeaders headers = new HttpHeaders(); ResponseEntity<Void> result = client.exchange(serverRunning.getUrl(userEndpoint) + "/{id}/password", HttpMethod.PUT, new HttpEntity<PasswordChangeRequest>(change, headers), null, joe.getId()); assertEquals(HttpStatus.OK, result.getStatusCode()); }
From source file:org.nuvola.tvshowtime.ApplicationLauncher.java
private void requestAccessToken() { try {/*from w w w . java 2 s . c o m*/ HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<String> entity = new HttpEntity<>("client_id=" + TVST_CLIENT_ID, headers); ResponseEntity<AuthorizationCode> content = tvShowTimeTemplate.exchange(TVST_AUTHORIZE_URI, POST, entity, AuthorizationCode.class); AuthorizationCode authorizationCode = content.getBody(); if (authorizationCode.getResult().equals("OK")) { LOG.info("Linking with your TVShowTime account using the code " + authorizationCode.getDevice_code()); LOG.info("Please open the URL " + authorizationCode.getVerification_url() + " in your browser"); LOG.info("Connect with your TVShowTime account and type in the following code : "); LOG.info(authorizationCode.getUser_code()); LOG.info("Waiting for you to type in the code in TVShowTime :-D ..."); tokenTimer = new Timer(); tokenTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { loadAccessToken(authorizationCode.getDevice_code()); } }, 1000 * authorizationCode.getInterval(), 1000 * authorizationCode.getInterval()); } else { LOG.error("OAuth authentication TVShowTime failed."); System.exit(1); } } catch (Exception e) { LOG.error("OAuth authentication TVShowTime failed."); LOG.error(e.getMessage()); System.exit(1); } }
From source file:org.cloudfoundry.identity.uaa.integration.ClientAdminEndpointsIntegrationTests.java
@Test public void implicitAndAuthCodeGrantClient() throws Exception { BaseClientDetails client = new BaseClientDetails(new RandomValueStringGenerator().generate(), "", "foo,bar", "implicit,authorization_code", "uaa.none"); ResponseEntity<UaaException> result = serverRunning.getRestTemplate().exchange( serverRunning.getUrl("/oauth/clients"), HttpMethod.POST, new HttpEntity<BaseClientDetails>(client, headers), UaaException.class); assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode()); assertEquals("invalid_client", result.getBody().getErrorCode()); }