qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject svn commit: r1688658 - in /qpid/java/trunk: broker-codegen/src/main/java/org/apache/qpid/server/model/validation/ broker-core/src/main/java/org/apache/qpid/server/logging/logback/ broker-core/src/main/java/org/apache/qpid/server/message/ broker-core/sr...
Date Wed, 01 Jul 2015 14:31:32 GMT
Author: rgodfrey
Date: Wed Jul  1 14:31:32 2015
New Revision: 1688658

URL: http://svn.apache.org/r1688658
Log:
QPID-6586 : Use operations mechanisms to get message info list

Added:
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfo.java
  (with props)
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfoFacade.java
  (with props)
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/CustomRestHeaders.java
  (with props)
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/RestContentHeader.java
      - copied, changed from r1688510, qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ContentHeader.java
Removed:
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ContentHeader.java
Modified:
    qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/validation/ContentHeaderAnnotationValidator.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/PathTypedContent.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/AutoGeneratedSelfSignedKeyStoreImpl.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java

Modified: qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/validation/ContentHeaderAnnotationValidator.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/validation/ContentHeaderAnnotationValidator.java?rev=1688658&r1=1688657&r2=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/validation/ContentHeaderAnnotationValidator.java
(original)
+++ qpid/java/trunk/broker-codegen/src/main/java/org/apache/qpid/server/model/validation/ContentHeaderAnnotationValidator.java
Wed Jul  1 14:31:32 2015
@@ -40,8 +40,8 @@ import java.util.Set;
 @SupportedAnnotationTypes(ContentHeaderAnnotationValidator.CONTENT_HEADER_CLASS_NAME)
 public class ContentHeaderAnnotationValidator extends AbstractProcessor
 {
-    public static final String CONTENT_HEADER_CLASS_NAME = "org.apache.qpid.server.model.ContentHeader";
-    public static final String CONTENT_CLASS_NAME = "org.apache.qpid.server.model.Content";
+    public static final String CONTENT_HEADER_CLASS_NAME = "org.apache.qpid.server.model.RestContentHeader";
+    public static final String CONTENT_CLASS_NAME = "org.apache.qpid.server.model.CustomRestHeaders";
     private static final Set<TypeKind> VALID_PRIMITIVE_TYPES = new HashSet<>(Arrays.asList(
             TypeKind.BOOLEAN,
             TypeKind.BYTE,

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/PathTypedContent.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/PathTypedContent.java?rev=1688658&r1=1688657&r2=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/PathTypedContent.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/logging/logback/PathTypedContent.java
Wed Jul  1 14:31:32 2015
@@ -26,10 +26,11 @@ import java.io.OutputStream;
 import java.nio.file.Files;
 import java.nio.file.Path;
 
-import org.apache.qpid.server.model.ContentHeader;
+import org.apache.qpid.server.model.CustomRestHeaders;
+import org.apache.qpid.server.model.RestContentHeader;
 import org.apache.qpid.server.model.Content;
 
-public class PathTypedContent implements Content
+public class PathTypedContent implements Content, CustomRestHeaders
 {
     private final Path _path;
     private final String _contentType;
@@ -44,19 +45,19 @@ public class PathTypedContent implements
         _contentSize = _path == null ? 0 : _path.toFile().length();
     }
 
-    @ContentHeader("Content-Type")
+    @RestContentHeader("Content-Type")
     public String getContentType()
     {
         return _contentType;
     }
 
-    @ContentHeader("Content-Length")
+    @RestContentHeader("Content-Length")
     public long getContentLength()
     {
         return _contentSize;
     }
 
-    @ContentHeader("Content-Disposition")
+    @RestContentHeader("Content-Disposition")
     public String getContentDisposition()
     {
         return _disposition;

Added: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfo.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfo.java?rev=1688658&view=auto
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfo.java
(added)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfo.java
Wed Jul  1 14:31:32 2015
@@ -0,0 +1,49 @@
+/*
+ *
+ * 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.message;
+
+import java.util.Map;
+
+import org.apache.qpid.server.model.ManagedAttributeValueType;
+
+@ManagedAttributeValueType
+public interface MessageInfo
+{
+    long getId();
+    long getSize();
+    int getDeliveryCount();
+    String getState();
+    String getDeliveredTo();
+    long getArrivalTime();
+    boolean isPersistent();
+    String getMessageId();
+    Long getExpirationTime();
+    String getApplicationId();
+    String getCorrelationId();
+    String getEncoding();
+    String getMimeType();
+    int getPriority();
+    String getReplyTo();
+    Long getTimestamp();
+    String getType();
+    String getUserId();
+    Map<String,Object> getHeaders();
+}

Propchange: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfoFacade.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfoFacade.java?rev=1688658&view=auto
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfoFacade.java
(added)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfoFacade.java
Wed Jul  1 14:31:32 2015
@@ -0,0 +1,236 @@
+/*
+ *
+ * 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.message;
+
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.qpid.server.consumer.ConsumerImpl;
+
+public class MessageInfoFacade implements MessageInfo
+{
+    private final MessageInstance _instance;
+    private final boolean _includeHeaders;
+
+    public MessageInfoFacade(final MessageInstance instance, final boolean includeHeaders)
+    {
+        _instance = instance;
+        _includeHeaders = includeHeaders;
+    }
+
+
+    @Override
+    public long getId()
+    {
+        return _instance.getMessage().getMessageNumber();
+    }
+
+    @Override
+    public long getSize()
+    {
+        return _instance.getMessage().getSize();
+    }
+
+    @Override
+    public int getDeliveryCount()
+    {
+        return _instance.getDeliveryCount();
+    }
+
+    @Override
+    public String getState()
+    {
+        return _instance.isAvailable()
+                ? "Available"
+                : _instance.isAcquired()
+                        ? "Acquired"
+                        : "";
+    }
+
+    @Override
+    public String getDeliveredTo()
+    {
+        final ConsumerImpl deliveredConsumer = _instance.getDeliveredConsumer();
+        return deliveredConsumer == null ? null : String.valueOf(deliveredConsumer.getConsumerNumber());
+    }
+
+    @Override
+    public long getArrivalTime()
+    {
+        return _instance.getMessage().getArrivalTime();
+    }
+
+    @Override
+    public boolean isPersistent()
+    {
+        return _instance.getMessage().isPersistent();
+    }
+
+    @Override
+    public String getMessageId()
+    {
+        return _instance.getMessage().getMessageHeader().getMessageId();
+    }
+
+    @Override
+    public Long getExpirationTime()
+    {
+        long expiration = _instance.getMessage().getMessageHeader().getExpiration();
+        return expiration == 0l ? null : expiration;
+    }
+
+    @Override
+    public String getApplicationId()
+    {
+        return _instance.getMessage().getMessageHeader().getAppId();
+    }
+
+    @Override
+    public String getCorrelationId()
+    {
+        return _instance.getMessage().getMessageHeader().getCorrelationId();
+    }
+
+    @Override
+    public String getEncoding()
+    {
+        return _instance.getMessage().getMessageHeader().getEncoding();
+    }
+
+    @Override
+    public String getMimeType()
+    {
+        return _instance.getMessage().getMessageHeader().getMimeType();
+    }
+
+    @Override
+    public int getPriority()
+    {
+        return _instance.getMessage().getMessageHeader().getPriority();
+    }
+
+    @Override
+    public String getReplyTo()
+    {
+        return _instance.getMessage().getMessageHeader().getReplyTo();
+    }
+
+    @Override
+    public Long getTimestamp()
+    {
+        long timestamp = _instance.getMessage().getMessageHeader().getTimestamp();
+        return timestamp == 0l ? null : timestamp;
+    }
+
+    @Override
+    public String getType()
+    {
+        return _instance.getMessage().getMessageHeader().getType();
+    }
+
+    @Override
+    public String getUserId()
+    {
+        return _instance.getMessage().getMessageHeader().getUserId();
+    }
+
+    @Override
+    public Map<String, Object> getHeaders()
+    {
+        if(_includeHeaders)
+        {
+            final Collection<String> headerNames =
+                    _instance.getMessage().getMessageHeader().getHeaderNames();
+            return new AbstractMap<String, Object>()
+            {
+                @Override
+                public Set<Entry<String, Object>> entrySet()
+                {
+                    return new AbstractSet<Entry<String, Object>>()
+                    {
+                        @Override
+                        public Iterator<Entry<String, Object>> iterator()
+                        {
+                            final Iterator<String> nameIterator = headerNames.iterator();
+
+                            return new Iterator<Entry<String, Object>>()
+                            {
+                                @Override
+                                public boolean hasNext()
+                                {
+                                    return nameIterator.hasNext();
+                                }
+
+                                @Override
+                                public Entry<String, Object> next()
+                                {
+                                    final String headerName = nameIterator.next();
+                                    final Object value =
+                                            _instance.getMessage().getMessageHeader().getHeader(headerName);
+                                    return new Entry<String, Object>()
+                                    {
+                                        @Override
+                                        public String getKey()
+                                        {
+                                            return headerName;
+                                        }
+
+                                        @Override
+                                        public Object getValue()
+                                        {
+                                            return value;
+                                        }
+
+                                        @Override
+                                        public Object setValue(final Object value)
+                                        {
+                                            throw new UnsupportedOperationException();
+                                        }
+                                    };
+                                }
+
+                                @Override
+                                public void remove()
+                                {
+                                    nameIterator.remove();
+                                }
+                            };
+                        }
+
+                        @Override
+                        public int size()
+                        {
+                            return headerNames.size();
+                        }
+                    };
+                }
+            };
+        }
+        else
+        {
+            return null;
+        }
+    }
+}

Propchange: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/message/MessageInfoFacade.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/CustomRestHeaders.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/CustomRestHeaders.java?rev=1688658&view=auto
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/CustomRestHeaders.java
(added)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/CustomRestHeaders.java
Wed Jul  1 14:31:32 2015
@@ -0,0 +1,25 @@
+/*
+ *
+ * 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.model;
+
+public interface CustomRestHeaders
+{
+}

Propchange: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/CustomRestHeaders.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java?rev=1688658&r1=1688657&r2=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java (original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/Queue.java Wed
Jul  1 14:31:32 2015
@@ -24,6 +24,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.qpid.server.message.MessageInfo;
 import org.apache.qpid.server.queue.QueueEntryVisitor;
 import org.apache.qpid.server.store.MessageDurability;
 
@@ -247,7 +248,11 @@ public interface Queue<X extends Queue<X
     @ManagedOperation
     long clearQueue();
 
-    @ManagedOperation
+    @ManagedOperation(nonModifying = true)
     Content getMessageContent(@Param(name = "messageId") long messageId);
 
+    @ManagedOperation(nonModifying = true)
+    List<MessageInfo> getMessageInfo(@Param(name = "first", defaultValue = "-1") int
first, @Param(name = "last", defaultValue = "-1") int last);
+
+
 }

Copied: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/RestContentHeader.java
(from r1688510, qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ContentHeader.java)
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/RestContentHeader.java?p2=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/RestContentHeader.java&p1=qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ContentHeader.java&r1=1688510&r2=1688658&rev=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ContentHeader.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/RestContentHeader.java
Wed Jul  1 14:31:32 2015
@@ -27,7 +27,7 @@ import java.lang.annotation.Target;
 
 @Retention(RetentionPolicy.RUNTIME)
 @Target(ElementType.METHOD)
-public @interface ContentHeader
+public @interface RestContentHeader
 {
     String value();
 }

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java?rev=1688658&r1=1688657&r2=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/queue/AbstractQueue.java
Wed Jul  1 14:31:32 2015
@@ -18,9 +18,7 @@
  */
 package org.apache.qpid.server.queue;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.nio.ByteBuffer;
 import java.security.AccessControlException;
@@ -49,7 +47,11 @@ import javax.security.auth.Subject;
 
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.ListenableFuture;
-import org.apache.qpid.server.model.ContentHeader;
+
+import org.apache.qpid.server.message.MessageInfo;
+import org.apache.qpid.server.message.MessageInfoFacade;
+import org.apache.qpid.server.model.CustomRestHeaders;
+import org.apache.qpid.server.model.RestContentHeader;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -2528,7 +2530,7 @@ public abstract class AbstractQueue<X ex
         }
     }
 
-    public static class MessageContent implements Content
+    public static class MessageContent implements Content, CustomRestHeaders
     {
         private final byte[] _data;
         private final String _mimeType;
@@ -2545,13 +2547,13 @@ public abstract class AbstractQueue<X ex
             outputStream.write(_data);
         }
 
-        @ContentHeader("Content-Type")
+        @RestContentHeader("Content-Type")
         public String getContentType()
         {
             return _mimeType;
         }
 
-        @ContentHeader("Content-Length")
+        @RestContentHeader("Content-Length")
         public long getSize()
         {
             return _data.length;
@@ -3302,6 +3304,14 @@ public abstract class AbstractQueue<X ex
         }
     }
 
+    public List<MessageInfo> getMessageInfo(int first, int last)
+    {
+        final MessageCollector messageCollector = new MessageCollector(first, last, false);
+        visit(messageCollector);
+        return messageCollector.getMessages();
+
+    }
+
     private void authorizeMethod(String methodName)
     {
         getSecurityManager().authoriseMethod(Operation.UPDATE,
@@ -3379,4 +3389,52 @@ public abstract class AbstractQueue<X ex
             return _found;
         }
     }
+
+    private class MessageCollector implements QueueEntryVisitor
+    {
+
+
+
+        private class MessageRangeList extends ArrayList<MessageInfo> implements CustomRestHeaders
+        {
+            @RestContentHeader("Content-Range")
+            public String getContentRange()
+            {
+                String min = isEmpty() ? "0" : String.valueOf(_first);
+                String max = isEmpty() ? "0" : String.valueOf(_first + size() - 1);
+                return "" + min + "-" + max + "/" + getQueueDepthMessages();
+            }
+        }
+
+        private final int _first;
+        private final int _last;
+        private int _position = -1;
+        private final List<MessageInfo> _messages = new MessageRangeList();
+        private final boolean _includeHeaders;
+
+        private MessageCollector(int first, int last, boolean includeHeaders)
+        {
+            _first = first;
+            _last = last;
+            _includeHeaders = includeHeaders;
+        }
+
+
+        public boolean visit(QueueEntry entry)
+        {
+
+            _position++;
+            if((_first == -1 || _position >= _first) && (_last == -1 || _position
<= _last))
+            {
+                _messages.add(new MessageInfoFacade(entry, _includeHeaders));
+            }
+            return _last != -1 && _position > _last;
+        }
+
+        public List<MessageInfo> getMessages()
+        {
+            return _messages;
+        }
+    }
+
 }

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/AutoGeneratedSelfSignedKeyStoreImpl.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/AutoGeneratedSelfSignedKeyStoreImpl.java?rev=1688658&r1=1688657&r2=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/AutoGeneratedSelfSignedKeyStoreImpl.java
(original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/security/AutoGeneratedSelfSignedKeyStoreImpl.java
Wed Jul  1 14:31:32 2015
@@ -299,7 +299,6 @@ public class AutoGeneratedSelfSignedKeyS
                     dnsNames.add(canonicalHostName);
                 }
             }
