草庐IT

Resttemplate

全部标签

java - 使用 spring restTemplate 对 REST API 进行基本身份验证

我是RestTemplate的新手,基本上也是RESTAPI的新手。我想通过JiraRESTAPI在我的应用程序中检索一些数据,但返回401Unauthorized。在jirarestapidocumentation上找到和文章但真的不知道如何将其重写为java,因为该示例使用curl的命令行方式。我将不胜感激任何关于如何重写的建议或建议:curl-D--XGET-H"Authorization:BasicZnJlZDpmcmVk"-H"Content-Type:application/json""http://kelpie9:8081/rest/api/2/issue/QA-31"使

spring - 使用 RestTemplate 时如何配置内部 Jackson 映射器?

我想更新SpringRestTemplate使用的jackson映射器的SerializationConfig.Feature...属性,知道如何获取它或我可以/应该在哪里配置它。 最佳答案 默认的RestTemplate构造函数注册了一组HttpMessageConverter:this.messageConverters.add(newByteArrayHttpMessageConverter());this.messageConverters.add(newStringHttpMessageConverter());this.

spring - 无法 Autowiring 字段 :RestTemplate in Spring boot application

我在启动期间运行SpringBoot应用程序时遇到异常:org.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname'testController':Injectionofautowireddependenciesfailed;nestedexceptionisorg.springframework.beans.factory.BeanCreationException:Couldnotautowirefield:privateorg.springframework.web.clien

Spring Resttemplate 异常处理

以下是代码片段;基本上,当错误代码不是200时,我试图传播异常。ResponseEntityresponse=restTemplate.exchange(url.toString().replace("{version}",version),HttpMethod.POST,entity,Object.class);if(response.getStatusCode().value()!=200){logger.debug("EncounteredErrorwhileCallingAPI");thrownewApplicationException();}但是,如果服务器发出500响应,

Spring RestTemplate 超时

我想为我的Web应用程序使用的休息服务设置连接超时。我正在使用Spring的RestTemplate与我的服务交谈。我做了一些研究,发现并使用了下面的xml(在我的应用程序xml中),我相信它是为了设置超时。我正在使用Spring3.0。我在这里也看到了同样的问题TimeoutconfigurationforspringwebserviceswithRestTemplate但解决方案似乎不是干净,我更愿意通过Springconfig设置超时值似乎无论我将readTimeout设置为什么,我都会得到以下信息:网线断开:等待大约20秒并报告以下异常:org.springframework.

spring - 如何在 Spring RestTemplate 请求上设置 "Accept:" header ?

我想在我使用Spring的RestTemplate发出的请求中设置Accept:的值。这是我的Spring请求处理代码@RequestMapping(value="/uom_matrix_save_or_edit",method=RequestMethod.POST,produces="application/json")public@ResponseBodyModelMapuomMatrixSaveOrEdit(ModelMapmodel,@RequestParam("parentId")StringparentId){model.addAttribute("attributeVal

json - RestTemplate PATCH 请求

我对PersonDTO有以下定义:publicclassPersonDTO{privateStringidprivateStringfirstName;privateStringlastName;privateStringmaritalStatus;}这是一个示例记录:{"id":1,"firstName":"John","lastName":"Doe","maritalStatus":"married"}现在,JohnDoe离婚了。所以我需要向这个URL发送一个PATCH请求:http://localhost:8080/people/1使用以下请求正文:{"maritalStatus

json - 为什么 RestTemplate 不将响应表示绑定(bind)到 PagedResources?

我正在使用spring-data-rest将实体公开为(分页)休息资源。一切正常,但是当我通过RestTemplate请求数据时,我得到了一个无用的HATEOASJSON(我没有要求)。JSON似乎是PagedResources。我可以忍受,但JSON没有正确转换为对象。里面没有content。存储库:@RepositoryRestResource(collectionResourceRel="people",path="people")publicinterfacePersonRepositoryextendsPagingAndSortingRepository{ListfindBy

java - 通过 JSON 中的 RestTemplate POST 请求

我没有找到任何示例如何解决我的问题,所以我想向您寻求帮助。我不能简单地使用JSON中的RestTemplate对象发送POST请求每次我得到:org.springframework.web.client.HttpClientErrorException:415UnsupportedMediaType我是这样使用RestTemplate的:...restTemplate=newRestTemplate();List>list=newArrayList>();list.add(newMappingJacksonHttpMessageConverter());restTemplate.set

java - Spring RestTemplate - 如何启用请求/响应的完整调试/日志记录?

我使用SpringRestTemplate已经有一段时间了,当我尝试调试它的请求和响应时,我总是碰壁。我基本上希望看到与打开“详细”选项使用curl时看到的相同的东西。例如:curl-vhttp://twitter.com/statuses/public_timeline.rss将显示发送的数据和接收的数据(包括header、cookie等)。我查看了一些相关的帖子,例如:HowdoIlogresponseinSpringRestTemplate?但我还没有设法解决这个问题。这样做的一种方法是实际更改RestTemplate源代码并在那里添加一些额外的日志记录语句,但我会发现这种方法确