diff options
| author | Martin Ritchie <ritchiem@apache.org> | 2010-05-24 12:53:28 +0000 |
|---|---|---|
| committer | Martin Ritchie <ritchiem@apache.org> | 2010-05-24 12:53:28 +0000 |
| commit | 47f7386bc2e4305c387d9a9147cd43d92cf3b615 (patch) | |
| tree | f183311f6e51fa5757b3e084122dc6906e1a2868 /java | |
| parent | 1a4016c7c44a532c1ffe1df65a70b08dbddbc9fc (diff) | |
| download | qpid-python-47f7386bc2e4305c387d9a9147cd43d92cf3b615.tar.gz | |
QPID-2555 : Commit Info OSGi plugin provided by Sorin Suciu.
Adds two new libraries to lib dir both ASL licensed.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@947629 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java')
18 files changed, 927 insertions, 2 deletions
diff --git a/java/broker-plugins/experimental/info/MANIFEST.MF b/java/broker-plugins/experimental/info/MANIFEST.MF new file mode 100644 index 0000000000..dabafe8305 --- /dev/null +++ b/java/broker-plugins/experimental/info/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: QpidPlugin +Bundle-SymbolicName: qpid_info_plugin;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Activator: org.apache.qpid.info.Activator +Import-Package: org.apache.qpid.server.configuration, + org.osgi.framework +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ClassPath: . +Bundle-ActivationPolicy: lazy +Export-Package: org.apache.qpid.info;uses:="org.osgi.framework" + diff --git a/java/broker-plugins/experimental/info/build.properties b/java/broker-plugins/experimental/info/build.properties new file mode 100644 index 0000000000..ca85cb7b66 --- /dev/null +++ b/java/broker-plugins/experimental/info/build.properties @@ -0,0 +1,13 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + lib/eventTrackerClient-2.7.0.jar,\ + lib/commons-logging-1.0.4.jar +src.includes = src/,\ + plugin.xml,\ + lib/,\ + build.properties,\ + bin/,\ + META-INF/ diff --git a/java/broker-plugins/experimental/info/build.xml b/java/broker-plugins/experimental/info/build.xml new file mode 100644 index 0000000000..e6927b5704 --- /dev/null +++ b/java/broker-plugins/experimental/info/build.xml @@ -0,0 +1,32 @@ +<!-- + - + - Licensed to the Apache Software Foundation (ASF) under one +nn - or more contributor license agreements. See the NOTICE file + -n distributed with this work for additional information + - regarding copyright ownership. The ASF licenses this file + - to you 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. + - + --> +<project name="AMQ Broker-Plugins" default="build"> + + <property name="module.depends" value="common management/common broker broker-plugins junit-toolkit"/> + <property name="module.test.depends" value="broker/test"/> + <property name="module.manifest" value="MANIFEST.MF"/> + <property name="module.plugin" value="true"/> + + <import file="../../../module.xml"/> + + <target name="bundle" depends="bundle-tasks"/> + +</project> 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 new file mode 100644 index 0000000000..167a53fdc5 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java @@ -0,0 +1,78 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + */ + +/** + * + * @author sorin + * + * Activator class for the tracking services + */ + +package org.apache.qpid.info; + +import java.io.File; +import java.io.FileInputStream; +import java.util.Properties; + +import org.apache.qpid.info.util.HttpPoster; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; + +public class Activator implements BundleActivator +{ + + BundleContext _ctx = null; + + public void start(BundleContext ctx) throws Exception + { + if (null != ctx) + { + BrokerInfoServiceImpl service = new BrokerInfoServiceImpl(ctx); + ctx.registerService(BrokerInfoService.class.getName(), service, + null); + _ctx = ctx; + HttpPoster hp; + try + { + Properties props = new Properties(); + String QPID_WORK = System.getenv("QPID_WORK"); + props.load(new FileInputStream(QPID_WORK + File.separator + + "etc" + File.separator + "qpidinfo.properties")); + hp = new HttpPoster(props, service.invoke().toXML()); + hp.run(); + } catch (Exception ex) + { + // Silently drop any exception + } + } + } + + public BundleContext getBundleContext() + { + return _ctx; + } + + public void stop(BundleContext ctx) throws Exception + { + // no need to do anything here, osgi will unregister the service for us + } + +} diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java new file mode 100644 index 0000000000..4c3c95d385 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java @@ -0,0 +1,27 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + */ + +package org.apache.qpid.info; + +public interface BrokerInfoService +{ + public Info<?> invoke(); +} diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java new file mode 100644 index 0000000000..fe10d55dea --- /dev/null +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java @@ -0,0 +1,120 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + */ + +/** + * + * @author sorin + * + * Implementation for Info service + */ + +package org.apache.qpid.info; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Calendar; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.Map.Entry; + +import org.apache.qpid.server.configuration.ServerConfiguration; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceReference; + +public class BrokerInfoServiceImpl implements BrokerInfoService +{ + + SortedMap<String, String> brokerInfoMap = new TreeMap<String, String>(); + + private final List<String> qpidProps = Arrays.asList("QPID_HOME", + "QPID_WORK", "java.class.path", "java.vm.name", + "java.class.version", "os.arch", "os.name", "os.version", + "sun.arch.data.model", "user.dir", "user.name", "user.timezone"); + + private final BundleContext _ctx; + + public BrokerInfoServiceImpl(BundleContext ctx) + { + _ctx = ctx; + } + + public Info<? extends Map<String, ?>> invoke() + { + // Get current time + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ"); + brokerInfoMap.put("time", sdf.format(Calendar.getInstance().getTime())); + // Get the hostname + try + { + InetAddress addr = InetAddress.getLocalHost(); + String hostname = addr.getHostName(); + brokerInfoMap.put("hostname", hostname); + brokerInfoMap.put("ip", addr.getHostAddress()); + } catch (UnknownHostException e) + { + // + } + // Dump system props + Properties sysprops = System.getProperties(); + String propName; + for (Iterator<Entry<Object, Object>> it = sysprops.entrySet() + .iterator(); it.hasNext();) + { + Entry<Object, Object> en = it.next(); + propName = en.getKey().toString(); + if (qpidProps.indexOf(propName) >= 0) + { + brokerInfoMap.put(propName, en.getValue().toString()); + } + } + + if (null == _ctx) + { + return new Info<SortedMap<String, String>>(brokerInfoMap); + } + + ServiceReference sref; + ServerConfiguration sc; + try + { + sref = _ctx + .getServiceReference(ServerConfiguration.class.getName()); + sc = (ServerConfiguration) _ctx.getService(sref); + if (null != sc) + { + brokerInfoMap.put("port", sc.getPorts().toString()); + } + } + catch (Exception e) + { + return new Info<SortedMap<String, String>>(brokerInfoMap); + } + + return new Info<SortedMap<String, String>>(brokerInfoMap); + } + +} 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 new file mode 100644 index 0000000000..e4d33817a1 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java @@ -0,0 +1,99 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + */ + +/** + * + * @author sorin + * + * Info object + */ + +package org.apache.qpid.info; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import org.apache.qpid.info.util.XMLWriter; + +public class Info<T extends Map<String, ?>> +{ + private T _info; + + public Info(T info) + { + _info = info; + } + + public String toString() + { + String result = ""; + for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) + { + String str = it.next(); + result += str + "=" + _info.get(str).toString() + "\n"; + } + return result; + } + + 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)); + } + return props; + } + + public StringBuffer toStringBuffer() + { + StringBuffer sb = new StringBuffer(); + for (Iterator<String> it = _info.keySet().iterator(); it.hasNext();) + { + String str = it.next(); + sb.append(str + "=" + _info.get(str).toString() + "\n"); + } + return sb; + } + + 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();) + { + attr.clear(); + key = it.next(); + xw.writeTag(key, attr, _info.get(key).toString()); + } + xw.writeCloseTag("qpidinfo"); + return xw.getXML(); + } + +} 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 new file mode 100644 index 0000000000..c67a7682f3 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java @@ -0,0 +1,97 @@ +/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ *
+ */
+
+/**
+ *
+ * @author sorin
+ *
+ * An simple Http post class for qpid info service
+ */
+
+package org.apache.qpid.info.util;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.URL;
+import java.net.URLConnection;
+
+public class HttpPoster implements Runnable {
+ private final String url;
+ private final Hashtable<String,String> header;
+ private final List<String> response = new ArrayList<String>();
+ private final StringBuffer _buf;
+ //
+ public HttpPoster(Properties props, StringBuffer buf)
+ {
+ _buf = buf;
+ if (null!= props) {
+ url = props.getProperty("URL");
+ header = new Hashtable<String, String>();
+ String hostname = props.getProperty("hostname");
+ if (null!= hostname) header.put("hostname", hostname);
+ } else {
+ url = null;
+ header = null;
+ }
+ }
+ //
+ @Override
+ public void run()
+ {
+ if (null==url) return;
+ String line;
+ URL urlDest;
+ URLConnection urlConn;
+ try {
+ urlDest = new URL(url);
+ urlConn = urlDest.openConnection();
+ urlConn.setDoOutput(true);
+ urlConn.setUseCaches(false);
+ for (Iterator<String> it=header.keySet().iterator(); it.hasNext();) {
+ String prop = (String)it.next();
+ urlConn.setRequestProperty(prop, header.get(prop));
+ }
+ OutputStreamWriter wr = new OutputStreamWriter(urlConn.getOutputStream());
+ wr.write(_buf.toString());
+ wr.flush();
+ // Get the response
+ BufferedReader rd = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
+ while ((line = rd.readLine()) != null) {
+ response.add(line);
+ }
+ } catch (Exception ex) {
+ return;
+ }
+ }
+
+ public List<String> getResponse()
+ {
+ return response;
+ }
+
+}
+
diff --git a/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java new file mode 100644 index 0000000000..81a41e812c --- /dev/null +++ b/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java @@ -0,0 +1,101 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + * + */ + +/** + * + * @author sorin + * + * Naive and rudimentary XML writer + */ + +package org.apache.qpid.info.util; + +import java.util.Map; + +public class XMLWriter +{ + + private final StringBuffer _sb; + + private final String INDENT = " "; + + public XMLWriter(StringBuffer sb) + { + _sb = sb; + } + + public StringBuffer getXML() + { + return _sb; + } + + public void writeXMLHeader() + { + _sb.append("<?xml version=\"1.0\"?>\n"); + } + + public void writeTag(String tagName, Map<String, String> attributes, + String value) + { + writeOpenTag(tagName, attributes); + writeValue(value); + writeCloseTag(tagName); + } + + public void writeOpenTag(String tagName, Map<String, String> attributes) + { + _sb.append("<").append(tagName); + if (null == attributes) + { + _sb.append(">\n"); + return; + } + for (String key : attributes.keySet()) + { + _sb.append(" ").append(key + "=\"" + attributes.get(key) + "\""); + } + _sb.append(">\n"); + + } + + private void writeValue(String val) + { + _sb.append(INDENT).append(escapeXML(val) + "\n"); + } + + public void writeCloseTag(String tagName) + { + _sb.append("</" + tagName + ">\n"); + } + + private String escapeXML(String xmlStr) + { + if (null == xmlStr) + return null; + xmlStr = xmlStr.replaceAll("&", "&"); + xmlStr = xmlStr.replace("<", "<"); + xmlStr = xmlStr.replace(">", ">"); + xmlStr = xmlStr.replace("\"", """); + xmlStr = xmlStr.replace("'", "'"); + return xmlStr; + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java new file mode 100644 index 0000000000..cec4d53409 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java @@ -0,0 +1,36 @@ +package org.apache.qpid.info.test; + +import junit.framework.TestCase; +import org.apache.qpid.info.Activator; + +/* + * This test verifies whether the activator for the info service is starting Ok. + */ +public class ActivatorTest extends TestCase +{ + private Activator activator; + + protected void setUp() throws Exception + { + super.setUp(); + activator = new Activator(); + activator.start(null); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + activator = null; + } + + public void testStart() + { + assertNotNull(activator); + } + + public void testGetBundleContext() + { + assertEquals(activator.getBundleContext(), null); + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java new file mode 100644 index 0000000000..9db779deb7 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java @@ -0,0 +1,46 @@ +package org.apache.qpid.info.test; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.apache.qpid.info.BrokerInfoServiceImpl; +import org.apache.qpid.info.Info; +import junit.framework.TestCase; + +/* + * This test verifies the invoke() method for the info service making sure that the parameters are returned + */ +public class BrokerInfoServiceImplTest extends TestCase +{ + + BrokerInfoServiceImpl bisi = null; + + public void testBrokerInfoServiceImpl() + { + bisi = new BrokerInfoServiceImpl(null); + assertNotNull(bisi); + } + + @SuppressWarnings("unchecked") + public void testInvoke() + { + bisi = new BrokerInfoServiceImpl(null); + assertNotNull(bisi); + Info<? extends Map<String, String>> info = (Info<? extends Map<String, String>>) bisi + .invoke(); + assertNotNull(info); + Properties props = info.toProps(); + assertNotNull(props); + List<String> qpidProps = Arrays.asList("java.class.path", + "java.vm.name", "java.class.version", "os.arch", "os.name", + "os.version", "sun.arch.data.model", "user.dir", "user.name", + "user.timezone"); + for (String tag : qpidProps) + { + assertNotNull(props.getProperty(tag)); + } + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java new file mode 100644 index 0000000000..8c0410d861 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java @@ -0,0 +1,66 @@ +package org.apache.qpid.info.test; + +import java.util.List; +import java.util.Properties; + +import org.apache.qpid.info.util.HttpPoster; +import org.mortbay.jetty.testing.ServletTester; + +import junit.framework.TestCase; + +/* + * This test verifies that the plugin posts correctly to a webserver + * We use an embedded jetty container to mimic the webserver + */ +public class HttpPosterTest extends TestCase +{ + + private HttpPoster hp; + + private Properties props; + + private StringBuffer sb; + + private ServletTester tester; + + private String baseURL; + + private final String contextPath = "/info"; + + protected void setUp() throws Exception + { + super.setUp(); + + tester = new ServletTester(); + tester.setContextPath("/"); + tester.addServlet(InfoServlet.class, contextPath); + baseURL = tester.createSocketConnector(true); + tester.start(); + // + props = new Properties(); + props.put("URL", baseURL + contextPath); + props.put("hostname", "localhost"); + sb = new StringBuffer("test=TEST"); + hp = new HttpPoster(props, sb); + + } + + protected void tearDown() throws Exception + { + super.tearDown(); + hp = null; + props = null; + sb = null; + tester.stop(); + } + + public void testHttpPoster() + { + assertNotNull(hp); + hp.run(); + List<String> response = hp.getResponse(); + assertTrue(response.size() > 0); + assertEquals("OK <br>", response.get(0).toString()); + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java new file mode 100644 index 0000000000..1d3c4323c0 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java @@ -0,0 +1,36 @@ +package org.apache.qpid.info.test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import javax.servlet.GenericServlet; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + +/* + * This is a servlet used by the embedded Jetty to be able to receive http post + * from the info plugin + */ + +public class InfoServlet extends GenericServlet +{ + private static final long serialVersionUID = 1L; + + @Override + public void service(ServletRequest request, ServletResponse response) + throws ServletException, IOException + { + String line; + BufferedReader in = request.getReader(); + while ((line = in.readLine()) != null) + { + System.out.println(line); + } + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println("OK <br>\n"); + System.out.println("ServletResponse: OK"); + } + +}
\ No newline at end of file diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java new file mode 100644 index 0000000000..83d378d621 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java @@ -0,0 +1,83 @@ +package org.apache.qpid.info.test; + +import java.util.HashMap; +import java.util.Properties; +import junit.framework.TestCase; +import org.apache.qpid.info.Info; + +/* + * This test verifies the toString(), toProps(), toXML() and toStringBuffer() methods of the Info object + * + */ +public class InfoTest extends TestCase +{ + private HashMap<String, String> infoPayLoad = null; + + private Info<HashMap<String, String>> info = null; + + protected void setUp() throws Exception + { + super.setUp(); + infoPayLoad = new HashMap<String, String>(); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + info = null; + infoPayLoad = null; + } + + public void testInfo() + { + info = new Info<HashMap<String, String>>(infoPayLoad); + assertNotNull(info); + } + + public void testToString() + { + infoPayLoad.clear(); + infoPayLoad.put("test", "Test"); + info = new Info<HashMap<String, String>>(infoPayLoad); + assertNotNull(info.toString()); + assertEquals("test=Test\n", info.toString()); + } + + public void testToProps() + { + Properties props = new Properties(); + props.put("test", "Test"); + infoPayLoad.clear(); + infoPayLoad.put("test", "Test"); + info = new Info<HashMap<String, String>>(infoPayLoad); + assertNotNull(info.toProps()); + assertEquals(props, info.toProps()); + } + + public void testToStringBuffer() + { + StringBuffer sb = new StringBuffer("test=Test\n"); + infoPayLoad.clear(); + infoPayLoad.put("test", "Test"); + info = new Info<HashMap<String, String>>(infoPayLoad); + assertNotNull(info.toStringBuffer()); + assertEquals(sb.toString(), info.toStringBuffer().toString()); + } + + public void testToXML() + { + String INDEND = " "; + infoPayLoad.clear(); + infoPayLoad.put("test", "Test"); + info = new Info<HashMap<String, String>>(infoPayLoad); + StringBuffer sb = new StringBuffer(); + sb.append("<?xml version=\"1.0\"?>\n"); + sb.append("<qpidinfo>\n"); + sb.append("<test>\n"); + sb.append(INDEND + "Test\n"); + sb.append("</test>\n"); + sb.append("</qpidinfo>\n"); + assertEquals(info.toXML().toString(), sb.toString()); + } + +} diff --git a/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java new file mode 100644 index 0000000000..cffb592064 --- /dev/null +++ b/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java @@ -0,0 +1,74 @@ +package org.apache.qpid.info.test; + +import java.util.HashMap; + +import org.apache.qpid.info.util.XMLWriter; + +import junit.framework.TestCase; + +/* + * This test verifies the XML writer custom class operations + */ +public class XMLWriterTest extends TestCase +{ + + private XMLWriter xw = null; + + protected void setUp() throws Exception + { + super.setUp(); + + } + + protected void tearDown() throws Exception + { + super.tearDown(); + + } + + public void testXMLWriter() + { + xw = new XMLWriter(new StringBuffer("Test")); + assertNotNull(xw); + assertEquals("Test", xw.getXML().toString()); + } + + public void testWriteXMLHeader() + { + xw = new XMLWriter(new StringBuffer()); + assertNotNull(xw); + xw.writeXMLHeader(); + assertEquals("<?xml version=\"1.0\"?>\n", xw.getXML().toString()); + } + + public void testWriteTag() + { + String INDEND = " "; + xw = new XMLWriter(new StringBuffer()); + assertNotNull(xw); + xw.writeTag("test", new HashMap<String, String>(), "TEST"); + assertEquals("<test>\n" + INDEND + "TEST\n" + "</test>\n", xw.getXML() + .toString()); + } + + public void testWriteOpenTag() + { + xw = new XMLWriter(new StringBuffer()); + assertNotNull(xw); + HashMap<String, String> attr = new HashMap<String, String>(); + xw.writeOpenTag("test", attr); + assertEquals("<test>\n", xw.getXML().toString()); + attr.put("id", "1"); + xw.writeOpenTag("test1", attr); + assertEquals("<test>\n" + "<test1 id=\"1\">\n", xw.getXML().toString()); + } + + public void testWriteCloseTag() + { + xw = new XMLWriter(new StringBuffer()); + assertNotNull(xw); + xw.writeCloseTag("test"); + assertEquals("</test>\n", xw.getXML().toString()); + } + +} diff --git a/java/build.deps b/java/build.deps index 692d5d78ec..56eeabac56 100644 --- a/java/build.deps +++ b/java/build.deps @@ -54,10 +54,12 @@ xml-apis=lib/xml-apis-1.3.03.jar javassist=lib/javassist.jar jetty=lib/jetty-6.1.14.jar jetty-util=lib/jetty-util-6.1.14.jar +jetty-servlet-tester=lib/jetty-servlet-tester-6.1.14.jar jetty-bootstrap=lib/start.jar jsp-api=lib/jsp-api-2.1.jar jsp-impl=lib/jsp-2.1.jar core-lib=lib/core-3.1.1.jar +servlet-api=lib/servlet-api.jar muse.libs = ${muse-core} ${muse-platform-mini} ${muse-util} ${muse-util-qname} \ ${muse-util-xml} ${muse-wsa-soap} ${muse-wsdm-muws-adv-api} ${muse-wsdm-muws-adv-impl} \ @@ -82,7 +84,7 @@ tools.libs=${commons-configuration.libs} broker.libs=${commons-cli} ${commons-logging} ${log4j} ${slf4j-log4j} \ ${xalan} ${felix.libs} ${derby-db} ${commons-configuration.libs} -broker-plugins.libs=${felix.libs} ${log4j} ${commons-configuration.libs} +broker-plugins.libs=${felix.libs} ${log4j} ${commons-configuration.libs} management-client.libs=${jsp.libs} ${log4j} ${slf4j-log4j} ${slf4j-api} \ ${commons-pool} ${geronimo-servlet} ${muse.libs} ${javassist} ${xalan} @@ -165,10 +167,12 @@ tools.test.libs= testkit.test.libs=${test.libs} systests.libs=${test.libs} +broker-plugins.test.libs=${test.libs} +broker-plugins-experimental-info.test.libs=${test.libs} ${servlet-api} ${jetty} ${jetty-util} ${jetty-servlet-tester} + management-client.test.libs=${muse.libs} ${test.libs} ${log4j} ${javassist} ${geronimo-servlet} ${commons-pool} management-console.test.libs=${junit4} ${slf4j-log4j} ${log4j} management-agent.test.libs=${junit} management-eclipse-plugin.test.libs=${systests.libs} -broker-plugins.test.libs=${test.libs} management-tools-qpid-cli.test.libs=${junit4} ${slf4j-log4j} ${log4j} management-common.test.libs=${test.libs} diff --git a/java/lib/jetty-servlet-tester-6.1.14.jar b/java/lib/jetty-servlet-tester-6.1.14.jar Binary files differnew file mode 100644 index 0000000000..c6d7c66f4a --- /dev/null +++ b/java/lib/jetty-servlet-tester-6.1.14.jar diff --git a/java/lib/servlet-api.jar b/java/lib/servlet-api.jar Binary files differnew file mode 100644 index 0000000000..e3b61e0079 --- /dev/null +++ b/java/lib/servlet-api.jar |
