resttemplate

SpringBoot TestRestTemplate and LocalDateTime not working

六眼飞鱼酱① 提交于 2019-12-25 03:12:25
问题 I am using LocalDateTime in my model, after including LocalDateTimeDeserializer, converted the bean field to @NotNull @Column(name = "created") @JsonDeserialize(using = LocalDateTimeDeserializer.class) private LocalDateTime created; and included the spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false property in the SpringBoot's application.properties file, the application is finally able to deserialize the JSON and show properly like, "created": "2018-04-22T21:21:53.025", But,

Fail filling object from JSON with RestTemplate

房东的猫 提交于 2019-12-25 02:32:03
问题 I work with websecrpits and I want to create an object from my JSON. I use RestTemplate to do that : MetaData entity = restTemplate.postForObject(url + "?alf_ticket={ticket}", requestEntity, MetaData.class, _ticket); but the problem is that I got this error : Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: No suitable constructor found for type [simple type, class custom.alfresco.logic.connect.models.MetaData$Item]: can not

Fail filling object from JSON with RestTemplate

核能气质少年 提交于 2019-12-25 02:31:33
问题 I work with websecrpits and I want to create an object from my JSON. I use RestTemplate to do that : MetaData entity = restTemplate.postForObject(url + "?alf_ticket={ticket}", requestEntity, MetaData.class, _ticket); but the problem is that I got this error : Exception in thread "main" org.springframework.http.converter.HttpMessageNotReadableException: Could not read JSON: No suitable constructor found for type [simple type, class custom.alfresco.logic.connect.models.MetaData$Item]: can not

Spring Boot实现系统间接口调用

孤街醉人 提交于 2019-12-24 22:12:31
Spring Boot实现跨系统接口调用 一、概述 在开发过程中经常会需要和其他系统进行对接,或者调用一些外部的第三方接口来获取所需要的数据信息,这个时候我们就需要跨系统去调用接口,本文基于spring boot项目整理三种方案。 1、使用httpClient请求; 2、使用RestTemplate方法; 3、使用Fegin进行消费; 1、使用httpClient请求 需要先在maven的pom.xml中添加httpClient依赖 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> </dependency> 代码如下: package com.henry.transport; import org.apache.http.HttpEntity; import org.apache.http.HttpStatus; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.config.RequestConfig; import org.apache.http

How to await when all http requests are finished using spring webClient?

拥有回忆 提交于 2019-12-24 19:14:01
问题 I want to execute http request for each queue element. These requests shoule be called in parallel. Also I need to await the termination of all requests. I developed the following code: List<Mono<MyResponseDTO>> monoList = queue.stream() .map(jobStatusBunch -> webClient .post() .uri("localhost:8080/api/some/url") .bodyValue(convertToRequestDto(someBean)) .retrieve() .toEntity(String.class) .filter(HttpEntity::hasBody) .map(stringResponseEntity -> { try { return objectMapper.readValue

Call REST webservice using Spring Integration and Oauth

北城以北 提交于 2019-12-24 18:43:57
问题 My goal is to perform a call to a REST webservice using an outbound gateway, this webservice needs a token provided by another web service. I've tried using Spring oauth without any luck since I am not sure how to integrate both frameworks. <int:chain input-channel="requestChannel"> <int-http:outbound-gateway url="https://webservice.url/..." http-method="GET" expected-response-type="java.lang.String" rest-template="restTemplate" /> ... </int:chain> <oauth:resource id="oauth1" client-id="admin

RestTemplate POSTing entity with associations to Spring Data REST server

拜拜、爱过 提交于 2019-12-24 16:39:50
问题 The problem I have three entities (taken from the Spring Data REST Exporter Example): Person, Address and Profile. A Person can have addresses and profiles. @Entity public class Person { @Id @GeneratedValue private Long id; private String name; @Version private Long version; @OneToMany private List<Address> addresses; @OneToMany private Map<String, Profile> profiles; // getters and setters } In the client side I use Spring's RestTemplate. I added the Jackson2HalModule to the ObjectMapper used

Parse JSON array with resttemplate

风格不统一 提交于 2019-12-24 15:31:48
问题 I think I have a very common problem but I cant find a solution :( I am using spring with restTemplate to recover a JSON object like this: ResponseEntity<Download_urls> result= restTemplate.exchange(URL, HttpMethod.GET, entity, Download_urls.class); Where "Download_urls " class have a JSON array inside: import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class Download_urls { private Video[] video; } And Video.class

Spring RestTemplate receives “401 Unauthorized”

二次信任 提交于 2019-12-24 12:30:20
问题 I am using the following to retrieve JSON via RestTemplate in Spring 4: protected DocInfoResponse retrieveData(String urlWithAuth) { RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Basic " + auth.getSig()); HttpEntity<String> request = new HttpEntity<String>(headers); ResponseEntity<DocInfoResponse> response = restTemplate.exchange(urlWithAuth, HttpMethod.GET, request, DocInfoResponse.class); return response.getBody(); } I

Reading JSON map structure via spring boot

瘦欲@ 提交于 2019-12-24 12:18:58
问题 If I have the following JSON structure returned by my REST service: { "foo" : { "id" : "baz" } "qux" : { "id" : "toto" } } To me it looks like a map structure. I am not sure how I can read this using spring boot (via Jackson). I have defined my JSON bind class like so: public class Foos { private Map<String, Foo> fooInstances; private void setFooInstances(Map<String, Foo> fooInstances) { this.fooInstances = fooInstances; } private Map<String, Foo> getFooInstances() { return fooInstances; } }