-
0 votesanswersviews
RestTemplate - 当响应体为null时处理潜在的NullPointerException
我正在编写调用一些后端REST服务的客户端 . 我发送的Product对象将保存在DB中,并在生成的productId的响应正文中返回 . public Long createProduct(Product product) { RestTemplate restTemplate = new RestTemplate(); final String url = " ... &qu... -
6 votesanswersviews
当响应代码为401时,ClientHttpResponse.getBody()抛出ResourceAccessException
我正在尝试为每个请求记录请求 - 响应对 . 问题是当响应代码是 401 时, ClientHttpResponse.getBody() 会抛出ResourceAccessException而我无法读取响应正文 . 这是RestTemplate配置 RestTemplate restTemplate = new RestTemplate(); // Added this requestFacto... -
2 votesanswersviews
Spring Boot集成测试 - TestRestTemplate如何将响应Content-Type设置为UTF-8
我尝试集成测试Spring Boot应用程序,现在我遇到了一个问题 org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class org.springframework.ht... -
0 votesanswersviews
使用JSon进行RestTemplate POST
我再次寻求专家的帮助/指导, 我的问题是,我需要创建动态网站,调用restfull服务器获取数据,所有请求都是POST并返回json对象 . 我想使用Spring RestTemplate来调用服务器 . 我的服务器工作正常,这意味着目前一些Android和Apple应用程序连接到相同的API,它们工作正常 . 但是当我尝试使用RestTemplate连接到服务器时,它会产生一些错误 org.s... -
0 votesanswersviews
RestTemplate在Google App Engine上使用基本身份验证
我使用Spring Security 3.1在Google App Engine上开发了一个Spring MVC Rest服务 . 由于该服务仅适用于我的其他应用程序,因此我使用预定义的用户名和密码进行基本身份验证设置 . 现在,我有一个使用RestTemplate开发的客户端 . 但我无法通过RestTemplate发送用户名和密码来安全访问我的服务 . 我已经阅读了很多文章,但大多数都使用Ap... -
167 votesanswersviews
使用Spring RestTemplate获取JSON对象的列表
我有两个问题: 如何使用Spring RestTemplate映射JSON对象列表 . 如何映射嵌套的JSON对象 . 我正按照http://spring.io/guides/gs/consuming-rest/的教程尝试使用https://bitpay.com/api/rates . -
2 votesanswersviews
使用RestTemplate测试Spring-data-rest一对多映射
我有一个Spring Boot应用程序使用Spring-data-rest暴露REST API . 我的一些实体具有OneToMany映射: @Entity @Table(name = "records") @Getter @Setter public class Record { @Id @GeneratedValue(strategy = GenerationTy... -
1 votesanswersviews
使用Spring RestTemplate请求XSRF-TOKEN时获取异常
我正在尝试调用已启用CSRF的服务,并且所有 endpoints 都配置为从用户请求身份验证标头 . 我正在使用Spring RestTemplate,如下所示: ResponseEntity<String> responseEntity = getRestTemplate().exchange( "localhost:9090/", &q... -
30 votesanswersviews
Spring RestTemplate调用带有错误的webservice并分析状态代码
如果请求参数正常,我设计了一个web服务来执行任务,如果请求参数错误或为空,我会返回401 Unauthorized HTTP状态代码 . 我正在使用 RestTemplate 来执行测试,如果webservice成功回复,我就能验证HTTP 200 OK状态 . 但是我无法测试HTTP 401错误,因为 RestTemplate 本身会抛出异常 . 我的测试方法是 @Test public vo... -
0 votesanswersviews
o.s.web.servlet.PageNotFound没有GET的映射
朋友,我正在使用Spring数据中的RestController来使用来自外部API的数据 . 当我使用PostMan获取数据时,我得到了这个404错误代码 . 但是如果我在POSTMAN上使用带有 Headers 的直接URL,我会得到正确的数据和响应代码200 请你帮助我好吗 控制台Intelij 2018-11-13 17:30:42.334 WARN 11820 --- [nio-808... -
2 votesanswersviews
Spring RestTemplate,当http状态代码为404时获得垃圾响应
我正在编写一个rest代理(它公开API并将调用委托给其他服务器)并且它适用于正常情况,并且对于500 http状态代码,我们从其余客户端获得响应 . 但是当我们获得404状态代码时,Rest API服务器返回消息但我们从RestTemplate获取垃圾值 . 我们需要将相同的响应传递给其他API用户,但无法获得相同的响应 . Message returned from REST API Serv... -
2 votesanswersviews
使用Google App Engine RestTemplate
我有一个带有Spring Framework的Google AppEngine应用程序,它必须使用List发出一个post请求到另一个暴露REST API的Spring Boot应用程序 . 我正在使用RestTemplate来调用api . 在GAE应用程序内我做: restTemplate.postForObject(NEO4J_URL_VERTEX, vertices, List.class... -
11 votesanswersviews
RestTemplate GET请求请求参数
我必须调用REST Web服务,我计划使用RestTemplate . 我查看了如何发出GET请求的示例,如下所示 . String result = restTemplate.getForObject("http://example.com/hotels/{hotel}/bookings/{booking}", String.class,"42",&quo... -
2 votesanswersviews
如何在Spring微服务之间传递原始的Oauth2承载令牌
我们有一些Spring微服务通过休息(Spring的RestTemplate)相互通信 . 在所有这些中都应用了Oauth2授权,并且使用一些自定义字段(即userRole,userId等)扩展了JWT令牌 . 我的问题如下: 当我们通过RestTemplate调用也调用另一个微服务的服务时,当微服务彼此通信时,不转发原始承载令牌(Oauth2) . 我们无法得到其他服务的回复,因为我们是未经授权... -
0 votesanswersviews
如何使用apache android httpclient设置credentialsencoding
我一直在我的Android应用程序中使用内置的android httpclient和Springs Android Resttemplate(1.0.0.M4) . 我正在使用Basic Auth进行身份验证 . 我在提出请求时需要设置一些东西,最重要的是凭据字符集 . 默认为US-Ascii,除非我将其设置为ISO-8859,否则北欧字符不起作用 . 我使用HttpClient做到了这一点: H... -
22 votesanswersviews
RestTemplate - 处理异常中的响应头/主体(RestClientException,HttpStatusCodeException)
在我的restful webservice中,如果出现错误请求(5xx)或4xx respose代码,我会在响应中写一个自定义 Headers “x-app-err-id” . 在客户端,我使用RestTemplate的交换方法来进行RestFul Web服务调用 . 当响应代码为2xx时,一切都很好 . ResponseEntity<Component> response = res... -
47 votesanswersviews
使用Spring RestTemplate for Android进行经过身份验证的POST请求
我有一个RESTful API I 'm trying to connect with via Android and RestTemplate. All requests to the API are authenticated with HTTP Authentication, through setting the headers of the HttpEntity and then usi... -
30 votesanswersviews
带有Header的Spring RestTemplate postForObject:webservice找不到我的头参数
我正在与RestTemplate斗争 . 我需要将一些身份验证信息发送到其他Web服务 . 我可以发送请求,我会收到回复 . 但根据响应我的 Headers 参数没有通过 . (使用SOAPUI发送相同的请求工作正常) 这是我的代码: HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICA... -
3 votesanswersviews
如何使用Spring RestTemplate执行设置http请求体?
我想使用RestTemplate发出请求 . 我必须发送带有GET请求的请求有效负载 . 是的,是的,我知道 . 所以我尝试了RestTemplate.exchange,但似乎它没有为GET请求发送有效负载,无论如何 . 所以我在文档和数字中进一步查看RestTemplate.execute可能是我正在寻找的...现在我在这里 . 所以doc说明了执行: 对给定的URI模板执行HTTP方法,使用... -
1 votesanswersviews
使用Spring RestTemplate处理多部分/混合响应
我正在休息调用返回多部分/混合有效负载的 endpoints . 这是使用Spring的RestTemplate的调用: ResponseEntity<String> res = template.exchange(queryStr, HttpMethod.GET, entity, String.class); 我知道我可以从ResponseEntity中获取整个身体作为一个字符串... -
1 votesanswersviews
使用REST API时Spring RestTemplate连接被拒绝
我正在使用 RestTemplate 来使用REST API . 为了测试,我采用了Internet中的一个示例REST API . `http://services.groupkt.com/country/get/iso2code/IN 这适用于浏览器,并能够使用 200 状态代码查看响应 . { "RestResponse" : { "messages"... -
0 votesanswersviews
获取400 null作为错误消息,使用rest模板调用带有查询参数的get方法API
我试图通过使用rest模板传递查询参数来调用一个get方法API . 我只是以正确的格式传递请求,但我收到错误消息为“400 null” . Following is the curl command which is working properly with POSTMAN: curl -X GET \ 'http://localhost:8086/uaa/Groups?filter=id... -
0 votesanswersviews
Sprint Rest模板获取错误:org.springframework.web.client.HttpClientErrorException:401
虽然我在httpheaders中发送用户名和密码,但在使用RestTemplate实现时仍然会获得org.springframework.web.client.HttpClientErrorException:401 . 我试图调用的网址是“https” Here is my code : method () { HttpEntity<ReviewPayload> request ... -
1 votesanswersviews
Spring Redis模板与Jedis连接工厂,Redis独立配置和多线程
我在多线程环境中使用Spring Redis模板 . 一个线程将数据保存到Redis中,另一个线程(调度程序)从中获取数据 . JedisConnectionFactory用于redis模板 . 以下是用于获取redis连接的代码段: JedisConnectionFactory jedisConnectionFactory() { JedisConnectionFactory jed... -
3 votesanswersviews
将Spring Boot和OAuth2客户端从使用Client Credentials流转换为Authorization Code Grant流
在尝试创建使用OAuth 2.0授权代码授权流程的示例客户端时,我一直在努力 . 我能够成功使用客户端凭据流,但是当我尝试使用授权代码流时,我没有被重定向到正确的uri . 调用OAuth2RestTmplate.exchange方法时,我在RestTemplate.doExecute(...)方法中获得重定向异常 . 它是从finally子句抛出的 . 响应为空,但if不会停止响应 . fina...