Tag: rest client

Spring Rest客户端exception处理

我使用spring RestTemplate来使用rest服务(在spring rest中暴露)。 我能够消耗成功的场景。 但对于负面情况,服务会返回错误消息和错误代码。 我需要在我的网页中显示这些错误消息。 例如,对于无效请求,服务会使用适当的消息抛出HttpStatus.BAD_REQUEST 。 如果我把try-catch块转到catch块,我就无法得到ResponseEntity对象。 try { ResponseEntity<ResponseWrapper> responseEntity = restTemplate.exchange(requestUrl, HttpMethod.POST, entity, new ParameterizedTypeReference<ResponseWrapper>() { }); responseEntity.getStatusCode(); } catch (Exception e) { //TODO How to get response here, so that i can get error messages? e.printStackTrace(); } 如何获取ResponseWrapperexception情况? 我从这里读到了CustomRestTemplate和ResponseExtractor ,但无法确定哪一个最适合我的情况。

使用Elastic Search 5.5.0获得最佳性能时如何正确关闭原始RestClient?

我使用Spring Boot 1.5.4.RELEASE Microservice使用ElasticSearch提供的低级Rest Client连接到ElasticSearch 5.5.0实例。 的pom.xml org.springframework.boot spring-boot-starter-parent 1.5.4.RELEASE org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-test test org.elasticsearch elasticsearch 5.5.0 org.elasticsearch.client transport 5.5.0 org.apache.commons commons-lang3 3.6 com.fasterxml.jackson.core jackson-core 2.8.9 com.fasterxml.jackson.core jackson-databind 2.8.9 com.fasterxml.jackson.core jackson-annotations 2.8.9 log4j log4j 1.2.17 junit junit 4.11 test io.springfox springfox-swagger2 2.6.1 compile io.springfox springfox-swagger-ui 2.6.1 compile 一切都设置正确,但在一堆点击后,客户端应用程序报告HTTP 500错误,这是日志文件中出现的: java.io.IOException: Too many open files […]

在Android中的AsynTask中解析json时出错

我有一个AsynTask并试图检索一个json并解析它,但我收到此错误: 03-21 11:38:07.033: E/AndroidRuntime(8439): FATAL EXCEPTION: main 03-21 11:38:07.033: E/AndroidRuntime(8439): java.lang.NullPointerException 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONTokener.nextValue(JSONTokener.java:94) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONObject.(JSONObject.java:154) 03-21 11:38:07.033: E/AndroidRuntime(8439): at org.json.JSONObject.(JSONObject.java:171) 03-21 11:38:07.033: E/AndroidRuntime(8439): at Dic.proj.pkg.notifService.parse_if_update(notifService.java:191) 03-21 11:38:07.033: E/AndroidRuntime(8439): at Dic.proj.pkg.notifService$1$1$1.onPostExecute(notifService.java:153) 03-21 11:38:07.033: E/AndroidRuntime(8439): at Dic.proj.pkg.notifService$1$1$1.onPostExecute(notifService.java:1) 03-21 11:38:07.033: E/AndroidRuntime(8439): at android.os.AsyncTask.finish(AsyncTask.java:631) 03-21 11:38:07.033: E/AndroidRuntime(8439): at […]

使用带有标头的REST客户端时获取ssl.SSLHandshakeException但与PostMan一起正常工作

我有一个外部REST资源,其中包含以下细节: url: abc.com/orders (域名为https ) 我需要将UserID作为HTTP标头传递,密钥“user”值为“abcd” 这将返回JSON响应 我正在使用Java代码以下: try { Client client = Client.create(); WebResource webResource = client.resource(“abc.com/orders”); ClientResponse response = webResource.header(“user”, “abcd”).accept(“application/json”) .get(ClientResponse.class); if (response.getStatus() != 200) { throw new RuntimeException(“Failed : HTTP error code : ” + response.getStatus()); } String output = response.getEntity(String.class); System.out.println(“Output from Server …. \n”); System.out.println(output); } catch (Exception e) […]