001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.activemq.transport.stomp;
018
019 import java.io.IOException;
020
021 import javax.jms.JMSException;
022
023 import org.apache.activemq.command.ConsumerInfo;
024 import org.apache.activemq.command.MessageAck;
025 import org.apache.activemq.command.MessageDispatch;
026 import org.apache.activemq.command.TransactionId;
027
028 public class StompQueueBrowserSubscription extends StompSubscription {
029
030 public StompQueueBrowserSubscription(ProtocolConverter stompTransport, String subscriptionId, ConsumerInfo consumerInfo, String transformation) {
031 super(stompTransport, subscriptionId, consumerInfo, transformation);
032 }
033
034 @Override
035 void onMessageDispatch(MessageDispatch md) throws IOException, JMSException {
036
037 if (md.getMessage() != null) {
038 super.onMessageDispatch(md);
039 } else {
040 StompFrame browseDone = new StompFrame(Stomp.Responses.MESSAGE);
041 browseDone.getHeaders().put(Stomp.Headers.Message.SUBSCRIPTION, this.getSubscriptionId());
042 browseDone.getHeaders().put(Stomp.Headers.Message.BROWSER, "end");
043 browseDone.getHeaders().put(Stomp.Headers.Message.DESTINATION,
044 protocolConverter.findTranslator(null).convertDestination(protocolConverter, this.destination));
045 browseDone.getHeaders().put(Stomp.Headers.Message.MESSAGE_ID, "0");
046
047 protocolConverter.sendToStomp(browseDone);
048 }
049 }
050
051 @Override
052 public MessageAck onStompMessageNack(String messageId, TransactionId transactionId) throws ProtocolException {
053 throw new ProtocolException("Cannot Nack a message on a Queue Browser Subscription.");
054 }
055
056 }