summaryrefslogtreecommitdiff
path: root/java/broker-plugins/experimental/info/src/main
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2010-06-22 13:42:41 +0000
committerMartin Ritchie <ritchiem@apache.org>2010-06-22 13:42:41 +0000
commit7b97af3ddcc281d7fe52c60e85aafadd77392cfd (patch)
tree01ef91a9738f2291b7bbe187719d240d07fcb4c4 /java/broker-plugins/experimental/info/src/main
parent3eac722310cc6a60d68fca6d8a73dcb7d5a73083 (diff)
downloadqpid-python-7b97af3ddcc281d7fe52c60e85aafadd77392cfd.tar.gz
Qpid-2555 Patch 4 provided by Sorin Suciu, based on local review comments
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@956893 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/broker-plugins/experimental/info/src/main')
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java124
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java27
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java78
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java20
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java11
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java66
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java82
-rw-r--r--java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java85
8 files changed, 260 insertions, 233 deletions
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java
index a442cf1f28..c7d3fd38ff 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java
@@ -21,70 +21,52 @@
package org.apache.qpid.info;
-import java.io.File;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
import org.apache.qpid.info.util.HttpPoster;
import org.apache.qpid.info.util.IniFileReader;
import org.apache.qpid.info.util.SoapClient;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-/**
- * The Activator class for the OSGI info service
- *
- */
+import java.io.File;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/** The Activator class for the OSGI info service */
public class Activator implements BundleActivator
{
- private final List<String> soapPropList = Arrays.asList("soap.hostname",
- "soap.port", "soap.path", "soap.action", "soap.envelope");
+ private final List<String> _soapPropList = Arrays.asList("soap.hostname",
+ "soap.port", "soap.path", "soap.action", "soap.envelope");
- private final List<String> httpPropList = Arrays.asList("http.url",
- "http.envelope");
+ private final List<String> _httpPropList = Arrays.asList("http.url",
+ "http.envelope");
- InfoServiceImpl service = null;
+ InfoServiceImpl _service = null;
BundleContext _ctx = null;
- Map<String, Properties> infoprops = new HashMap<String, Properties>();
-
/**
* Start bundle method
- *
- * @param ctx
- * the bundle context
+ *
+ * @param ctx the bundle context
*/
public void start(BundleContext ctx) throws Exception
{
if (null != ctx)
{
_ctx = ctx;
- service = new InfoServiceImpl();
- ctx.registerService(InfoService.class.getName(), service, null);
+ _service = new InfoServiceImpl();
+ ctx.registerService(InfoService.class.getName(), _service, null);
sendInfo("STARTUP");
}
}
/**
- * Getter for the bundle context
- *
- * @return BundleContext the bundle context
- */
- public BundleContext getBundleContext()
- {
- return _ctx;
- }
-
- /**
* Stop the bundle method
- *
- * @param ctx
- * the bundle context
+ *
+ * @param ctx the bundle context
*/
public void stop(BundleContext ctx) throws Exception
{
@@ -93,13 +75,12 @@ public class Activator implements BundleActivator
/**
* Sends the information message
- *
- * @param action
- * label that identifies if we are starting up or shutting down
+ *
+ * @param action label that identifies if we are starting up or shutting down
*/
private void sendInfo(String action)
{
- if ((null == _ctx) && (null == service))
+ if ((null == _ctx) && (null == _service))
{
// invalid state
return;
@@ -110,37 +91,35 @@ public class Activator implements BundleActivator
{
String QPID_HOME = System.getProperty("QPID_HOME");
String cfgFilePath = QPID_HOME + File.separator + "etc"
- + File.separator + "qpidinfo.properties";
+ + File.separator + "qpidinfo.ini";
ifr.load(cfgFilePath);
- } catch (Exception ex)
+ }
+ catch (Throwable ex)
{
- // drop the exception
+ // drop everything to be silent
return;
}
- // If we have no sections, something has gone really wrong, abort
- if (ifr.getSections().size() == 0)
- return;
-
- Info<? extends Map<String, ?>> info = service.invoke(action);
- String protocol = ifr.getSections().get("").getProperty("protocol");
- sendMessages(protocol, ifr, info);
+ // Only send Messages if we have some sections.
+ if (ifr.getSections().size() != 0)
+ {
+ Info<? extends Map<String, ?>> info = _service.invoke(action);
+ String protocol = ifr.getSections().get("").getProperty("protocol");
+ sendMessages(protocol, ifr, info);
+ }
}
/**
* Sends all the messages configured in the properties file
- *
- * @param protocol
- * indicates what protocol to be used: http and soap implemented
- * for now
- * @param ifr
- * an instance of IniFileReader class
- * @param info
- * an instance of an Info object, encapsulating the information
- * we want to send
+ *
+ * @param protocol indicates what protocol to be used: http and soap implemented
+ * for now
+ * @param ifr an instance of IniFileReader class
+ * @param info an instance of an Info object, encapsulating the information
+ * we want to send
*/
private void sendMessages(String protocol, IniFileReader ifr,
- Info<? extends Map<String, ?>> info)
+ Info<? extends Map<String, ?>> info)
{
if (null != protocol)
{
@@ -152,7 +131,9 @@ public class Activator implements BundleActivator
{
// Skip the defaults
if (section.equals(""))
+ {
continue;
+ }
Properties props = new Properties();
props.putAll(defaultProps);
props.putAll(ifr.getSections().get(section));
@@ -162,7 +143,8 @@ public class Activator implements BundleActivator
}
}
- } else if (protocol.toLowerCase().startsWith("soap"))
+ }
+ else if (protocol.toLowerCase().startsWith("soap"))
{
for (String section : ifr.getSections().keySet())
{
@@ -175,38 +157,38 @@ public class Activator implements BundleActivator
}
}
}
- } else
- {
- return;
}
}
/**
* Checks if the properties for a specified protocol are valid
- *
- * @param protocol
- * String representing the protocol
- * @param props
- * The properties associate with the specified protocol
+ *
+ * @param protocol String representing the protocol
+ * @param props The properties associate with the specified protocol
+ * @return boolean
*/
private boolean isValid(String protocol, Properties props)
{
if (null == protocol)
+ {
return false;
+ }
String value = "";
if (protocol.toLowerCase().startsWith("http"))
{
- for (String prop : httpPropList)
+ for (String prop : _httpPropList)
{
if (null == props.get(prop))
+ {
return false;
+ }
}
return true;
}
if (protocol.toLowerCase().startsWith("soap"))
{
- for (String prop : soapPropList)
+ for (String prop : _soapPropList)
{
value = props.getProperty(prop);
if (null == value)
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
index 15d9f6f55f..a5d267282b 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/AppInfo.java
@@ -21,34 +21,32 @@
package org.apache.qpid.info;
+import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import java.util.TreeMap;
-import java.util.Map.Entry;
-import org.apache.qpid.common.QpidProperties;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-
-/**
- * AppInfo class is gathering application specific informations
- *
- */
+/** AppInfo class is gathering application specific information */
public class AppInfo
{
private static final List<String> appProps = Arrays.asList("QPID_HOME",
- "QPID_WORK");
+ "QPID_WORK");
private static Map<String, String> appInfoMap = new TreeMap<String, String>();
/**
* getInfo method retrieves a key-value map for specific application properties
+ *
* @return Map<String,String>
- */
+ */
public static Map<String, String> getInfo()
{
@@ -76,8 +74,6 @@ public class AppInfo
appInfoMap.put("port", sc.getPorts().toString());
appInfoMap.put("version", QpidProperties.getReleaseVersion());
appInfoMap.put("vhosts", "standalone");
- // brokerInfoMap.put("DefaultVirtualHost",
- // sc.getDefaultVirtualHost());
appInfoMap.put("JMXPrincipalDatabase", sc
.getJMXPrincipalDatabase());
appInfoMap.put("KeystorePath", sc.getKeystorePath());
@@ -86,9 +82,10 @@ public class AppInfo
appInfoMap.put("QpidWork", sc.getQpidWork());
appInfoMap.put("Bind", sc.getBind());
}
- } catch (Exception e)
+ }
+ catch (Exception e)
{
- //
+ // drop everything to be silent
}
return appInfoMap;
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java
index 2c6db8df12..2fb9382526 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java
@@ -20,31 +20,32 @@
*/
/**
- *
+ *
* @author sorin
- *
+ *
* Info object
*/
package org.apache.qpid.info;
+import org.apache.qpid.info.util.XMLWriter;
+
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
-import org.apache.qpid.info.util.XMLWriter;
-
/**
- * The Info class encapsulates all the informations we are collecting
- * and it is able to render it in different data representations
+ * The Info class encapsulates all the information we are collecting
+ * and it is able to render it in different data representations
*/
public class Info<T extends Map<String, ?>>
{
private T _info;
/**
- * Constructor.
+ * Constructor.
+ *
* @param info instantiates the object with a Map<String,?>
*/
public Info(T info)
@@ -65,24 +66,32 @@ public class Info<T extends Map<String, ?>>
}
/**
- * Renders Info map to a property object
- * @return A Properties object representing the Info map
+ * Renders Info map to a property object
+ *
+ * @return A Properties object representing the Info map
*/
- public Properties toProps() {
+ public Properties toProps()
+ {
Properties props = new Properties();
- if (null==_info) return null;
- for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) {
- String key = it.next();
- props.put(key, _info.get(key));
+ if (null == _info)
+ {
+ return null;
+ }
+ for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
+ {
+ String key = it.next();
+ props.put(key, _info.get(key));
}
return props;
}
-
+
/**
- * Renders Info map to a StringBuffer
- * @return A StringBuffer object representing the Info map
+ * Renders Info map to a StringBuffer
+ *
+ * @return A StringBuffer object representing the Info map
*/
- public StringBuffer toStringBuffer() {
+ public StringBuffer toStringBuffer()
+ {
StringBuffer sb = new StringBuffer();
for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
{
@@ -91,37 +100,42 @@ public class Info<T extends Map<String, ?>>
}
return sb;
}
-
+
/**
- * Renders Info map to a StringBuffer containing an XML string
- * @return A StringBuffer object containing an XML representation of the Info map
+ * Renders Info map to a StringBuffer containing an XML string
+ *
+ * @return A StringBuffer object containing an XML representation of the Info map
*/
- public StringBuffer toXML()
+ public StringBuffer toXML()
{
XMLWriter xw = new XMLWriter(new StringBuffer());
xw.writeXMLHeader();
Map<String, String> attr = new HashMap<String, String>();
xw.writeOpenTag("qpidinfo", attr);
String key;
- for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) {
+ for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
+ {
attr.clear();
key = it.next();
- xw.writeTag(key, attr, _info.get(key).toString());
- }
+ xw.writeTag(key, attr, _info.get(key).toString());
+ }
xw.writeCloseTag("qpidinfo");
return xw.getXML();
}
-
+
/**
- * Renders Info map to a HashMap
- * @return A HashMap object representing the Info map
+ * Renders Info map to a HashMap
+ *
+ * @return A HashMap object representing the Info map
*/
- public HashMap<String,String> toMap() {
+ public HashMap<String, String> toMap()
+ {
String key;
- HashMap<String,String> infoMap = new HashMap<String,String>();
- for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) {
+ HashMap<String, String> infoMap = new HashMap<String, String>();
+ for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();)
+ {
key = it.next();
- infoMap.put(key, _info.get(key).toString());
+ infoMap.put(key, _info.get(key).toString());
}
return infoMap;
}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
index a2ffaea3bb..5522f2701e 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/InfoServiceImpl.java
@@ -20,9 +20,9 @@
*/
/**
- *
+ *
* @author sorin
- *
+ *
* Implementation for Info service
*/
@@ -39,28 +39,28 @@ public class InfoServiceImpl implements InfoService
{
SortedMap<String, String> infoMap = new TreeMap<String, String>();
-
+
/**
- * invoke method collects all the informations from System and Application
- * and encapsulates them in an Info object
- * @return An instance of an Info object
+ * invoke method collects all the information from System and Application
+ * and encapsulates them in an Info object
+ * @return An instance of an Info object
*/
public Info<? extends Map<String,?>> invoke(String action)
{
// Record the action (STARTUP/SHUTDOWN)
infoMap.put("action",action);
-
+
// Record the current time stamp
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
infoMap.put("time", sdf.format(Calendar.getInstance().getTime()));
-
+
// Add the system specific properties
infoMap.putAll(SystemInfo.getInfo());
// Add the application specific properties
infoMap.putAll(AppInfo.getInfo());
-
+
return new Info<SortedMap<String, String>>(infoMap);
- }
+ }
}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
index 25095b62dc..8bd94fe14d 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/SystemInfo.java
@@ -32,7 +32,7 @@ import java.util.TreeMap;
import java.util.Map.Entry;
/**
- * Collector for system specific information
+ * Collector for system specific information
*/
public class SystemInfo
{
@@ -46,8 +46,8 @@ public class SystemInfo
"user.home", "user.dir", "user.name", "user.timezone");
/**
- * getInfo collects all the properties specified in sysprops list
- * @return A Map<String,String>
+ * getInfo collects all the properties specified in sysprops list
+ * @return A Map<String,String>
*/
public static Map<String, String> getInfo()
{
@@ -59,9 +59,10 @@ public class SystemInfo
String hostname = addr.getHostName();
sysInfoMap.put("hostname", hostname);
sysInfoMap.put("ip", addr.getHostAddress());
- } catch (UnknownHostException e)
+ }
+ catch (UnknownHostException e)
{
- //
+ // drop everything to be silent
}
// Get the runtime info
sysInfoMap.put("CPUCores", Runtime.getRuntime().availableProcessors()
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
index a9cd96845c..d27980be05 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
@@ -40,63 +40,67 @@ import java.net.UnknownHostException;
*/
public class HttpPoster implements Runnable
{
- private final String url;
+ private final String _url;
- private final Hashtable<String, String> header;
+ private final Hashtable<String, String> _header;
- private final List<String> response = new ArrayList<String>();
+ private final List<String> _response = new ArrayList<String>();
private final StringBuffer _buf;
/**
* Constructor
- * @param props Properties containing the URL
- * @param buf Buffer containing the message to be posted
+ *
+ * @param props Properties containing the URL
+ * @param buf Buffer containing the message to be posted
*/
public HttpPoster(Properties props, StringBuffer buf)
{
_buf = buf;
if (null != props)
{
- url = props.getProperty("http.url");
- header = new Hashtable<String, String>();
+ _url = props.getProperty("http.url");
+ _header = new Hashtable<String, String>();
try
{
- String hostname = InetAddress.getLocalHost().getHostName();
- header.put("hostname", hostname);
- } catch (UnknownHostException e)
+ String hostname = InetAddress.getLocalHost().getHostName();
+ _header.put("hostname", hostname);
+ }
+ catch (UnknownHostException e)
{
- // Silently ignoring the error ;)
+ // Silently ignoring the error ;)
}
- } else
+ }
+ else
{
- url = null;
- header = null;
+ _url = null;
+ _header = null;
}
}
- /**
- * Posts the message from the _buf StringBuffer to the http server
- */
+
+ /** Posts the message from the _buf StringBuffer to the http server */
public void run()
{
- if (null == url)
+ if (null == _url)
+ {
return;
+ }
String line;
URL urlDest;
URLConnection urlConn;
try
{
- urlDest = new URL(url);
+ urlDest = new URL(_url);
urlConn = urlDest.openConnection();
urlConn.setDoOutput(true);
urlConn.setUseCaches(false);
- for (Iterator<String> it = header.keySet().iterator(); it.hasNext();)
+ for (Iterator<String> it = _header.keySet().iterator(); it.hasNext();)
{
- String prop = (String) it.next();
- urlConn.setRequestProperty(prop, header.get(prop));
+ String prop = it.next();
+ urlConn.setRequestProperty(prop, _header.get(prop));
}
- OutputStreamWriter wr = new OutputStreamWriter(urlConn
- .getOutputStream());
+ OutputStreamWriter wr =
+ new OutputStreamWriter(urlConn.getOutputStream());
wr.write(_buf.toString());
wr.flush();
// Get the response
@@ -104,21 +108,23 @@ public class HttpPoster implements Runnable
urlConn.getInputStream()));
while ((line = rd.readLine()) != null)
{
- response.add(line);
+ _response.add(line);
}
- } catch (Exception ex)
+ }
+ catch (Exception ex)
{
- return;
+ // Silently ignoring the error ;)
}
}
-
+
/**
* Retrieves the response from the http server
+ *
* @return List<String> response received from the http server
*/
- public List<String> getResponse()
+ public List<String> get_response()
{
- return response;
+ return _response;
}
}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
index 3faac5aeaa..60a025d322 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java
@@ -21,37 +21,42 @@
package org.apache.qpid.info.util;
-import java.util.*;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
/**
- * This class is simple implementation of an ini file reader. It expects a
+ * This class is simple implementation of an ini file reader. It expects a
* file with the following structure:
- *
- * ; global values, can be overwritten in sections
+ *
+ * ; global values, can be overwritten in sections
* key1=value1
* key2=value2
- *
+ *
* [Section1]
* key1=value1_new ; overwriting the global key1
* key3=value3
* key4=value4
- *
+ *
* [Section2]
* key5=value5
* key6=value6
* key7=value7
- *
+ *
* Note: Commentaries are preceded by ; or # and are supported throughout
- * A commentary line at the end of section is interpreted as
- * a section end marker
- *
- * A structure <String,Properties> (section name, associated properties)
- * is generated as a result of processing the ini file.
+ * A commentary line at the end of section is interpreted as
+ * a section end marker
+ *
+ * A structure <String,Properties> (section name, associated properties)
+ * is generated as a result of processing the ini file.
*/
public class IniFileReader
{
- private final Map<String, Properties> sections;
+ private final Map<String, Properties> _sections;
private final String COMMENT_SEMICOLON = ";";
@@ -65,33 +70,45 @@ public class IniFileReader
/*
* IniFileReader constructor
*/
+
public IniFileReader()
{
- sections = new HashMap<String, Properties>();
+ _sections = new HashMap<String, Properties>();
}
/**
* Cleans up the after comments or the empty spaces/tabs surrounding the given string
- * @param str The String to be cleaned
+ *
+ * @param str The String to be cleaned
+ *
* @return String Cleanup Version
*/
private String cleanUp(String str)
{
if (str.contains(COMMENT_SEMICOLON))
+ {
str = str.substring(0, str.indexOf(COMMENT_SEMICOLON));
+ }
if (str.contains(COMMENT_HASH))
+ {
str = str.substring(0, str.indexOf(COMMENT_HASH));
+ }
return str.trim();
}
/**
* Loads and parses the ini file with the full path specified in the argument
- * @param fileName Full path to the ini file
- * @throws IllegalArgumentException If the file cannot be processed
+ *
+ * @param fileName Full path to the ini file
+ *
+ * @throws IllegalArgumentException If the file cannot be processed
*/
public void load(String fileName) throws IllegalArgumentException
{
- if (! new File(fileName).isFile()) throw new IllegalArgumentException("File: "+fileName+ " does not exist or cannot be read.");
+ if (!new File(fileName).isFile())
+ {
+ throw new IllegalArgumentException("File: " + fileName + " does not exist or cannot be read.");
+ }
State state = State.GLOBAL;
String line;
Properties sectionProps = new Properties();
@@ -104,12 +121,19 @@ public class IniFileReader
String str = cleanUp(line);
// Did we get a section header?
- if (str.startsWith("[") && str.endsWith("]"))
+ if (str.startsWith("["))
{
+ if (!str.endsWith("]"))
+ {
+ // Index of 1 to skip '['
+ throw new IllegalArgumentException(str.substring(1)
+ + " is not closed");
+ }
+
// We encountered a new section header
if (state != State.IN_SECTION)
{
- sections.put(sectionName, sectionProps);
+ _sections.put(sectionName, sectionProps);
sectionProps = new Properties();
sectionName = str.replace("[", "").replace("]", "")
.trim();
@@ -125,10 +149,11 @@ public class IniFileReader
// mean we are off the section
if (state == State.IN_SECTION)
{
- sections.put(sectionName, sectionProps);
+ _sections.put(sectionName, sectionProps);
state = State.OFF_SECTION;
}
- } else
+ }
+ else
{
// proper line, add it to the props
if (state != State.OFF_SECTION)
@@ -143,25 +168,26 @@ public class IniFileReader
}
}
in.close();
- } catch (IOException e)
+ }
+ catch (IOException e)
{
- sections.clear();
+ _sections.clear();
return;
}
if (state != State.OFF_SECTION)
{
- sections.put(sectionName, sectionProps);
+ _sections.put(sectionName, sectionProps);
}
}
/**
* Getter for the Sections Map
+ *
* @return Map<String,Properties> The parsed content of the ini file in this structure
*/
public Map<String, Properties> getSections()
{
- return sections;
+ return _sections;
}
-
}
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
index 01a2ccd457..0f66085fc3 100644
--- a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
+++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java
@@ -19,19 +19,16 @@
*
*/
/**
- *
+ *
* @author sorin
- *
+ *
* An simple SOAP client for qpid info service
*/
package org.apache.qpid.info.util;
import java.io.BufferedWriter;
-
import java.io.OutputStreamWriter;
-
import java.net.InetAddress;
-
import java.net.Socket;
import java.util.HashMap;
import java.util.Properties;
@@ -39,52 +36,56 @@ import java.util.Properties;
public class SoapClient
{
- private final StringBuffer xmlData;
+ private final StringBuffer _xmlData;
private final Properties _destprops;
- private final String hostname;
+ private final String _hostname;
- private final int port;
+ private final int _port;
- private final String urlpath;
+ private final String _urlpath;
- private final String soapenvelope;
+ private final String _soapenvelope;
- private final String soapaction;
+ private final String _soapaction;
- private final StringBuffer soapMessage = new StringBuffer();
+ private final StringBuffer _soapMessage = new StringBuffer();
public SoapClient(HashMap<String, String> map, Properties destprops)
{
_destprops = destprops;
- hostname = (String) _destprops.get("soap.hostname");
- port = Integer.parseInt((String) _destprops.get("soap.port"));
- urlpath = (String) destprops.get("soap.path");
- soapenvelope = (String) destprops.get("soap.envelope");
- soapaction = (String) destprops.get("soap.action");
- xmlData = new StringBuffer(soapenvelope);
+ _hostname = (String) _destprops.get("soap.hostname");
+ _port = Integer.parseInt((String) _destprops.get("soap.port"));
+ _urlpath = (String) destprops.get("soap.path");
+ _soapenvelope = (String) destprops.get("soap.envelope");
+ _soapaction = (String) destprops.get("soap.action");
+ _xmlData = new StringBuffer(_soapenvelope);
replaceVariables(map);
}
public StringBuffer getXMLData()
{
- return xmlData;
+ return _xmlData;
}
public StringBuffer getSoapMessage() {
- return soapMessage;
+ return _soapMessage;
}
public String getSoapEnvelope() {
- return soapenvelope;
+ return _soapenvelope;
}
-
+
+ /**
+ * Clears and sets new XML data
+ * @param sb the new data to set
+ */
public void setXMLData(StringBuffer sb)
{
- xmlData.delete(0, xmlData.length());
- xmlData.append(sb);
+ _xmlData.delete(0, _xmlData.length());
+ _xmlData.append(sb);
}
@@ -93,9 +94,9 @@ public class SoapClient
int ix = 0;
for (String var : vars.keySet())
{
- while ((ix = xmlData.indexOf("@" + var.toUpperCase())) >= 0)
+ while ((ix = _xmlData.indexOf("@" + var.toUpperCase())) >= 0)
{
- xmlData.replace(ix, ix + 1 + var.length(), vars.get(var));
+ _xmlData.replace(ix, ix + 1 + var.length(), vars.get(var));
}
}
}
@@ -103,13 +104,15 @@ public class SoapClient
public void replaceVariables(Properties varProps)
{
if (varProps == null)
+ {
return;
+ }
int ix = 0;
for (Object var : varProps.keySet())
{
- while ((ix = xmlData.indexOf("@" + var)) >= 0)
+ while ((ix = _xmlData.indexOf("@" + var)) >= 0)
{
- xmlData.replace(ix, ix + 1 + var.toString().length(), varProps
+ _xmlData.replace(ix, ix + 1 + var.toString().length(), varProps
.get(var).toString());
}
}
@@ -121,34 +124,32 @@ public class SoapClient
try
{
- InetAddress addr = InetAddress.getByName(hostname);
- Socket sock = new Socket(addr, port);
+ InetAddress addr = InetAddress.getByName(_hostname);
+ Socket sock = new Socket(addr, _port);
StringBuffer sb = new StringBuffer();
- sb.append("POST " + urlpath + " HTTP/1.1\r\n");
- sb.append("Host: " + hostname + ":" + port + "\r\n");
- sb.append("Content-Length: " + xmlData.length() + "\r\n");
+ sb.append("POST " + _urlpath + " HTTP/1.1\r\n");
+ sb.append("Host: " + _hostname + ":" + _port + "\r\n");
+ sb.append("Content-Length: " + _xmlData.length() + "\r\n");
sb.append("Content-Type: text/xml; charset=\"utf-8\"\r\n");
- sb.append("SOAPAction: \"urn:"+soapaction+"\"\r\n");
+ sb.append("SOAPAction: \"urn:"+ _soapaction +"\"\r\n");
sb.append("User-Agent: Axis2\r\n");
sb.append("\r\n");
// Send header
BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(sock
.getOutputStream(), "UTF-8"));
- synchronized(soapMessage) {
- soapMessage.setLength(0);
- soapMessage.append(sb);
- soapMessage.append(xmlData);
+ synchronized(_soapMessage) {
+ _soapMessage.setLength(0);
+ _soapMessage.append(sb);
+ _soapMessage.append(_xmlData);
}
- System.out.println(soapMessage.toString());
- // Send data
- wr.write(soapMessage.toString());
+ // Send data
+ wr.write(_soapMessage.toString());
wr.flush();
wr.close();
} catch (Exception ex)
{
// Drop any exception
- System.out.println("*** INFO Exception at sending SOAP msg: "+ex.getMessage());
}
}
}