resttemplate

RestTemplate - Handling response headers/body in Exceptions (RestClientException, HttpStatusCodeException)

瘦欲@ 提交于 2019-12-03 09:10:57
问题 In my restful webservice, in case of bad request (5xx) or 4xx respose codes, I write a custom header "x-app-err-id" to the response. On the client side, I use exchange method of RestTemplate to make a RestFul web service call. Everything is fine when the response code is 2xx. ResponseEntity<Component> response = restTemplate.exchange(webSvcURL, HttpMethod.POST, requestEntity, Component.class); But if there is an exception(HttpStatusCodeException) because of it being a bad request(5xx) or 4xx,

Spring REST - Can a RestTemplate consume multipart/mixed?

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I want to write a REST service which does responed with a zipFile and some json data, everything in one multipart/mixed request. The server part works fine and i am testing it with the REST Client from firefox. My Server sends a multipart like this --k-dXaXvCFusLVXUsg-ryiHMmkdttadgcBqi4XH Content-Disposition: form-data; name="form" Content-type: application/json {"projectName":"test","signal":"true"} --k-dXaXvCFusLVXUsg-ryiHMmkdttadgcBqi4XH Content-Disposition: form-data; name="file2"; filename="file2.txt" Content-type: application/octet

Resttemplate form/multipart: image + JSON in POST

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to call a rest ws (using resttemplate), that accepts an image and some JSON. However, I don't seem to be able to get it running. The relevant code is as follows: HttpHeaders header = new HttpHeaders(); header.setContentType(MediaType.MULTIPART_FORM_DATA); MultiValueMap<String, Object> map = new LinkedMultiValueMap<>(); ByteArrayResource bytes = new ByteArrayResource(pictureData) { @Override public String getFilename() { return pictureName; } }; map.add("x", x); map.add("file", bytes); HttpEntity<MultiValueMap<String, Object>>

Spring RestTemplate follow redirect with cookie

匿名 (未验证) 提交于 2019-12-03 08:46:08
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Recently I ran into a problem where I needed to do a GET request to a remote service (Using a simple servlet i presume), and RestTemplate returned Too many redirects! . After some investigation, it seems like the first request made to the specified remote service, is actually just a 302-redirect (to itself) with some Set-Cookie headers. If I were using a "normal" browser, it would acknowledge the header, set the cookies correctly, and follow the redirect where it should meet a normal 200 response. What I've found is that RestTemplate doesn't

关于spring resttemplate超时设置

让人想犯罪 __ 提交于 2019-12-03 08:34:49
Spring org.springframework.web.client.RestTemplate 使用 org.springframework.http.client.SimpleClientHttpRequestFactory建立 java.net.HttpURLConnection 后者采用 HttpURLConnection 的默认超时配置 HttpURLConnection 超时属性 ConnectTimeout(ms) a specified timeout value, in milliseconds, to be used when opening a communications link to the resource referenced by this URLConnection. If the timeout expires before the connection can be established, a java.net.SocketTimeoutException is raised. A timeout of zero is interpreted as an infinite timeout. ReadTimeout(ms) a specified timeout, in milliseconds. A non-zero value

org.glassfish.jersey.server.model.ModelValidationException: Validation of the application resource model has failed during application initialization

匿名 (未验证) 提交于 2019-12-03 08:30:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm developing spring boot microservices example from the link: https://dzone.com/articles/spring-boot-creating . In this project I simply updated the parent dependency to its latest version and other code files are unchanged. I faced the following error when I click http://localhost:8080/order?idCustomer=2&idProduct=3&amount=4 2016-09-09 11:46:20.888 ERROR 14152 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : StandardWrapper.Throwable org.glassfish.jersey.server.model.ModelValidationException: Validation of the application

How to call HTTPS restful web services using Spring RestTemplate

不羁的心 提交于 2019-12-03 08:09:01
问题 I am using Tomcat7, Spring framework for ReST web services. I am trying to call an https web service using Spring RestTemplate . I am getting the following error: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target I check online at

POST request via RestTemplate in JSON

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I didn't find any example how to solve my problem, so I want to ask you for help. I can't simply send POST request using RestTemplate object in JSON Every time I get org.springframework.web.client.HttpClientErrorException: 415 Unsupported Media Type I use RestTemplate in this way: ... restTemplate = new RestTemplate (); List > list = new ArrayList >(); list . add ( new MappingJacksonHttpMessageConverter ()); restTemplate . setMessageConverters ( list ); ... Payment payment = new Payment ( "Aa4bhs" ); Payment res = restTemplate .

Spring RestTemplate - Need to release connection?

夙愿已清 提交于 2019-12-03 07:48:05
This is my Configuration for Rest Template, @Bean @Qualifier("myRestService") public RestTemplate createRestTemplate(@Value("${connection.timeout}") String maxConn) { PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); connectionManager.setMaxTotal(maxTotalConn); connectionManager.setDefaultMaxPerRoute(maxPerChannel); RequestConfig config = RequestConfig.custom().setConnectTimeout(100000).build(); CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionManager(connectionManager) .setDefaultRequestConfig(config).build();

spring cloud常用注解及关键类

拟墨画扇 提交于 2019-12-03 07:39:53
1.@SpringCloudApplication @SpringCloudApplication @EnableFeignClients @MapperScan("com.xx.common.domain.mapper") @ComponentScan({"com.xx.common", "com.xx.api"}) public class ApiApp { public static void main(String[] args) { SpringApplication.run(ApiApp.class, args); } } @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @SpringBootApplication @EnableDiscoveryClient @EnableCircuitBreaker public @interface SpringCloudApplication { } 2.@EnableFeignClients 通过EnableFeignClients调用其他服务的api // 步骤1 @SpringCloudApplication @EnableFeignClients @MapperScan("com.xx