Coverage Report - org.mule.transport.ajax.container.AjaxServletConnector
 
Classes in this File Line Coverage Branch Coverage Complexity
AjaxServletConnector
0%
0/57
0%
0/12
0
 
 1  
 /*
 2  
  * $Id: AjaxServletConnector.java 20321 2010-11-24 15:21:24Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 package org.mule.transport.ajax.container;
 11  
 
 12  
 import org.mule.api.MuleContext;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.construct.FlowConstruct;
 15  
 import org.mule.api.endpoint.ImmutableEndpoint;
 16  
 import org.mule.api.endpoint.InboundEndpoint;
 17  
 import org.mule.api.transport.MessageReceiver;
 18  
 import org.mule.api.transport.ReplyToHandler;
 19  
 import org.mule.transport.AbstractConnector;
 20  
 import org.mule.transport.ajax.AjaxMessageReceiver;
 21  
 import org.mule.transport.ajax.AjaxReplyToHandler;
 22  
 import org.mule.transport.ajax.BayeuxAware;
 23  
 import org.mule.transport.ajax.embedded.AjaxConnector;
 24  
 import org.mule.transport.servlet.ServletConnector;
 25  
 
 26  
 import org.cometd.DataFilter;
 27  
 import org.mortbay.cometd.AbstractBayeux;
 28  
 
 29  
 /**
 30  
  * A servlet connector that binds to the container and makes a configured 
 31  
  * Bayeux available to dispatchers and receivers.
 32  
  */
 33  
 public class AjaxServletConnector extends ServletConnector implements BayeuxAware
 34  
 {
 35  
     public static final String PROTOCOL = "ajax-servlet";
 36  
 
 37  
     /**
 38  
      * The client side poll timeout in milliseconds (default 0). How long a client
 39  
      * will wait between reconnects
 40  
      */
 41  0
     private int interval = INT_VALUE_NOT_SET;
 42  
 
 43  
     /**
 44  
      * The max client side poll timeout in milliseconds (default 30000). A client 
 45  
      * will be removed if a connection is not received in this time.
 46  
      */
 47  0
     private int maxInterval = INT_VALUE_NOT_SET;
 48  
 
 49  
     /**
 50  
      * The client side poll timeout if multiple connections are detected from the 
 51  
      * same browser (default 1500).
 52  
      */
 53  0
     private int multiFrameInterval = INT_VALUE_NOT_SET;
 54  
 
 55  
     /**
 56  
      * 0=none, 1=info, 2=debug
 57  
      */
 58  0
     private int logLevel = INT_VALUE_NOT_SET;
 59  
 
 60  
     /**
 61  
      * The server side poll timeout in milliseconds (default 250000). This is how long 
 62  
      * the server will hold a reconnect request before responding.
 63  
      */
 64  0
     private int timeout = INT_VALUE_NOT_SET;
 65  
 
 66  
     /**
 67  
      * If "true" (default) then the server will accept JSON wrapped in a comment and 
 68  
      * will generate JSON wrapped in a comment. This is a defence against Ajax Hijacking.
 69  
      */
 70  0
     private boolean jsonCommented = true;
 71  
 
 72  
     /**
 73  
      * TODO SUPPORT FILTERS
 74  
      * the location of a JSON file describing {@link DataFilter} instances to be installed
 75  
      */
 76  
     private String filters;
 77  
 
 78  
     /**
 79  
      * If true, the current request is made available via the 
 80  
      * {@link AbstractBayeux#getCurrentRequest()} method
 81  
      */
 82  0
     private boolean requestAvailable = true;
 83  
 
 84  
     /**
 85  
      * The number of message refs at which the a single message response will be
 86  
      * cached instead of being generated for every client delivered to. Done to optimize
 87  
      * a single message being sent to multiple clients.
 88  
      */
 89  0
     private int refsThreshold = INT_VALUE_NOT_SET;
 90  
     
 91  
 
 92  
     protected AbstractBayeux bayeux;
 93  
 
 94  
     public AjaxServletConnector(MuleContext context) 
 95  
     {
 96  0
         super(context);
 97  0
         registerSupportedProtocolWithoutPrefix(AjaxConnector.PROTOCOL);
 98  
         //Dont start until the servletContainer is up
 99  0
         setInitialStateStopped(true);
 100  0
     }
 101  
 
 102  
     public AbstractBayeux getBayeux()
 103  
     {
 104  0
         return bayeux;
 105  
     }
 106  
 
 107  
     public void setBayeux(AbstractBayeux bayeux) throws MuleException
 108  
     {
 109  0
         this.bayeux = bayeux;
 110  0
         this.getBayeux().setJSONCommented(isJsonCommented());
 111  0
         if(getLogLevel() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setLogLevel(getLogLevel());
 112  0
         if(getMaxInterval() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setMaxInterval(getMaxInterval());
 113  0
         if(getInterval() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setInterval(getMaxInterval());
 114  0
         if(getMultiFrameInterval() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setMultiFrameInterval(getMultiFrameInterval());
 115  0
         if(getTimeout() != AbstractConnector.INT_VALUE_NOT_SET) this.getBayeux().setTimeout(getMultiFrameInterval());
 116  
         //Only start once we have this
 117  0
         this.setInitialStateStopped(false);
 118  
         
 119  0
         for (Object receiver : receivers.values())
 120  
         {
 121  0
             ((AjaxMessageReceiver)receiver).setBayeux(getBayeux());
 122  
         }
 123  0
         start();
 124  0
     }
 125  
 
 126  
     @Override
 127  
     public String getProtocol()
 128  
     {
 129  0
         return PROTOCOL;
 130  
     }
 131  
 
 132  
     public int getInterval()
 133  
     {
 134  0
         return interval;
 135  
     }
 136  
 
 137  
     public void setInterval(int interval)
 138  
     {
 139  0
         this.interval = interval;
 140  0
     }
 141  
 
 142  
     public int getMaxInterval()
 143  
     {
 144  0
         return maxInterval;
 145  
     }
 146  
 
 147  
     public void setMaxInterval(int maxInterval)
 148  
     {
 149  0
         this.maxInterval = maxInterval;
 150  0
     }
 151  
 
 152  
     public int getMultiFrameInterval()
 153  
     {
 154  0
         return multiFrameInterval;
 155  
     }
 156  
 
 157  
     public void setMultiFrameInterval(int multiFrameInterval)
 158  
     {
 159  0
         this.multiFrameInterval = multiFrameInterval;
 160  0
     }
 161  
 
 162  
     public int getLogLevel()
 163  
     {
 164  0
         return logLevel;
 165  
     }
 166  
 
 167  
     public void setLogLevel(int logLevel)
 168  
     {
 169  0
         this.logLevel = logLevel;
 170  0
     }
 171  
 
 172  
     public int getTimeout()
 173  
     {
 174  0
         return timeout;
 175  
     }
 176  
 
 177  
     public void setTimeout(int timeout)
 178  
     {
 179  0
         this.timeout = timeout;
 180  0
     }
 181  
 
 182  
     public boolean isJsonCommented()
 183  
     {
 184  0
         return jsonCommented;
 185  
     }
 186  
 
 187  
     public void setJsonCommented(boolean jsonCommented)
 188  
     {
 189  0
         this.jsonCommented = jsonCommented;
 190  0
     }
 191  
 
 192  
     public String getFilters()
 193  
     {
 194  0
         return filters;
 195  
     }
 196  
 
 197  
     public void setFilters(String filters)
 198  
     {
 199  0
         this.filters = filters;
 200  0
     }
 201  
 
 202  
     public boolean isRequestAvailable()
 203  
     {
 204  0
         return requestAvailable;
 205  
     }
 206  
 
 207  
     public void setRequestAvailable(boolean requestAvailable)
 208  
     {
 209  0
         this.requestAvailable = requestAvailable;
 210  0
     }
 211  
 
 212  
     public int getRefsThreshold()
 213  
     {
 214  0
         return refsThreshold;
 215  
     }
 216  
 
 217  
     public void setRefsThreshold(int refsThreshold)
 218  
     {
 219  0
         this.refsThreshold = refsThreshold;
 220  0
     }
 221  
 
 222  
     @Override
 223  
     public ReplyToHandler getReplyToHandler(ImmutableEndpoint endpoint)
 224  
     {
 225  0
         return new AjaxReplyToHandler(getDefaultResponseTransformers(endpoint), this);
 226  
     }
 227  
 
 228  
     @Override
 229  
     protected MessageReceiver createReceiver(FlowConstruct flowConstruct, InboundEndpoint endpoint) throws Exception
 230  
     {
 231  0
         AjaxMessageReceiver receiver = (AjaxMessageReceiver) super.createReceiver(flowConstruct, endpoint);
 232  
         //The Bayeux object will be null of the connector has not started yet, nothing to worry about
 233  0
         receiver.setBayeux(getBayeux());
 234  0
         return receiver;
 235  
     }
 236  
 }