List of usage examples for org.springframework.http ResponseEntity toString
@Override
public String toString()
From source file:cn.org.once.cstack.utils.RestUtils.java
@SuppressWarnings("rawtypes") public static String sendPostCommand(String url, String volume) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); headers.add("Accept", "text/plain"); MultiValueMap<String, String> params = new LinkedMultiValueMap<String, String>(); params.add("Binds", volume); @SuppressWarnings("unchecked") HttpEntity request = new HttpEntity(params, headers); ResponseEntity<String> response = restTemplate.postForEntity(url, request, String.class); return response.toString(); }
From source file:demo.geocoders.MapquestGeocoder.java
@Override public LatLong geocode(String address) { Map<String, String> map = new HashMap<>(); map.put("key", this.key); map.put("location", address); ResponseEntity<JsonNode> responseEntity = this.restTemplate.getForEntity(this.urlPath, JsonNode.class, map); System.out.println(responseEntity.toString()); JsonNode jsonNode = responseEntity.getBody(); if (jsonNode.path("results").size() > 0) { JsonNode results = jsonNode.path("results").get(0); JsonNode locations = results.path("locations").get(0); JsonNode latLng = locations.path("latLng"); double lng = latLng.get("lng").doubleValue(), lat = latLng.get("lat").doubleValue(); return new LatLong(lat, lng); }/*from www.j ava 2 s. com*/ return null; }
From source file:org.nebula.service.exception.NebulaExceptionHandler.java
@ExceptionHandler({ IllegalArgumentException.class, GeneralSecurityException.class }) protected ResponseEntity<Object> badRequest(IllegalArgumentException ex, WebRequest request) { String bodyOfResponse = ex.getMessage(); ResponseEntity<Object> response = handleExceptionInternal(null, bodyOfResponse, new HttpHeaders(), HttpStatus.BAD_REQUEST, request); logger.error("Exception:" + response.toString(), ex); return response; }
From source file:org.opendatakit.api.odktables.OdkTablesTest.java
@Test public void contextLoads() { ResponseEntity<String> entity = this.restTemplate.getForEntity( "http://localhost:" + server.getEmbeddedServletContainer().getPort() + "/odktables", String.class); logger.info(entity.toString()); logger.info(entity.getBody());/*from ww w .j a va 2 s . c o m*/ assertThat(entity.getBody()).isEqualTo("[\"default\"]"); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); }
From source file:org.nebula.service.exception.NebulaExceptionHandler.java
@ExceptionHandler({ Exception.class }) protected ResponseEntity<Object> exceptions(Exception ex, WebRequest request) { String bodyOfResponse = "Internal Server Error"; ResponseEntity<Object> response = handleExceptionInternal(null, bodyOfResponse, new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request); logger.error("Exception:" + response.toString(), ex); return response; }
From source file:org.oauth2.SampleServletApplicationTests.java
@Test public void testHomeIsSecure() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity("http://localhost:8080/home.beannote", String.class); System.out.println(entity.getStatusCode()); System.out.println(entity.toString()); }
From source file:org.avidj.zuul.client.ZuulRestClient.java
@Override public boolean lock(String sessionId, List<String> path, LockType type, LockScope scope) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); HttpEntity<String> entity = new HttpEntity<String>("parameters", headers); Map<String, String> parameters = new HashMap<>(); parameters.put("id", sessionId); // set the session id UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(serviceUrl + lockPath(path)) .queryParam("t", type(type)).queryParam("s", scope(scope)); ResponseEntity<String> result = restTemplate.exchange(uriBuilder.build().encode().toUri(), HttpMethod.PUT, entity, String.class); LOG.info(result.toString()); HttpStatus code = result.getStatusCode(); return code.equals(HttpStatus.CREATED); }
From source file:org.glytoucan.admin.service.AuthService.java
/** * @param auth//from w w w. j a va2 s .c o m * @return * @throws UserException */ @Transactional public ResponseMessage authenticate(Authentication auth) { System.out.println("user:>" + auth.getId()); System.out.println("key:>" + auth.getApiKey()); // String id = auth.getId(); ResponseMessage rm = new ResponseMessage(); rm.setErrorCode(ErrorCode.AUTHENTICATION_SUCCESS.toString()); try { // if (StringUtils.contains(id, "@")) { // id = userProcedure.getIdByEmail(id); // } if (!userProcedure.checkApiKey(auth.getId(), auth.getApiKey())) { DefaultOAuth2AccessToken defToken = new DefaultOAuth2AccessToken(auth.getApiKey()); DefaultOAuth2ClientContext defaultContext = new DefaultOAuth2ClientContext(); defaultContext.setAccessToken(defToken); OAuth2RestOperations rest = new OAuth2RestTemplate(googleOAuth2Details(), defaultContext); UserInfo user = null; try { final ResponseEntity<UserInfo> userInfoResponseEntity = rest .getForEntity("https://www.googleapis.com/oauth2/v2/userinfo", UserInfo.class); logger.debug("userInfo:>" + userInfoResponseEntity.toString()); user = userInfoResponseEntity.getBody(); } catch (HttpClientErrorException e) { logger.debug("oauth failed:>" + e.getMessage()); rm.setErrorCode(ErrorCode.AUTHENTICATION_FAILURE.toString()); rm.setMessage("oauth failed:>" + e.getMessage()); return rm; } // String idFromEmail = userProcedure.getIdByEmail(user.getEmail()); if (!StringUtils.equals(user.getEmail(), auth.getId())) { rm.setErrorCode(ErrorCode.AUTHENTICATION_FAILURE.toString()); rm.setMessage("id do not equal:>" + user.getEmail() + "<> " + auth.getId()); return rm; } } else { return rm; } } catch (UserException e1) { rm.setErrorCode(ErrorCode.AUTHENTICATION_FAILURE.toString()); rm.setMessage("rdf checks failed:>" + e1.getMessage()); return rm; } return rm; }
From source file:org.kurento.repository.test.RangePutTests.java
protected void uploadFileWithSeqPUTs(RepositoryHttpRecorder recorder, File fileToUpload, RepositoryItem repositoryItem) throws Exception { recorder.setAutoTerminationTimeout(500000); String url = recorder.getURL(); DataInputStream is = null;/*from w w w .j a v a 2 s. c o m*/ try { is = new DataInputStream(new FileInputStream(fileToUpload)); int sentBytes = 0; byte[] info = new byte[40000]; int readBytes; int numRequest = 0; while ((readBytes = is.read(info)) != -1) { ResponseEntity<String> response = putContent(url, Arrays.copyOf(info, readBytes), sentBytes); sentBytes += readBytes; log.info(numRequest + ": " + response.toString()); assertEquals("Returned response: " + response.getBody(), HttpStatus.OK, response.getStatusCode()); if (numRequest == 3) { // Simulating retry response = putContent(url, Arrays.copyOf(info, readBytes), sentBytes - readBytes); log.info(numRequest + ": " + response.toString()); assertEquals("Returned response: " + response.getBody(), HttpStatus.OK, response.getStatusCode()); } else if (numRequest == 4) { // Simulating retry with new data byte[] newInfo = new byte[500]; int newReadBytes = is.read(newInfo); response = putContent(url, concat(Arrays.copyOf(info, readBytes), Arrays.copyOf(newInfo, newReadBytes)), sentBytes - readBytes); sentBytes += newReadBytes; log.info(numRequest + ": " + response.toString()); assertEquals("Returned response: " + response.getBody(), HttpStatus.OK, response.getStatusCode()); } else if (numRequest == 5) { // Simulating send ahead data response = putContent(url, Arrays.copyOf(info, readBytes), sentBytes + 75000); log.info(numRequest + ": " + response.toString()); assertEquals("Returned response: " + response.getBody(), HttpStatus.NOT_IMPLEMENTED, response.getStatusCode()); } numRequest++; } } finally { if (is != null) { try { is.close(); } catch (IOException e) { } } recorder.stop(); } }
From source file:org.cloudfoundry.community.servicebroker.vrealize.VraClient.java
public VrServiceInstance createInstance(CreateServiceInstanceRequest request, ServiceDefinition sd) { try {//from w w w .j ava 2s . c o m LOG.info("creating instance."); VrServiceInstance instance = new VrServiceInstance(request); String token = tokenService.getToken(); LOG.info("getting a template for the create request."); JsonElement template = getCreateRequestTemplate(token, sd); String serviceType = getServiceType(template); LOG.debug("template for create request: " + template.toString()); LOG.info("customizing the create template."); JsonObject edited = prepareCreateRequestTemplate(template, instance); LOG.debug("customed create template: " + edited.toString()); LOG.info("posting the create request."); ResponseEntity<JsonElement> response = postCreateRequest(token, edited, sd); LOG.debug("service request response: " + response.toString()); String location = getLocation(response); String requestId = getRequestId(response.getBody()); LOG.info("loading metadata onto instance from catalog item request response."); instance.getMetadata().put(VrServiceInstance.LOCATION, location); instance.getMetadata().put(VrServiceInstance.CREATE_REQUEST_ID, requestId); instance.setServiceType(serviceType); LastOperation lo = new LastOperation(OperationState.IN_PROGRESS, requestId, false); instance.withLastOperation(lo); return instance; } catch (Throwable t) { LOG.error("error processing create request.", t); throw new ServiceBrokerException("Unable to process create request.", t); } }