spring-rest

Spring boot send async tasks

那年仲夏 提交于 2021-01-02 03:28:12
问题 I need to send the email/sms/events as a background async task inside spring boot rest. My REST controller @RestController public class UserController { @PostMapping(value = "/register") public ResponseEntity<Object> registerUser(@RequestBody UserRequest userRequest){ // I will create the user // I need to make the asyn call to background job to send email/sms/events sendEvents(userId, type) // this shouldn't block the response. // need to send immediate response Response x = new Response();

Spring boot send async tasks

百般思念 提交于 2021-01-02 03:28:06
问题 I need to send the email/sms/events as a background async task inside spring boot rest. My REST controller @RestController public class UserController { @PostMapping(value = "/register") public ResponseEntity<Object> registerUser(@RequestBody UserRequest userRequest){ // I will create the user // I need to make the asyn call to background job to send email/sms/events sendEvents(userId, type) // this shouldn't block the response. // need to send immediate response Response x = new Response();

Can we specify the CSRF token expiry timeout?

梦想的初衷 提交于 2020-12-12 07:59:43
问题 I am using spring security and Java configurations in my project. The Java configurations for spring security by default have csrf enabled. Is it possible to set the timeout after which the csrf token expires? This was a requirement to specify the timeout for the token based application. After going through some blogs and articles, I noticed that the behavior of csrf token is unpredictable to make it more secured. Here is a sample code for configuring spring security. @Override protected void

Can we specify the CSRF token expiry timeout?

生来就可爱ヽ(ⅴ<●) 提交于 2020-12-12 07:59:28
问题 I am using spring security and Java configurations in my project. The Java configurations for spring security by default have csrf enabled. Is it possible to set the timeout after which the csrf token expires? This was a requirement to specify the timeout for the token based application. After going through some blogs and articles, I noticed that the behavior of csrf token is unpredictable to make it more secured. Here is a sample code for configuring spring security. @Override protected void

XmlElement(name=“custom_name”) not working in spring boot integrated with rest services

半城伤御伤魂 提交于 2020-12-03 07:12:22
问题 I am almost new to rest services world,here i am trying to change the field name displayed in the output xml. Not sure,am i following the right method,any help is a good thing. Activity.java import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement @XmlAccessorType(XmlAccessType.PROPERTY) public class Activity { private int activityId; private

KeycloakRestTemplate with spring application

☆樱花仙子☆ 提交于 2020-06-28 01:57:55
问题 I have a spring client with spring rest api's which are protected with keycloak. I am trying to call it using keycloakresttemplate from another client which is a pure java code with no security. I am getting the keycloak access token from java client and setting it in the header of rest url. It is not able to initialize the keycloakresttemplate. Any view why I am facing this issue. //Below is the code to hit the spring url using keycloakresttemplate.I have added Dependency of keycloack

KeycloakRestTemplate with spring application

☆樱花仙子☆ 提交于 2020-06-28 01:57:35
问题 I have a spring client with spring rest api's which are protected with keycloak. I am trying to call it using keycloakresttemplate from another client which is a pure java code with no security. I am getting the keycloak access token from java client and setting it in the header of rest url. It is not able to initialize the keycloakresttemplate. Any view why I am facing this issue. //Below is the code to hit the spring url using keycloakresttemplate.I have added Dependency of keycloack

MockRestServiceServer: how to mock a POST call with a body?

微笑、不失礼 提交于 2020-06-10 03:46:11
问题 I am trying to mock a POST method with MockRestServiceServer in the following way: MockRestServiceServer server = bindTo(restTemplate).build(); server.expect(requestTo("/my-api")) .andExpect(method(POST)) .andRespond(withSuccess(expectedResponce, APPLICATION_JSON)); Problem: How do I verify a request body in this setup? I browsed through the documentation and some examples and still can't figure out how it can be done. 回答1: You can use content().string to verify body: .andExpect(content()

MockRestServiceServer: how to mock a POST call with a body?

我的梦境 提交于 2020-06-10 03:45:59
问题 I am trying to mock a POST method with MockRestServiceServer in the following way: MockRestServiceServer server = bindTo(restTemplate).build(); server.expect(requestTo("/my-api")) .andExpect(method(POST)) .andRespond(withSuccess(expectedResponce, APPLICATION_JSON)); Problem: How do I verify a request body in this setup? I browsed through the documentation and some examples and still can't figure out how it can be done. 回答1: You can use content().string to verify body: .andExpect(content()

Request not reaching to the controller but still get 200 response

两盒软妹~` 提交于 2020-06-09 02:54:28
问题 I was playing around spring security and trying to secure an restful application, but then ran into this rather absurd problem. All the action on my controllers are fine and the requests are accepted but the request actually never reaches the controller and always 200 is returned with no content. My security config looks likes so: package com.bpawan.interview.api.config; import com.bpawan.interview.api.model.Error; import com.bpawan.interview.api.security.JWTAuthenticationFilter; import com