Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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.activemq.web.controller;
 
 import java.util.Map;
 
 import  javax.jms.JMSException;
 import  javax.jms.Message;
 
Sends a message

Version:
$Revision: 565003 $
 
 public class SendMessage extends DestinationFacade implements Controller {
 
     private String jmsText;
     private boolean jmsPersistent;
     private int jmsPriority;
     private int jmsTimeToLive = -1;
     private String jmsCorrelationID;
     private String jmsReplyTo;
     private String jmsType;
     private int jmsMessageCount = 1;
     private String jmsMessageCountHeader = "JMSXMessageNumber";
     private boolean redirectToBrowse;
 
     public SendMessage(BrokerFacade brokerFacade) {
         super(brokerFacade);
     }
 
     public ModelAndView handleRequest(HttpServletRequest requestHttpServletResponse responsethrows Exception {
         WebClient client = WebClient.getWebClient(request);
         ActiveMQDestination dest = createDestination();
 
         sendMessages(requestclientdest);
         if () {
             if (isQueue()) {
                 return new ModelAndView("redirect:browse.jsp?destination=" + getJMSDestination());
             }
         }
         return redirectToBrowseView();
     }
 
     protected void sendMessages(HttpServletRequest requestWebClient clientActiveMQDestination destthrows JMSException {
         if ( <= 1) {
              = 1;
         }
         for (int i = 0; i < i++) {
             Message message = createMessage(clientrequest);
             appendHeaders(messagerequest);
             if ( > 1) {
                 message.setIntProperty(i + 1);
             }
 
             client.send(destmessage);
         }
     }
 
     // Properties
     // -------------------------------------------------------------------------
 
     public String getJMSCorrelationID() {
         return ;
     }
 
     public void setJMSCorrelationID(String correlationID) {
          = correlationID;
     }
 
     public String getJMSReplyTo() {
         return ;
     }
 
     public void setJMSReplyTo(String replyTo) {
         = replyTo;
    }
    public String getJMSType() {
        return ;
    }
    public void setJMSType(String type) {
         = type;
    }
    public boolean isJMSPersistent() {
        return ;
    }
    public void setJMSPersistent(boolean persistent) {
        this. = persistent;
    }
    public int getJMSPriority() {
        return ;
    }
    public void setJMSPriority(int priority) {
        this. = priority;
    }
    public String getJMSText() {
        return ;
    }
    public void setJMSText(String text) {
        this. = text;
    }
    public int getJMSTimeToLive() {
        return ;
    }
    public void setJMSTimeToLive(int timeToLive) {
        this. = timeToLive;
    }
    public int getJMSMessageCount() {
        return ;
    }
    public void setJMSMessageCount(int copies) {
         = copies;
    }
    public String getJMSMessageCountHeader() {
        return ;
    }
    public void setJMSMessageCountHeader(String messageCountHeader) {
         = messageCountHeader;
    }
    // Implementation methods
    // -------------------------------------------------------------------------
    protected Message createMessage(WebClient clientHttpServletRequest requestthrows JMSException {
        if ( != null) {
            return client.getSession().createTextMessage();
        }
        // TODO create Bytes message from request body...
        return client.getSession().createMessage();
    }
    protected void appendHeaders(Message messageHttpServletRequest requestthrows JMSException {
        message.setJMSCorrelationID();
        if ( != null && .trim().length() > 0) {
            message.setJMSReplyTo(ActiveMQDestination.createDestination(.));
        }
        message.setJMSType();
        // now lets add all of the parameters
        Map map = request.getParameterMap();
        if (map != null) {
            for (Iterator iter = map.entrySet().iterator(); iter.hasNext();) {
                Map.Entry entry = (Map.Entry)iter.next();
                String name = (String)entry.getKey();
                Object value = entry.getValue();
                if (isValidPropertyName(name)) {
                    if (value instanceof String[]) {
                        String[] array = (String[])value;
                        if (array.length > 0) {
                            value = array[0];
                        } else {
                            value = null;
                        }
                    }
                    if (value instanceof String) {
                        String text = value.toString().trim();
                        if (text.length() == 0) {
                            value = null;
                        } else {
                            value = text;
                        }
                    }
                    if (value != null) {
                        message.setObjectProperty(namevalue);
                    }
                }
            }
        }
    }
    protected boolean isValidPropertyName(String name) {
        // allow JMSX extensions or non JMS properties
        return name.startsWith("JMSX") || !name.startsWith("JMS");
    }
New to GrepCode? Check out our FAQ X