Package org.apache.activemq.web
Class WebClient
- java.lang.Object
-
- org.apache.activemq.web.WebClient
-
- All Implemented Interfaces:
Externalizable,Serializable,EventListener,javax.servlet.http.HttpSessionActivationListener,javax.servlet.http.HttpSessionBindingListener
- Direct Known Subclasses:
AjaxWebClient
public class WebClient extends Object implements javax.servlet.http.HttpSessionActivationListener, javax.servlet.http.HttpSessionBindingListener, Externalizable
Represents a messaging client used from inside a web container typically stored inside a HttpSession TODO controls to prevent DOS attacks with users requesting many consumers TODO configure consumers with small prefetch.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringBROKER_URL_INIT_PARAMstatic StringCONNECTION_FACTORY_ATTRIBUTEstatic StringCONNECTION_FACTORY_OPTIMIZE_ACK_PARAMstatic StringCONNECTION_FACTORY_PREFETCH_PARAMstatic StringPASSWORD_INIT_PARAMstatic StringSELECTOR_NAMEstatic StringselectorNamestatic StringUSERNAME_INIT_PARAMstatic StringWEB_CLIENT_ATTRIBUTE
-
Constructor Summary
Constructors Constructor Description WebClient()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidcloseConsumer(javax.jms.Destination destination)voidcloseConsumers()protected javax.jms.SessioncreateSession()protected static WebClientcreateWebClient(javax.servlet.http.HttpServletRequest request)javax.jms.ConnectiongetConnection()javax.jms.MessageConsumergetConsumer(javax.jms.Destination destination, String selector)javax.jms.MessageConsumergetConsumer(javax.jms.Destination destination, String selector, boolean create)List<javax.jms.MessageConsumer>getConsumers()intgetDeliveryMode()StringgetPassword()javax.jms.MessageProducergetProducer()SemaphoregetSemaphore()javax.jms.SessiongetSession()StringgetUsername()static WebClientgetWebClient(javax.servlet.http.HttpServletRequest request)Helper method to get the client for the current session, lazily creating a client if there is none currentlystatic WebClientgetWebClient(javax.servlet.http.HttpSession session)protected static voidinitConnectionFactory(javax.servlet.ServletContext servletContext)static voidinitContext(javax.servlet.ServletContext context)booleanisClosed()voidreadExternal(ObjectInput in)voidsend(javax.jms.Destination destination, javax.jms.Message message)voidsend(javax.jms.Destination destination, javax.jms.Message message, boolean persistent, int priority, long timeToLive)voidsessionDidActivate(javax.servlet.http.HttpSessionEvent event)voidsessionWillPassivate(javax.servlet.http.HttpSessionEvent event)voidsetDeliveryMode(int deliveryMode)voidsetPassword(String password)voidsetProducer(javax.jms.MessageProducer producer)voidsetUsername(String username)voidvalueBound(javax.servlet.http.HttpSessionBindingEvent event)voidvalueUnbound(javax.servlet.http.HttpSessionBindingEvent event)voidwriteExternal(ObjectOutput out)
-
-
-
Field Detail
-
WEB_CLIENT_ATTRIBUTE
public static final String WEB_CLIENT_ATTRIBUTE
- See Also:
- Constant Field Values
-
CONNECTION_FACTORY_ATTRIBUTE
public static final String CONNECTION_FACTORY_ATTRIBUTE
- See Also:
- Constant Field Values
-
CONNECTION_FACTORY_PREFETCH_PARAM
public static final String CONNECTION_FACTORY_PREFETCH_PARAM
- See Also:
- Constant Field Values
-
CONNECTION_FACTORY_OPTIMIZE_ACK_PARAM
public static final String CONNECTION_FACTORY_OPTIMIZE_ACK_PARAM
- See Also:
- Constant Field Values
-
BROKER_URL_INIT_PARAM
public static final String BROKER_URL_INIT_PARAM
- See Also:
- Constant Field Values
-
USERNAME_INIT_PARAM
public static final String USERNAME_INIT_PARAM
- See Also:
- Constant Field Values
-
PASSWORD_INIT_PARAM
public static final String PASSWORD_INIT_PARAM
- See Also:
- Constant Field Values
-
SELECTOR_NAME
public static final String SELECTOR_NAME
- See Also:
- Constant Field Values
-
selectorName
public static String selectorName
-
-
Method Detail
-
getWebClient
public static WebClient getWebClient(javax.servlet.http.HttpServletRequest request)
Helper method to get the client for the current session, lazily creating a client if there is none currently- Parameters:
request- is the current HTTP request- Returns:
- the current client or a newly creates
-
getWebClient
public static WebClient getWebClient(javax.servlet.http.HttpSession session)
- Returns:
- the web client for the current HTTP session or null if there is not a web client created yet
-
initContext
public static void initContext(javax.servlet.ServletContext context)
-
getDeliveryMode
public int getDeliveryMode()
-
setDeliveryMode
public void setDeliveryMode(int deliveryMode)
-
getUsername
public String getUsername()
-
setUsername
public void setUsername(String username)
-
getPassword
public String getPassword()
-
setPassword
public void setPassword(String password)
-
closeConsumers
public void closeConsumers()
-
close
public void close()
-
isClosed
public boolean isClosed()
-
writeExternal
public void writeExternal(ObjectOutput out) throws IOException
- Specified by:
writeExternalin interfaceExternalizable- Throws:
IOException
-
readExternal
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
- Specified by:
readExternalin interfaceExternalizable- Throws:
IOExceptionClassNotFoundException
-
send
public void send(javax.jms.Destination destination, javax.jms.Message message) throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
send
public void send(javax.jms.Destination destination, javax.jms.Message message, boolean persistent, int priority, long timeToLive) throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
getSession
public javax.jms.Session getSession() throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
getConnection
public javax.jms.Connection getConnection() throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
initConnectionFactory
protected static void initConnectionFactory(javax.servlet.ServletContext servletContext)
-
getProducer
public javax.jms.MessageProducer getProducer() throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
setProducer
public void setProducer(javax.jms.MessageProducer producer)
-
getConsumer
public javax.jms.MessageConsumer getConsumer(javax.jms.Destination destination, String selector) throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
getConsumer
public javax.jms.MessageConsumer getConsumer(javax.jms.Destination destination, String selector, boolean create) throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
closeConsumer
public void closeConsumer(javax.jms.Destination destination) throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
getConsumers
public List<javax.jms.MessageConsumer> getConsumers()
-
createSession
protected javax.jms.Session createSession() throws javax.jms.JMSException- Throws:
javax.jms.JMSException
-
getSemaphore
public Semaphore getSemaphore()
-
sessionWillPassivate
public void sessionWillPassivate(javax.servlet.http.HttpSessionEvent event)
- Specified by:
sessionWillPassivatein interfacejavax.servlet.http.HttpSessionActivationListener
-
sessionDidActivate
public void sessionDidActivate(javax.servlet.http.HttpSessionEvent event)
- Specified by:
sessionDidActivatein interfacejavax.servlet.http.HttpSessionActivationListener
-
valueBound
public void valueBound(javax.servlet.http.HttpSessionBindingEvent event)
- Specified by:
valueBoundin interfacejavax.servlet.http.HttpSessionBindingListener
-
valueUnbound
public void valueUnbound(javax.servlet.http.HttpSessionBindingEvent event)
- Specified by:
valueUnboundin interfacejavax.servlet.http.HttpSessionBindingListener
-
createWebClient
protected static WebClient createWebClient(javax.servlet.http.HttpServletRequest request)
-
-