40
40
import org .springframework .util .LinkedMultiValueMap ;
41
41
import org .springframework .util .MultiValueMap ;
42
42
import org .springframework .web .client .RestTemplate ;
43
+ import org .springframework .web .context .request .RequestContextHolder ;
44
+ import org .springframework .web .context .request .ServletRequestAttributes ;
43
45
44
46
import com .fasterxml .jackson .databind .ObjectMapper ;
45
47
import com .google .gson .Gson ;
48
50
import com .iemr .ecd .repo .call_conf_allocation .MotherRecordRepo ;
49
51
import com .iemr .ecd .repo .call_conf_allocation .OutboundCallsRepo ;
50
52
import com .iemr .ecd .utils .advice .exception_handler .ECDException ;
53
+ import com .iemr .ecd .utils .mapper .CookieUtil ;
51
54
55
+ import jakarta .servlet .http .HttpServletRequest ;
52
56
import jakarta .transaction .Transactional ;
53
57
54
58
@ Service
@@ -69,6 +73,8 @@ public class BeneficiaryRegistrationServiceImpl {
69
73
@ Value ("${beneficiaryEditUrl}" )
70
74
private String beneficiaryEditUrl ;
71
75
ObjectMapper objectMapper = new ObjectMapper ();
76
+ @ Autowired
77
+ private CookieUtil cookieUtil ;
72
78
73
79
@ Transactional (rollbackOn = Exception .class )
74
80
public String beneficiaryRegistration (RequestBeneficiaryRegistrationDTO request , String Authorization ) {
@@ -100,11 +106,15 @@ public String beneficiaryRegistration(RequestBeneficiaryRegistrationDTO request,
100
106
// request.setEdd(getTimestampFromString(request.getEddStr()));
101
107
102
108
RestTemplate restTemplate = new RestTemplate ();
109
+ HttpServletRequest requestHeader = ((ServletRequestAttributes ) RequestContextHolder .getRequestAttributes ())
110
+ .getRequest ();
111
+ String jwtTokenFromCookie = cookieUtil .getJwtTokenFromCookie (requestHeader );
103
112
MultiValueMap <String , String > headers = new LinkedMultiValueMap <String , String >();
104
113
headers .add ("Content-Type" , MediaType .APPLICATION_JSON + ";charset=utf-8" );
105
114
headers .add ("AUTHORIZATION" , Authorization );
115
+ headers .add ("Cookie" , "Jwttoken=" + jwtTokenFromCookie );
106
116
String json = objectMapper .writeValueAsString (request );
107
-
117
+
108
118
HttpEntity <Object > requestObj = new HttpEntity <Object >(json , headers );
109
119
110
120
ResponseEntity <String > response = restTemplate .exchange (registerBeneficiaryUrl , HttpMethod .POST , requestObj ,
@@ -174,9 +184,13 @@ public String updateBeneficiaryDetails(RequestBeneficiaryRegistrationDTO request
174
184
}
175
185
176
186
RestTemplate restTemplate = new RestTemplate ();
187
+ HttpServletRequest requestHeader = ((ServletRequestAttributes ) RequestContextHolder .getRequestAttributes ())
188
+ .getRequest ();
189
+ String jwtTokenFromCookie = cookieUtil .getJwtTokenFromCookie (requestHeader );
177
190
MultiValueMap <String , String > headers = new LinkedMultiValueMap <String , String >();
178
191
headers .add ("Content-Type" , MediaType .APPLICATION_JSON + ";charset=utf-8" );
179
192
headers .add ("AUTHORIZATION" , Authorization );
193
+ headers .add ("Cookie" , "Jwttoken=" + jwtTokenFromCookie );
180
194
HttpEntity <Object > requestObj = new HttpEntity <Object >(request , headers );
181
195
ResponseEntity <String > response = restTemplate .exchange (beneficiaryEditUrl , HttpMethod .POST , requestObj ,
182
196
String .class );
0 commit comments