diff --git a/javaUtilities/com.raytheon.wes2bridge.manager/META-INF/MANIFEST.MF b/javaUtilities/com.raytheon.wes2bridge.manager/META-INF/MANIFEST.MF index b2a3ee4147..41c95f3a62 100644 --- a/javaUtilities/com.raytheon.wes2bridge.manager/META-INF/MANIFEST.MF +++ b/javaUtilities/com.raytheon.wes2bridge.manager/META-INF/MANIFEST.MF @@ -4,6 +4,7 @@ Bundle-Name: Wes2Bridge Manager Bundle-SymbolicName: com.raytheon.wes2bridge.manager Bundle-Version: 1.0.0.qualifier Bundle-Vendor: RAYTHEON -Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Require-Bundle: com.raytheon.wes2bridge.common;bundle-version="1.0.0", - org.apache.commons.lang;bundle-version="2.3.0" + org.apache.commons.lang;bundle-version="2.3.0", + org.codehaus.jackson;bundle-version="1.7.3" diff --git a/javaUtilities/com.raytheon.wes2bridge.manager/build.xml b/javaUtilities/com.raytheon.wes2bridge.manager/build.xml index e0ee4a8ab9..0a0d2eca93 100644 --- a/javaUtilities/com.raytheon.wes2bridge.manager/build.xml +++ b/javaUtilities/com.raytheon.wes2bridge.manager/build.xml @@ -11,7 +11,7 @@ - + @@ -36,6 +36,9 @@ + + + diff --git a/javaUtilities/com.raytheon.wes2bridge.manager/src/com/raytheon/wes2bridge/manager/IQpidConfigurationXML.java b/javaUtilities/com.raytheon.wes2bridge.manager/src/com/raytheon/wes2bridge/manager/IQpidConfigurationXML.java deleted file mode 100644 index bc036eeb47..0000000000 --- a/javaUtilities/com.raytheon.wes2bridge.manager/src/com/raytheon/wes2bridge/manager/IQpidConfigurationXML.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * This software was developed and / or modified by Raytheon Company, - * pursuant to Contract DG133W-05-CQ-1067 with the US Government. - * - * U.S. EXPORT CONTROLLED TECHNICAL DATA - * This software product contains export-restricted data whose - * export/transfer/disclosure is restricted by U.S. law. Dissemination - * to non-U.S. persons whether in the United States or abroad requires - * an export license or other authorization. - * - * Contractor Name: Raytheon Company - * Contractor Address: 6825 Pine Street, Suite 340 - * Mail Stop B8 - * Omaha, NE 68106 - * 402.291.0100 - * - * See the AWIPS II Master Rights File ("Master Rights File.pdf") for - * further licensing information. - **/ -package com.raytheon.wes2bridge.manager; - -/** - * Identifies XML tag names of interest as constants within the qpid config.xml - * configuration. - * - *
- * 
- * SOFTWARE HISTORY
- * 
- * Date         Ticket#    Engineer    Description
- * ------------ ---------- ----------- --------------------------
- * Apr 17, 2013            bkowal     Initial creation
- * 
- * 
- * - * @author bkowal - * @version 1.0 - */ - -public interface IQpidConfigurationXML { - public static final String XML_BROKER = "broker"; - public static final String XML_CONNECTOR = "connector"; - public static final String XML_MANAGEMENT = "management"; - public static final String XML_JMXPORT = "jmxport"; - public static final String XML_HTTP = "http"; - public static final String XML_REGISTRY_SERVER = "registryServer"; - public static final String XML_PORT = "port"; -} diff --git a/javaUtilities/com.raytheon.wes2bridge.manager/src/com/raytheon/wes2bridge/manager/Wes2BridgeManager.java b/javaUtilities/com.raytheon.wes2bridge.manager/src/com/raytheon/wes2bridge/manager/Wes2BridgeManager.java index d837d1551f..1848654a15 100644 --- a/javaUtilities/com.raytheon.wes2bridge.manager/src/com/raytheon/wes2bridge/manager/Wes2BridgeManager.java +++ b/javaUtilities/com.raytheon.wes2bridge.manager/src/com/raytheon/wes2bridge/manager/Wes2BridgeManager.java @@ -26,27 +26,17 @@ import java.io.BufferedReader; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; +import java.util.ArrayList; +import java.util.Map; import java.util.regex.Pattern; import java.util.regex.Matcher; import javax.xml.bind.JAXBException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.TransformerFactoryConfigurationError; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import org.apache.commons.lang.StringUtils; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.TypeReference; -import com.raytheon.wes2bridge.manager.IQpidConfigurationXML; import com.raytheon.wes2bridge.common.configuration.Wes2BridgeCase; import com.raytheon.wes2bridge.configuration.jaxb.Wes2BridgeJaxbManager; @@ -73,6 +63,7 @@ import com.raytheon.wes2bridge.configuration.jaxb.Wes2BridgeJaxbManager; * Aug 14, 2014 3521 bkowal Updated to use Wes2BridgeCase. Eliminated * configuration that is no longer used and * updated EDEX re-configuration. + * Apr 15, 2015 4392 dlovely Updates the new qpid json configuration now * * * @@ -101,6 +92,16 @@ public class Wes2BridgeManager { private String wes2BridgeScripts = null; + private static final TypeReference> MAP_TYPE_REFERENCE = new TypeReference>() + { + }; + + public static final String QPID_NAME = "name"; + public static final String QPID_AMQP = "AMQP"; + public static final String QPID_HTTP = "HTTP"; + public static final String QPID_PORT = "port"; + public static final String QPID_PORTS = "ports"; + /** * */ @@ -409,87 +410,60 @@ public class Wes2BridgeManager { } } - public void reconfigureQPID() throws FileNotFoundException, IOException, - ParserConfigurationException, SAXException, - TransformerFactoryConfigurationError, TransformerException { + public void reconfigureQPID() throws FileNotFoundException, IOException { final String srcQpidDirectory = AWIPSII + "/" + "qpid"; final String qpidDirectory = WES2BRIDGE_DIRECTORY + "/" + this.wes2BridgeCase.getName() + "/" + "qpid"; - this.updateQpidConfigXML(srcQpidDirectory, qpidDirectory); + this.updateQpidConfigJSON(srcQpidDirectory, qpidDirectory); this.updateQPIDD(qpidDirectory); } - /* Updates qpid config.xml */ - private void updateQpidConfigXML(String srcQpidDirectory, - String qpidDirectory) throws FileNotFoundException, IOException, - ParserConfigurationException, SAXException, - TransformerFactoryConfigurationError, TransformerException { - String srcconfig_xml = srcQpidDirectory + "/etc/config.xml"; - String config_xml = qpidDirectory + "/etc/config.xml"; + /* Updates qpid config.json */ + private void updateQpidConfigJSON(String srcQpidDirectory, + String qpidDirectory) throws FileNotFoundException, IOException { + String srcconfig_json = srcQpidDirectory + "/config.json"; + String config_json = qpidDirectory + "/config.json"; - DocumentBuilder documentBuilder = DocumentBuilderFactory.newInstance() - .newDocumentBuilder(); - Document document = documentBuilder.parse(srcconfig_xml); + ObjectMapper mapper = new ObjectMapper(); - // Get the root broker node. - Node brokerNode = document.getElementsByTagName( - IQpidConfigurationXML.XML_BROKER).item(0); - // Get the connector node. - Node connectorNode = this.getChildNodeByName(brokerNode, - IQpidConfigurationXML.XML_CONNECTOR); - // Get the management node. - Node managementNode = this.getChildNodeByName(brokerNode, - IQpidConfigurationXML.XML_MANAGEMENT); - // Get the jmxport node. - Node jmxPortNode = this.getChildNodeByName(managementNode, - IQpidConfigurationXML.XML_JMXPORT); - // Get the http port node. - Node httpPortNode = this.getChildNodeByName(managementNode, - IQpidConfigurationXML.XML_HTTP); + BufferedReader br = null; + BufferedWriter bw = null; + try { + br = this.getBufferedReader(srcconfig_json); + bw = this.getBufferedWriter(config_json); - Node portNode = null; - - // Get the connector port node. - portNode = this.getChildNodeByName(connectorNode, - IQpidConfigurationXML.XML_PORT); - portNode.setTextContent(Integer.toString(this.wes2BridgeCase - .getJmsPort())); - // Get the jmxport registryServer node - portNode = this.getChildNodeByName(jmxPortNode, - IQpidConfigurationXML.XML_REGISTRY_SERVER); - portNode.setTextContent(Integer.toString(this.wes2BridgeCase - .getQpidJmxPort())); - // Get the http port node. - portNode = this.getChildNodeByName(httpPortNode, - IQpidConfigurationXML.XML_PORT); - portNode.setTextContent(Integer.toString(this.wes2BridgeCase - .getQpidHttpPort())); - - /* - * Write the updated configuration file to its destination. - */ - Transformer transformer = TransformerFactory.newInstance() - .newTransformer(); - DOMSource domSource = new DOMSource(document); - StreamResult streamResult = new StreamResult(new File(config_xml)); - transformer.transform(domSource, streamResult); - } - - private Node getChildNodeByName(Node parentNode, String childName) { - if (parentNode.hasChildNodes() == false) { - return null; - } - - NodeList nodeList = parentNode.getChildNodes(); - for (int i = 0; i < nodeList.getLength(); i++) { - Node node = nodeList.item(i); - if (node.getNodeName().equals(childName)) { - return node; + String line = StringUtils.EMPTY; + StringBuilder stringBuilder = new StringBuilder(); + while( ( line = br.readLine() ) != null ) { + stringBuilder.append( line ); } - } - return null; + Map attributesMap = mapper.readValue(stringBuilder.toString(), MAP_TYPE_REFERENCE); + + @SuppressWarnings("unchecked") + ArrayList ports = (ArrayList) attributesMap.get(QPID_PORTS); + + for(int x = 0; x < ports.size(); x++) { + @SuppressWarnings("unchecked") + Map port = (Map) ports.get(x); + String name = (String) port.get(QPID_NAME); + if (QPID_AMQP.equals(name)) { + port.put(QPID_PORT, this.wes2BridgeCase.getQpidJmxPort()); + } else if (QPID_HTTP.equals(name)) { + port.put(QPID_PORT, this.wes2BridgeCase.getQpidHttpPort()); + } + } + + /* + * Write the updated configuration file to its destination. + */ + mapper.defaultPrettyPrintingWriter().writeValue(bw, attributesMap); + + } finally { + br.close(); + bw.close(); + } } private void updateQPIDD(String qpidDirectory)