You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2010/05/24 14:53:29 UTC

svn commit: r947629 - in /qpid/trunk/qpid/java: ./ broker-plugins/experimental/info/ broker-plugins/experimental/info/src/ broker-plugins/experimental/info/src/main/ broker-plugins/experimental/info/src/main/java/ broker-plugins/experimental/info/src/m...

Author: ritchiem
Date: Mon May 24 12:53:28 2010
New Revision: 947629

URL: http://svn.apache.org/viewvc?rev=947629&view=rev
Log:
QPID-2555 : Commit Info OSGi plugin provided by Sorin Suciu.

Adds two new libraries to lib dir both ASL licensed.

Added:
    qpid/trunk/qpid/java/broker-plugins/experimental/info/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/MANIFEST.MF
    qpid/trunk/qpid/java/broker-plugins/experimental/info/build.properties
    qpid/trunk/qpid/java/broker-plugins/experimental/info/build.xml
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java
    qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java
    qpid/trunk/qpid/java/lib/jetty-servlet-tester-6.1.14.jar
    qpid/trunk/qpid/java/lib/servlet-api.jar
Modified:
    qpid/trunk/qpid/java/build.deps

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/MANIFEST.MF
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/MANIFEST.MF?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/MANIFEST.MF (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/MANIFEST.MF Mon May 24 12:53:28 2010
@@ -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"
+

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/build.properties
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/build.properties?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/build.properties (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/build.properties Mon May 24 12:53:28 2010
@@ -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/

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/build.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/build.xml?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/build.xml (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/build.xml Mon May 24 12:53:28 2010
@@ -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>

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Activator.java Mon May 24 12:53:28 2010
@@ -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
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoService.java Mon May 24 12:53:28 2010
@@ -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();
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/BrokerInfoServiceImpl.java Mon May 24 12:53:28 2010
@@ -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);
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/Info.java Mon May 24 12:53:28 2010
@@ -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();
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/HttpPoster.java Mon May 24 12:53:28 2010
@@ -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;
+	}
+	
+}
+

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/main/java/org/apache/qpid/info/util/XMLWriter.java Mon May 24 12:53:28 2010
@@ -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("&", "&amp;");
+        xmlStr = xmlStr.replace("<", "&lt;");
+        xmlStr = xmlStr.replace(">", "&gt;");
+        xmlStr = xmlStr.replace("\"", "&quot;");
+        xmlStr = xmlStr.replace("'", "&apos;");
+        return xmlStr;
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/ActivatorTest.java Mon May 24 12:53:28 2010
@@ -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);
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/BrokerInfoServiceImplTest.java Mon May 24 12:53:28 2010
@@ -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));
+        }
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/HttpPosterTest.java Mon May 24 12:53:28 2010
@@ -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());
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoServlet.java Mon May 24 12:53:28 2010
@@ -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

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/InfoTest.java Mon May 24 12:53:28 2010
@@ -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());
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java?rev=947629&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/info/src/test/java/org/apache/qpid/info/test/XMLWriterTest.java Mon May 24 12:53:28 2010
@@ -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());
+    }
+
+}

Modified: qpid/trunk/qpid/java/build.deps
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/build.deps?rev=947629&r1=947628&r2=947629&view=diff
==============================================================================
--- qpid/trunk/qpid/java/build.deps (original)
+++ qpid/trunk/qpid/java/build.deps Mon May 24 12:53:28 2010
@@ -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}

Added: qpid/trunk/qpid/java/lib/jetty-servlet-tester-6.1.14.jar
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/lib/jetty-servlet-tester-6.1.14.jar?rev=947629&view=auto
==============================================================================
Files qpid/trunk/qpid/java/lib/jetty-servlet-tester-6.1.14.jar (added) and qpid/trunk/qpid/java/lib/jetty-servlet-tester-6.1.14.jar Mon May 24 12:53:28 2010 differ

Added: qpid/trunk/qpid/java/lib/servlet-api.jar
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/lib/servlet-api.jar?rev=947629&view=auto
==============================================================================
Files qpid/trunk/qpid/java/lib/servlet-api.jar (added) and qpid/trunk/qpid/java/lib/servlet-api.jar Mon May 24 12:53:28 2010 differ



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org