spring-restcontroller

FileUpload Multipart Springboot Error -> Required request part 'file' is not present

三世轮回 提交于 2019-12-11 18:27:38
问题 I am trying to upload a json file using Angular 4.0 and SpringBoot Application. I have checked and tried other solutions from Stackoverflow, but I cannot figur out what the exact problem is. I receive the 400 BAD Request Error message with the message: Required request part 'file' is not present. My RestController looks like this (for testing purposes), but unfortunately nothing happens. @RestController @RequestMapping("/api") public class UploadRequestResource { .... @PostMapping("

Springboot request object validation [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-11 17:51:00
问题 This question already has answers here : JSR-303 @Valid annotation not working for list of child objects (4 answers) Closed last year . I have a request object public class OrderRequest { private List<Details> detailsList; } public class Details{ Private String id; private List<Detail> detailList; } public class Detail{ @NotNull(message = "Please provide the inventory name") Private String inventoryName; Private String inventoryId; Private String inventoryLoc; } and i want to validate each

Autmapping of xml list of string response by rest service to respective java object using RestTemplate.postForObject(…)

假如想象 提交于 2019-12-11 15:28:01
问题 I have below XML which I am getting from third party(rest service) <response> <error>Document Too Small</error> <error>Barcode Not Detected</error> <error>Face Image Not Detected</error> </response> I am calling third party service with below code which is trying to convert the xml to respective java object - restTemplate.postForObject("/test", new HttpEntity<>(request, headers), Eror.class); We have added the MappingJackson2XmlHttpMessageConverter- MappingJackson2XmlHttpMessageConverter

Return list of errors

丶灬走出姿态 提交于 2019-12-11 07:33:16
问题 I wan to return a list of errors using this Response object: public class StringResponseDTO { private String response; public StringResponseDTO(String response) { super(); this.response = response; } public String getResponse() { return response; } public void setResponse(String response) { this.response = response; } } I use this code to generate errors: List<FieldError> errors = result.getFieldErrors(); for (FieldError error : errors ) { System.out.println ("Validation error in field: " +

Did not find handler method

こ雲淡風輕ζ 提交于 2019-12-11 06:59:55
问题 I am trying to invoke a rest endpoint, but getting this info when i call it, resulting in a 404 error in UI 2016-08-07 13:43:42.611 DEBUG 27834 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /api/v1/operations 2016-08-07 13:43:42.614 DEBUG 27834 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/api/v1/operations] 2016-08-07 13:43:42.615 DEBUG 27834 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching

RestController - Use @DateTimeFormat inside deserialized POJO

て烟熏妆下的殇ゞ 提交于 2019-12-11 06:19:58
问题 I have JSON body with date parameters that I need to deserialized Following Working with Date Parameters in Spring annotate the parameters with the @DateTimeFormat annotation and provide a formatting pattern parameter: We can also use our own conversion patterns. We can just provide a pattern parameter in the @DateTimeFormat annotation: @PostMapping("/date") public void date(@RequestParam("date") @DateTimeFormat(pattern = "dd.MM.yyyy") Date date) { I created a POJO @JsonIgnoreProperties

Rest service with oauth2: Failed to find access token for token

▼魔方 西西 提交于 2019-12-10 19:17:34
问题 I try to create spring rest service, whis is autenticated by my own oauth2 resources server. I created resource server: @Configuration @EnableResourceServer protected static class ResourceServer extends ResourceServerConfigurerAdapter { @Autowired private TokenStore tokenStore; @Override public void configure(ResourceServerSecurityConfigurer resources) throws Exception { resources.tokenStore(tokenStore).resourceId("mobileapp"); } @Override public void configure(HttpSecurity http) throws

Spring @GetMapping with @RequestParam and @RequestBody fails with HttpMessageNotReadableException

*爱你&永不变心* 提交于 2019-12-10 16:23:38
问题 Request to the endpoint fails with the following error: 400 Bad request org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing @GetMapping public List<SomeObject> list(@RequestParam(required = false) String parameter, @RequestBody String body, @RequestHeader("Authorization") String token) { ..... } if @GetMapping would be changed to @PostMapping everything works like a charm though. Any ideas what the heck is going on ? NOTE: Swagger is used for

Ajax request to Spring REST api 415 error

白昼怎懂夜的黑 提交于 2019-12-10 16:07:17
问题 I have a problem with my Spring Rest controller. I am trying to post ( PUT ) data from my client ( angularJS ) to my server ( Spring ), but every time I try to send something I get a 415 Media not supported error. With Maven I have added jackson-core (2.6.3) and jackson-databind (2.6.3) to my Spring API. I am also using @EnableWebMvc to automatically add the Jackson message converter to Spring. In my Spring controller I am using @RestController for access to the REST methods of Spring. My

Spring REST Upload file as binary

主宰稳场 提交于 2019-12-10 15:28:29
问题 I'm using spring. I want to implement rest controller to upload file to server. I found a lot examples like this: public ResponseEntity doSomething(@PathVariable String paramOne, @RequestParam(required = false, name="file") List<MultipartFile> attachments ) throws IOException { //Some logic here } Then I test it with postman, I create a request of type "form-data", add pram name "file", select type file, and select file. And it works ok. It creates a post request as multipart request. But for