90cc7a433f42e09b0dd5b67488a566ee165d4e32
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / hub / service / NotifierService.java
1 /**
2  * Copyright (c) 2018 Orange
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5  * the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11  * specific language governing permissions and limitations under the License.
12  */
13 package org.onap.nbi.apis.hub.service;
14
15 import javax.validation.Valid;
16 import org.onap.nbi.apis.hub.model.Event;
17 import org.onap.nbi.apis.hub.model.Subscriber;
18 import org.onap.nbi.exceptions.BackendFunctionalException;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.scheduling.annotation.Async;
23 import org.springframework.stereotype.Service;
24 import org.springframework.web.client.RestTemplate;
25
26 @Service
27 public class NotifierService {
28
29     private final Logger logger = LoggerFactory.getLogger(NotifierService.class);
30
31     @Autowired
32     RestTemplate restTemplate;
33
34     @Async
35     public void run(Subscriber subscriber, @Valid Event event) {
36         try {
37             restTemplate.postForEntity(subscriber.getCallback(), event, Object.class);
38         } catch (BackendFunctionalException e) {
39             logger.error(" unable to post event to {} , receive {}, {}", subscriber.getCallback(), e.getHttpStatus(),
40                 e.getBodyResponse());
41         }
42
43     }
44 }