qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r1355072 [6/16] - in /qpid/trunk/qpid/java: ./ bdbstore/ bdbstore/jmx/ bdbstore/jmx/src/ bdbstore/jmx/src/main/ bdbstore/jmx/src/main/java/ bdbstore/jmx/src/main/java/org/ bdbstore/jmx/src/main/java/org/apache/ bdbstore/jmx/src/main/java/or...
Date Thu, 28 Jun 2012 16:46:36 GMT
Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/api/VhostsServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,118 @@
+/*
+ *
+ * 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.server.management.plugin.servlet.api;
+
+import org.codehaus.jackson.map.ObjectMapper;
+
+import org.apache.qpid.common.QpidProperties;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.LifetimePolicy;
+import org.apache.qpid.server.model.State;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.protocol.AMQConnectionModel;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.*;
+
+public class VhostsServlet extends HttpServlet
+{
+
+
+    private Broker _broker;
+
+    public VhostsServlet()
+    {
+        super();
+        _broker = ApplicationRegistry.getInstance().getBroker();
+    }
+
+    public VhostsServlet(Broker broker)
+    {
+        _broker = broker;
+    }
+
+    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    {
+System.out.println("Get /api/vhosts");
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        Collection<VirtualHost> vhosts = _broker.getVirtualHosts();
+
+
+
+        final PrintWriter writer = response.getWriter();
+
+        ObjectMapper mapper = new ObjectMapper();
+
+        if(request.getPathInfo() == null || request.getPathInfo().length()==0)
+        {
+
+            LinkedHashMap<String, Object> vhostObject = new LinkedHashMap<String, Object>();
+            List<Map> vhostList = new ArrayList<Map>();
+
+            for(VirtualHost vhost : vhosts)
+            {
+                vhostList.add(Collections.singletonMap("name", vhost.getName()));
+            }
+            mapper.writeValue(writer, vhostList);
+        }
+        else
+        {
+            LinkedHashMap<String, Object> vhostObject = new LinkedHashMap<String, Object>();
+            String vhostName = request.getPathInfo().substring(1);
+
+            for(VirtualHost vhost : vhosts)
+            {
+                if(vhostName.equals(vhost.getName()))
+                {
+                    vhostObject.put("name", vhost.getName());
+                    break;
+                }
+            }
+            mapper.writeValue(writer, vhostObject);
+        }
+    }
+
+
+    protected void doPut(final HttpServletRequest request, final HttpServletResponse response)
+            throws ServletException, IOException
+    {
+
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0)
+        {
+            String vhostName = request.getPathInfo().substring(1);
+            _broker.createVirtualHost(vhostName, State.ACTIVE, true, LifetimePolicy.PERMANENT, 0L, Collections.EMPTY_MAP);
+        }
+
+
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,215 @@
+/*
+ *
+ * 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.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.security.Principal;
+import java.util.Collections;
+import javax.security.auth.Subject;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.auth.AuthenticationResult;
+import org.apache.qpid.server.security.auth.manager.AnonymousAuthenticationManager;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+
+public abstract class AbstractServlet extends HttpServlet
+{
+    private final Broker _broker;
+    private SocketAddress _socketAddress;
+
+    protected AbstractServlet()
+    {
+        super();
+        _broker = ApplicationRegistry.getInstance().getBroker();
+        _socketAddress = null;
+    }
+
+    protected AbstractServlet(Broker broker, SocketAddress socketAddress)
+    {
+        _broker = broker;
+        _socketAddress = socketAddress;
+    }
+
+    @Override
+    protected final void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException
+    {
+        setAuthorizedSubject(request);
+        try
+        {
+            onGet(request, resp);
+        }
+        finally
+        {
+            clearAuthorizedSubject();
+        }
+    }
+
+    protected void onGet(HttpServletRequest request, HttpServletResponse resp) throws IOException, ServletException
+    {
+        super.doGet(request, resp);
+    }
+
+    private void clearAuthorizedSubject()
+    {
+        org.apache.qpid.server.security.SecurityManager.setThreadSubject(null);
+    }
+
+
+    private void setAuthorizedSubject(HttpServletRequest request)
+    {
+        HttpSession session = request.getSession(true);
+        Subject subject = (Subject) session.getAttribute("subject");
+
+        if(subject == null)
+        {
+            Principal principal = request.getUserPrincipal();
+            if(principal != null)
+            {
+                subject = new Subject(false, Collections.singleton(principal),Collections.emptySet(),
+                                      Collections.emptySet());
+            }
+            else
+            {
+                String header = request.getHeader("Authorization");
+
+                /*
+                 * TODO - Should configure whether basic authentication is allowed... and in particular whether it
+                 * should be allowed over non-ssl connections
+                 * */
+
+                if (header != null)
+                {
+                    String[] tokens = header.split("\\s");
+                    if(tokens.length >= 2
+                       && "BASIC".equalsIgnoreCase(tokens[0]))
+                    {
+                        String[] credentials = (new String(Base64.decodeBase64(tokens[1].getBytes()))).split(":",2);
+                        if(credentials.length == 2)
+                        {
+                            SocketAddress address = getSocketAddress(request);
+                            AuthenticationManager authenticationManager =
+                                    ApplicationRegistry.getInstance().getAuthenticationManager(address);
+                            AuthenticationResult authResult =
+                                    authenticationManager.authenticate(credentials[0], credentials[1]);
+                            subject = authResult.getSubject();
+
+                        }
+                    }
+                }
+            }
+        }
+        if (subject == null)
+        {
+            subject = AnonymousAuthenticationManager.ANONYMOUS_SUBJECT;
+        }
+        org.apache.qpid.server.security.SecurityManager.setThreadSubject(subject);
+
+    }
+
+    protected Subject getSubject(HttpSession session)
+    {
+        return (Subject)session.getAttribute("subject");
+    }
+
+    @Override
+    protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+    {
+        setAuthorizedSubject(req);
+        try
+        {
+            onPost(req, resp);
+        }
+        finally
+        {
+            clearAuthorizedSubject();
+        }
+
+    }
+
+    protected void onPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+    {
+        super.doPost(req, resp);
+    }
+
+    @Override
+    protected final void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+    {
+        setAuthorizedSubject(req);
+        try
+        {
+            onPut(req, resp);
+
+        }
+        finally
+        {
+            clearAuthorizedSubject();
+        }
+    }
+
+    protected void onPut(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException
+    {
+        super.doPut(req,resp);
+    }
+
+    @Override
+    protected final void doDelete(HttpServletRequest req, HttpServletResponse resp)
+            throws ServletException, IOException
+    {
+        setAuthorizedSubject(req);
+        try
+        {
+            onDelete(req, resp);
+        }
+        finally
+        {
+            clearAuthorizedSubject();
+        }
+    }
+
+    protected void onDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+    {
+        super.doDelete(req, resp);
+    }
+
+
+    protected Broker getBroker()
+    {
+        return _broker;
+    }
+
+    protected SocketAddress getSocketAddress(HttpServletRequest request)
+    {
+        if (_socketAddress == null)
+        {
+            return InetSocketAddress.createUnresolved(request.getServerName(), request.getServerPort());
+        }
+        return _socketAddress;
+    }
+}

