From aefeb9ff5ec5c7ce3c20f420db1116c31f034615 Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Tue, 30 Jan 2018 14:04:13 -0500 Subject: Update the files for ajsc 6 changes Issue-ID: AAI-33 Change-Id: I897566e79eb7505232b692e551f6347e69fafed6 Signed-off-by: Venkata Harish K Kajur --- .../main/java/org/onap/aai/config/DmaapConfig.java | 110 ++++++++++++++ .../org/onap/aai/config/SpringContextAware.java | 42 ++++++ .../onap/aai/dmaap/AAIDmaapEventJMSProducer.java | 14 +- .../main/java/org/onap/aai/dmaap/JMSConsumer.java | 160 ++++++++++++++++++++ .../main/java/org/onap/aai/dmaap/JMSProducer.java | 58 +++++++ .../java/org/onap/aai/dmaap/MessageProducer.java | 29 ++++ .../org/onap/aai/introspection/ModelInjestor.java | 31 +++- .../org/onap/aai/introspection/MoxyLoader.java | 18 ++- .../org/onap/aai/util/AAIApiServerURLBase.java | 35 ++--- .../main/java/org/onap/aai/util/AAICSVWriter.java | 168 --------------------- .../src/main/java/org/onap/aai/util/AAIConfig.java | 9 -- .../org/onap/aai/util/StoreNotificationEvent.java | 47 +++++- 12 files changed, 506 insertions(+), 215 deletions(-) create mode 100644 aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java create mode 100644 aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java create mode 100644 aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java create mode 100644 aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java create mode 100644 aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java delete mode 100644 aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java (limited to 'aai-core/src/main') diff --git a/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java b/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java new file mode 100644 index 00000000..313775d9 --- /dev/null +++ b/aai-core/src/main/java/org/onap/aai/config/DmaapConfig.java @@ -0,0 +1,110 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.aai.config; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.command.ActiveMQQueue; +import org.onap.aai.dmaap.JMSConsumer; +import org.onap.aai.dmaap.JMSProducer; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.jms.connection.CachingConnectionFactory; +import org.springframework.jms.core.JmsTemplate; +import org.springframework.jms.listener.DefaultMessageListenerContainer; + +import javax.annotation.PostConstruct; + +@Profile("dmaap") +@Configuration +public class DmaapConfig { + + @Value("${jms.bind.address}") + private String bindAddress; + + @PostConstruct + public void init(){ + System.setProperty("activemq.tcp.url", bindAddress); + } + + @Bean(destroyMethod = "stop") + public BrokerService brokerService() throws Exception { + + BrokerService broker = new BrokerService(); + broker.addConnector(bindAddress); + broker.setPersistent(false); + broker.setUseJmx(false); + broker.setSchedulerSupport(false); + broker.start(); + + return broker; + } + + @Bean(name = "connectionFactory") + public ActiveMQConnectionFactory activeMQConnectionFactory(){ + return new ActiveMQConnectionFactory(bindAddress); + } + + @Bean + public CachingConnectionFactory cachingConnectionFactory(){ + return new CachingConnectionFactory(activeMQConnectionFactory()); + } + + @Bean(name = "destinationQueue") + public ActiveMQQueue activeMQQueue(){ + return new ActiveMQQueue("IN_QUEUE"); + } + + @Bean + public JmsTemplate jmsTemplate(){ + JmsTemplate jmsTemplate = new JmsTemplate(); + + jmsTemplate.setConnectionFactory(activeMQConnectionFactory()); + jmsTemplate.setDefaultDestination(activeMQQueue()); + + return jmsTemplate; + } + + @Bean + public JMSProducer jmsProducer(){ + return new JMSProducer(); + } + + @Bean + public JMSConsumer jmsConsumer() throws Exception { + return new JMSConsumer(); + } + + @Bean + public DefaultMessageListenerContainer defaultMessageListenerContainer() throws Exception { + + DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer(); + + messageListenerContainer.setConnectionFactory(cachingConnectionFactory()); + messageListenerContainer.setDestinationName("IN_QUEUE"); + messageListenerContainer.setMessageListener(jmsConsumer()); + + return messageListenerContainer; + } +} diff --git a/aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java b/aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java new file mode 100644 index 00000000..4ab9373a --- /dev/null +++ b/aai-core/src/main/java/org/onap/aai/config/SpringContextAware.java @@ -0,0 +1,42 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.aai.config; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class SpringContextAware implements ApplicationContextAware { + + private static ApplicationContext context = null; + + public static ApplicationContext getApplicationContext() { + return context; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + context = applicationContext; + } +} diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java index 914042d4..a034b9fb 100644 --- a/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java +++ b/aai-core/src/main/java/org/onap/aai/dmaap/AAIDmaapEventJMSProducer.java @@ -24,20 +24,24 @@ package org.onap.aai.dmaap; import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.command.ActiveMQQueue; import org.json.JSONObject; +import org.onap.aai.config.SpringContextAware; import org.onap.aai.util.AAIConfig; +import org.springframework.context.ApplicationContext; import org.springframework.jms.connection.CachingConnectionFactory; import org.springframework.jms.core.JmsTemplate; -public class AAIDmaapEventJMSProducer { +public class AAIDmaapEventJMSProducer implements MessageProducer { private JmsTemplate jmsTemplate; + private ApplicationContext applicationContext; + public AAIDmaapEventJMSProducer() { if(AAIConfig.get("aai.jms.enable", "true").equals("true")){ - this.jmsTemplate = new JmsTemplate(); - String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61447"); - this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl))); - this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE")); + this.jmsTemplate = new JmsTemplate(); + String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547"); + this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl))); + this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE")); } } diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java b/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java new file mode 100644 index 00000000..b7638876 --- /dev/null +++ b/aai-core/src/main/java/org/onap/aai/dmaap/JMSConsumer.java @@ -0,0 +1,160 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.aai.dmaap; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.log4j.MDC; +import org.json.JSONException; +import org.json.JSONObject; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.logging.LoggingContext.LoggingField; +import org.onap.aai.logging.LoggingContext.StatusCode; +import org.springframework.cloud.client.ServiceInstance; +import org.springframework.cloud.client.loadbalancer.LoadBalancerClient; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.web.client.RestTemplate; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.TextMessage; +import java.util.Base64; +import java.util.Collections; + +public class JMSConsumer implements MessageListener { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(JMSConsumer.class); + + private static final int HTTPS_PORT = 3905; + private static final Base64.Encoder base64Encoder = Base64.getEncoder(); + + private HttpHeaders httpHeaders; + private RestTemplate restTemplate; + + private Environment environment; + private LoadBalancerClient loadBalancerClient; + + public JMSConsumer() throws Exception { + this((LoadBalancerClient)SpringContextAware.getApplicationContext().getBean("loadBalancerClient")); + } + + public JMSConsumer(LoadBalancerClient loadBalancerClient) throws Exception { + this.loadBalancerClient = loadBalancerClient; + this.httpHeaders = new HttpHeaders(); + this.httpHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + this.environment = SpringContextAware.getApplicationContext().getEnvironment(); + + String username = this.environment.getProperty("dmaap.ribbon.username"); + String password = this.environment.getProperty("dmaap.ribbon.password"); + + if(username == null || password == null){ + throw new Exception("Unable to retrive username/password from the application properties"); + } + + String auth = String.format("%s:%s", username, password); + String authString = "Basic " + base64Encoder.encodeToString(auth.getBytes()); + httpHeaders.add("Authorization", authString); + + restTemplate = new RestTemplate(); + } + + @Override + public void onMessage(Message message) { + + String jsmMessageTxt = ""; + String aaiEvent = ""; + String eventName = ""; + + String environment = System.getProperty("lrmRO"); + if (environment == null) { + environment = ""; + } + + 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")); + } + MDC.put("targetEntity", "DMAAP"); + if (jo.getString("event-topic") != null) { + eventName = jo.getString("event-topic"); + MDC.put("targetServiceName", eventName); + } + MDC.put("serviceName", "AAI"); + MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.COMPLETE.toString()); + MDC.put(LoggingField.RESPONSE_CODE.toString(), "0"); + LOGGER.info(eventName + "|" + aaiEvent); + + HttpEntity httpEntity = new HttpEntity<>(aaiEvent, httpHeaders); + ServiceInstance serviceInstance = loadBalancerClient.choose("dmaap"); + String url = serviceInstance.getHost() + ":" + serviceInstance.getPort(); + + if(serviceInstance.getPort() == HTTPS_PORT){ + url = "https://" + url; + } else { + url = "http://" + url; + } + + url += "/events/" + eventName; + + if ("AAI-EVENT".equals(eventName)) { + restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); + LOGGER.info(eventName + "|Event sent."); + } else if ("AAI-VCE-INTERFACE-DATA".equals(eventName)) { + restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class); + String msg = ""; + LOGGER.info(eventName + "|Event sent. " + msg); + } else { + MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString()); + MDC.put(LoggingField.RESPONSE_CODE.toString(), "900"); + LOGGER.error(eventName + "|Event Topic invalid."); + } + } catch (JMSException | JSONException e) { + MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString()); + MDC.put(LoggingField.RESPONSE_CODE.toString(), "200"); + LOGGER.error("AAI_7350 Error parsing aaievent jms message for sending to dmaap. " + jsmMessageTxt, e); + } catch (Exception e) { + MDC.put(LoggingField.STATUS_CODE.toString(), StatusCode.ERROR.toString()); + MDC.put(LoggingField.RESPONSE_CODE.toString(), "200"); + LOGGER.error("AAI_7350 Error sending message to dmaap. " + jsmMessageTxt, e); + } + } + + } + +} \ No newline at end of file diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java new file mode 100644 index 00000000..6dbfbb77 --- /dev/null +++ b/aai-core/src/main/java/org/onap/aai/dmaap/JMSProducer.java @@ -0,0 +1,58 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.aai.dmaap; + +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.command.ActiveMQQueue; +import org.json.JSONObject; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.util.AAIConfig; +import org.springframework.context.ApplicationContext; +import org.springframework.jms.connection.CachingConnectionFactory; +import org.springframework.jms.core.JmsTemplate; + +public class JMSProducer implements MessageProducer { + + private JmsTemplate jmsTemplate; + + private ApplicationContext applicationContext; + + public JMSProducer() { + if(AAIConfig.get("aai.jms.enable", "true").equals("true")){ + applicationContext = SpringContextAware.getApplicationContext(); + if(applicationContext == null){ + this.jmsTemplate = new JmsTemplate(); + String activeMqTcpUrl = System.getProperty("activemq.tcp.url", "tcp://localhost:61547"); + this.jmsTemplate.setConnectionFactory(new CachingConnectionFactory(new ActiveMQConnectionFactory(activeMqTcpUrl))); + this.jmsTemplate.setDefaultDestination(new ActiveMQQueue("IN_QUEUE")); + } else { + jmsTemplate = (JmsTemplate) applicationContext.getBean("jmsTemplate"); + } + } + } + + public void sendMessageToDefaultDestination(JSONObject finalJson) { + if(jmsTemplate != null){ + jmsTemplate.convertAndSend(finalJson.toString()); + } + } +} diff --git a/aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java b/aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java new file mode 100644 index 00000000..229ba1a5 --- /dev/null +++ b/aai-core/src/main/java/org/onap/aai/dmaap/MessageProducer.java @@ -0,0 +1,29 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.aai.dmaap; + +import org.json.JSONObject; + +public interface MessageProducer { + + void sendMessageToDefaultDestination(JSONObject finalJson); +} diff --git a/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java b/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java index c670e946..524dcbf0 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/ModelInjestor.java @@ -21,6 +21,8 @@ */ package org.onap.aai.introspection; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.eclipse.persistence.dynamic.DynamicType; import org.eclipse.persistence.jaxb.JAXBContextProperties; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; @@ -42,6 +44,7 @@ public class ModelInjestor { private Map versionContextMap = new HashMap<>(); private static final Pattern classNamePattern = Pattern.compile("\\.(v\\d+)\\."); private static final Pattern uriPattern = Pattern.compile("(v\\d+)\\/"); + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ModelInjestor.class); /** @@ -90,8 +93,24 @@ public class ModelInjestor { */ private void injestModel (Version version) throws JAXBException, FileNotFoundException { String fileName = this.getOXMFileName(version); - InputStream iStream = new FileInputStream(new File(fileName)); - Map properties = new HashMap(); + + File oxmFile = new File(AAIConstants.AAI_HOME_ETC + fileName); + + // Check if the file exists on the path and if it doesn't exist then + // Using classloader makes it easy to have a different oxm file + // for unit testing the oxm files otherwise, you will be + // stuck with using the main oxm for even the testing + + InputStream iStream; + if(oxmFile.exists()){ + LOGGER.info("Oxm file exists on the system {}", oxmFile); + iStream = new FileInputStream(oxmFile); + } else { + LOGGER.warn("Unable to find oxm file {} on the system so using classloader", oxmFile); + iStream = getClass().getClassLoader().getResourceAsStream(fileName); + } + + Map properties = new HashMap(); properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, iStream); final DynamicJAXBContext jaxbContext = DynamicJAXBContextFactory.createContextFromOXM(this.getClass().getClassLoader(), properties); versionContextMap.put(version, jaxbContext); @@ -168,7 +187,13 @@ public class ModelInjestor { } public String getOXMFileName(Version v) { - return AAIConstants.AAI_HOME_ETC_OXM + "aai_oxm_" + v.toString() + ".xml"; + // Changed the /oxm/aai_oxm_*.xml to oxm/aai_oxm_*.xml + // Modified to load from input stream using getClass().getClassLoader() + // As this will be able to relatively get the oxm if the oxm file is there + // So if there is a src/main/resources/oxm/ and src/test/resources/oxm, the + // test oxm will end up being used for tests and src oxm for source files + // Don't change this unless you understand the details specified + return "oxm/aai_oxm_" + v.toString() + ".xml"; } } diff --git a/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java b/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java index 56ad2dc2..a2a673ec 100644 --- a/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java +++ b/aai-core/src/main/java/org/onap/aai/introspection/MoxyLoader.java @@ -34,6 +34,7 @@ import org.onap.aai.introspection.exceptions.AAIUnmarshallingException; import org.onap.aai.logging.ErrorLogHelper; import org.onap.aai.logging.LogFormatTools; import org.onap.aai.restcore.MediaType; +import org.onap.aai.util.AAIConstants; import org.onap.aai.workarounds.NamingExceptions; import org.w3c.dom.Document; import org.w3c.dom.NodeList; @@ -46,8 +47,7 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.stream.StreamSource; -import java.io.IOException; -import java.io.StringReader; +import java.io.*; import java.util.HashSet; import java.util.Map; import java.util.Set; @@ -176,7 +176,19 @@ public class MoxyLoader extends Loader { docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); - final Document doc = docBuilder.parse(fileName); + + InputStream inputStream; + File oxmFile = new File(AAIConstants.AAI_HOME_ETC + fileName); + + if(oxmFile.exists()){ + LOGGER.info("Oxm file exists on the system {}", oxmFile); + inputStream = new FileInputStream(oxmFile); + } else { + LOGGER.warn("Unable to find oxm file {} on the system so using classloader", oxmFile); + inputStream = getClass().getClassLoader().getResourceAsStream(fileName); + } + + final Document doc = docBuilder.parse(inputStream); final NodeList list = doc.getElementsByTagName("java-type"); for (int i = 0; i < list.getLength(); i++) { diff --git a/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java b/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java index e458c4f9..68869909 100644 --- a/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java +++ b/aai-core/src/main/java/org/onap/aai/util/AAIApiServerURLBase.java @@ -21,13 +21,6 @@ */ package org.onap.aai.util; -import java.util.List; -import java.util.Map; - -import org.apache.cxf.helpers.CastUtils; -import org.apache.cxf.message.Message; -import org.apache.cxf.phase.PhaseInterceptorChain; - import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Version; @@ -42,20 +35,20 @@ public class AAIApiServerURLBase { public static String get() throws AAIException { String hostName = null; - try { - Message message = PhaseInterceptorChain.getCurrentMessage(); - Map> headers = CastUtils.cast((Map) message.get(Message.PROTOCOL_HEADERS)); - List sa = null; - if (headers != null) { - sa = headers.get("host"); - } - - if (sa != null && sa.size() == 1) { - hostName = "https://"+ sa.get(0).toString() + "/aai/"; - } - } catch (Exception e) { - // TODO: we may want to log an error here - } +// try { +// Message message = PhaseInterceptorChain.getCurrentMessage(); +// Map> headers = CastUtils.cast((Map) message.get(Message.PROTOCOL_HEADERS)); +// List sa = null; +// if (headers != null) { +// sa = headers.get("host"); +// } +// +// if (sa != null && sa.size() == 1) { +// hostName = "https://"+ sa.get(0).toString() + "/aai/"; +// } +// } catch (Exception e) { +// // TODO: we may want to log an error here +// } // TODO: should this check the value a little closer and look for a pattern? if (hostName == null) { hostName = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE); diff --git a/aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java b/aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java deleted file mode 100644 index c091fc24..00000000 --- a/aai-core/src/main/java/org/onap/aai/util/AAICSVWriter.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - */ -/** - * - */ -package org.onap.aai.util; - -import java.io.IOException; -import java.io.PrintWriter; -import java.io.Writer; - -import com.opencsv.CSVWriter; - -/** - * had to overwrite the separate character to separate string - * Based on the public - A very simple CSV writer released under a commercial-friendly license. - * - - */ -public class AAICSVWriter extends CSVWriter { - - private String separatorStr; - private char overridequotechar; - private String overridelineEnd; - private Writer rawWriter; - private PrintWriter pw; - - /** - * Instantiates a new AAICSV writer. - * - * @param writer the writer - */ - public AAICSVWriter(Writer writer) { - super(writer); - // TODO Auto-generated constructor stub - } - - /** - * Constructs AAICSVWriter with supplied separator string and quote char. - * - * @param writer the writer to an underlying CSV source. - * @param overrideseparator the overrideseparator - * @param quotechar the character to use for quoted elements - * @param lineEnd the line feed terminator to use - */ - public AAICSVWriter(Writer writer, String overrideseparator, char quotechar, String lineEnd) { - super(writer, CSVWriter.DEFAULT_SEPARATOR, quotechar, DEFAULT_ESCAPE_CHARACTER, lineEnd); - separatorStr = overrideseparator; - overridequotechar = quotechar; - overridelineEnd = lineEnd; - this.rawWriter = writer; - this.pw = new PrintWriter(writer); - } - - /** - * String contains special characters. - * - * @param line the line - * @return true, if successful - */ - private boolean stringContainsSpecialCharacters(String line) { - return line.indexOf(overridequotechar) != -1 || line.indexOf(DEFAULT_ESCAPE_CHARACTER) != -1 || line.indexOf(separatorStr) != -1 || line.contains("\n") || line.contains("\r"); - } - - /** - * Close the underlying stream writer flushing any buffered content. - * - * @throws IOException if bad things happen - */ - public void close() throws IOException { - flush(); - pw.close(); - rawWriter.close(); - } - - /** - * Writes the next line to the file. - * - * @param nextLine a string array with each comma-separated element as a separate - * entry. - * @param applyQuotesToAll true if all values are to be quoted. false applies quotes only - * to values which contain the separator, escape, quote or new line characters. - */ - public void writeNext(String[] nextLine, boolean applyQuotesToAll) { - - if (nextLine == null) - return; - - StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE); - for (int i = 0; i < nextLine.length; i++) { - - if (i != 0) { - sb.append(separatorStr); - } - - String nextElement = nextLine[i]; - - if (nextElement == null) - continue; - - Boolean stringContainsSpecialCharacters = stringContainsSpecialCharacters(nextElement); - - if ((applyQuotesToAll || stringContainsSpecialCharacters) && overridequotechar != NO_QUOTE_CHARACTER) - sb.append(overridequotechar); - - if (stringContainsSpecialCharacters) { - sb.append(processLine(nextElement)); - } else { - sb.append(nextElement); - } - - if ((applyQuotesToAll || stringContainsSpecialCharacters) && overridequotechar != NO_QUOTE_CHARACTER) - sb.append(overridequotechar); - } - - sb.append(overridelineEnd); - pw.write(sb.toString()); - } - - - /** - * Writes the next line to the file ignoring all exceptions. - * - * @param nextLine a string array with each comma-separated element as a separate - * entry. - */ - public void writeColumn(String[] nextLine) { - - if (nextLine == null) - return; - - StringBuilder sb = new StringBuilder(INITIAL_STRING_SIZE); - for (int i = 0; i < nextLine.length; i++) { - - - String nextElement = nextLine[i]; - - if (nextElement == null) - continue; - - sb.append(nextElement); - - - } - - sb.append(overridelineEnd); - pw.write(sb.toString()); - } -} diff --git a/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java b/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java index 57bf2cc7..6f904970 100644 --- a/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java +++ b/aai-core/src/main/java/org/onap/aai/util/AAIConfig.java @@ -52,8 +52,6 @@ public class AAIConfig { // this (probably) won't change between releases, put it in the config if it gets annoying... private static HashMap> defaultBools = new HashMap>(); - private static Timer timer = new Timer(); - /** * Instantiates a new AAI config. */ @@ -122,13 +120,6 @@ public class AAIConfig { return defaultBools; } - /** - * Cleanup. - */ - public static void cleanup() { - timer.cancel(); - } - /** * Gets the config file. * diff --git a/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java b/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java index 0ad33cb9..2a64e996 100644 --- a/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java +++ b/aai-core/src/main/java/org/onap/aai/util/StoreNotificationEvent.java @@ -27,35 +27,70 @@ import java.util.UUID; import javax.xml.bind.Marshaller; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.eclipse.persistence.dynamic.DynamicEntity; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.json.JSONException; import org.json.JSONObject; +import org.onap.aai.config.SpringContextAware; import org.onap.aai.dmaap.AAIDmaapEventJMSProducer; +import org.onap.aai.dmaap.JMSProducer; +import org.onap.aai.dmaap.MessageProducer; import org.onap.aai.domain.notificationEvent.NotificationEvent; import org.onap.aai.exceptions.AAIException; import org.onap.aai.introspection.Introspector; import org.onap.aai.introspection.Loader; import org.onap.aai.introspection.exceptions.AAIUnknownObjectException; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.context.ApplicationContext; +import org.springframework.core.env.Environment; public class StoreNotificationEvent { - private AAIDmaapEventJMSProducer messageProducer; + private static final EELFLogger logger = EELFManager.getInstance().getLogger(StoreNotificationEvent.class); + private MessageProducer messageProducer; private String fromAppId = ""; private String transId = ""; private final String transactionId; private final String sourceOfTruth; + + private ApplicationContext context; + private Environment env; + /** * Instantiates a new store notification event. */ public StoreNotificationEvent(String transactionId, String sourceOfTruth) { - this(new AAIDmaapEventJMSProducer(), transactionId, sourceOfTruth); + this.context = SpringContextAware.getApplicationContext(); + // If the context is null then this is being invoked from + // non spring context so creating the jms producer each time + // Otherwise, get the jms producer from the spring context so + // no need to create a instance of this each time + // Also check if the environment has the dmaap profile + // TODO - Add the constants for profile so do this when adding the https two-way ssl and one way with basic auth + if(this.context == null){ + this.messageProducer = new AAIDmaapEventJMSProducer(); + } else { + env = context.getEnvironment(); + if(env.acceptsProfiles("dmaap")){ + try { + this.messageProducer = (JMSProducer)context.getBean("jmsProducer"); + } catch(NoSuchBeanDefinitionException ex){ + logger.error("Currently using the dmaap profile but still not able to find bean so check DmaapConfig", ex); + } + } else { + this.messageProducer = new AAIDmaapEventJMSProducer(); + } + } + this.transactionId = transactionId; + this.sourceOfTruth = sourceOfTruth; } - + public StoreNotificationEvent(AAIDmaapEventJMSProducer producer, String transactionId, String sourceOfTruth) { - this.messageProducer = producer; - this.transactionId = transactionId; - this.sourceOfTruth = sourceOfTruth; + this.messageProducer = producer; + this.transactionId = transactionId; + this.sourceOfTruth = sourceOfTruth; } /** -- cgit 1.2.3-korg