2 * Copyright © 2021 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.dmaap.client.listener;
10 import javax.ws.rs.WebApplicationException;
11 import javax.ws.rs.client.Client;
12 import javax.ws.rs.client.ClientBuilder;
13 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
14 import org.glassfish.jersey.client.proxy.WebResourceFactory;
15 import org.glassfish.jersey.jackson.JacksonFeature;
16 import org.glassfish.jersey.logging.LoggingFeature;
17 import org.opendaylight.transportpce.dmaap.client.resource.EventsApi;
18 import org.opendaylight.transportpce.dmaap.client.resource.config.JsonConfigurator;
19 import org.opendaylight.transportpce.dmaap.client.resource.model.CreatedEvent;
20 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.NbiNotificationsListener;
21 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationAlarmService;
22 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishNotificationProcessService;
23 import org.opendaylight.yang.gen.v1.nbi.notifications.rev211013.PublishTapiNotificationService;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
27 public class NbiNotificationsListenerImpl implements NbiNotificationsListener {
28 private static final Logger LOG = LoggerFactory.getLogger(NbiNotificationsListenerImpl.class);
29 private String topic = "unauthenticated.TPCE";
30 private EventsApi api;
32 public NbiNotificationsListenerImpl(String baseUrl, String username, String password) {
33 LOG.info("Dmaap server {} for user {}", baseUrl, username);
34 Client client = ClientBuilder.newClient();
35 if (username != null && username.isBlank() && password != null && !password.isBlank()) {
36 HttpAuthenticationFeature authFeature = HttpAuthenticationFeature.basic(username, password);
37 client.register(authFeature);
38 topic = "authenticated.TPCE";
40 client.register(new LoggingFeature(java.util.logging.Logger.getLogger(this.getClass().getName())))
41 .register(JacksonFeature.class).register(JsonConfigurator.class);
42 api = WebResourceFactory.newResource(EventsApi.class, client.target(baseUrl));
47 public void onPublishNotificationProcessService(PublishNotificationProcessService notification) {
49 CreatedEvent response = api.sendEvent(topic, notification);
50 LOG.info("Response received {}", response);
51 } catch (WebApplicationException e) {
52 LOG.warn("Cannot send event {}", notification, e);
58 public void onPublishNotificationAlarmService(PublishNotificationAlarmService notification) {
62 public void onPublishTapiNotificationService(PublishTapiNotificationService notification) {