summaryrefslogtreecommitdiffstats
path: root/aai-traversal/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-traversal/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java')
-rw-r--r--aai-traversal/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java211
1 files changed, 93 insertions, 118 deletions
diff --git a/aai-traversal/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java b/aai-traversal/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java
index e0c4ec7..a30ebc0 100644
--- a/aai-traversal/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java
+++ b/aai-traversal/src/main/java/org/openecomp/aai/dmaap/AAIDmaapEventJMSConsumer.java
@@ -20,144 +20,119 @@
package org.openecomp.aai.dmaap;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Properties;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.ClientResponse;
+import com.sun.jersey.api.client.WebResource;
+import org.apache.log4j.MDC;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.openecomp.aai.logging.ErrorLogHelper;
+import org.openecomp.aai.util.AAIConstants;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.ws.rs.core.MediaType;
-
-import org.apache.log4j.MDC;
-import org.eclipse.jetty.util.security.Password;
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import org.openecomp.aai.logging.ErrorLogHelper;
-import org.openecomp.aai.util.AAIConstants;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-//import com.att.nsa.mr.client.MRBatchingPublisher;
-//import com.att.nsa.mr.client.MRClientFactory;
-import com.sun.jersey.api.client.Client;
-import com.sun.jersey.api.client.ClientResponse;
-import com.sun.jersey.api.client.WebResource;
-import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Properties;
public class AAIDmaapEventJMSConsumer implements MessageListener {
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(AAIDmaapEventJMSConsumer.class);
- private final static String COMPONENT = "aaiDmaapEvent";
- //private MRBatchingPublisher adp = null;
+ private Client httpClient;
- private Properties props;
+ private Properties aaiEventProps;
+ private String aaiEventUrl = "";
- private String username;
- private String password;
- private String contentType;
+ public AAIDmaapEventJMSConsumer() throws org.apache.commons.configuration.ConfigurationException {
+ super();
+ try {
- private String url;
- private Client client;
+ if (this.httpClient == null) {
+ FileReader reader = new FileReader(new File(AAIConstants.AAI_EVENT_DMAAP_PROPS));
+ aaiEventProps = new Properties();
+ aaiEventProps.load(reader);
+ reader.close();
- public AAIDmaapEventJMSConsumer() throws org.apache.commons.configuration.ConfigurationException {
- //super();
-
- //if (this.adp == null) {
- //try {
- //FileReader reader = new FileReader(new File(AAIConstants.AAI_EVENT_DMAAP_PROPS));
- //props = new Properties();
- //props.load(reader);
- //props.setProperty("DME2preferredRouterFilePath", AAIConstants.AAI_HOME_ETC_APP_PROPERTIES + "preferredRoute.txt");
- //if (props.getProperty("password") != null && props.getProperty("password").startsWith("OBF:")) {
- //props.setProperty("password", Password.deobfuscate(props.getProperty("password")));
- //}
- //this.adp = MRClientFactory.createBatchingPublisher(props);
-
- //String host = props.getProperty("host");
- //String topic = props.getProperty("topic");
- //String protocol = props.getProperty("Protocol");
-
- //username = props.getProperty("username");
- //password = props.getProperty("password");
- //contentType = props.getProperty("contenttype");
-
- //url = protocol + "://" + host + "/events/" + topic;
- //client = Client.create();
- //client.addFilter(new HTTPBasicAuthFilter(username, password));
-
- //} catch (IOException e) {
- //ErrorLogHelper.logError("AAI_4000", "Error updating dmaap config file for aai event.");
- //}
- //}
+ String host = aaiEventProps.getProperty("host");
+ String topic = aaiEventProps.getProperty("topic");
+ String protocol = aaiEventProps.getProperty("Protocol");
+
+ aaiEventUrl = protocol + "://" + host + "/events/" + topic;
+ httpClient = Client.create();
+ }
+
+ } catch (IOException e) {
+ ErrorLogHelper.logError("AAI_4000", "Error updating dmaap config file for aai event.");
+ }
}
@Override
public void onMessage(Message message) {
- //String jsmMessageTxt = "";
- //String aaiEvent = "";
- //String transId = "";
- //String fromAppId = "";
- //String fullId = "";
-
- //if (message instanceof TextMessage) {
- //try {
- //jsmMessageTxt = ((TextMessage) message).getText();
- //JSONObject jo = new JSONObject(jsmMessageTxt);
-
- //if (jo.has("aaiEventPayload")) {
- //aaiEvent = jo.getJSONObject("aaiEventPayload").toString();
- //} else {
- //return;
- //}
- //if (jo.getString("transId") != null) {
- //MDC.put("requestId", jo.getString("transId"));
- //}
- //if (jo.getString("fromAppId") != null) {
- //MDC.put("partnerName", jo.getString("fromAppId"));
- //}
- //if (jo.getString("fullId") != null) {
- //fullId = jo.getString("fullId");
- //}
-
- //LOGGER.info(fullId + "|" + transId + "|" + fromAppId + "|" + aaiEvent);
-
- //String environment = System.getProperty("lrmRO");
-
- //if (environment == null) {
- //this.adp.send(aaiEvent);
- //} else {
- //if (environment.startsWith("dev") || environment.startsWith("testINT") || environment.startsWith("testEXT")) {
-
- //WebResource webResource = client.resource(url);
-
- //ClientResponse response = webResource.accept(contentType).type(MediaType.APPLICATION_JSON).post(ClientResponse.class, aaiEvent);
-
- //if (response.getStatus() != 200) {
- //System.out.println("Failed : HTTP error code : " + response.getStatus());
- //}
- //} else {
- //this.adp.send(aaiEvent);
- //}
- //}
-
- //} catch (IOException e) {
- //if (e instanceof java.net.SocketException) {
- //if (e.getMessage().contains("Connection reset")) {
- //} else {
- //ErrorLogHelper.logError("AAI_7304", "Error reaching DMaaP to send event. " + aaiEvent);
- //}
- //} else {
- //ErrorLogHelper.logError("AAI_7304", "Error reaching DMaaP to send event. " + aaiEvent);
- //}
- //} catch (JMSException | JSONException e) {
- //ErrorLogHelper.logError("AAI_7350", "Error parsing aaievent jsm message for sending to dmaap. " + jsmMessageTxt);
- //}
- //}
+ String jsmMessageTxt = "";
+ String aaiEvent = "";
+ String eventName = "";
+
+ if (message instanceof TextMessage) {
+ try {
+ jsmMessageTxt = ((TextMessage) message).getText();
+ JSONObject jo = new JSONObject(jsmMessageTxt);
+
+ if (jo.has("aaiEventPayload")) {
+ aaiEvent = jo.getJSONObject("aaiEventPayload").toString();
+ } else {
+ return;
+ }
+ if (jo.getString("transId") != null) {
+ MDC.put("requestId", jo.getString("transId"));
+ }
+ if (jo.getString("fromAppId") != null) {
+ MDC.put("partnerName", jo.getString("fromAppId"));
+ }
+ if (jo.getString("event-topic") != null) {
+ eventName = jo.getString("event-topic");
+ }
+
+ LOGGER.info(eventName + "|" + aaiEvent);
+ if ("AAI-EVENT".equals(eventName)) {
+ this.sentWithHttp(this.httpClient, this.aaiEventUrl, aaiEvent);
+ }
+ } catch (java.net.SocketException e) {
+ if (!e.getMessage().contains("Connection reset")) {
+ LOGGER.error("AAI_7304 Error reaching DMaaP to send event. " + aaiEvent, e);
+ }
+ } catch (IOException e) {
+ LOGGER.error("AAI_7304 Error reaching DMaaP to send event. " + aaiEvent, e);
+ } catch (JMSException | JSONException e) {
+ LOGGER.error("AAI_7350 Error parsing aaievent jsm message for sending to dmaap. " + jsmMessageTxt, e);
+ } catch (Exception e) {
+ LOGGER.error("AAI_7350 Error sending message to dmaap. " + jsmMessageTxt, e);
+ }
+ }
+
+ }
+
+ private boolean sentWithHttp(Client client, String url, String aaiEvent) throws IOException {
+
+ WebResource webResource = client.resource(url);
+
+ ClientResponse response = webResource
+ .accept(MediaType.APPLICATION_JSON)
+ .type(MediaType.APPLICATION_JSON)
+ .post(ClientResponse.class, aaiEvent);
+
+ if (response.getStatus() != 200) {
+ LOGGER.info("Failed : HTTP error code : " + response.getStatus());
+ return false;
+ }
+ return true;
}
}