Copied: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/KeyComparator.java (from r1354912, qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java)
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/KeyComparator.java?p2=qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/KeyComparator.java&p1=qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java&r1=1354912&r2=1355072&rev=1355072&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/transport/QpidAcceptor.java (original)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/KeyComparator.java Thu Jun 28 16:46:12 2012
@@ -18,27 +18,36 @@
  * under the License.
  *
  */
-package org.apache.qpid.server.transport;
+package org.apache.qpid.server.management.plugin.servlet.rest;
 
-import org.apache.qpid.transport.network.NetworkTransport;
+import java.util.Comparator;
+import java.util.Map;
 
-public class QpidAcceptor
+class KeyComparator implements Comparator<Map>
 {
-    private NetworkTransport _transport;
-    private String _protocol;
-    public QpidAcceptor(NetworkTransport transport, String protocol)
-    {
-        _transport = transport;
-        _protocol = protocol;
-    }
+    private String _key;
 
-    public NetworkTransport getNetworkTransport()
+    public KeyComparator(final String key)
     {
-        return _transport;
+        _key = key;
     }
 
-    public String toString()
+    public int compare(final Map o1, final Map o2)
     {
-        return _protocol;
-    }    
+        Comparable left = (Comparable) o1.get(_key);
+        Comparable right = (Comparable) o2.get(_key);
+
+        int result;
+        if(left == null)
+        {
+            result =  right == null ? 0 : -1;
+        }
+        else
+        {
+            result = left.compareTo(right);
+        }
+
+        return result;
+
+    }
 }

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/LogRecordsServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,86 @@
+/*
+ * 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.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.SocketAddress;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.qpid.server.logging.LogRecorder;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class LogRecordsServlet extends AbstractServlet
+{
+    public LogRecordsServlet()
+    {
+        super(ApplicationRegistry.getInstance().getBroker(), null);
+    }
+
+    public LogRecordsServlet(Broker broker, SocketAddress socketaddress)
+    {
+        super(broker, socketaddress);
+    }
+
+    @Override
+    protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+    {
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+
+        ApplicationRegistry applicationRegistry = (ApplicationRegistry) ApplicationRegistry.getInstance();
+        List<Map<String,Object>> logRecords = new ArrayList<Map<String, Object>>();
+
+        for(LogRecorder.Record record : applicationRegistry.getLogRecorder())
+        {
+            logRecords.add(logRecordToObject(record));
+        }
+
+        final PrintWriter writer = response.getWriter();
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        mapper.writeValue(writer, logRecords);
+
+        response.setStatus(HttpServletResponse.SC_OK);
+
+    }
+
+    private Map<String, Object> logRecordToObject(LogRecorder.Record record)
+    {
+        Map<String, Object> recordMap = new LinkedHashMap<String, Object>();
+        recordMap.put("id",record.getId());
+        recordMap.put("timestamp", record.getTimestamp());
+        recordMap.put("level", record.getLevel());
+        recordMap.put("thread", record.getThreadName());
+        recordMap.put("logger", record.getLogger());
+        recordMap.put("message", record.getMessage());
+        return recordMap;
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MapComparator.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MapComparator.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MapComparator.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MapComparator.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,74 @@
+/*
+ *
+ * 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.server.management.plugin.servlet.rest;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Map;
+
+class MapComparator implements Comparator<Map>
+{
+    private Comparator<Map>[] _sortKeys;
+
+    public MapComparator(final String[] sortKeys)
+    {
+        _sortKeys = parseKeys(sortKeys);
+    }
+
+    private static Comparator<Map>[] parseKeys(final String[] sortKeys)
+    {
+        Comparator<Map>[] comparators = new Comparator[sortKeys.length];
+        for(int i = 0; i < sortKeys.length; i++)
+        {
+            String key = sortKeys[i];
+
+            if(key.startsWith("+") || key.startsWith(" "))
+            {
+                comparators[i] = new KeyComparator(key.substring(1));
+            }
+            else if(key.startsWith("-"))
+            {
+                comparators[i] = Collections.reverseOrder(new KeyComparator(key.substring(1)));
+            }
+            else
+            {
+                comparators[i] = new KeyComparator(key);
+            }
+        }
+        return comparators;
+    }
+
+
+    public int compare(final Map o1, final Map o2)
+    {
+        int result = 0;
+        for(int i = 0; i < _sortKeys.length; i++)
+        {
+            result = _sortKeys[i].compare(o1, o2);
+            if(result != 0)
+            {
+                return result;
+            }
+        }
+        return 0;
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageContentServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,177 @@
+/*
+ * 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.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.qpid.server.message.MessageReference;
+import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.queue.QueueEntry;
+import org.apache.qpid.server.queue.QueueEntryVisitor;
+
+public class MessageContentServlet extends AbstractServlet
+{
+    public MessageContentServlet()
+    {
+        super();
+    }
+
+    public MessageContentServlet(Broker broker, SocketAddress socketaddress)
+    {
+        super(broker, socketaddress);
+    }
+
+    @Override
+    protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+    {
+
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0 && request.getPathInfo().substring(1).split("/").length > 2)
+        {
+            getMessageContent(request, response);
+        }
+
+    }
+
+    private void getMessageContent(HttpServletRequest request, HttpServletResponse response) throws IOException
+    {
+        Queue queue = getQueueFromRequest(request);
+        String path[] = request.getPathInfo().substring(1).split("/");
+        MessageFinder finder = new MessageFinder(Long.parseLong(path[2]));
+        queue.visit(finder);
+        if(finder.isFound())
+        {
+            response.setContentType(finder.getMimeType());
+            response.setContentLength((int) finder.getSize());
+            response.getOutputStream().write(finder.getContent());
+
+        }
+
+    }
+
+    private Queue getQueueFromRequest(HttpServletRequest request)
+    {
+        List<String> names = new ArrayList<String>();
+        // TODO - validation that there is a vhost and queue and only those in the path
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0)
+        {
+            String path = request.getPathInfo().substring(1);
+            names.addAll(Arrays.asList(path.split("/")));
+        }
+        String vhostName = names.get(0);
+        String queueName = names.get(1);
+
+        VirtualHost vhost = null;
+
+        for(VirtualHost vh : getBroker().getVirtualHosts())
+        {
+            if(vh.getName().equals(vhostName))
+            {
+                vhost = vh;
+                break;
+            }
+        }
+
+        return getQueueFromVirtualHost(queueName, vhost);
+    }
+
+    private Queue getQueueFromVirtualHost(String queueName, VirtualHost vhost)
+    {
+        Queue queue = null;
+
+        for(Queue q : vhost.getQueues())
+        {
+            if(q.getName().equals(queueName))
+            {
+                queue = q;
+                break;
+            }
+        }
+        return queue;
+    }
+
+    private class MessageFinder implements QueueEntryVisitor
+    {
+        private final long _messageNumber;
+        private String _mimeType;
+        private long _size;
+        private byte[] _content;
+        private boolean _found;
+
+        private MessageFinder(long messageNumber)
+        {
+            _messageNumber = messageNumber;
+        }
+
+
+        public boolean visit(QueueEntry entry)
+        {
+            ServerMessage message = entry.getMessage();
+            if(message != null)
+            {
+                if(_messageNumber == message.getMessageNumber())
+                {
+                    MessageReference reference = message.newReference();
+
+                    _mimeType = message.getMessageHeader().getMimeType();
+                    _size = message.getSize();
+                    _content = new byte[(int)_size];
+                    _found = true;
+                    message.getContent(ByteBuffer.wrap(_content),0);
+                    reference.release();
+                    return true;
+                }
+
+            }
+            return false;
+        }
+
+        public String getMimeType()
+        {
+            return _mimeType;
+        }
+
+        public long getSize()
+        {
+            return _size;
+        }
+
+        public byte[] getContent()
+        {
+            return _content;
+        }
+
+        public boolean isFound()
+        {
+            return _found;
+        }
+    }
+
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,503 @@
+/*
+ * 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.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.SocketAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.log4j.Logger;
+import org.apache.qpid.server.message.AMQMessageHeader;
+import org.apache.qpid.server.message.MessageReference;
+import org.apache.qpid.server.message.ServerMessage;
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.Queue;
+import org.apache.qpid.server.model.VirtualHost;
+import org.apache.qpid.server.queue.QueueEntry;
+import org.apache.qpid.server.queue.QueueEntryVisitor;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.registry.IApplicationRegistry;
+import org.apache.qpid.server.security.SecurityManager;
+import org.apache.qpid.server.security.access.Operation;
+import org.apache.qpid.server.subscription.Subscription;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class MessageServlet extends AbstractServlet
+{
+    private static final Logger LOGGER = Logger.getLogger(MessageServlet.class);
+
+    public MessageServlet()
+    {
+        super();
+    }
+
+    public MessageServlet(Broker broker, SocketAddress socketaddress)
+    {
+        super(broker, socketaddress);
+    }
+
+    @Override
+    protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+    {
+
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0 && request.getPathInfo().substring(1).split("/").length > 2)
+        {
+            getMessageContent(request, response);
+        }
+        else
+        {
+            getMessageList(request, response);
+        }
+
+    }
+
+    private void getMessageContent(HttpServletRequest request, HttpServletResponse response) throws IOException
+    {
+        Queue queue = getQueueFromRequest(request);
+        String path[] = request.getPathInfo().substring(1).split("/");
+        MessageFinder messageFinder = new MessageFinder(Long.parseLong(path[2]));
+        queue.visit(messageFinder);
+
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+
+        final PrintWriter writer = response.getWriter();
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        mapper.writeValue(writer, messageFinder.getMessageObject());
+    }
+
+    private void getMessageList(HttpServletRequest request, HttpServletResponse response) throws IOException
+    {
+        Queue queue = getQueueFromRequest(request);
+
+        int first = -1;
+        int last = -1;
+        String range = request.getHeader("Range");
+        if(range != null)
+        {
+            String[] boundaries = range.split("=")[1].split("-");
+            first = Integer.parseInt(boundaries[0]);
+            last = Integer.parseInt(boundaries[1]);
+        }
+        final MessageCollector messageCollector = new MessageCollector(first, last);
+        queue.visit(messageCollector);
+
+        response.setContentType("application/json");
+        final List<Map<String, Object>> messages = messageCollector.getMessages();
+        int queueSize = ((Number) queue.getStatistics().getStatistic(Queue.QUEUE_DEPTH_MESSAGES)).intValue();
+        String min = messages.isEmpty() ? "0" : messages.get(0).get("position").toString();
+        String max = messages.isEmpty() ? "0" : messages.get(messages.size()-1).get("position").toString();
+        response.setHeader("Content-Range", (min + "-" + max + "/" + queueSize));
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+
+        final PrintWriter writer = response.getWriter();
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        mapper.writeValue(writer, messages);
+    }
+
+    private Queue getQueueFromRequest(HttpServletRequest request)
+    {
+        List<String> names = new ArrayList<String>();
+        // TODO - validation that there is a vhost and queue and only those in the path
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0)
+        {
+            String path = request.getPathInfo().substring(1);
+            names.addAll(Arrays.asList(path.split("/")));
+        }
+        String vhostName = names.get(0);
+        String queueName = names.get(1);
+
+        VirtualHost vhost = null;
+
+        for(VirtualHost vh : getBroker().getVirtualHosts())
+        {
+            if(vh.getName().equals(vhostName))
+            {
+                vhost = vh;
+                break;
+            }
+        }
+
+        return getQueueFromVirtualHost(queueName, vhost);
+    }
+
+    private Queue getQueueFromVirtualHost(String queueName, VirtualHost vhost)
+    {
+        Queue queue = null;
+
+        for(Queue q : vhost.getQueues())
+        {
+
+            if(q.getName().equals(queueName))
+            {
+                queue = q;
+                break;
+            }
+        }
+        return queue;
+    }
+
+    private abstract static class QueueEntryTransaction implements VirtualHost.TransactionalOperation
+    {
+        private final Queue _sourceQueue;
+        private final List _messageIds;
+
+        protected QueueEntryTransaction(Queue sourceQueue, List messageIds)
+        {
+            _sourceQueue = sourceQueue;
+            _messageIds = messageIds;
+        }
+
+
+        public void withinTransaction(final VirtualHost.Transaction txn)
+        {
+
+            _sourceQueue.visit(new QueueEntryVisitor()
+            {
+
+                public boolean visit(final QueueEntry entry)
+                {
+                    final ServerMessage message = entry.getMessage();
+                    if(message != null)
+                    {
+                        final long messageId = message.getMessageNumber();
+                        if (_messageIds.remove(messageId) || (messageId <= (long) Integer.MAX_VALUE
+                                                              && _messageIds.remove(Integer.valueOf((int)messageId))))
+                        {
+                            updateEntry(entry, txn);
+                        }
+                    }
+                    return _messageIds.isEmpty();
+                }
+            });
+        }
+
+
+        protected abstract void updateEntry(QueueEntry entry, VirtualHost.Transaction txn);
+    }
+
+    private static class MoveTransaction extends QueueEntryTransaction
+    {
+        private final Queue _destinationQueue;
+
+        public MoveTransaction(Queue sourceQueue, List<Long> messageIds, Queue destinationQueue)
+        {
+            super(sourceQueue, messageIds);
+            _destinationQueue = destinationQueue;
+        }
+
+        protected void updateEntry(QueueEntry entry, VirtualHost.Transaction txn)
+        {
+            txn.move(entry, _destinationQueue);
+        }
+    }
+
+    private static class CopyTransaction extends QueueEntryTransaction
+    {
+        private final Queue _destinationQueue;
+
+        public CopyTransaction(Queue sourceQueue, List<Long> messageIds, Queue destinationQueue)
+        {
+            super(sourceQueue, messageIds);
+            _destinationQueue = destinationQueue;
+        }
+
+        protected void updateEntry(QueueEntry entry, VirtualHost.Transaction txn)
+        {
+            txn.copy(entry, _destinationQueue);
+        }
+    }
+
+    private static class DeleteTransaction extends QueueEntryTransaction
+    {
+        public DeleteTransaction(Queue sourceQueue, List<Long> messageIds)
+        {
+            super(sourceQueue, messageIds);
+        }
+
+        protected void updateEntry(QueueEntry entry, VirtualHost.Transaction txn)
+        {
+            txn.dequeue(entry);
+        }
+    }
+
+
+
+    private class MessageCollector implements QueueEntryVisitor
+    {
+        private final int _first;
+        private final int _last;
+        private int _position = -1;
+        private final List<Map<String, Object>> _messages = new ArrayList<Map<String, Object>>();
+
+        private MessageCollector(int first, int last)
+        {
+            _first = first;
+            _last = last;
+        }
+
+
+        public boolean visit(QueueEntry entry)
+        {
+
+            _position++;
+            if((_first == -1 || _position >= _first) && (_last == -1 || _position <= _last))
+            {
+                final Map<String, Object> messageObject = convertToObject(entry, false);
+                messageObject.put("position", _position);
+                _messages.add(messageObject);
+            }
+            return _last != -1 && _position > _last;
+        }
+
+        public List<Map<String, Object>> getMessages()
+        {
+            return _messages;
+        }
+    }
+
+
+    private class MessageFinder implements QueueEntryVisitor
+    {
+        private final long _messageNumber;
+        private Map<String, Object> _messageObject;
+
+        private MessageFinder(long messageNumber)
+        {
+            _messageNumber = messageNumber;
+        }
+
+
+        public boolean visit(QueueEntry entry)
+        {
+            ServerMessage message = entry.getMessage();
+            if(message != null)
+            {
+                if(_messageNumber == message.getMessageNumber())
+                {
+                    MessageReference reference = message.newReference();
+                    _messageObject = convertToObject(entry, true);
+                    reference.release();
+                    return true;
+                }
+            }
+            return false;
+        }
+
+        public Map<String, Object> getMessageObject()
+        {
+            return _messageObject;
+        }
+    }
+
+    private Map<String, Object> convertToObject(QueueEntry entry, boolean includeContent)
+    {
+        Map<String, Object> object = new LinkedHashMap<String, Object>();
+        object.put("size", entry.getSize());
+        object.put("deliveryCount", entry.getDeliveryCount());
+        object.put("state",entry.isAvailable()
+                                   ? "Available"
+                                   : entry.isAcquired()
+                                             ? "Acquired"
+                                             : "");
+        final Subscription deliveredSubscription = entry.getDeliveredSubscription();
+        object.put("deliveredTo", deliveredSubscription == null ? null : deliveredSubscription.getSubscriptionID());
+        ServerMessage message = entry.getMessage();
+
+        if(message != null)
+        {
+            convertMessageProperties(object, message);
+            if(includeContent)
+            {
+                convertMessageHeaders(object, message);
+            }
+        }
+
+        return object;
+    }
+
+    private void convertMessageProperties(Map<String, Object> object, ServerMessage message)
+    {
+        object.put("id", message.getMessageNumber());
+        object.put("arrivalTime",message.getArrivalTime());
+        object.put("persistent", message.isPersistent());
+
+        final AMQMessageHeader messageHeader = message.getMessageHeader();
+        if(messageHeader != null)
+        {
+            addIfPresent(object, "messageId", messageHeader.getMessageId());
+            addIfPresent(object, "expirationTime", messageHeader.getExpiration());
+            addIfPresent(object, "applicationId", messageHeader.getAppId());
+            addIfPresent(object, "correlationId", messageHeader.getCorrelationId());
+            addIfPresent(object, "encoding", messageHeader.getEncoding());
+            addIfPresent(object, "mimeType", messageHeader.getMimeType());
+            addIfPresent(object, "priority", messageHeader.getPriority());
+            addIfPresent(object, "replyTo", messageHeader.getReplyTo());
+            addIfPresent(object, "timestamp", messageHeader.getTimestamp());
+            addIfPresent(object, "type", messageHeader.getType());
+            addIfPresent(object, "userId", messageHeader.getUserId());
+        }
+
+    }
+
+    private void addIfPresent(Map<String, Object> object, String name, Object property)
+    {
+        if(property != null)
+        {
+            object.put(name, property);
+        }
+    }
+
+    private void convertMessageHeaders(Map<String, Object> object, ServerMessage message)
+    {
+        final AMQMessageHeader messageHeader = message.getMessageHeader();
+        if(messageHeader != null)
+        {
+            Map<String, Object> headers = new HashMap<String,Object>();
+            for(String headerName : messageHeader.getHeaderNames())
+            {
+                headers.put(headerName, messageHeader.getHeader(headerName));
+            }
+            object.put("headers", headers);
+        }
+    }
+
+    /*
+     * POST moves or copies messages to the given queue from a queue specified in the posted JSON data
+     */
+    @Override
+    protected void onPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    {
+
+        try
+        {
+            final Queue sourceQueue = getQueueFromRequest(request);
+
+            ObjectMapper mapper = new ObjectMapper();
+
+            @SuppressWarnings("unchecked")
+            Map<String,Object> providedObject = mapper.readValue(request.getInputStream(), LinkedHashMap.class);
+
+            String destQueueName = (String) providedObject.get("destinationQueue");
+            Boolean move = (Boolean) providedObject.get("move");
+
+            final VirtualHost vhost = sourceQueue.getParent(VirtualHost.class);
+
+            boolean isMoveTransaction = move != null && Boolean.valueOf(move);
+
+            // FIXME: added temporary authorization check until we introduce management layer
+            // and review current ACL rules to have common rules for all management interfaces
+            String methodName = isMoveTransaction? "moveMessages":"copyMessages";
+            if (isQueueUpdateMethodAuthorized(methodName, vhost.getName()))
+            {
+                final Queue destinationQueue = getQueueFromVirtualHost(destQueueName, vhost);
+                final List messageIds = new ArrayList((List) providedObject.get("messages"));
+                QueueEntryTransaction txn =
+                        isMoveTransaction
+                                ? new MoveTransaction(sourceQueue, messageIds, destinationQueue)
+                                : new CopyTransaction(sourceQueue, messageIds, destinationQueue);
+                vhost.executeTransaction(txn);
+                response.setStatus(HttpServletResponse.SC_OK);
+            }
+            else
+            {
+                response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+            }
+        }
+        catch(RuntimeException e)
+        {
+            LOGGER.error("Failure to perform message opertion", e);
+            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+        }
+    }
+
+
+    /*
+     * DELETE removes messages from the queue
+     */
+    @Override
+    protected void onDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    {
+
+        final Queue sourceQueue = getQueueFromRequest(request);
+
+        final VirtualHost vhost = sourceQueue.getParent(VirtualHost.class);
+
+
+        final List<Long> messageIds = new ArrayList<Long>();
+        for(String idStr : request.getParameterValues("id"))
+        {
+            messageIds.add(Long.valueOf(idStr));
+        }
+
+        // FIXME: added temporary authorization check until we introduce management layer
+        // and review current ACL rules to have common rules for all management interfaces
+        if (isQueueUpdateMethodAuthorized("deleteMessages", vhost.getName()))
+        {
+            vhost.executeTransaction(new DeleteTransaction(sourceQueue, messageIds));
+            response.setStatus(HttpServletResponse.SC_OK);
+        }
+        else
+        {
+            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+        }
+
+    }
+
+    private boolean isQueueUpdateMethodAuthorized(String methodName, String virtualHost)
+    {
+        SecurityManager securityManager = getSecurityManager(virtualHost);
+        return securityManager.authoriseMethod(Operation.UPDATE, "VirtualHost.Queue", methodName);
+    }
+
+    private SecurityManager getSecurityManager(String virtualHost)
+    {
+        IApplicationRegistry appRegistry = ApplicationRegistry.getInstance();
+        SecurityManager security;
+        if (virtualHost == null)
+        {
+            security = appRegistry.getSecurityManager();
+        }
+        else
+        {
+            security = appRegistry.getVirtualHostRegistry().getVirtualHost(virtualHost).getSecurityManager();
+        }
+        return security;
+    }
+
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,576 @@
+package org.apache.qpid.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.SocketAddress;
+import java.util.*;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.qpid.AMQSecurityException;
+import org.apache.qpid.server.model.*;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.
+ */
+public class RestServlet extends AbstractServlet
+{
+    /**
+     * An initialization parameter to specify hierarchy
+     */
+    private static final String HIERARCHY_INIT_PARAMETER = "hierarchy";
+
+    public static final String DEPTH_PARAM = "depth";
+    public static final String SORT_PARAM = "sort";
+
+    public static final Set<String> RESERVED_PARAMS = new HashSet<String>(Arrays.asList(DEPTH_PARAM, SORT_PARAM));
+
+    private Class<? extends ConfiguredObject>[] _hierarchy;
+
+    private volatile boolean initializationRequired = false;
+
+    public RestServlet()
+    {
+        super();
+        initializationRequired = true;
+    }
+
+    public RestServlet(Broker broker, SocketAddress socketaddress, Class<? extends ConfiguredObject>... hierarchy)
+    {
+        super(broker, socketaddress);
+        _hierarchy = hierarchy;
+    }
+
+    @Override
+    public void init() throws ServletException
+    {
+        if (initializationRequired)
+        {
+            doInitialization();
+            initializationRequired = false;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void doInitialization() throws ServletException
+    {
+        ServletConfig config = getServletConfig();
+        String hierarchy = config.getInitParameter(HIERARCHY_INIT_PARAMETER);
+        if (hierarchy != null && !"".equals(hierarchy))
+        {
+            List<Class<? extends ConfiguredObject>> classes = new ArrayList<Class<? extends ConfiguredObject>>();
+            String[] hierarchyItems = hierarchy.split(",");
+            for (String item : hierarchyItems)
+            {
+                Class<?> itemClass = null;
+                try
+                {
+                    itemClass = Class.forName(item);
+                }
+                catch (ClassNotFoundException e)
+                {
+                    try
+                    {
+                        itemClass = Class.forName("org.apache.qpid.server.model." + item);
+                    }
+                    catch (ClassNotFoundException e1)
+                    {
+                        throw new ServletException("Unknown configured object class '" + item
+                                + "' is specified in hierarchy for " + config.getServletName());
+                    }
+                }
+                Class<? extends ConfiguredObject> clazz = (Class<? extends ConfiguredObject>)itemClass;
+                classes.add(clazz);
+            }
+            Class<? extends ConfiguredObject>[] hierachyClasses = (Class<? extends ConfiguredObject>[])new Class[classes.size()];
+            _hierarchy = classes.toArray(hierachyClasses);
+        }
+        else
+        {
+            _hierarchy = (Class<? extends ConfiguredObject>[])new Class[0];
+        }
+    }
+
+    protected Collection<ConfiguredObject> getObjects(HttpServletRequest request)
+    {
+        List<String> names = new ArrayList<String>();
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0)
+        {
+            String path = request.getPathInfo().substring(1);
+            names.addAll(Arrays.asList(path.split("/")));
+
+            if(names.size() > _hierarchy.length)
+            {
+                throw new IllegalArgumentException("Too many entries in path");
+            }
+        }
+
+        Collection<ConfiguredObject> parents = Collections.singleton((ConfiguredObject) getBroker());
+        Collection<ConfiguredObject> children = new ArrayList<ConfiguredObject>();
+
+        Map<Class<? extends ConfiguredObject>, String> filters =
+                new HashMap<Class<? extends ConfiguredObject>, String>();
+
+        for(int i = 0; i < _hierarchy.length; i++)
+        {
+            if(i == 0 || Model.getChildTypes(_hierarchy[i - 1]).contains(_hierarchy[i]))
+            {
+
+                for(ConfiguredObject parent : parents)
+                {
+                    if(names.size() > i
+                            && names.get(i) != null
+                            && !names.get(i).equals("*")
+                            && names.get(i).trim().length() != 0)
+                    {
+                        for(ConfiguredObject child : parent.getChildren(_hierarchy[i]))
+                        {
+                            if(child.getName().equals(names.get(i)))
+                            {
+                                children.add(child);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        children.addAll(parent.getChildren(_hierarchy[i]));
+                    }
+                }
+            }
+            else
+            {
+                children = parents;
+                if(names.size() > i
+                        && names.get(i) != null
+                        && !names.get(i).equals("*")
+                        && names.get(i).trim().length() != 0)
+                {
+                    filters.put(_hierarchy[i], names.get(i));
+                }
+            }
+
+            parents = children;
+            children = new ArrayList<ConfiguredObject>();
+        }
+
+        if(!filters.isEmpty())
+        {
+            Collection<ConfiguredObject> potentials = parents;
+            parents = new ArrayList<ConfiguredObject>();
+
+            for(ConfiguredObject o : potentials)
+            {
+
+                boolean match = true;
+
+                for(Map.Entry<Class<? extends ConfiguredObject>, String> entry : filters.entrySet())
+                {
+                    Collection<? extends ConfiguredObject> ancestors =
+                            getAncestors(getConfiguredClass(),entry.getKey(), o);
+                    match = false;
+                    for(ConfiguredObject ancestor : ancestors)
+                    {
+                        if(ancestor.getName().equals(entry.getValue()))
+                        {
+                            match = true;
+                            break;
+                        }
+                    }
+                    if(!match)
+                    {
+                        break;
+                    }
+                }
+                if(match)
+                {
+                    parents.add(o);
+                }
+
+            }
+        }
+
+        return filter(parents, request);
+    }
+
+    private Collection<ConfiguredObject> filter(Collection<ConfiguredObject> objects, HttpServletRequest request)
+    {
+
+
+        Map<String, Collection<String>> filters = new HashMap<String, Collection<String>>();
+
+        for(String param : (Collection<String>) Collections.list(request.getParameterNames()))
+        {
+            if(!RESERVED_PARAMS.contains(param))
+            {
+                filters.put(param, Arrays.asList(request.getParameterValues(param)));
+            }
+        }
+
+        if(filters.isEmpty())
+        {
+            return objects;
+        }
+
+        Collection<ConfiguredObject> filteredObj = new ArrayList<ConfiguredObject>(objects);
+
+        Iterator<ConfiguredObject> iter = filteredObj.iterator();
+
+        while(iter.hasNext())
+        {
+            ConfiguredObject obj = iter.next();
+            for(Map.Entry<String, Collection<String>> entry : filters.entrySet())
+            {
+                Object value = obj.getAttribute(entry.getKey());
+                if(!entry.getValue().contains(String.valueOf(value)))
+                {
+                    iter.remove();
+                }
+            }
+
+        }
+
+        return filteredObj;
+    }
+
+    private Collection<? extends ConfiguredObject> getAncestors(Class<? extends ConfiguredObject> childType,
+                                                                Class<? extends ConfiguredObject> ancestorType,
+                                                                ConfiguredObject child)
+    {
+        Collection<ConfiguredObject> ancestors = new HashSet<ConfiguredObject>();
+        Collection<Class<? extends ConfiguredObject>> parentTypes = Model.getParentTypes(childType);
+
+        for(Class<? extends ConfiguredObject> parentClazz : parentTypes)
+        {
+            if(parentClazz == ancestorType)
+            {
+                ConfiguredObject parent = child.getParent(parentClazz);
+                if(parent != null)
+                {
+                    ancestors.add(parent);
+                }
+            }
+            else
+            {
+                ConfiguredObject parent = child.getParent(parentClazz);
+                if(parent != null)
+                {
+                    ancestors.addAll(getAncestors(parentClazz, ancestorType, parent));
+                }
+            }
+        }
+
+        return ancestors;
+    }
+
+
+    protected Map<String, Object> convertObjectToMap(final ConfiguredObject confObject,
+                                                     Class<? extends  ConfiguredObject> clazz,
+                                                     int depth)
+    {
+        Map<String, Object> object = new LinkedHashMap<String, Object>();
+
+        for(String name : confObject.getAttributeNames())
+        {
+            Object value = confObject.getAttribute(name);
+            if(value != null)
+            {
+                object.put(name, value);
+            }
+        }
+
+        Statistics statistics = confObject.getStatistics();
+        Map<String, Object> statMap = new HashMap<String, Object>();
+        for(String name : statistics.getStatisticNames())
+        {
+            Object value = statistics.getStatistic(name);
+            if(value != null)
+            {
+                statMap.put(name, value);
+            }
+        }
+
+        if(!statMap.isEmpty())
+        {
+            object.put("statistics", statMap);
+        }
+
+        if(depth > 0)
+        {
+            for(Class<? extends ConfiguredObject> childClass : Model.getChildTypes(clazz))
+            {
+                Collection<? extends ConfiguredObject> children = confObject.getChildren(childClass);
+                if(children != null)
+                {
+                    List<Map<String, Object>> childObjects = new ArrayList<Map<String, Object>>();
+
+                    for(ConfiguredObject child : children)
+                    {
+                        childObjects.add(convertObjectToMap(child, childClass, depth-1));
+                    }
+
+                    if(!childObjects.isEmpty())
+                    {
+                        object.put(childClass.getSimpleName().toLowerCase()+"s",childObjects);
+                    }
+                }
+            }
+        }
+        return object;
+    }
+
+    @Override
+    protected void onGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    {
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+
+        Collection<ConfiguredObject> allObjects = getObjects(request);
+
+        @SuppressWarnings("unchecked")
+        Map params = new HashMap(request.getParameterMap());
+
+        int depth = 1;
+        try
+        {
+            depth = Integer.parseInt(String.valueOf(params.remove("depth")));
+        }
+        catch (NumberFormatException e)
+        {
+            // Ignore
+        }
+
+        List<Map<String, Object>> output = new ArrayList<Map<String, Object>>();
+
+        // TODO - depth and sort special params, everything else should act as a filter
+        if(request.getParameter(DEPTH_PARAM)!=null)
+        {
+            try
+            {
+                depth = Integer.parseInt(request.getParameter(DEPTH_PARAM));
+            }
+            catch (NumberFormatException e)
+            {
+
+            }
+        }
+
+        for(ConfiguredObject configuredObject : allObjects)
+        {
+            output.add(convertObjectToMap(configuredObject, getConfiguredClass(),depth));
+        }
+
+        final PrintWriter writer = response.getWriter();
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        mapper.writeValue(writer, output);
+
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+    }
+
+    private Class<? extends ConfiguredObject> getConfiguredClass()
+    {
+        return _hierarchy.length == 0 ? Broker.class : _hierarchy[_hierarchy.length-1];
+    }
+
+    @Override
+    protected void onPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    {
+        response.setContentType("application/json");
+
+        ObjectMapper mapper = new ObjectMapper();
+        @SuppressWarnings("unchecked")
+        Map<String,Object> providedObject = mapper.readValue(request.getInputStream(), LinkedHashMap.class);
+
+
+        List<String> names = new ArrayList<String>();
+        if(request.getPathInfo() != null && request.getPathInfo().length()>0)
+        {
+            String path = request.getPathInfo().substring(1);
+            names.addAll(Arrays.asList(path.split("/")));
+
+            if(names.size() != _hierarchy.length)
+            {
+                throw new IllegalArgumentException("Path to object to create must be fully specified");
+            }
+        }
+
+
+        providedObject.put("name", names.get(names.size()-1));
+
+        @SuppressWarnings("unchecked")
+        Collection<ConfiguredObject>[] objects = new Collection[_hierarchy.length];
+        if(_hierarchy.length == 1)
+        {
+            try
+            {
+                getBroker().createChild(_hierarchy[0], providedObject);
+            }
+            catch (RuntimeException e)
+            {
+                setResponseStatus(response, e);
+                return;
+            }
+
+        }
+        else
+        {
+            for(int i = 0; i < _hierarchy.length-1; i++)
+            {
+                objects[i] = new HashSet<ConfiguredObject>();
+                if(i == 0)
+                {
+                    for(ConfiguredObject object : getBroker().getChildren(_hierarchy[0]))
+                    {
+                        if(object.getName().equals(names.get(0)))
+                        {
+                            objects[0].add(object);
+                            break;
+                        }
+                    }
+                }
+                else
+                {
+                    for(int j = i-1; j >=0; j--)
+                    {
+                        if(Model.getChildTypes(_hierarchy[j]).contains(_hierarchy[i]))
+                        {
+                            for(ConfiguredObject parent : objects[j])
+                            {
+                                for(ConfiguredObject object : parent.getChildren(_hierarchy[i]))
+                                {
+                                    if(object.getName().equals(names.get(i)))
+                                    {
+                                        objects[i].add(object);
+                                    }
+                                }
+                            }
+                            break;
+                        }
+                    }
+                }
+
+            }
+            List<ConfiguredObject> parents = new ArrayList<ConfiguredObject>();
+            Class<? extends ConfiguredObject> objClass = getConfiguredClass();
+            Collection<Class<? extends ConfiguredObject>> parentClasses = Model.getParentTypes(objClass);
+            for(int i = _hierarchy.length-2; i >=0 ; i--)
+            {
+                if(parentClasses.contains(_hierarchy[i]))
+                {
+                    if(objects[i].size() == 1)
+                    {
+                        parents.add(objects[i].iterator().next());
+                    }
+                    else
+                    {
+                        throw new IllegalArgumentException("Cannot deduce parent of class "
+                                + _hierarchy[i].getSimpleName());
+                    }
+                }
+
+            }
+            ConfiguredObject theParent = parents.remove(0);
+            ConfiguredObject[] otherParents = parents.toArray(new ConfiguredObject[parents.size()]);
+
+            try
+            {
+
+                Collection<? extends ConfiguredObject> existingChildren = theParent.getChildren(objClass);
+                for(ConfiguredObject obj: existingChildren)
+                {
+                    if((providedObject.containsKey("id") && String.valueOf(providedObject.get("id")).equals(obj.getId().toString()))
+                       || (obj.getName().equals(providedObject.get("name")) && equalParents(obj, otherParents)))
+                    {
+                        doUpdate(obj, providedObject);
+                    }
+                }
+                theParent.createChild(objClass, providedObject, otherParents);
+            }
+            catch (RuntimeException e)
+            {
+                setResponseStatus(response, e);
+                return;
+            }
+
+        }
+        response.setStatus(HttpServletResponse.SC_CREATED);
+    }
+
+    private void doUpdate(ConfiguredObject obj, Map<String, Object> providedObject)
+    {
+        for(Map.Entry<String,Object> entry : providedObject.entrySet())
+        {
+            obj.setAttribute(entry.getKey(), obj.getAttribute(entry.getKey()), entry.getValue());
+        }
+        //TODO - Implement.
+    }
+
+    private boolean equalParents(ConfiguredObject obj, ConfiguredObject[] otherParents)
+    {
+        if(otherParents == null || otherParents.length == 0)
+        {
+            return true;
+        }
+        return false;  //TODO - Implement.
+    }
+
+    private void setResponseStatus(HttpServletResponse response, RuntimeException e) throws IOException
+    {
+        if (e.getCause() instanceof AMQSecurityException)
+        {
+            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+        }
+        else
+        {
+            // TODO
+            response.setStatus(HttpServletResponse.SC_CONFLICT);
+        }
+    }
+
+    @Override
+    protected void onDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+    {
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+        try
+        {
+            Collection<ConfiguredObject> allObjects = getObjects(request);
+            for(ConfiguredObject o : allObjects)
+            {
+                o.setDesiredState(o.getActualState(), State.DELETED);
+            }
+
+            response.setStatus(HttpServletResponse.SC_OK);
+        }
+        catch(RuntimeException e)
+        {
+            setResponseStatus(response, e);
+        }
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/SaslServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,253 @@
+/*
+ *
+ * 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.server.management.plugin.servlet.rest;
+
+import org.apache.commons.codec.binary.Base64;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.security.auth.manager.AuthenticationManager;
+import org.apache.qpid.server.security.auth.sasl.UsernamePrincipal;
+
+import javax.security.auth.Subject;
+import javax.security.sasl.SaslException;
+import javax.security.sasl.SaslServer;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.SocketAddress;
+import java.security.Principal;
+import java.security.SecureRandom;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Random;
+
+public class SaslServlet extends AbstractServlet
+{
+
+    private static final SecureRandom SECURE_RANDOM = new SecureRandom();
+    private static final String ATTR_RANDOM = "SaslServlet.Random";
+    private static final String ATTR_ID = "SaslServlet.ID";
+    private static final String ATTR_SASL_SERVER = "SaslServlet.SaslServer";
+    private static final String ATTR_EXPIRY = "SaslServlet.Expiry";
+    private static final long SASL_EXCHANGE_EXPIRY = 1000L;
+
+
+    public SaslServlet()
+    {
+        super();
+    }
+
+    public SaslServlet(Broker broker, SocketAddress socketaddress)
+    {
+        super(broker, socketaddress);
+    }
+
+    protected void onGet(HttpServletRequest request, HttpServletResponse response) throws
+                                                                                   ServletException,
+                                                                                   IOException
+    {
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+
+        HttpSession session = request.getSession();
+        Random rand = getRandom(session);
+
+        AuthenticationManager authManager = ApplicationRegistry.getInstance().getAuthenticationManager(getSocketAddress(request));
+        String[] mechanisms = authManager.getMechanisms().split(" ");
+        Map<String, Object> outputObject = new LinkedHashMap<String, Object>();
+        final Subject subject = (Subject) session.getAttribute("subject");
+        if(subject != null)
+        {
+            final Principal principal = subject.getPrincipals().iterator().next();
+            outputObject.put("user", principal.getName());
+        }
+
+        outputObject.put("mechanisms", (Object) mechanisms);
+
+        final PrintWriter writer = response.getWriter();
+
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        mapper.writeValue(writer, outputObject);
+
+    }
+
+    private Random getRandom(final HttpSession session)
+    {
+        Random rand = (Random) session.getAttribute(ATTR_RANDOM);
+        if(rand == null)
+        {
+            synchronized (SECURE_RANDOM)
+            {
+                rand = new Random(SECURE_RANDOM.nextLong());
+            }
+            session.setAttribute(ATTR_RANDOM, rand);
+        }
+        return rand;
+    }
+
+
+    @Override
+    protected void onPost(final HttpServletRequest request, final HttpServletResponse response)
+            throws ServletException, IOException
+    {
+        try
+        {
+            response.setContentType("application/json");
+            response.setHeader("Cache-Control","no-cache");
+            response.setHeader("Pragma","no-cache");
+            response.setDateHeader("Expires", 0);
+
+            HttpSession session = request.getSession();
+
+            String mechanism = request.getParameter("mechanism");
+            String id = request.getParameter("id");
+            String saslResponse = request.getParameter("response");
+
+            AuthenticationManager authManager = ApplicationRegistry.getInstance().getAuthenticationManager(getSocketAddress(request));
+
+            if(mechanism != null)
+            {
+                if(id == null)
+                {
+                    SaslServer saslServer = authManager.createSaslServer(mechanism, request.getServerName(), null/*TODO*/);
+                    evaluateSaslResponse(response, session, saslResponse, saslServer);
+                }
+                else
+                {
+                    response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
+                    session.removeAttribute(ATTR_ID);
+                    session.removeAttribute(ATTR_SASL_SERVER);
+                    session.removeAttribute(ATTR_EXPIRY);
+
+                }
+
+            }
+            else
+            {
+                if(id != null)
+                {
+                    if(id.equals(session.getAttribute(ATTR_ID)) && System.currentTimeMillis() < (Long) session.getAttribute(ATTR_EXPIRY))
+                    {
+                        SaslServer saslServer = (SaslServer) session.getAttribute(ATTR_SASL_SERVER);
+                        evaluateSaslResponse(response, session, saslResponse, saslServer);
+
+                    }
+                    else
+                    {
+                        response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
+                        session.removeAttribute(ATTR_ID);
+                        session.removeAttribute(ATTR_SASL_SERVER);
+                        session.removeAttribute(ATTR_EXPIRY);
+                    }
+                }
+                else
+                {
+                    response.setStatus(HttpServletResponse.SC_EXPECTATION_FAILED);
+                    session.removeAttribute(ATTR_ID);
+                    session.removeAttribute(ATTR_SASL_SERVER);
+                    session.removeAttribute(ATTR_EXPIRY);
+
+                }
+            }
+        }
+        catch(IOException e)
+        {
+            //TODO
+            e.printStackTrace();
+            throw e;
+        }
+        catch(RuntimeException e)
+        {
+            //TODO
+            e.printStackTrace();
+            throw e;
+        }
+
+    }
+
+    private void evaluateSaslResponse(final HttpServletResponse response,
+                                      final HttpSession session,
+                                      final String saslResponse, final SaslServer saslServer) throws IOException
+    {
+        final String id;
+        byte[] challenge;
+        try
+        {
+            challenge  = saslServer.evaluateResponse(saslResponse == null ? new byte[0] : Base64.decodeBase64(saslResponse.getBytes()));
+        }
+        catch(SaslException e)
+        {
+
+            session.removeAttribute(ATTR_ID);
+            session.removeAttribute(ATTR_SASL_SERVER);
+            session.removeAttribute(ATTR_EXPIRY);
+            response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+
+            return;
+        }
+
+        if(saslServer.isComplete())
+        {
+            final Subject subject = new Subject();
+            subject.getPrincipals().add(new UsernamePrincipal(saslServer.getAuthorizationID()));
+            session.setAttribute("subject", subject);
+            session.removeAttribute(ATTR_ID);
+            session.removeAttribute(ATTR_SASL_SERVER);
+            session.removeAttribute(ATTR_EXPIRY);
+
+            response.setStatus(HttpServletResponse.SC_OK);
+
+
+        }
+        else
+        {
+            Random rand = getRandom(session);
+            id = String.valueOf(rand.nextLong());
+            session.setAttribute(ATTR_ID, id);
+            session.setAttribute(ATTR_SASL_SERVER, saslServer);
+            session.setAttribute(ATTR_EXPIRY, System.currentTimeMillis() + SASL_EXCHANGE_EXPIRY);
+
+            response.setStatus(HttpServletResponse.SC_OK);
+
+            Map<String, Object> outputObject = new LinkedHashMap<String, Object>();
+            outputObject.put("id", id);
+            outputObject.put("challenge", new String(Base64.encodeBase64(challenge)));
+
+            final PrintWriter writer = response.getWriter();
+
+            ObjectMapper mapper = new ObjectMapper();
+            mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+            mapper.writeValue(writer, outputObject);
+
+        }
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/StructureServlet.java Thu Jun 28 16:46:12 2012
@@ -0,0 +1,104 @@
+/**
+ * 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
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * 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.server.management.plugin.servlet.rest;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.net.SocketAddress;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.qpid.server.model.Broker;
+import org.apache.qpid.server.model.ConfiguredObject;
+import org.apache.qpid.server.model.Model;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.SerializationConfig;
+
+public class StructureServlet extends AbstractServlet
+{
+    public StructureServlet()
+    {
+        super();
+    }
+
+    public StructureServlet(Broker broker, SocketAddress socketaddress)
+    {
+        super(broker, socketaddress);
+    }
+
+    @Override
+    protected void onGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+    {
+        response.setContentType("application/json");
+        response.setStatus(HttpServletResponse.SC_OK);
+
+        response.setHeader("Cache-Control","no-cache");
+        response.setHeader("Pragma","no-cache");
+        response.setDateHeader ("Expires", 0);
+
+        Map<String,Object> structure = generateStructure(getBroker(), Broker.class);
+
+        final PrintWriter writer = response.getWriter();
+        ObjectMapper mapper = new ObjectMapper();
+        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
+        mapper.writeValue(writer, structure);
+
+        response.setStatus(HttpServletResponse.SC_OK);
+
+    }
+
+    private Map<String, Object> generateStructure(ConfiguredObject object, Class<? extends ConfiguredObject> clazz)
+    {
+        Map<String, Object> structure = new LinkedHashMap<String, Object>();
+        structure.put("id", object.getId());
+        structure.put("name", object.getName());
+
+        for(Class<? extends ConfiguredObject> childClass : Model.getChildTypes(clazz))
+        {
+            Collection<? extends ConfiguredObject> children = object.getChildren(childClass);
+            if(children != null)
+            {
+                List<Map<String, Object>> childObjects = new ArrayList<Map<String, Object>>();
+
+                for(ConfiguredObject child : children)
+                {
+                    childObjects.add(generateStructure(child, childClass));
+                }
+
+                if(!childObjects.isEmpty())
+                {
+                    structure.put(pluralize(childClass),childObjects);
+                }
+            }
+        }
+
+        return structure;
+    }
+
+    private String pluralize(Class<? extends ConfiguredObject> childClass)
+    {
+        String name = childClass.getSimpleName().toLowerCase();
+        return name + (name.endsWith("s") ? "es" : "s");
+    }
+}

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addBinding.html
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addBinding.html?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addBinding.html (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addBinding.html Thu Jun 28 16:46:12 2012
@@ -0,0 +1,42 @@
+<!--
+  ~ 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.
+  -->
+<div class="dijitHidden">
+    <div data-dojo-type="dijit.Dialog" style="width:600px;" data-dojo-props="title:'Add Binding'" id="addBinding">
+        <form id="formAddBinding" method="post" dojoType="dijit.form.Form">
+            <table cellpadding="0" cellspacing="2">
+                <tr>
+                    <td valign="top"><strong>Exchange Name*: </strong></td>
+                    <td><div id="addBinding.selectExchangeDiv"></div></td>
+                </tr>
+                <tr>
+                    <td valign="top"><strong>Queue Name*: </strong></td>
+                    <td><div id="addBinding.selectQueueDiv"></div></td>
+                </tr>
+                <tr>
+                    <td valign="top"><strong>Binding Key*: </strong></td>
+                    <td><input type="text" required="true" name="name" id="formAddbinding.bindingKey" placeholder="Binding Key"
+                        dojoType="dijit.form.ValidationTextBox" missingMessage="A name must be supplied" /></td>
+                </tr>
+            </table>
+            <br/>
+
+            <!-- submit buttons -->
+            <input type="submit" value="Create Binding" label="Create Binding" dojoType="dijit.form.Button" />
+
+        </form>
+    </div>
+</div>

Added: qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addExchange.html
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addExchange.html?rev=1355072&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addExchange.html (added)
+++ qpid/trunk/qpid/java/broker-plugins/management/src/main/java/resources/addExchange.html Thu Jun 28 16:46:12 2012
@@ -0,0 +1,53 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<div class="dijitHidden">
+    <div data-dojo-type="dijit.Dialog" style="width:600px;" data-dojo-props="title:'Add Exchange'" id="addExchange">
+        <form id="formAddExchange" method="post" dojoType="dijit.form.Form">
+            <table cellpadding="0" cellspacing="2">
+                <tr>
+                    <td valign="top"><strong>Exchange Name*: </strong></td>
+                    <td><input type="text" required="true" name="name" id="formAddExchange.name" placeholder="Exchange Name"
+                        dojoType="dijit.form.ValidationTextBox" missingMessage="A name must be supplied" /></td>
+                </tr>
+                <tr>
+                    <td valign="top"><strong>Durable? </strong></td>
+                    <td><input type="checkbox" name="durable" id="formAddExchange.durable" value="durable" checked="checked" dojoType="dijit.form.CheckBox" /></td>
+                </tr>
+                <tr>
+                    <td valign="top"><strong>Exchange Type: </strong></td>
+                    <td>
+                        <select name="type" id="formAddExchange.type" dojoType="dijit.form.FilteringSelect">
+                            <option value="direct">direct</option>
+                            <option value="topic">topic</option>
+                            <option value="headers">headers</option>
+                            <option value="fanout">fanout</option>
+                        </select>
+                    </td>
+                </tr>
+            </table>
+            <br/>
+
+            <!-- submit buttons -->
+            <input type="submit" value="Create Exchange" label="Create Exchange" dojoType="dijit.form.Button" />
+
+        </form>
+    </div>
+</div>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message