List of usage examples for org.springframework.http HttpEntity HttpEntity
public HttpEntity(@Nullable T body, @Nullable MultiValueMap<String, String> headers)
From source file:org.n52.restfulwpsproxy.wps.GetStatusClient.java
public ResultDocument getResults(String processId, String jobId) { HttpEntity<?> requestEntity = new HttpEntity<Object>(null, headers); ResponseEntity<ResultDocument> resultDocument = restTemplate.exchange( new RequestUrlBuilder(GET_RESULT).jobID(jobId).build(), HttpMethod.GET, requestEntity, ResultDocument.class); return resultDocument.getBody(); }
From source file:cz.muni.fi.mushroomhunter.restclient.LocationCreateSwingWorker.java
@Override protected Void doInBackground() throws Exception { LocationDto locationDto = new LocationDto(); locationDto.setName(restClient.getTfLocationName().getText()); locationDto.setDescription(restClient.getTfLocationDescription().getText()); locationDto.setNearCity(restClient.getTfLocationNearCity().getText()); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); List<MediaType> mediaTypeList = new ArrayList<>(); mediaTypeList.add(MediaType.ALL);/* ww w. ja v a 2 s .c om*/ headers.setAccept(mediaTypeList); ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); String json = ow.writeValueAsString(locationDto); 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); headers.add("Authorization", "Basic " + base64Creds); HttpEntity request = new HttpEntity(json, headers); Long[] result = restTemplate.postForObject(RestClient.SERVER_URL + "pa165/rest/location", request, Long[].class); RestClient.getLocationIDs().add(result[0]); return null; }
From source file:com.cemeterylistingswebtest.test.rest.LoginControllerTest.java
@Test(enabled = false) public void testCreate() { Long subID = new Long(17); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(1).build(); Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com") .setFirstName("Manfred").setSurname("Osulivan").setPwd("applesandsuch").setUsername("ManiFredOssy") .setSubscriptionDate(javaSqlDate).setUserRoleID(user).build(); HttpEntity<Subscriber> requestEntity = new HttpEntity<>(newSub, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/Subscriber/create", HttpMethod.POST, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); id = newSub.getSubscriberID();//from w w w.ja v a 2 s. com }
From source file:com.marklogic.mgmt.admin.AdminManager.java
public void init(String licenseKey, String licensee) { final URI uri = adminConfig.buildUri("/admin/v1/init"); String json = null;/*from ww w . jav a2 s. com*/ if (licenseKey != null && licensee != null) { json = format("{\"license-key\":\"%s\", \"licensee\":\"%s\"}", licenseKey, licensee); } else { json = "{}"; } final String payload = json; logger.info("Initializing MarkLogic at: " + uri); invokeActionRequiringRestart(new ActionRequiringRestart() { @Override public boolean execute() { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(payload, headers); try { ResponseEntity<String> response = restTemplate.exchange(uri, HttpMethod.POST, entity, String.class); logger.info("Initialization response: " + response); // According to http://docs.marklogic.com/REST/POST/admin/v1/init, a 202 is sent back in the event a // restart is needed. A 400 or 401 will be thrown as an error by RestTemplate. return HttpStatus.ACCEPTED.equals(response.getStatusCode()); } catch (HttpClientErrorException hcee) { String body = hcee.getResponseBodyAsString(); if (logger.isTraceEnabled()) { logger.trace("Response body: " + body); } if (body != null && body.contains("MANAGE-ALREADYINIT")) { logger.info("MarkLogic has already been initialized"); return false; } else { logger.error("Caught error, response body: " + body); throw hcee; } } } }); }
From source file:com.cemeterylistingswebtest.test.rest.DisplayDeceasedControllerTest.java
@Test(enabled = false) public void testCreate() { System.out.println("PublishListingService Testing"); Long subID = new Long(17); List<PersonOtherNames> names = null; PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Hendrika") .setSurname("Fourie").setMaidenName("Gerber").setGender("Female").setDateOfBirth("08/06/1969") .setDateOfDeath("14/02/2005").setGraveInscription("Hippiest person eva").setGraveNumber("2456") .setImageOfBurialSite("/images/001.jpg").setLastKnownContactName("Berry") .setLastKnownContactNumber("0725576482").setSubscriberSubmitID(subID).setNames(names).build(); HttpEntity<PublishedDeceasedListing> requestEntity = new HttpEntity<>(newListing, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/DeceasedListing/create", HttpMethod.POST, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); id = newListing.getPublishedListingID(); }
From source file:com.cemeterylistingswebtest.test.rest.RegistrationControllerTest.java
@Test(enabled = false) public void testCreate() { System.out.println("Registration Testing"); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); UserRole user = new UserRole.Builder().setLevel(1).build(); Subscriber newSub = new Subscriber.Builder().setEmail("zaakir@gmail.com").setFirstName("zaakir") .setSurname("arendse").setPwd("123").setUsername("zak").setSubscriptionDate(javaSqlDate) .setUserRoleID(user).build(); HttpEntity<Subscriber> requestEntity = new HttpEntity<>(newSub, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/Registration/create", HttpMethod.POST, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); id = newSub.getSubscriberID();/* w ww.j ava 2 s . c o m*/ }
From source file:jetbrains.buildServer.vsoRooms.rest.impl.VSOTeamRoomsAPIConnectionImpl.java
@Nullable public TeamRoomMessage sendMessageToRoom(@NotNull String account, @NotNull Long roomId, @NotNull String messageContent) { final HttpHeaders requestHeaders = getRequestHeaders(); requestHeaders.setContentType(MediaType.APPLICATION_JSON); final HttpEntity<String> request = new HttpEntity<String>(getMessageBody(messageContent), requestHeaders); final ResponseEntity<TeamRoomMessage> responseEntity = myRestTemplate .postForEntity(getRoomMessagesUrl(account, roomId), request, TeamRoomMessage.class); return responseEntity.getBody(); }
From source file:org.n52.restfulwpsproxy.wps.ExecuteClient.java
public ResultDocument syncExecute(String processId, ExecuteDocument executeDocument) throws URISyntaxException { HttpEntity<ExecuteDocument> requestEntity = new HttpEntity<ExecuteDocument>(executeDocument, headers); return restTemplate.exchange(baseUrl, HttpMethod.POST, requestEntity, ResultDocument.class).getBody(); }
From source file:org.awesomeagile.webapp.security.google.GoogleConfigurableOAuth2Template.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) protected AccessGrant postForAccessGrant(String accessTokenUrl, MultiValueMap<String, String> parameters) { HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>( parameters, headers);//www. ja va 2s . co m ResponseEntity<Map> responseEntity = getRestTemplate().exchange(accessTokenUrl, HttpMethod.POST, requestEntity, Map.class); Map<String, Object> responseMap = responseEntity.getBody(); return extractAccessGrant(responseMap); }
From source file:com.cemeterylistingswebtest.test.rest.SearchSurnameControllerTest.java
@Test(enabled = false) public void testCreate() { System.out.println("PublishedDeceasedListing Testing"); Long subID = new Long(17); List<PersonOtherNames> names = null; PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Hendrika") .setSurname("Fourie").setMaidenName("Gerber").setGender("Female").setDateOfBirth("08/06/1969") .setDateOfDeath("14/02/2005").setGraveInscription("Hippiest person eva").setGraveNumber("2456") .setImageOfBurialSite("/images/001.jpg").setLastKnownContactName("Berry") .setLastKnownContactNumber("0725576482").setSubscriberSubmitID(subID).setNames(names).build(); HttpEntity<PublishedDeceasedListing> requestEntity = new HttpEntity<>(newListing, getContentType()); // Make the HTTP POST request, marshaling the request to JSON, and the response to a String ResponseEntity<String> responseEntity = restTemplate.exchange(URL + "api/SearchSurname/create", HttpMethod.POST, requestEntity, String.class); System.out.println(" THE RESPONSE BODY " + responseEntity.getBody()); System.out.println(" THE RESPONSE STATUS CODE " + responseEntity.getStatusCode()); System.out.println(" THE RESPONSE IS HEADERS " + responseEntity.getHeaders()); Assert.assertEquals(responseEntity.getStatusCode(), HttpStatus.OK); id = newListing.getPublishedListingID(); }