Guest User

Untitled

a guest
Feb 3rd, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. DZIAŁA DLA SZTYWNEGO URL
  2.  
  3. String url3 = "https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&maxradiuskm=2000.0&latitude=30.21&longitude=12.9";
  4.  
  5.   @GetMapping("/4")
  6.     public List<EarhquakeDTO> getCostam2() {
  7. //        RestTemplate rest = new RestTemplate();
  8.  
  9.         ResponseEntity<DataModel> responseEntity = restTemplate.getForEntity(url4, DataModel.class);
  10.         MediaType contentType = responseEntity.getHeaders().getContentType();
  11.         HttpStatus statusCode = responseEntity.getStatusCode();
  12.         String listOfResults = responseEntity
  13.                 .getBody().getFeaturez().toString();
  14.  
  15.         var tempres2 = responseEntity.getBody().getFeaturez()
  16.                 .stream()
  17.                 .map(o -> new EarhquakeDTO(
  18.                         o.getProperties(),
  19.                         o.getProperties().getMag(),
  20.                         o.getGeometry().getCoordinates().get(0),
  21.                         o.getGeometry().getCoordinates().get(1),
  22.                         o.getId()))
  23.                 .sorted()
  24.                 .collect(toList());
  25.  
  26.         System.out.println(findAll(responseEntity));
  27.         return tempres2;
  28.  
  29.  
  30.     }
  31.  
  32.  
  33.  
  34. --
  35.  
  36. NIE DZIAŁA KIEDY WYSYŁAM ZAPYTANIE http://localhost:8080/test/5?latitude=30.21&longitude=12.9
  37.  
  38. @GetMapping("/5")
  39.     public List<EarhquakeDTO> getCostam3(@RequestParam Map<String, String> allParams) {
  40.         RestTemplate rest = new RestTemplate();
  41.  
  42.         final String urlX = "https://earthquake.usgs.gov/fdsnws/event/1/query?";
  43.         allParams.put("format", "geojson");
  44.         allParams.put("maxradiuskm", "2000.0");
  45.         logger.info("request received in /api1" + allParams.entrySet());
  46.  
  47.  
  48.         ResponseEntity<DataModel> responseEntity = restTemplate.getForEntity(urlX, DataModel.class,allParams);
  49.         MediaType contentType = responseEntity.getHeaders().getContentType();
  50.         HttpStatus statusCode = responseEntity.getStatusCode();
  51.         String listOfResults = responseEntity
  52.                 .getBody().getFeaturez().toString();
  53.  
  54.         var tempres2 = responseEntity.getBody().getFeaturez()
  55.                 .stream()
  56.                 .map(o -> new EarhquakeDTO(
  57.                         o.getProperties(),
  58.                         o.getProperties().getMag(),
  59.                         o.getGeometry().getCoordinates().get(0),
  60.                         o.getGeometry().getCoordinates().get(1),
  61.                         o.getId()))
  62.                 .sorted()
  63.                 .collect(toList());
  64.  
  65.         System.out.println(findAll(responseEntity));
  66.         return tempres2;
  67.  
  68.  
  69.     }
  70.  
  71. Wywala błąd
  72.  
  73. org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class XXX.jsonObject.DataModel] and content type [application/xml;charset=utf-8]
Advertisement
Add Comment
Please, Sign In to add comment