-            System.err.println(dnsNames);
             for(String dnsName : dnsNames)
             {
                 if(dnsName.matches("[\\w&&[^\\d]][\\w\\d.-]*"))

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java?rev=1688658&r1=1688657&r2=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/AbstractServlet.java
Wed Jul  1 14:31:32 2015
@@ -42,7 +42,8 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 
 import org.apache.qpid.server.model.Content;
-import org.apache.qpid.server.model.ContentHeader;
+import org.apache.qpid.server.model.CustomRestHeaders;
+import org.apache.qpid.server.model.RestContentHeader;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.map.SerializationConfig;
 import org.slf4j.Logger;
@@ -259,7 +260,7 @@ public abstract class AbstractServlet ex
         sendJsonResponse(object, request, response, HttpServletResponse.SC_OK, true);
     }
 
-    protected void sendJsonResponse(Object object, HttpServletRequest request, HttpServletResponse
response, int responseCode, boolean sendCachingHeaders) throws IOException
+    protected final void sendJsonResponse(Object object, HttpServletRequest request, HttpServletResponse
response, int responseCode, boolean sendCachingHeaders) throws IOException
     {
         response.setStatus(responseCode);
         response.setContentType("application/json");
@@ -270,19 +271,20 @@ public abstract class AbstractServlet ex
             sendCachingHeadersOnResponse(response);
         }
 
