3
3
import it .gov .pagopa .message .core .dto .MessageDTO ;
4
4
import it .gov .pagopa .message .core .dto .TokenDTO ;
5
5
import lombok .extern .slf4j .Slf4j ;
6
+ import org .springframework .beans .factory .annotation .Value ;
6
7
import org .springframework .http .HttpEntity ;
7
8
import org .springframework .http .HttpHeaders ;
8
9
import org .springframework .http .HttpMethod ;
@@ -17,16 +18,30 @@ public class SendMessageServiceImpl implements SendMessageService {
17
18
18
19
private final RestTemplate restTemplate ;
19
20
private final MessageErrorProducerService errorProducerService ;
21
+
22
+ private final String client ;
23
+ private final String clientId ;
24
+ private final String grantType ;
25
+
26
+ private final String tenantId ;
20
27
public SendMessageServiceImpl (MessageErrorProducerService errorProducerService ,
21
- RestTemplate restTemplate ) {
28
+ RestTemplate restTemplate ,
29
+ @ Value ("${app.token.client}" )String client ,
30
+ @ Value ("${app.token.clientId}" ) String clientId ,
31
+ @ Value ("${app.token.grantType}" ) String grantType ,
32
+ @ Value ("${app.token.tenantId}" ) String tenantId ) {
22
33
this .restTemplate = restTemplate ;
23
34
this .errorProducerService = errorProducerService ;
35
+ this .client = client ;
36
+ this .clientId = clientId ;
37
+ this .grantType = grantType ;
38
+ this .tenantId = tenantId ;
24
39
}
25
40
26
41
@ Override
27
42
public void sendMessage (MessageDTO messageDTO , String messageUrl , String authenticationUrl ) {
28
43
try {
29
- toUrl (messageDTO , messageUrl , getToken (authenticationUrl , messageDTO . getRecipientId () ));
44
+ toUrl (messageDTO , messageUrl , getToken (authenticationUrl ));
30
45
}
31
46
catch (Exception e ) {
32
47
log .info ("[EMD][SEND-MESSAGE] Error while sending message" );
@@ -37,32 +52,28 @@ public void sendMessage(MessageDTO messageDTO, String messageUrl, String authent
37
52
@ Override
38
53
public void sendMessage (MessageDTO messageDTO , String messageUrl , String authenticationUrl , long retry ) {
39
54
try {
40
- toUrl (messageDTO , messageUrl , getToken (authenticationUrl , messageDTO . getRecipientId () ));
55
+ toUrl (messageDTO , messageUrl , getToken (authenticationUrl ));
41
56
}
42
57
catch (Exception e ) {
43
58
log .info ("[EMD][SEND-MESSAGE] Error while sending message" );
44
59
errorProducerService .sendError (messageDTO ,messageUrl ,authenticationUrl ,retry );
45
60
}
46
61
}
47
62
48
- private TokenDTO getToken (String authenticationUrl , String recipientId ) throws Exception {
63
+ private TokenDTO getToken (String authenticationUrl ) throws Exception {
49
64
50
65
HttpHeaders headers = new HttpHeaders ();
51
- headers .set ("RequestId" , "00000000-0000-0000-0000-000000000006" );
52
66
headers .setContentType (MediaType .APPLICATION_FORM_URLENCODED );
53
67
54
- String client = "64b5f14d-56ef-4d14-8b65-ff7bc5d4661e" ;
55
- String clientId = "6010064c-ec73-4fa5-9ed5-5446af8920cf" ;
56
- String grantType = "client_credentials" ;
57
68
MultiValueMap <String , String > map = new LinkedMultiValueMap <>();
58
69
map .add ("client_secret" , client );
59
70
map .add ("client_id" , clientId );
60
71
map .add ("grant_type" , grantType );
61
- map .add ("fiscal_code" , recipientId );
62
72
63
- HttpEntity <MultiValueMap <String , String >> entity = new HttpEntity <>(map , headers );
73
+ HttpEntity <MultiValueMap <String , String >> entity = new HttpEntity <>(map ,headers );
64
74
TokenDTO token ;
65
75
76
+ authenticationUrl = authenticationUrl .replace ("tenantId" ,tenantId );
66
77
log .info ("[EMD][SEND-MESSAGE] Getting Token" );
67
78
token = restTemplate .exchange (
68
79
authenticationUrl ,
0 commit comments