resttemplate

Why do I always get 403 when fetching data with RestTemplate? [duplicate]

落爺英雄遲暮 提交于 2019-12-03 22:19:37
This question already has answers here : Closed last year . 403 Forbidden with Java but not web browser? (4 answers) I'm trying to fetch data but always getting 403(Forbidden) with RestTemplate . But when I try org.apache.http.client.HttpClient instead, everything is OK. I'm also able to get data with Postman on my machine. The code is quite simple but I don't know what's wrong. public Object get() { try { RestTemplate restTemplate = new RestTemplate(); Object result = restTemplate.getForObject("https://api.hearthstonejson.com/v1/19776/enUS/cards.json", Object.class); return result; } catch

RestTemplate: exchange() vs postForEntity() vs execute()

匆匆过客 提交于 2019-12-03 17:50:17
问题 I am working on Rest API using Spring boot and I had to access an application's endpoint. I used RestTemplate for it. I was able to do it using 2 methods, postForEntity() : responseEntity = restTemplate.postForEntity(uri, httpEntity, ResponseClass.class); exchange() : responseEntity = restTemplate.exchange(uri, HttpMethod.POST, httpEntity, ResponseClass.class); I would like to know the usage and differences of these two methods. I also see another method execute() . Please shed some light on

Using Proxy with HttpComponentsClientHttpRequestFactory and RestTemplate

非 Y 不嫁゛ 提交于 2019-12-03 16:52:19
问题 Can some one guide me how can I configure HttpComponentsClientHttpRequestFactory to use proxy server. All examples I have seen are using SimpleClientHttpRequestFactory . 回答1: If you do not mind using Apache Http Client it is not very complicated and there are 2 possibilities: If single proxy for all targets is enough for you: HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() .setProxy(new HttpHost("myproxy

Spring RestTemplate Connection Timeout is not working

泪湿孤枕 提交于 2019-12-03 13:21:06
问题 I am trying to configure time out when external web service call. I am calling external web service by Spring Rest Template in my service. For connection timeout testing purpose, the external web service is stopped and application server is down. I have configured 10 seconds for timeout, but unfortunately i get connection refused exception after a second. try { final RestTemplate restTemplate = new RestTemplate(); ((org.springframework.http.client.SimpleClientHttpRequestFactory) restTemplate

How to use Spring RestTemplate and JAXB marshalling on a URL that returns multiple types of XML

不想你离开。 提交于 2019-12-03 12:43:13
问题 I need to make a Rest POST to a service that returns either a <job/> or an <exception/> and always status code 200 . (lame 3rd party product!). I have code like: Job job = getRestTemplate().postForObject(url, postData, Job.class); And my applicationContext.xml looks like: <bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> <constructor-arg ref="httpClientFactory"/> <property name="messageConverters"> <list> <bean class="org.springframework.http.converter.xml

CustomDeserializer has no default (no arg) constructor

吃可爱长大的小学妹 提交于 2019-12-03 12:12:34
I am consuming a REST Api with RestTemplate. The response I'm getting from the API has lots of nested objects. Here's a little snippet as an example: "formularios": [ { "form_data_id": "123006", "form_data": { "form_data_id": "123006", "form_id": "111", "efs": { "1": {}, "2": "{\"t\":\"c\",\"st\":\"m\",\"v\":[{\"id\":\"3675\",\"l\":\"a) Just an example\",\"v\":\"1\"},{\"id\":\"3676\",\"l\":\"b) Another example.\",\"v\":\"2\"}]}" } } The problem I'm having is that most of the times the "1" actually has content, just like "2", and the jackson just parses it as a String on the object "efs". But

How to prevent auto start of tomcat/jetty in Spring Boot when I only want to use RestTemplate

孤者浪人 提交于 2019-12-03 11:04:08
问题 I want to use RestTemplate/TestRestTemplate by including the artifact in a SpringBoot application <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> But this automatically starts Tomcat or Jetty. Is there a way to turn it off, or by not including the above artifact. TestRestTemplate is in the boot artifact, but not the base RestTemplate. 回答1: Spring Boot is not going to start a web container if it's not present. spring-web does not provide

What's the proper way to escape URL variables with Spring's RestTemplate when calling a Spring RestController?

☆樱花仙子☆ 提交于 2019-12-03 11:00:53
问题 When calling RestTemplate.exchange to do a get request, such as: String foo = "fo+o"; String bar = "ba r"; restTemplate.exchange("http://example.com/?foo={foo}&bar={bar}", HttpMethod.GET, null, foo, bar) what's the proper to have the URL variables correctly escaped for the get request? Specifically, how do I get pluses ( + ) correctly escaped because Spring is interpreting as spaces, so, I need to encode them. I tried using UriComponentsBuilder like this: String foo = "fo+o"; String bar = "ba

Why do I get 403 forbidden error while posting a json to elasticsearch endpoint on AWS?

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am posting a json to AWS elasticsearch,using a java lambda function. public Object handleRequest(DynamodbEvent dynamodbEvent, Context context) { //code to general the json document AmazonDynamoDBClient amazonDynamoDBClient = new AmazonDynamoDBClient(); List<DynamodbEvent.DynamodbStreamRecord> dynamodbStreamRecordlist = dynamodbEvent.getRecords(); if (!dynamodbStreamRecordlist.isEmpty()) { DynamodbEvent.DynamodbStreamRecord record = dynamodbStreamRecordlist.get(0); if(record.getEventSource().equalsIgnoreCase("aws:dynamodb")) tableName =

Timeout configuration for spring webservices with RestTemplate

﹥>﹥吖頭↗ 提交于 2019-12-03 09:13:08
I would like to configure a timeout on the client side for spring webservices using RestTemplate. I tried the following configuration : <bean id="restTemplate" class="org.springframework.web.client.RestTemplate"> <constructor-arg> <bean class="org.springframework.http.client.CommonsClientHttpRequestFactory"> <property name="readTimeout" value="10000" /> </bean> </constructor-arg> <property name="messageConverters"> <list> <ref bean="stringHttpMessageConverter" /> <ref bean="marshallingHttpMessageConverter" /> </list> </property> </bean> But I have a NoClassDefFoundError when I start my tomcat