+
+        if(object instanceof CustomRestHeaders)
+        {
+            setResponseHeaders(response, (CustomRestHeaders) object);
+        }
         writeObjectToResponse(object, request, response);
     }
 
-    protected void sendJsonErrorResponse(HttpServletRequest request,
-                                         HttpServletResponse response,
-                                         int responseCode,
-                                         String message) throws IOException
+    protected final void sendJsonErrorResponse(HttpServletRequest request,
+                                               HttpServletResponse response,
+                                               int responseCode,
+                                               String message) throws IOException
     {
-        response.setStatus(responseCode);
-        response.setContentType("application/json");
-        response.setCharacterEncoding(StandardCharsets.UTF_8.name());
-
-        writeObjectToResponse(Collections.singletonMap("errorMessage", message), request,
response);
+        sendJsonResponse(Collections.singletonMap("errorMessage", message), request, response,
responseCode, false);
     }
 
     protected void sendError(final HttpServletResponse resp, int responseCode)
@@ -337,15 +339,34 @@ public abstract class AbstractServlet ex
 
     protected void writeTypedContent(Content content, HttpServletRequest request, HttpServletResponse
response) throws IOException
     {
-        Map<ContentHeader, Method> contentHeaderGetters = getContentHeaderMethods(content);
+        try(OutputStream os = getOutputStream(request, response))
+        {
+            if(content instanceof CustomRestHeaders)
+            {
+                setResponseHeaders(response, (CustomRestHeaders) content);
+            }
+            response.setStatus(HttpServletResponse.SC_OK);
+            content.write(os);
+
+        }
+        catch(IOException e)
+        {
+            LOGGER.warn("Unexpected exception processing request", e);
+            sendJsonErrorResponse(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
e.getMessage());
+        }
+    }
+
+    private void setResponseHeaders(final HttpServletResponse response, final CustomRestHeaders
customRestHeaders)
+    {
+        Map<RestContentHeader, Method> contentHeaderGetters = getContentHeaderMethods(customRestHeaders);
         if (contentHeaderGetters != null)
         {
-            for (Map.Entry<ContentHeader, Method> entry: contentHeaderGetters.entrySet())
+            for (Map.Entry<RestContentHeader, Method> entry : contentHeaderGetters.entrySet())
             {
                 final String headerName = entry.getKey().value();
                 try
                 {
-                    response.setHeader(headerName, String.valueOf(entry.getValue().invoke(content)));
+                    response.setHeader(headerName, String.valueOf(entry.getValue().invoke(customRestHeaders)));
                 }
                 catch (Exception e)
                 {
@@ -354,29 +375,15 @@ public abstract class AbstractServlet ex
             }
 
         }
-        try(OutputStream os = getOutputStream(request, response))
-        {
-            content.write(os);
-            response.setStatus(HttpServletResponse.SC_OK);
-        }
-        catch (FileNotFoundException e)
-        {
-            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
-        }
-        catch(IOException e)
-        {
-            LOGGER.warn("Unexpected exception processing request", e);
-            sendJsonErrorResponse(request, response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
e.getMessage());
-        }
     }
 
-    private Map<ContentHeader, Method> getContentHeaderMethods(Content content)
+    private Map<RestContentHeader, Method> getContentHeaderMethods(CustomRestHeaders
content)
     {
-        Map<ContentHeader, Method> results = new HashMap<>();
+        Map<RestContentHeader, Method> results = new HashMap<>();
         Method[] methods = content.getClass().getMethods();
         for (Method method: methods)
         {
-            if (method.isAnnotationPresent(ContentHeader.class))
+            if (method.isAnnotationPresent(RestContentHeader.class))
             {
                 final Class<?>[] parameterTypes = method.getParameterTypes();
                 if (parameterTypes.length >0)
@@ -386,7 +393,8 @@ public abstract class AbstractServlet ex
                 }
                 else
                 {
-                    results.put(method.getAnnotation(ContentHeader.class), method);
+                    method.setAccessible(true);
+                    results.put(method.getAnnotation(RestContentHeader.class), method);
                 }
             }
         }

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java?rev=1688658&r1=1688657&r2=1688658&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
(original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/MessageServlet.java
Wed Jul  1 14:31:32 2015
@@ -279,6 +279,7 @@ public class MessageServlet extends Abst
 
     }
 
+
     private void addIfPresentAndNotZero(Map<String, Object> object, String name, Object
property)
     {
         if(property instanceof Number)



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


Mime
View raw message