resttemplate

Spring RestTemplate - I/O error reading PNG header

耗尽温柔 提交于 2019-12-11 16:19:44
问题 I am making an API call to an external app (this app converts all images originally loaded into it to PNG). If the image was originally loaded into that app as a PNG then RestTemplate can get it fine. If it was originally loaded as something else then converted to PNG the below code throws an error when trying to get it using RestTemplate in Spring 4.1.1. The image displays fine on the external app. Caused by: javax.imageio.IIOException: I/O error reading PNG header! at com.sun.imageio

Get Request with raw JSON as a filter

眉间皱痕 提交于 2019-12-11 16:02:54
问题 I want to make a HTTP GET request to a not local elasticSearch and use this filter: { "query": { "bool": { "filter": [ { "range": { "timestamp": { "gte": "2019-08- 09T06:00:00","lt":"2019-08-09T08:00:00"}}} ] } } } but I don't know how to put this filter in the restTemplate.getForEntity request. The request in Kotlin is something like this: val forEntity_Flow= restTemplate.getForEntity("https://X.X.X.X:6200/bla_bal-${da}/_search/? size=50&pretty=1", ResultsBla::class.java) How can I put that

response body from restTemplate is getting truncated when downloading a file

£可爱£侵袭症+ 提交于 2019-12-11 15:56:36
问题 I am using spring RestTemplate to download a file. The file size is small. I want to get base64 encoded String. but I see the base64 encoded string is truncated from what it is supposed to be. Here is my code RestTemplate restTemplate = new RestTemplate(); restTemplate.getMessageConverters().add( new ByteArrayHttpMessageConverter()); StreamResourceReader reader = new StreamResourceReader(); restTemplate.execute(uri, HttpMethod.POST, null, new StreamResponseExtractor(reader)); return reader

RestTemplate does send null values in object

好久不见. 提交于 2019-12-11 15:53:19
问题 I have written a very simple EmailService using Spring boot. A controller received an EmailRequest and sends the Mail: @RestController @Slf4j public class EmailController { private final EmailService emailService; public EmailController(EmailService emailService) { this.emailService = emailService; } @PostMapping public ResponseEntity sendEmail(EmailRequest request) { try { emailService.sendEmail(request); } catch (Exception e) { log.error("Error while sending email", e); return

Autmapping of xml list of string response by rest service to respective java object using RestTemplate.postForObject(…)

假如想象 提交于 2019-12-11 15:28:01
问题 I have below XML which I am getting from third party(rest service) <response> <error>Document Too Small</error> <error>Barcode Not Detected</error> <error>Face Image Not Detected</error> </response> I am calling third party service with below code which is trying to convert the xml to respective java object - restTemplate.postForObject("/test", new HttpEntity<>(request, headers), Eror.class); We have added the MappingJackson2XmlHttpMessageConverter- MappingJackson2XmlHttpMessageConverter

REST Android Client using Spring and OAuth2 Error DexArchiveMergerException: Unable to merge dex

邮差的信 提交于 2019-12-11 14:48:32
问题 I have a server running and I want to connect an android client to the server with spring's oauth2. I use Android Studio. My problem is related to the gradle configurations, which I don't know how it should be. Problem : When I run the app, I get this error: Error:Execution failed for task':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.> com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex I have seen many other questions with the same problem, I tried the

Rest Template Spring Android PUT with Raw content type

一世执手 提交于 2019-12-11 11:36:33
问题 I am trying to fix an issue with my RestTemplate PUT request. Basically, the server expects data(an object) to be put in "Raw" content-type but as xml stream. I tried many combinations(of converter, content-type etc..) but nothing helps. I either end up in getting exception as " org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type com.test.myObject" Or: "The server encountered an error processing the request. The

Unable to consume JSON array using Spring RestTemplate

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 08:43:38
问题 Am trying to populate a DTO from a published RESTful URL (simple HTTP GET) by using Spring's RestTemplate HTTP Client. This is the content of the published JSON that I am trying to consume: [{"startDate":"2017-01-29","cost":"$50000.00","id":1112,"name":"Porsche"},{"startDate":"2017-03-06","cost":"$27000.00","id":38626,"name":"BMW"}] My DTO: class DTO { private String startDate; private String cost; private String name; // Getters and Setters } My Response Object: public class Response {

Spring's RestTemplate: complex object to query params

末鹿安然 提交于 2019-12-11 07:55:02
问题 I have a complex object like this: public class ComplexObject { private String a; private String b; ... private String z; //getters and setters } I want to call a web service that receives all the complex object fields: http://localhost:8080/api/some_service?a=something&b=something&...&z=something Is there any way to pass a ComplexObject to RestTemplate and have the work done automatically or I have to do the manual mapping by myself? Thanks! 回答1: YES! there is a way to pass complete complex

Spring RestTemplate exchange DELETE with body jdk 1.8

旧巷老猫 提交于 2019-12-11 07:34:07
问题 I'm trying to do a HTTP DELETE request with body with Spring RestTemplate via exchange method but I always get a 400 Bad Request like this question. With JavaScript and other tools it is posible to make this API call with DELETE. I know java <1.8 doesent support DELETE with body, but with 1.8 it should be able: see here. I'm using spring-web-4.2.6.RELEASE with jdk 1.8 so I think there must be a way. My code: public DealResponse closePosition(DealCloseRequest dealCloseRequest) { try {