spring-restcontroller

Spring @RestController not setting cookies with response

只谈情不闲聊 提交于 2019-12-24 00:46:17
问题 I have the following rest endpoint that I would like to send a cookie along with my ResponseEntity . However after succesfully sending the response, the cookie is nowhere to be found. @RequestMapping(value = "myPath", method = RequestMethod.POST) public ResponseEntity<?> createToken(HttpServletResponse response) final String token = "a1b2c3d4e"; Cookie cookie = new Cookie("token", token); response.addCookie(cookie); // Return the token return ResponseEntity.ok(new MyCustomResponse(token)); }

How to add csrf token to angular 2 application

社会主义新天地 提交于 2019-12-23 16:03:59
问题 I have enabled the CSRF in the java back-end (in SecurityConfig.java file) due to maintain user sessions between the angular2 and spring app. but when the post submission fired, I haven't seen any CSRF token binded to the POST request. How would be possible way to add the CSRF token to my angular2 app. (add to the post request ) loginService.ts userLogin(loginDTO){ let headers = new Headers({ 'Content-Type': 'application/json' }); let options = new RequestOptions({ headers: headers }); var

Using Spring @RestController to handle HTTP GET with ZonedDateTime parameters

戏子无情 提交于 2019-12-23 08:28:40
问题 I'm creating an endpoint that will receive dates to do some filtering in the server side. The code looks like this: @RequestMapping( value = "/test", method = RequestMethod.GET, produces = {MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE} ) @ResponseStatus(HttpStatus.OK) public TestSummaryModel getTestSummaryByDate( @RequestParam ZonedDateTime start, @RequestParam ZonedDateTime end) { return testService.getTestBetween(start, end); } When I try to invoke my endpoint I get an

Add Access-Control-Allow-Origin to Web Service

六眼飞鱼酱① 提交于 2019-12-23 04:52:32
问题 I have a webservice like: @Controller @RequestMapping("/") public class ApplicationController { @RequestMapping(value="/Changes", method = RequestMethod.GET) public String inspect(ModelMap model) { model.addAttribute("msg", "example"); return "index"; } } in the link: "localhost:8081/ChangesPDF/Changes?..." I'm trying to get the response of this webservice through Alfresco that is in the link: "localhost:8080/share" . I have different ports now (when I have same ports, this works good), so,

SpringBoot @RestController not accessible from outside docker container

a 夏天 提交于 2019-12-23 02:51:14
问题 tl;dr One RestController answers properly, the other doesn't, if run inside a Docker container. The service has two APIs alive @CrossOrigin(origins = "*", maxAge = 3600) @RestController public class AliveController { @RequestMapping(value = "/alive", method = RequestMethod.GET) public ResponseEntity<?> alive() { return new ResponseEntity<>(HttpStatus.OK); } } and callcount . @CrossOrigin @RestController public class CallController { private static int callCount = 0; @RequestMapping(value = "

Content type 'text/plain;charset=UTF-8' not supported error in spring boot inside RestController class

ぃ、小莉子 提交于 2019-12-22 18:35:24
问题 I got the following @RestController inside a spring boot application : @Data @RestController public class Hello { @Autowired private ResturantExpensesRepo repo; @RequestMapping(value = "/expenses/restaurants",method = RequestMethod.POST,consumes =MediaType.APPLICATION_JSON_VALUE , headers = MediaType.APPLICATION_JSON_VALUE) @ResponseBody public void hello(@RequestBody ResturantExpenseDto dto) { Logger logger = LoggerFactory.getLogger("a"); logger.info("got a request"); ResturantExpenseEntity

Spring 4.1.5 MVC @RequestParam(required = false, value = “somevalue”) fails if a parameter is absent

梦想的初衷 提交于 2019-12-22 11:35:50
问题 I have a spring mvc controller which is serving web service requests with multiple request parameters. All the parameters are marked required = false . Still if in the request a parameter is not available, @RequestMapping(value = "/service/deployNew", method = RequestMethod.POST) @ResponseBody public ResponseEntity<DeploymentId> deploy(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false, value = "abc") String abc, @RequestParam(required = false, value =

How to wrap JSON response from Spring REST repository?

南楼画角 提交于 2019-12-22 05:21:47
问题 I have a spring REST controller which returns the following JSON payload: [ { "id": 5920, "title": "a title" }, { "id": 5926, "title": "another title", } ] The REST controller with its corresponding get request method: @RequestMapping(value = "example") public Iterable<Souvenir> souvenirs(@PathVariable("user") String user) { return new souvenirRepository.findByUserUsernameOrderById(user); } Now the Souvenir class is a pojo: @Entity @Data public class Souvenir { @Id @GeneratedValue private

How to wrap JSON response from Spring REST repository?

随声附和 提交于 2019-12-22 05:21:28
问题 I have a spring REST controller which returns the following JSON payload: [ { "id": 5920, "title": "a title" }, { "id": 5926, "title": "another title", } ] The REST controller with its corresponding get request method: @RequestMapping(value = "example") public Iterable<Souvenir> souvenirs(@PathVariable("user") String user) { return new souvenirRepository.findByUserUsernameOrderById(user); } Now the Souvenir class is a pojo: @Entity @Data public class Souvenir { @Id @GeneratedValue private

Spring @RestController Get Request Content-Type to response json or html

心已入冬 提交于 2019-12-20 05:13:24
问题 how can I take request Content-Type value? We need this to print json response or Html respone. My code is this: @RestController public class GestorController { @RequestMapping(value="/gestores", method = RequestMethod.GET) public Object gestoresHtml(@RequestParam(value="name", required=false, defaultValue="sh14") String name) throws Exception { String json = "prueba json"; String contentType = ????? if(contentType.equals("application/json")){ return json; }else{ ModelAndView mav = new