resttemplate

Rest API - how add custom headers?

那年仲夏 提交于 2021-02-19 04:33:05
问题 I want to make POST request with custom header. I can't find information how to do this using AA Rest API - https://github.com/excilys/androidannotations/wiki/Rest%20API . Should I use ClientHttpRequestInterceptor, which is used for authenticated requests? https://github.com/excilys/androidannotations/wiki/Authenticated-Rest-Client Thanks for any help! 回答1: There is currently an open issue for this : https://github.com/excilys/androidannotations/issues/323 For now, the only way to do this is

RestTemplate set timeout per request

∥☆過路亽.° 提交于 2021-02-18 11:52:15
问题 I have a @Service with several methods, each method consumes a different web api. Each call should have a custom read timeout. Is it thread-safe to have one RestTemplate instance and change the timeout via the factory in each method like so ((HttpComponentsClientHttpRequestFactory)restTemplate.getRequestFactory()) .setReadTimeout(customMillis); My concern is that I'm changing the timeout on the factory and its not like a RequestConfig . Will this approach be thread-safe considering these

java.lang.IllegalArgumentException: 'json' argument must be an instance of: [class java.lang.String, class [B

余生颓废 提交于 2021-02-11 13:43:19
问题 I am making a third party request in Hybris1811 framework using Spring Rest Template . But after getting response I am Getting below error: Could not properly initialize user sessionorg.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: 'json' argument must be an instance of: [class java.lang.String, class [B, class java.io.File, class java.net.URL, class java.io.InputStream, class java.io.Reader] , but gotten:

Using RestTemplate in Spring. Exception- Not enough variables available to expand

可紊 提交于 2021-02-08 10:42:46
问题 I am trying to access the contents of an API and I need to send a URL using RestTemplate. String url1 = "http://api.example.com/Search?key=52ddafbe3ee659bad97fcce7c53592916a6bfd73&term=&limit=100&sort={\"price\":\"desc\"}"; OutputPage page = restTemplate.getForObject(url1, OutputPage .class); But, I am getting the following error. Exception in thread "main" java.lang.IllegalArgumentException: Not enough variable values available to expand '"price"' at org.springframework.web.util

Missing request header 'authToken' calling RestAPI method

為{幸葍}努か 提交于 2021-02-08 07:46:31
问题 I have this RestAPI method @GetMapping(path = "/menus", consumes = "application/json", produces = "application/json") public ResponseEntity<List<MenuPriceSummary>> allMenus(HttpServletRequest request, @RequestHeader(value="Authorization: Bearer") String authToken) { String username = jwtTokenUtil.getUsernameFromToken(authToken); User user = userService.findByUserName(username); return ResponseEntity.ok(menuService.allMenus(user)); } which I call from curl curl -X GET -H "Content-Type:

Missing request header 'authToken' calling RestAPI method

丶灬走出姿态 提交于 2021-02-08 07:46:00
问题 I have this RestAPI method @GetMapping(path = "/menus", consumes = "application/json", produces = "application/json") public ResponseEntity<List<MenuPriceSummary>> allMenus(HttpServletRequest request, @RequestHeader(value="Authorization: Bearer") String authToken) { String username = jwtTokenUtil.getUsernameFromToken(authToken); User user = userService.findByUserName(username); return ResponseEntity.ok(menuService.allMenus(user)); } which I call from curl curl -X GET -H "Content-Type:

RestTemplate send file as bytes from one controller to another

試著忘記壹切 提交于 2021-02-07 19:50:54
问题 assume we have a one controller on third party service which accepts multipart files and its code is like (assume it's running on localhost:9090) @RequestMapping("/file") @RestController public class FileController { @RequestMapping(value = "/load", method = RequestMethod.POST) public String getFile(@RequestPart("file") MultipartFile file){ return file.getName(); } } The question is: How write a correct code in my controller, with RestTemplate, that calls the third party service, with file in

RestTemplate send file as bytes from one controller to another

一个人想着一个人 提交于 2021-02-07 19:48:16
问题 assume we have a one controller on third party service which accepts multipart files and its code is like (assume it's running on localhost:9090) @RequestMapping("/file") @RestController public class FileController { @RequestMapping(value = "/load", method = RequestMethod.POST) public String getFile(@RequestPart("file") MultipartFile file){ return file.getName(); } } The question is: How write a correct code in my controller, with RestTemplate, that calls the third party service, with file in

Sending Request body as json to GET request through httpentity

半城伤御伤魂 提交于 2021-01-29 07:09:04
问题 Sample Request Body as Json to send through the GET request for external API. Below is sample json need to be added in Request Body to send through GET request to external API: ''' {"nameidentify":["Name-1","Name-2","Name-3"]} ''' 'Assume i am getting values from one API like.. "Name-1","Name-2","Name-3" those values i need to pass to other API through GET request.For example below i am hardcoding the values for reference...' ''' String[] namesArray={"Name-1","Name-2","Name-3"} JSONObject

Problem calling a “bearer-only” keycloak endpoint from a springboot (client app) to a also spring boot (bearer only app)

限于喜欢 提交于 2021-01-28 08:47:14
问题 Basically I'm trying to access a bearer-only endpoint from a client app which is using a "KeycloakRestTemplate". I did follow this guidelines 1:1 (it is in German) : https://blog.codecentric.de/2017/09/keycloak-und-spring-security-teil-1-einrichtung-frontend/ My problem is that when I see the logs, the authentication on the side of the bearer only endpoint seems successful, as shown bellow: Found [1] values in authorization header, selecting the first value for Bearer. o.k.a