diff options
6 files changed, 87 insertions, 57 deletions
diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java index d07f34dec0..a9cd96845c 100644 --- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java +++ b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java @@ -19,13 +19,6 @@ *
*/
-/**
- *
- * @author sorin
- *
- * An simple Http post class for qpid info service
- */
-
package org.apache.qpid.info.util;
import java.util.ArrayList;
@@ -41,6 +34,10 @@ import java.net.URL; import java.net.URLConnection;
import java.net.UnknownHostException;
+/**
+ *
+ * An simple Http post class for qpid info service
+ */
public class HttpPoster implements Runnable
{
private final String url;
diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java index f5e8396cbe..3faac5aeaa 100644 --- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java +++ b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/IniFileReader.java @@ -24,6 +24,31 @@ package org.apache.qpid.info.util; import java.util.*; import java.io.*; +/** + * 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 + * 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. + */ public class IniFileReader { private final Map<String, Properties> sections; diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java index 703a710568..01a2ccd457 100644 --- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java +++ b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/SoapClient.java @@ -45,30 +45,25 @@ public class SoapClient private final String hostname; - private final String port; + private final int port; private final String urlpath; private final String soapenvelope; - + private final String soapaction; - + private final StringBuffer soapMessage = new StringBuffer(); + public SoapClient(HashMap<String, String> map, Properties destprops) { - if (null == destprops) - { - _destprops = new Properties(); - } else - { - _destprops = destprops; - } - hostname = _destprops.getProperty("soap.hostname", "null"); - port = _destprops.getProperty("soap.port", "null"); - urlpath = _destprops.getProperty("soap.path", "null"); - soapenvelope = _destprops.getProperty("soap.envelope", "null"); - soapaction = _destprops.getProperty("soap.action", "null"); + _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); replaceVariables(map); } @@ -78,26 +73,23 @@ public class SoapClient return xmlData; } - public StringBuffer getSoapMessage() - { + public StringBuffer getSoapMessage() { return soapMessage; } - - public String getSoapEnvelope() - { + + public String getSoapEnvelope() { return soapenvelope; } - - public void setXMLData(StringBuilder sb) + + public void setXMLData(StringBuffer sb) { - xmlData.delete(0, xmlData.length() - 1); + xmlData.delete(0, xmlData.length()); xmlData.append(sb); } + public void replaceVariables(HashMap<String, String> vars) { - if (vars == null) - return; int ix = 0; for (String var : vars.keySet()) { @@ -122,41 +114,41 @@ public class SoapClient } } } + - public String sendSOAPMessage() + public void sendSOAPMessage() { try { InetAddress addr = InetAddress.getByName(hostname); - Socket sock = new Socket(addr, Integer.parseInt(port)); + 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("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) - { + synchronized(soapMessage) { soapMessage.setLength(0); soapMessage.append(sb); soapMessage.append(xmlData); } - String msg = soapMessage.toString(); - // Send data - wr.write(msg); + System.out.println(soapMessage.toString()); + // Send data + wr.write(soapMessage.toString()); wr.flush(); wr.close(); - return msg; + } catch (Exception ex) { // Drop any exception - return null; + System.out.println("*** INFO Exception at sending SOAP msg: "+ex.getMessage()); } } } diff --git a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java index 81a41e812c..a266edae00 100644 --- a/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java +++ b/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java @@ -19,17 +19,16 @@ * */ -/** - * - * @author sorin - * - * Naive and rudimentary XML writer - */ - package org.apache.qpid.info.util; import java.util.Map; +/** + * + * Naive and rudimentary XML writer + * It has methods to write the header, a tag with attributes + * and values. It escapes the XML special characters + */ public class XMLWriter { diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java index bcaf2328a6..642327a198 100644 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java +++ b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/systest/InfoPluginTest.java @@ -1,4 +1,4 @@ -package org.apache.qpid.info; +package org.apache.qpid.info.systest; import java.io.BufferedReader; import java.io.BufferedWriter; diff --git a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java index 4f977e1f99..5d503e1ba9 100644 --- a/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java +++ b/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/SoapClientTest.java @@ -38,7 +38,7 @@ import org.apache.qpid.info.util.SoapClient; public class SoapClientTest extends TestCase { - private final int port = 9900; + private final int port = 9100; private final String hostName = "localhost"; @@ -148,12 +148,29 @@ public class SoapClientTest extends TestCase sc.sendSOAPMessage(); socketAcceptor.join(2000); } - - public void testSoapClientFailure() throws Exception - { - SoapClient sc = new SoapClient(null, null); - assertNull("No response expected for the failure test", sc - .sendSOAPMessage()); + + public void testSoapClientXMLData() { + SoapClient sc = getSoapClient(); + StringBuffer sb = new StringBuffer("<?xml version=\"1.0\"?><ip=@IP><port=@PORT>"); + sc.setXMLData(sb); + assertEquals(sc.getXMLData().length(),sb.length()); + assertEquals("getXMLData does not return the same StringBuffer set by setXMLData",sb.toString(),sc.getXMLData().toString()); + } + + public void testReplaceVariablesMap() { + Properties props = new Properties(); + props.setProperty("soap.hostname", hostName); + props.setProperty("soap.port", port + ""); + props.setProperty("soap.urlpath", urlPath); + props.setProperty("soap.action", "send"); + props.setProperty("soap.envelope", "<addr>@IP:@PORT</addr>"); + HashMap<String, String> soapmap = new HashMap<String, String>(); + soapmap.put("IP", "127.0.0.1"); + soapmap.put("PORT","8080"); + SoapClient sc = new SoapClient(soapmap,props); + assertNotNull("SoapClient is null",sc); + assertTrue("Replace variables did not work as expected","<addr>127.0.0.1:8080</addr>".equals(sc.getXMLData().toString())); } + } |