javax.servlet.ServletContext
object
- * as an attribute under the name Bayeux.DOJOX_COMETD_BAYEUX
Bayeux bx = (Bayeux)getServletContext().getAttribute(Bayeux.DOJOX_COMETD_BAYEUX);
- *
- * The Bayeux protocol is pretty straight forward and includes a bunch of messaging that is not needed to be known to clients,
- * both server side and remote clients.
- * This object gets initialized by a container dependent servlet, and the servlet then handles all Bayeux communication from the client.
- * Remote messsages are delivered to channels, and to server side clients using the Listener
interface.
- *
- * A Bayeux session
is active as long as the webapp hosting the Bayeux object is active.
- * When the webapplication shuts down, the Bayeux object will unsubscribe all clients and remove all the active channels.
- *
- * @author Greg Wilkins
- * @author Filip Hanik
- */
-public interface Bayeux {
-
- /**Meta definitions for channels*/
- public static final String META="/meta";
- /**Meta definitions for channels*/
- public static final String META_SLASH="/meta/";
- /**Meta definitions for channels - connect message*/
- public static final String META_CONNECT="/meta/connect";
- /**Meta definitions for channels - client messsage*/
- public static final String META_CLIENT="/meta/client";
- /**Meta definitions for channels - disconnect messsage*/
- public static final String META_DISCONNECT="/meta/disconnect";
- /**Meta definitions for channels - handshake messsage*/
- public static final String META_HANDSHAKE="/meta/handshake";
- /**Meta definitions for channels - ping messsage*/
- public static final String META_PING="/meta/ping";
- /**Meta definitions for channels - reconnect messsage
- * @deprecated
- */
- public static final String META_RECONNECT="/meta/reconnect";
- /**Meta definitions for channels - status messsage*/
- public static final String META_STATUS="/meta/status";
- /**Meta definitions for channels - subscribe messsage*/
- public static final String META_SUBSCRIBE="/meta/subscribe";
- /**Meta definitions for channels - unsubscribe messsage*/
- public static final String META_UNSUBSCRIBE="/meta/unsubscribe";
- /*Field names inside Bayeux messages*/
- /**Field names inside Bayeux messages - clientId field*/
- public static final String CLIENT_FIELD="clientId";
- /**Field names inside Bayeux messages - data field*/
- public static final String DATA_FIELD="data";
- /**Field names inside Bayeux messages - channel field*/
- public static final String CHANNEL_FIELD="channel";
- /**Field names inside Bayeux messages - id field*/
- public static final String ID_FIELD="id";
- /**Field names inside Bayeux messages - error field*/
- public static final String ERROR_FIELD="error";
- /**Field names inside Bayeux messages - timestamp field*/
- public static final String TIMESTAMP_FIELD="timestamp";
- /**Field names inside Bayeux messages - transport field*/
- public static final String TRANSPORT_FIELD="transport";
- /**Field names inside Bayeux messages - advice field*/
- public static final String ADVICE_FIELD="advice";
- /**Field names inside Bayeux messages - successful field*/
- public static final String SUCCESSFUL_FIELD="successful";
- /**Field names inside Bayeux messages - subscription field*/
- public static final String SUBSCRIPTION_FIELD="subscription";
- /**Field names inside Bayeux messages - ext field*/
- public static final String EXT_FIELD="ext";
- /**Field names inside Bayeux messages - connectionType field*/
- public static final String CONNECTION_TYPE_FIELD="connectionType";
- /**Field names inside Bayeux messages - version field*/
- public static final String VERSION_FIELD="version";
- /**Field names inside Bayeux messages - minimumVersion field*/
- public static final String MIN_VERSION_FIELD="minimumVersion";
- /**Field names inside Bayeux messages - supportedConnectionTypes field*/
- public static final String SUPP_CONNECTION_TYPE_FIELD="supportedConnectionTypes";
- /**Field names inside Bayeux messages - json-comment-filtered field*/
- public static final String JSON_COMMENT_FILTERED_FIELD="json-comment-filtered";
- /**Field names inside Bayeux messages - reconnect field*/
- public static final String RECONNECT_FIELD = "reconnect";
- /**Field names inside Bayeux messages - interval field*/
- public static final String INTERVAL_FIELD = "interval";
- /**Field values inside Bayeux messages - retry response*/
- public static final String RETRY_RESPONSE = "retry";
- /**Field values inside Bayeux messages - handshake response*/
- public static final String HANDSHAKE_RESPONSE = "handshake";
- /**Field values inside Bayeux messages - none response*/
- public static final String NONE_RESPONSE = "none";
- /**Service channel names-starts with*/
- public static final String SERVICE="/service";
- /**Service channel names-trailing slash*/
- public static final String SERVICE_SLASH="/service/";
- /*Transport types*/
- /**Transport types - long polling*/
- public static final String TRANSPORT_LONG_POLL="long-polling";
- /**Transport types - callback polling*/
- public static final String TRANSPORT_CALLBACK_POLL="callback-polling";
- /**Transport types - iframe*/
- public static final String TRANSPORT_IFRAME="iframe";
- /**Transport types - flash*/
- public static final String TRANSPORT_FLASH="flash";
- /** ServletContext attribute name used to obtain the Bayeux object */
- public static final String DOJOX_COMETD_BAYEUX="dojox.cometd.bayeux";
- /*http field names*/
- /**http helpers - text/json content type*/
- public static final String JSON_CONTENT_TYPE="text/json";
- /**http helpers - parameter name for json message*/
- public static final String MESSAGE_PARAMETER="message";
- /**http helpers - name of the jsonp parameter*/
- public static final String JSONP_PARAMETER="jsonp";
- /**http helpers - default name of the jsonp callback function*/
- public static final String JSONP_DEFAULT_NAME="jsonpcallback";
-
- /*--Client----------------------------------------------------------- */
- /**
- * Creates a new server side client. This method is to be invoked
- * by server side objects only. You cannot create a remote client by using this method.
- * A client represents an entity that can subscribe to channels and publish and receive messages
- * through these channels
- * @param idprefix String - the prefix string for the id generated, can be null
- * @param listener Listener - a callback object to be called when messages are to be delivered to the new client
- * @return Client - returns an implementation of the client interface.
- */
- public Client newClient(String idprefix, Listener listener);
-
- /**
- * retrieve a client based on an ID. Will return null if the client doesn't exist.
- * @param clientid String
- * @return Client-null if the client doesn't exist.returns the client if it does.
- */
- public Client getClient(String clientid);
-
- /**
- * Returns a non modifiable list of all the clients that are currently active
- * in this Bayeux session
- * @return List - a list containing all clients. The List can not be modified.
- */
- public List getClients();
-
- /**
- * Returns true if a client with the given id exists.
- * Same as executing getClient(id)!=null
.
- * @param clientId String
- * @return boolean - true if the client exists
- */
- public boolean hasClient(String clientId);
-
- /**
- * Removes the client all together.
- * This will unsubscribe the client to any channels it may be subscribed to
- * and remove it from the list.
- * @param client Client
- * @return Client - returns the client that was removed, or null if no client was removed.
- */
- public Client remove(Client client);
-
-
- /*--Channel---------------------------------------------------------- */
- /**
- * Returns the channel for a given channel id.
- * If the channel doesn't exist, and the create
parameter is set to true,
- * the channel will be created and added to the list of active channels.
- * if create
is set to false, and the channel doesn't exist, null will be returned.
- * @param channelId String - the id of the channel to be retrieved or created
- * @param create boolean - true if the Bayeux impl should create the channel
- * @return Channel - null if create
is set to false and the channel doesn't exist,
- * otherwise it returns a channel object.
- */
- public Channel getChannel(String channelId, boolean create);
-
- /**
- * Returns a list of currently active channels in this Bayeux session.
- * @return List
- */
- public List getChannels();
-
- /**
- * Removes a channel from the Bayeux object.
- * This will also unsubscribe all the clients currently subscribed to the
- * the channel.
- * @param channel Channel - the channel to be removed
- * @return Channel - returns the channel that was removed, or null if no channel was removed.
- */
- public Channel remove(Channel channel);
-
- /**
- * returns true if a channel with the given channelId exists.
- *
Same as executing Bayeux.getChannel(channelId,false)!=null
- * @param channelId String
- * @return boolean - true if the channel exists.
- */
- public boolean hasChannel(String channelId);
-
- /* --Message---------------------------------------------------------- */
- /**
- * Creates a new message to be sent by a server side client.
- * @return Message - returns a new Message object, that has a unique id.
- */
- public Message newMessage(Client from);
-
-
- /*--Security policy----------------------------------------------------------- */
- /**
- * Returns the security policy associated with this Bayeux session
- * @return SecurityPolicy
- */
- public SecurityPolicy getSecurityPolicy();
-
- /**
- * Sets the security policy to be used in this Bayeux session
- * @param securityPolicy SecurityPolicy
- */
- public void setSecurityPolicy(SecurityPolicy securityPolicy);
-
-}
\ No newline at end of file
diff --git a/modules/bayeux/java/org/apache/cometd/bayeux/Channel.java b/modules/bayeux/java/org/apache/cometd/bayeux/Channel.java
deleted file mode 100644
index 468b5e181811..000000000000
--- a/modules/bayeux/java/org/apache/cometd/bayeux/Channel.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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.cometd.bayeux;
-
-import java.util.List;
-
-/**
- * A Bayeux Channel represents a channel used to receive messages from and to publish messages to.
- * In order to publish messages to or receive messages from, one must subscribe to the channel.
- * This is easily done by invoking the subscribe
method.
- * A channel is created by calling the Bayeux.getChannel(channelId,true)
method.
- * A channel can be created either server side by invoking the getChannel, or client side
- * by using the /meta/subscribe message without a wildcard.
- * @author Greg Wilkins
- * @author Filip Hanik
- */
-public interface Channel
-{
- /**
- * Returns the id for this channel. The id is unique within bayeux session.
- * @return String - will never be null.
- */
- public String getId();
-
- /**
- * Publishes a message to all the subscribers of this channel.
- * The from
is contained within the message, by calling
- * msg.getClient()
- * @param data - the message to be published, can not be null.
- */
- public void publish(Message msg);
-
- /**
- * Publishes more than one message to all the subscribers of this channel.
- * The from
is contained within the message, by calling
- * msg[x].getClient()
- * @param data - the message to be published, can not be null.
- */
- public void publish(Message[] msgs);
-
- /**
- * Non persistent channels are removed when the last subscription is
- * removed. Persistent channels survive periods without any subscribers.
- * @return true if the Channel will persist without any subscription.
- */
- public boolean isPersistent();
-
- /**
- * @param persistent true if the Channel will persist without any subscription.
- * @see isPersistent
- */
- public void setPersistent(boolean persistent);
-
- /**
- * Subscribes a client to a channel.
- * @param subscriber - the client to be subscribed. If the client
- * already is subscribed, this call will not create a duplicate subscription.
- */
- public void subscribe(Client subscriber);
-
- /**
- * Unsubscribes a client from a channel
- * @param subscriber - the client to be subscribed.
- * @return - returns the client that was unsubscribed, or null if the client wasn't subscribed.
- */
- public Client unsubscribe(Client subscriber);
-
- /**
- * returns a non modifiable list of all the subscribers to this
- * channel.
- * @return a list of subscribers
- */
- public List getSubscribers();
-
- /**
- * Adds a data filter to this channel. All messages received by this channel
- * will run through this filter.
- * @param filter Filter
- */
- public void addFilter(DataFilter filter);
-
- /**
- * Removes a filter from this channel.
- * returns the filter that was removed, or null if the filter wasn't in the channel.
- * @param filter Filter
- * @return Filter - null if no filter was removed otherwise it returns the filter that was removed.
- */
- public DataFilter removeFilter(DataFilter filter);
-}
\ No newline at end of file
diff --git a/modules/bayeux/java/org/apache/cometd/bayeux/Client.java b/modules/bayeux/java/org/apache/cometd/bayeux/Client.java
deleted file mode 100644
index 32e8773b09e1..000000000000
--- a/modules/bayeux/java/org/apache/cometd/bayeux/Client.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.cometd.bayeux;
-
-
-
-/** A Bayeux Client.
- *
- * A client may subscribe to channels and publish messages to channels.
- * Client instances should not be directly created by uses, but should
- * be obtained via the {@link Bayeux#getClient(String)} or {@link Bayeux#newClient(String, Listener)}
- * methods.
- *
- *
- * Three types of client may be represented by this interface:
- * The server representation of a remote client connected via HTTP,
- * automatically created by the Bayeux server when a connect message comes in
- * A server side client, created by the application using the {@link Bayeux#newClient(String, Listener)} method
- * A java client connected to a remote Bayeux server - not implemented
- *
- * @author Greg Wilkins
- * @author Filip Hanik
- */
-public interface Client
-{
- /**
- * Returns a unique id for this client. The id is unique within this Bayeux session.
- * @return String - will not be null
- */
- public String getId();
-
- /**
- * Returns true if this client is holding messages to be delivered to the remote client.
- * This method always returns false for local clients, since messages are delivered instantly using the
- * Listener(callback) object
- * @return boolean
- */
- public boolean hasMessages();
-
- /**
- * Deliver a message to this client only
- * Deliver a message directly to the client. The message is not
- * filtered or published to a channel.
- * @param message
- */
- public void deliver(Message message);
-
- /**
- * Deliver a batch of messages to this client only
- * Deliver a batch messages directly to the client. The messages are not
- * filtered or published to a channel.
- * @param message
- */
- public void deliver(Message[] message);
-
- /**
- * @return True if the client is local. False if this client is either a remote HTTP client or
- * a java client to a remote server.
- */
- public boolean isLocal();
-
- /**
- * Starts a batch, no messages will be delivered until endBatch is called.
- * Batches can be nested, and messages will only be delivered after
- * the last endBatch has been called.
- */
- public void startBatch();
-
- /**
- * Ends a batch. since batches can be nested, messages will only be delivered
- * after the endBatch has been called as many times as startBatch has.
- */
- public void endBatch();
-
-
-}
\ No newline at end of file
diff --git a/modules/bayeux/java/org/apache/cometd/bayeux/DataFilter.java b/modules/bayeux/java/org/apache/cometd/bayeux/DataFilter.java
deleted file mode 100644
index abc964e21edf..000000000000
--- a/modules/bayeux/java/org/apache/cometd/bayeux/DataFilter.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.cometd.bayeux;
-
-/**
- * Data Filter
- * Data filters are used to transform data as it is sent to a Channel.
- * Messages are filtered as the message is published to a channel, invoking the
- * {@link Channel#publish(Message)} method.
- * This method gets invoked in two different scenarios, the first being when a message is received from
- * a remote client, and the Bayeux implementation invokes the publish method directly.
- * The second scenario is when a local client invokes {@link Channel#publish(Message)} directly in the local JVM.
- * @author Greg Wilkins
- * @author Filip Hanik
- *
- */
-public interface DataFilter
-{
- /**
- * Runs a message through the filter. Filtering can only modify an existing object, it can not replace it.
- * @param data Message - the message to be filtered, may not be null
- */
- public void filter(Message data);
-}
diff --git a/modules/bayeux/java/org/apache/cometd/bayeux/Listener.java b/modules/bayeux/java/org/apache/cometd/bayeux/Listener.java
deleted file mode 100644
index 9cd86d014f35..000000000000
--- a/modules/bayeux/java/org/apache/cometd/bayeux/Listener.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.cometd.bayeux;
-
-/**
- * Cometd Listener interface.
- * For local clients, in order to receive messages, they pass in a callback object
- * when the local client is created using the {@link Bayeux#newClient(String,Listener)} method.
- * This callback object, implementing the Listener interface, is used to deliver messages to local, in JVM, clients.
- * @author Greg Wilkins
- * @author Filip Hanik
- *
- */
-public interface Listener
-{
- /**
- * This method is called when the client is removed (explicitly or from a timeout)
- * @param timeout - true if the client was removed from a timeout
- * false if it was removed explicitly.
- */
- public void removed(boolean timeout);
-
- /**
- * Invoked when a message is delivered to the client.
- * The message contains the message itself, as well as what channel this message came through
- * and who the sender is. If someone invoked {@link Client#deliver(Message)} then the channel reference will
- * be null.
- * @param msg
- */
- public void deliver(Message[] msg);
-}
diff --git a/modules/bayeux/java/org/apache/cometd/bayeux/Message.java b/modules/bayeux/java/org/apache/cometd/bayeux/Message.java
deleted file mode 100644
index 12b525bf9853..000000000000
--- a/modules/bayeux/java/org/apache/cometd/bayeux/Message.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.cometd.bayeux;
-
-import java.util.Map;
-
-/**
- * A Bayeux Message
- * A Bayeux message is a Map of String/Object key value pairs representing the data in the message.
- * The message contains information about the channel it was published through and who the sender was
- *
- * @author Greg Wilkins
- * @author Filip Hanik
- */
-public interface Message extends Map
-{
- /**
- * Returns a reference to the client that sent this message
- * @return Client - may be null
- */
- public Client getClient();
- /**
- * Returns a reference to the channel that this message was published throuhg
- * @return Channel - may be null
- */
- public Channel getChannel();
- /**
- * Returns the unique id of this message
- * @return String
- */
- public String getId();
-
- /**
- * Sets the time to live in milliseconds. If the message hasn't been delivered
- * when the time passed after the creation time is longer than the TTL the message will
- * expire and removed from any delivery queues.
- * @param ttl long
- */
- public void setTTL(long ttl);
-
- /**
- * Returns the time to live (in milliseconds) for this message
- * @return long
- */
- public long getTTL();
-
- /**
- * returns the timestamp in milliseconds(System.currentTimeMillis()) of when this message was created.
- * @return long
- */
- public long getCreationTime();
-}
-
-
diff --git a/modules/bayeux/java/org/apache/cometd/bayeux/SecurityPolicy.java b/modules/bayeux/java/org/apache/cometd/bayeux/SecurityPolicy.java
deleted file mode 100644
index 55e71586d046..000000000000
--- a/modules/bayeux/java/org/apache/cometd/bayeux/SecurityPolicy.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.cometd.bayeux;
-
-/**
- * @author Greg Wilkins
- */
-public interface SecurityPolicy
-{
- boolean canHandshake(Message message);
- boolean canCreate(Client client,String channel,Message message);
- boolean canSubscribe(Client client,String channel,Message messsage);
- boolean canPublish(Client client,String channel,Message messsage);
-}
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxException.java b/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxException.java
deleted file mode 100644
index 6d96bb362388..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxException.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-/**
- *
- * @author Filip Hanik
- * @version 1.0
- */
-public class BayeuxException extends Exception {
- public BayeuxException() {
- super();
- }
-
- public BayeuxException(String message) {
- super(message);
- }
-
- public BayeuxException(String message, Throwable cause) {
- super(message, cause);
- }
-
- public BayeuxException(Throwable cause) {
- super(cause);
- }
-}
\ No newline at end of file
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxRequest.java b/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxRequest.java
deleted file mode 100644
index 6dd9b33ff8c6..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxRequest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import org.apache.tomcat.bayeux.HttpError;
-
-/**
- * An interface that defines methods for managing Bayeux request meta
- * messages.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 0.9
- */
-public interface BayeuxRequest {
-
- public static final String LAST_REQ_ATTR = "org.apache.cometd.bayeux.last_request";
- public static final String CURRENT_REQ_ATTR = "org.apache.cometd.bayeux.current_request";
- public static final String JSON_MSG_ARRAY = "org.apache.cometd.bayeux.json_msg_array";
-
- /**
- * Validates a specific request.
- * This method must be called prior to process()
- * as a request can do pre processing in the validate method.
- *
- * Should the validation fail, an error object is returned
- * containing an error message, and potentially a stack trace
- * if an exception was generated
- * @return HttpError - null if no error was detected, an HttpError object containing information about the error.
- */
- public HttpError validate();
-
- /**
- * processes a remote client Bayeux message
- * @param prevops - the operation requested by the previous request, in case of chained requests.
- * @return int - returns the interest operation for a CometEvent. Currently not used
- * @throws BayeuxException - if an error was detected, and the appropriate error response couldn't be delivered to the client.
- */
- public int process(int prevops) throws BayeuxException;
-}
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxServlet.java b/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxServlet.java
deleted file mode 100644
index d53c80aad19c..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/BayeuxServlet.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import java.io.IOException;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.catalina.comet.CometProcessor;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-
-/**
- *
- * @author Filip Hanik
- * @author Guy Molinari
- * @version 1.0
- */
-public class BayeuxServlet implements CometProcessor {
-
- /**
- * Attribute to hold the TomcatBayeux object in the servlet context
- */
- public static final String TOMCAT_BAYEUX_ATTR = Bayeux.DOJOX_COMETD_BAYEUX;
-
- /**
- * Logger object
- */
- private static final Log log = LogFactory.getLog(BayeuxServlet.class);
-
- /**
- * Servlet config - for future use
- */
- protected ServletConfig servletConfig;
-
- /**
- * Reference to the global TomcatBayeux object
- */
- protected TomcatBayeux tb;
-
- /**
- * Upon servlet destruction, the servlet will clean up the
- * TomcatBayeux object and terminate any outstanding events.
- */
- public void destroy() {
- servletConfig = null;
- //to do, close all outstanding comet events
- //tb.destroy();
- tb = null;//TO DO, close everything down
-
- }
-
- /**
- * Returns the preconfigured connection timeout.
- * If no timeout has been configured as a servlet init parameter named timeout
- * then the default of 2min will be used.
- * @return int - the timeout for a connection in milliseconds
- */
- protected int getTimeout() {
- String timeoutS = servletConfig.getInitParameter("timeout");
- int timeout = 120*1000; //2 min
- try {
- timeout = Integer.parseInt(timeoutS);
- }catch (NumberFormatException nfe) {
- //ignore, we have a default value
- }
- return timeout;
- }
-
- protected int getReconnectInterval() {
- String rs = servletConfig.getInitParameter("reconnectInterval");
- int rct = 1000; //1 seconds
- try {
- rct = Integer.parseInt(rs);
- }catch (NumberFormatException nfe) {
- //ignore, we have a default value
- }
- return rct;
- }
-
-
- public void event(CometEvent cometEvent) throws IOException, ServletException {
- CometEvent.EventType type = cometEvent.getEventType();
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Received Comet Event type="+type+" subtype:"+cometEvent.getEventSubType());
- }
- synchronized (cometEvent) {
- if (type==CometEvent.EventType.BEGIN) {
- //begin event, set the timeout
- cometEvent.setTimeout(getTimeout());
- //checkBayeux(cometEvent); - READ event should always come
- } else if (type==CometEvent.EventType.READ) {
- checkBayeux(cometEvent);
- } else if (type==CometEvent.EventType.ERROR) {
- tb.remove(cometEvent);
- cometEvent.close();
- } else if (type==CometEvent.EventType.END) {
- tb.remove(cometEvent);
- cometEvent.close();
- }//end if
-
- }//synchronized
- }//event
-
- /**
- *
- * @param cometEvent CometEvent
- * @return boolean - true if we comet event stays open
- * @throws IOException
- * @throws UnsupportedOperationException
- */
- protected void checkBayeux(CometEvent cometEvent) throws IOException, UnsupportedOperationException {
- //we actually have data.
- //data can be text/json or
- if (Bayeux.JSON_CONTENT_TYPE.equals(cometEvent.getHttpServletRequest().getContentType())) {
- //read and decode the bytes according to content length
- log.warn("["+Thread.currentThread().getName()+"] JSON encoding not supported, will throw an exception and abort the request.");
- int contentlength = cometEvent.getHttpServletRequest().getContentLength();
- throw new UnsupportedOperationException("Decoding "+Bayeux.JSON_CONTENT_TYPE+" not yet implemented.");
- } else { //GET method or application/x-www-form-urlencoded
- String message = cometEvent.getHttpServletRequest().getParameter(Bayeux.MESSAGE_PARAMETER);
- if (log.isTraceEnabled()) {
- log.trace("["+Thread.currentThread().getName()+"] Received JSON message:"+message);
- }
- try {
- int action = handleBayeux(message, cometEvent);
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Bayeux handling complete, action result="+action);
- }
- if (action<=0) {
- cometEvent.close();
- }
- }catch (Exception x) {
- x.printStackTrace();
- tb.remove(cometEvent);
- log.error(x);
- cometEvent.close();
- }
- }
- }
-
- protected int handleBayeux(String message, CometEvent event) throws IOException, ServletException {
- int result = 0;
- if (message==null || message.length()==0) return result;
- try {
- BayeuxRequest request = null;
- //a message can be an array of messages
- JSONArray jsArray = new JSONArray(message);
- for (int i = 0; i < jsArray.length(); i++) {
- JSONObject msg = jsArray.getJSONObject(i);
-
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Processing bayeux message:"+msg);
- }
- request = RequestFactory.getRequest(tb,event,msg);
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Processing bayeux message using request:"+request);
- }
- result = request.process(result);
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Processing bayeux message result:"+result);
- }
- }
- if (result>0 && request!=null) {
- event.getHttpServletRequest().setAttribute(BayeuxRequest.LAST_REQ_ATTR, request);
- ClientImpl ci = (ClientImpl)tb.getClient(((RequestBase)request).getClientId());
- ci.addCometEvent(event);
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Done bayeux message added to request attribute");
- }
- } else if (result == 0 && request!=null) {
- RequestBase.deliver(event,(ClientImpl)tb.getClient(((RequestBase)request).getClientId()));
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Done bayeux message, delivered to client");
- }
- }
-
- }catch (JSONException x) {
- log.error(x);//to do impl error handling
- result = -1;
- }catch (BayeuxException x) {
- log.error(x); //to do impl error handling
- result = -1;
- }
- return result;
- }
-
- public ServletConfig getServletConfig() {
- return servletConfig;
- }
-
- public String getServletInfo() {
- return "Tomcat/BayeuxServlet/1.0";
- }
-
- public void init(ServletConfig servletConfig) throws ServletException {
-
- this.servletConfig = servletConfig;
- ServletContext ctx = servletConfig.getServletContext();
- if (ctx.getAttribute(TOMCAT_BAYEUX_ATTR)==null)
- ctx.setAttribute(TOMCAT_BAYEUX_ATTR,new TomcatBayeux());
- this.tb = (TomcatBayeux)ctx.getAttribute(TOMCAT_BAYEUX_ATTR);
- tb.setReconnectInterval(getReconnectInterval());
- }
-
- public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
- if (servletResponse instanceof HttpServletResponse) {
- ( (HttpServletResponse) servletResponse).sendError(500, "Misconfigured Tomcat server, must be configured to support Comet operations.");
- } else {
- throw new ServletException("Misconfigured Tomcat server, must be configured to support Comet operations for the Bayeux protocol.");
- }
- }
-}
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/ChannelImpl.java b/modules/bayeux/java/org/apache/tomcat/bayeux/ChannelImpl.java
deleted file mode 100644
index 353af6c8cb65..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/ChannelImpl.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import java.util.LinkedList;
-
-import org.apache.cometd.bayeux.Channel;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.DataFilter;
-import java.util.Collections;
-import java.util.List;
-import org.apache.cometd.bayeux.Message;
-import java.util.Iterator;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-/**
- *
- * @author Filip Hanik
- * @version 1.0
- */
-public class ChannelImpl implements Channel {
-
- private static final Log log = LogFactory.getLog(ChannelImpl.class);
-
- /**
- * The unique id of this channel
- */
- protected String id = null;
-
- /**
- * A list of the current subscribers
- */
- protected LinkedList subscribers = new LinkedList();
-
- /**
- * A list of the current filters
- */
- protected LinkedList filters = new LinkedList();
-
- /**
- * Is this channel persistent, default value is true
- */
- protected boolean persistent = true;
-
- /**
- * Creates a new channel
- * @param id String - the id of the channel, can not be null
- */
- protected ChannelImpl(String id) {
- assert id != null;
- this.id = id;
- }
-
- /**
- * returns the id of this channel
- * @return String
- */
- public String getId() {
- return id;
- }
-
- /**
- * Returns true if this channel matches the pattern to its id.
- * The channel pattern can be a complete name like /service/mychannel
- * or it can be a wild card pattern like /service/app2/**
- * @param pattern String according to the Bayeux specification section 2.2.1 Channel Globbing, can not be null.
- * @return boolean true if the id of this channel matches the pattern
- */
- public boolean matches(String pattern) {
- if (pattern == null)
- throw new NullPointerException("Channel pattern must not be null.");
- if (getId().equals(pattern))
- return true;
- int wildcardPos = pattern.indexOf("/*");
- if (wildcardPos == -1)
- return false;
- boolean multiSegment = pattern.indexOf("**") != -1;
- String leadSubstring = pattern.substring(0, wildcardPos);
- if (leadSubstring == null)
- return false;
- if (multiSegment)
- return getId().startsWith(leadSubstring);
- else {
- if (getId().length() <= wildcardPos + 2)
- return false;
- return !(getId().substring(wildcardPos + 2).contains("/"));
- }
- }
-
-
-
- /**
- * @return returns a non modifiable list of the subscribers for this channel.
- */
- public List getSubscribers() {
- return Collections.unmodifiableList(subscribers);
- }
-
- /**
- * @return true if the Channel will persist without any subscription.
- */
- public boolean isPersistent() {
- return persistent;
- }
-
- public void publish(Message msg) {
- publish(new Message[] {msg});
- }
-
- public void publish(Message[] msgs) {
- if (msgs==null) return;
- MessageImpl[] imsgs = new MessageImpl[msgs.length];
- for (int i=0; msgs!=null && i it = filters.iterator(); it.hasNext(); ) {
- it.next().filter(msg);
- }
- imsgs[i] = msg;
- }
- //deliver it to the clients
- for (Iterator it = subscribers.iterator(); it.hasNext(); ) {
- ClientImpl c = (ClientImpl)it.next();
- c.deliverInternal(this,imsgs);
- }
-
- }
-
- public void setPersistent(boolean persistent) {
- this.persistent = persistent;
- }
-
- public void subscribe(Client subscriber) {
- if (!subscribers.contains((subscriber))) {
- subscribers.addLast(subscriber);
- ((ClientImpl)subscriber).subscribed(this);
- }
- }
-
- public Client unsubscribe(Client subscriber) {
- if (subscribers.remove(subscriber)) {
- ((ClientImpl)subscriber).unsubscribed(this);
- return subscriber;
- } else
- return null;
- }
-
- public void addFilter(DataFilter filter) {
- if (!filters.contains(filter))
- filters.addLast(filter);
- }
-
- public DataFilter removeFilter(DataFilter filter) {
- if ( filters.remove(filter) ) return filter;
- else return null;
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder(super.toString());
- buf.append("; channelId=").append(getId());
- return buf.toString();
- }
-
-}
\ No newline at end of file
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/ClientImpl.java b/modules/bayeux/java/org/apache/tomcat/bayeux/ClientImpl.java
deleted file mode 100644
index 4a9de3c39543..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/ClientImpl.java
+++ /dev/null
@@ -1,279 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import org.apache.catalina.comet.CometEvent;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.Listener;
-import org.apache.cometd.bayeux.Message;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.HashMap;
-import java.util.ArrayList;
-
-public class ClientImpl implements Client {
-
- public static final int SUPPORT_CALLBACK_POLL = 0x1;
- public static final int SUPPORT_LONG_POLL = 0x2;
-
- public static final String COMET_EVENT_ATTR = "org.apache.cometd.bayeux.client";
-
- private static final Log log = LogFactory.getLog(ClientImpl.class);
-
- protected static LinkedList EMPTY_LIST = new LinkedList();
- /**
- * queued message for remote clients.
- */
- protected LinkedList messages = null;
-
- /**
- *
- */
- protected Queue events = new LinkedList();
-
- /**
- * Unique id representing this client
- */
- protected String id;
-
- /**
- * supported connection types, defaults to long-polling
- */
- protected int supportedConnTypes = SUPPORT_LONG_POLL | SUPPORT_CALLBACK_POLL;
-
- /**
- * The desired connection type
- */
- protected int desirectConnType = SUPPORT_LONG_POLL;
-
- /**
- * Does this client use json-comment-filtered messages
- */
- protected boolean useJsonFiltered = false;
-
- /**
- * Same JVM clients, get local=true
- */
- protected boolean local;
-
- /**
- * The callback object for local clients
- */
- protected Listener listener;
-
- protected AtomicInteger nrofsubscriptions = new AtomicInteger(0);
-
- protected ClientImpl(String id, boolean local) {
- this.id = id;
- this.local = local;
- if (!local) messages = new LinkedList();
- }
-
- protected ClientImpl(String id, CometEvent event) {
- this(id,false);
- events = new ConcurrentLinkedQueue();
- addCometEvent(event);
- }
-
- public synchronized void deliver(Message message) {
- deliverInternal(null,new MessageImpl[] {(MessageImpl)message});
- }
-
- public synchronized void deliver(Message[] message) {
- deliverInternal(null,message);
- }
-
- protected synchronized void deliverInternal(ChannelImpl channel, MessageImpl message) {
- deliverInternal(channel,new MessageImpl[] {message});
- }
-
- protected synchronized void deliverInternal(ChannelImpl channel, Message[] msgs) {
- if (isLocal()) {
- //local clients must have a listener
- ArrayList list = new ArrayList();
- for (int i=0; msgs!=null && i0) {
- getListener().deliver(list.toArray(new Message[0]));
- }
- } else {
- for (int i=0; msgs!=null && i 0;
- }
- }
-
- public boolean isLocal() {
- return local;
- }
-
- public int getSupportedConnTypes() {
- return supportedConnTypes;
- }
-
- public int getDesirectConnType() {
- return desirectConnType;
- }
-
- public boolean useJsonFiltered() {
- return useJsonFiltered;
- }
-
- public void setListener(Listener listener) {
- this.listener = listener;
- }
-
- public void setSupportedConnTypes(int supportedConnTypes) {
- this.supportedConnTypes = supportedConnTypes;
- }
-
- public void setUseJsonFiltered(boolean useJsonFiltered) {
- this.useJsonFiltered = useJsonFiltered;
- }
-
- public void setDesirectConnType(int desirectConnType) {
- this.desirectConnType = desirectConnType;
- }
-
- public boolean supportsCallbackPoll() {
- return (supportedConnTypes & SUPPORT_CALLBACK_POLL) == SUPPORT_CALLBACK_POLL;
- }
-
- public boolean supportsLongPoll() {
- return (supportedConnTypes & SUPPORT_LONG_POLL) == SUPPORT_LONG_POLL;
- }
-
- public synchronized List takeMessages() {
- if (isLocal()) return null;
- if (messages.size()==0) return EMPTY_LIST;
- List result = new LinkedList(messages);
- messages.clear();
- return result;
- }
-
- public String toString() {
- StringBuilder buf = new StringBuilder(super.toString());
- buf.append(" id=").append(getId());
- return buf.toString();
- }
-
- public boolean isSubscribed() {
- return nrofsubscriptions.get()>0;
- }
-
- protected synchronized boolean addCometEvent(CometEvent event) {
- boolean result = false;
- if (!events.contains(event)) {
- events.add(event);
- result = true;
- }
- event.getHttpServletRequest().setAttribute(COMET_EVENT_ATTR,this);
- return result;
- }
-
- protected synchronized boolean removeCometEvent(CometEvent event) {
- boolean result = events.remove(event);
- event.getHttpServletRequest().removeAttribute(COMET_EVENT_ATTR);
- return result;
- }
-
-
- protected void subscribed(ChannelImpl ch) {
- nrofsubscriptions.addAndGet(1);
- }
-
- protected void unsubscribed(ChannelImpl ch) {
- nrofsubscriptions.addAndGet(-1);
- }
-
- public void startBatch(){
- //noop until improved
- }
- public void endBatch() {
- //noop until improved
- }
-
-}
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/HttpError.java b/modules/bayeux/java/org/apache/tomcat/bayeux/HttpError.java
deleted file mode 100644
index 57d5636ea854..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/HttpError.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-public class HttpError {
- private int code;
- private String status;
- private Throwable cause;
- public HttpError(int code, String status, Throwable cause) {
- this.code = code;
- this.status = status;
- this.cause = cause;
- }
-
- public void setCode(int code) {
- this.code = code;
- }
-
- public void setStatus(String status) {
- this.status = status;
- }
-
- public void setCause(Throwable exception) {
- this.cause = exception;
- }
-
- public int getCode() {
- return code;
- }
-
- public String getStatus() {
- return status;
- }
-
- public Throwable getCause() {
- return cause;
- }
-
- public String toString() {
- if (cause != null)
- return code + ":" + status + " - [" + cause + "]";
- else
- return code + ":" + status;
- }
-}
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/MessageImpl.java b/modules/bayeux/java/org/apache/tomcat/bayeux/MessageImpl.java
deleted file mode 100644
index 8a3a24f98387..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/MessageImpl.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import java.util.HashMap;
-
-import org.apache.cometd.bayeux.Channel;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.Message;
-
-public class MessageImpl extends HashMap implements Message {
-
- protected Channel channel;
- protected Client client;
- protected String id;
- private long TTL = 1000*60*5; //5min is the default TTL for a message
- protected long creationTime = System.currentTimeMillis();
-
- public Object clone() {
- MessageImpl copy = new MessageImpl(id);
- copy.putAll(this);
- copy.channel = channel;
- copy.client = client;
- copy.id = id;
- copy.creationTime = creationTime;
- copy.TTL = TTL;
- return copy;
- }
-
- protected MessageImpl(String id) {
- assert id != null;
- this.id = id;
- }
-
- public Channel getChannel() {
- return channel;
- }
-
- public Client getClient() {
- return client;
- }
-
- public long getCreationTime() {
- return creationTime;
- }
-
- public long getTTL() {
- return TTL;
- }
-
- public String getId() {
- return id;
- }
-
- protected void setChannel(Channel channel) {
- this.channel = channel;
- }
-
- protected void setClient(Client client) {
- this.client = client;
- }
-
- public void setTTL(long TTL) {
- this.TTL = TTL;
- }
-}
\ No newline at end of file
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/RequestBase.java b/modules/bayeux/java/org/apache/tomcat/bayeux/RequestBase.java
deleted file mode 100644
index 0daa2cc49114..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/RequestBase.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.TimeZone;
-import java.util.Date;
-import java.text.SimpleDateFormat;
-import javax.servlet.ServletException;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.tomcat.bayeux.HttpError;
-
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.cometd.bayeux.Message;
-
-/**
- * Common functionality and member variables for all Bayeux requests.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 0.9
- *
- */
-public abstract class RequestBase implements BayeuxRequest {
-
- protected static final SimpleDateFormat timestampFmt =
- new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
- static {
- timestampFmt.setTimeZone(TimeZone.getTimeZone("GMT"));
- }
- //message properties, combined for all messages
- protected TomcatBayeux tomcatBayeux;
- protected String channel;
- protected String id;
- protected String clientId;
- protected String version = null;
- protected String[] suppConnTypes = null;
- protected int suppConnTypesFlag = 0;
- protected int desiredConnTypeFlag = 0;
- protected String minVersion = null;
- protected String subscription = null;
- protected String data = null;
- protected String conType = null;
- protected LinkedHashMap ext = new LinkedHashMap ();
-
-
- protected CometEvent event;
-
- protected HashMap response = null;
-
- private static final Log log = LogFactory.getLog(RequestBase.class);
-
- protected int reconnectInterval = 1000;
-
- protected RequestBase(TomcatBayeux tb, CometEvent event, JSONObject jsReq) throws JSONException {
- this.tomcatBayeux = tb;
- this.event = event;
- channel = jsReq.optString(Bayeux.CHANNEL_FIELD);
- id = jsReq.optString(Bayeux.ID_FIELD);
- clientId = jsReq.optString(Bayeux.CLIENT_FIELD);
- version = jsReq.optString(Bayeux.VERSION_FIELD);
- minVersion = jsReq.optString(Bayeux.MIN_VERSION_FIELD);
- conType = jsReq.optString(Bayeux.CONNECTION_TYPE_FIELD);
- subscription = jsReq.optString(Bayeux.SUBSCRIPTION_FIELD);
- data = jsReq.optString(Bayeux.DATA_FIELD);
- reconnectInterval = tb.getReconnectInterval();
- if (jsReq.has(Bayeux.EXT_FIELD)) {
- JSONObject jext = jsReq.getJSONObject(Bayeux.EXT_FIELD);
- for (Iterator i = jext.keys(); i.hasNext(); ) {
- String key = i.next();
- ext.put(key, jext.get(key));
- }//for
- }//end if
-
- if (jsReq.has(Bayeux.SUPP_CONNECTION_TYPE_FIELD)) {
- JSONArray types = jsReq.getJSONArray(Bayeux.SUPP_CONNECTION_TYPE_FIELD);
- suppConnTypes = new String[types.length()];
- for (int i = 0; i < types.length(); i++) {
- suppConnTypes[i] = types.getString(i);
- if (Bayeux.TRANSPORT_CALLBACK_POLL.equals(suppConnTypes[i]))
- suppConnTypesFlag = suppConnTypesFlag|ClientImpl.SUPPORT_CALLBACK_POLL;
- else if (Bayeux.TRANSPORT_LONG_POLL.equals(suppConnTypes[i]))
- suppConnTypesFlag = suppConnTypesFlag|ClientImpl.SUPPORT_LONG_POLL;
- }//for
- }//end if
-
- if (conType!=null) {
- if (Bayeux.TRANSPORT_CALLBACK_POLL.equals(conType))
- desiredConnTypeFlag = ClientImpl.SUPPORT_CALLBACK_POLL;
- else if (Bayeux.TRANSPORT_LONG_POLL.equals(conType))
- desiredConnTypeFlag = ClientImpl.SUPPORT_LONG_POLL;
- }//end if
-
- //due to the fact that the javascript doesn't send up a required field
- //we have to fake it
- suppConnTypesFlag = ClientImpl.SUPPORT_CALLBACK_POLL | ClientImpl.SUPPORT_LONG_POLL;
-
- }
-
- public HttpError validate() {
- HttpError result = null;
-// if (clientId == null) {
-// result = new HttpError(401,"No Client ID.", null);
-// }
- return result;
- }
-
- public TomcatBayeux getTomcatBayeux() {
- return tomcatBayeux;
- }
-
- public String getChannel() {
- return channel;
- }
-
- public String getId() {
- return id;
- }
-
- public String getClientId() {
- return clientId;
- }
-
- public LinkedHashMap getExt() {
- return ext;
- }
-
- public CometEvent getEvent() {
- return event;
- }
-
- protected static void deliver(CometEvent event, ClientImpl to) throws IOException, ServletException, BayeuxException {
- JSONArray jarray = getJSONArray(event,true);
- if ( jarray == null ) throw new BayeuxException("No message to send!");
- String jsonstring = jarray.toString();
- if (log.isDebugEnabled()) {
- log.debug("["+Thread.currentThread().getName()+"] Delivering message to[" + to + "] message:" + jsonstring);
- }
-
- if (to!=null) {
- if (to.useJsonFiltered()) {
- if (!event.getHttpServletResponse().isCommitted()) event.getHttpServletResponse().setContentType("text/json-comment-filtered");
- }else {
- if (!event.getHttpServletResponse().isCommitted()) event.getHttpServletResponse().setContentType("text/json");
- }
- }
-
- PrintWriter out = event.getHttpServletResponse().getWriter();
- if (to==null) {
- //do nothing
- }else if ( (to.getDesirectConnType() == 0 && to.supportsLongPoll()) || to.getDesirectConnType() == ClientImpl.SUPPORT_LONG_POLL) {
- if (to.useJsonFiltered())
- out.print("/*");
- } else if ( (to.getDesirectConnType() == 0 && to.supportsCallbackPoll()) || to.getDesirectConnType() == ClientImpl.SUPPORT_CALLBACK_POLL) {
- String jsonp = event.getHttpServletRequest().getParameter(Bayeux.JSONP_PARAMETER);
- if (jsonp == null)
- jsonp = Bayeux.JSONP_DEFAULT_NAME;
- out.print(jsonp);
- out.print('(');
- } else {
- throw new BayeuxException("Client doesn't support any appropriate connection type.");
- }
- out.print(jsonstring);
- if ( to == null ) {
- //do nothing
- } else if ( (to.getDesirectConnType() == 0 && to.supportsLongPoll()) || to.getDesirectConnType() == ClientImpl.SUPPORT_LONG_POLL) {
- if (to.useJsonFiltered())
- out.print("*/");
- } else if ( (to.getDesirectConnType() == 0 && to.supportsCallbackPoll()) || to.getDesirectConnType() == ClientImpl.SUPPORT_CALLBACK_POLL) {
- out.print(");");
- }
- out.flush();
- event.getHttpServletResponse().flushBuffer();
-
-
- }
-
- protected static JSONArray getJSONArray(CometEvent event, boolean nullok) {
- synchronized(event) {
- JSONArray jarray = (JSONArray) event.getHttpServletRequest().getAttribute(JSON_MSG_ARRAY);
- if (jarray == null && (!nullok)) {
- jarray = new JSONArray();
- event.getHttpServletRequest().setAttribute(JSON_MSG_ARRAY, jarray);
- }
- return jarray;
- }
- }
-
- protected JSONArray getJSONArray() {
- return getJSONArray(event,false);
- }
-
- protected void addToDeliveryQueue(ClientImpl to, JSONObject msg) throws IOException, ServletException, BayeuxException {
- synchronized (event) {
- getJSONArray().put(msg);
- }
- }
-
- protected void flushMessages(ClientImpl client) throws BayeuxException {
- List msgs = client.takeMessages();
- synchronized (event) {
- try {
- for (Iterator it = msgs.iterator(); it.hasNext(); ){
- MessageImpl msg = (MessageImpl)it.next();
- Map map = new HashMap();
- map.put(Bayeux.CHANNEL_FIELD,msg.getChannel().getId());
- if (msg.getClient()!=null) map.put(Bayeux.CLIENT_FIELD,msg.getClient().getId());
- map.put(Bayeux.DATA_FIELD,msg);
- JSONObject obj = new JSONObject(map);
- addToDeliveryQueue(client, obj);
- }
- } catch (ServletException x) {
- throw new BayeuxException(x);
- } catch (IOException x) {
- throw new BayeuxException(x);
- }
- }
- }
-
- public int process(int prevops) throws BayeuxException {
- event.getHttpServletRequest().setAttribute(CURRENT_REQ_ATTR,this);
- return prevops;
- }
-
- public int getReconnectInterval() {
- return reconnectInterval;
- }
-
- public String getTimeStamp() {
- return timestampFmt.format(new Date(System.currentTimeMillis()));
- }
-
-}
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/RequestFactory.java b/modules/bayeux/java/org/apache/tomcat/bayeux/RequestFactory.java
deleted file mode 100644
index 203d94dc1a50..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/RequestFactory.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import org.json.JSONObject;
-import org.apache.tomcat.bayeux.request.MetaHandshakeRequest;
-import org.apache.catalina.comet.CometEvent;
-import org.json.JSONException;
-import org.apache.tomcat.bayeux.request.MetaConnectRequest;
-import org.apache.tomcat.bayeux.request.MetaDisconnectRequest;
-import org.apache.tomcat.bayeux.request.MetaSubscribeRequest;
-import org.apache.tomcat.bayeux.request.MetaUnsubscribeRequest;
-import org.apache.tomcat.bayeux.request.PublishRequest;
-import org.apache.cometd.bayeux.Bayeux;
-
-public class RequestFactory {
-
- public static BayeuxRequest getRequest(TomcatBayeux tomcatBayeux, CometEvent event, JSONObject msg) throws JSONException {
- String channel = msg.optString(Bayeux.CHANNEL_FIELD);
- if (Bayeux.META_HANDSHAKE.equals(channel)) {
- return new MetaHandshakeRequest(tomcatBayeux,event,msg);
- }else if (Bayeux.META_CONNECT.equals(channel)) {
- return new MetaConnectRequest(tomcatBayeux,event,msg);
- }else if (Bayeux.META_DISCONNECT.equals(channel)) {
- return new MetaDisconnectRequest(tomcatBayeux,event,msg);
- }else if (Bayeux.META_SUBSCRIBE.equals(channel)) {
- return new MetaSubscribeRequest(tomcatBayeux,event,msg);
- }else if (Bayeux.META_UNSUBSCRIBE.equals(channel)) {
- return new MetaUnsubscribeRequest(tomcatBayeux,event,msg);
- } else {
- return new PublishRequest(tomcatBayeux,event,msg);
- }
- }
-}
\ No newline at end of file
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java b/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java
deleted file mode 100644
index d6f17f72c600..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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.tomcat.bayeux;
-
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.catalina.tribes.util.Arrays;
-import org.apache.catalina.tribes.util.UUIDGenerator;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.cometd.bayeux.Channel;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.Listener;
-import org.apache.cometd.bayeux.Message;
-import org.apache.cometd.bayeux.SecurityPolicy;
-/**
- *
- * @author Filip Hanik
- * @version 1.0
- */
-public class TomcatBayeux implements Bayeux {
-
-
- protected int reconnectInterval = 5000;
- /**
- * a list of all active clients
- */
- protected HashMap clients = new HashMap();
-
- /**
- * a list of all active channels
- */
- protected LinkedHashMap channels = new LinkedHashMap();
-
- /**
- * security policy to be used.
- */
- protected SecurityPolicy securityPolicy = null;
- /**
- * default client to use when we need to send an error message but don't have a client valid reference
- */
- protected static ClientImpl errorClient = new ClientImpl("error-no-client",false);
-
- /**
- * returns the default error client
- * @return ClientImpl
- */
- public static ClientImpl getErrorClient() {
- return errorClient;
- }
-
- protected TomcatBayeux() {
- }
-
- /**
- * should be invoked when the servlet is destroyed or when the context shuts down
- */
- public void destroy() {
- throw new UnsupportedOperationException("TomcatBayeux.destroy() not yet implemented");
- }
-
- public Channel getChannel(String channelId, boolean create) {
- Channel result = channels.get(channelId);
- if (result==null && create) {
- result = new ChannelImpl(channelId);
- channels.put(channelId,result);
- }
- return result;
- }
-
- public Channel remove(Channel channel) {
- return channels.remove(channel.getId());
- }
-
- public Client remove(Client client) {
- if (client==null) return null;
- for (Channel ch : getChannels()) {
- ch.unsubscribe(client);
- }
- return clients.remove(client.getId());
- }
-
- public Client getClient(String clientId) {
- return clients.get(clientId);
- }
-
- public boolean hasClient(String clientId) {
- return clients.containsKey(clientId);
- }
-
- public List getClients() {
- return java.util.Arrays.asList(clients.values().toArray(new Client[0]));
- }
-
- public SecurityPolicy getSecurityPolicy() {
- return securityPolicy;
- }
-
- public int getReconnectInterval() {
- return reconnectInterval;
- }
-
- public boolean hasChannel(String channel) {
- return channels.containsKey(channel);
- }
-
- public Client newClient(String idprefix, Listener listener, boolean local, CometEvent event) {
- String id = createUUID(idprefix);
- ClientImpl client = new ClientImpl(id, local);
- client.setListener(listener);
- clients.put(id, client);
- return client;
- }
-
- public Client newClient(String idprefix, Listener listener) {
- assert listener!=null;
- //if this method gets called, someone is using the API inside
- //the JVM, this is a local client
- return newClient(idprefix,listener,true, null);
- }
-
- protected ClientImpl getClientImpl(CometEvent event) {
- return (ClientImpl)event.getHttpServletRequest().getAttribute(ClientImpl.COMET_EVENT_ATTR);
- }
-
- protected void remove(CometEvent event) {
- ClientImpl client = getClientImpl(event);
- if (client!=null) {
- client.removeCometEvent(event);
- }
- }
-
- public String createUUID(String idprefix) {
- if (idprefix==null) idprefix="";
- return idprefix + Arrays.toString(UUIDGenerator.randomUUID(false));
- }
-
- public List getChannels() {
- return java.util.Arrays.asList(channels.entrySet().toArray(new Channel[0]));
- }
-
- protected Message newMessage() {
- String id = createUUID("msg-");
- return new MessageImpl(id);
- }
-
- public Message newMessage(Client from) {
- MessageImpl msg = (MessageImpl)newMessage();
- msg.setClient(from);
- return msg;
- }
- public void setSecurityPolicy(SecurityPolicy securityPolicy) {
- this.securityPolicy = securityPolicy;
- }
-
- public void setReconnectInterval(int reconnectTimeout) {
- this.reconnectInterval = reconnectTimeout;
- }
-
-}
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java b/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java
deleted file mode 100644
index f2f509af0ab9..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * 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.tomcat.bayeux.request;
-
-import java.io.IOException;
-import java.util.HashMap;
-import javax.servlet.ServletException;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.tomcat.bayeux.HttpError;
-import org.apache.tomcat.bayeux.BayeuxException;
-import org.apache.tomcat.bayeux.BayeuxRequest;
-import org.apache.tomcat.bayeux.ClientImpl;
-import org.apache.tomcat.bayeux.TomcatBayeux;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.tomcat.bayeux.*;
-
-/******************************************************************************
- * Handshake request Bayeux message.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 1.0
- *
- */
-public class MetaConnectRequest extends RequestBase implements BayeuxRequest {
- protected static HashMap responseTemplate = new HashMap();
-
- static {
- responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_CONNECT);
- responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
- responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap());
- }
-
- public MetaConnectRequest(TomcatBayeux tb, CometEvent event, JSONObject jsReq) throws JSONException {
- super(tb, event, jsReq);
- if (clientId!=null && getTomcatBayeux().hasClient(clientId)) {
- event.getHttpServletRequest().setAttribute("client",getTomcatBayeux().getClient(clientId));
- }
- }
-
-
- /**
- * Check client request for validity.
- *
- * Per section 4.2.1 of the Bayuex spec a connect request must contain:
- * 1) The "/meta/connect" channel identifier.
- * 2) The clientId returned by the server after handshake.
- * 3) The desired connectionType (must be one of the server's supported
- * types returned by handshake response.
- *
- * @return HttpError This method returns null if no errors were found
- */
- public HttpError validate() {
- if(clientId==null|| (!getTomcatBayeux().hasClient(clientId)))
- return new HttpError(400,"Client Id not valid.", null);
- if (! (Bayeux.TRANSPORT_LONG_POLL.equals(conType) || Bayeux.TRANSPORT_CALLBACK_POLL.equals(conType)))
- return new HttpError(400,"Unsupported connection type.",null);
- return null;//no error
- }
-
- /**
- * Transition to connected state, flushing pending messages if
- * available. If there are pending subscriptions and no messages to
- * flush then the connection is held until there is a pending publish
- * event to be delivered to this client (Section 4.2.2 of spec).
- */
- public int process(int prevops) throws BayeuxException {
- super.process(prevops);
- response = (HashMap)responseTemplate.clone();
- ClientImpl client = (ClientImpl)getTomcatBayeux().getClient(clientId);
- boolean success = false;
- HttpError error = validate();
- if (error == null) {
- client.setDesirectConnType(desiredConnTypeFlag);
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.RECONNECT_FIELD, Bayeux.RETRY_RESPONSE);
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.INTERVAL_FIELD, getReconnectInterval());
- success = true;
- }else {
- response.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
- response.put(Bayeux.ERROR_FIELD, error.toString());
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.RECONNECT_FIELD, Bayeux.HANDSHAKE_RESPONSE);
- if (client==null) client = TomcatBayeux.getErrorClient();
- }
- response.put(Bayeux.CLIENT_FIELD, client.getId());
- response.put(Bayeux.TIMESTAMP_FIELD,getTimeStamp());
- try {
- JSONObject obj = new JSONObject(response);
- addToDeliveryQueue(client, obj);
- } catch (ServletException x) {
- throw new BayeuxException(x);
- } catch (IOException x) {
- throw new BayeuxException(x);
- }
-
- //return immediately if there is no subscriptions
- //so that we can process the next message
- int result = client.isSubscribed()?1:0;
-
- if (success && client!=null && client.hasMessages()) {
- //send out messages
- flushMessages(client);
- result = 0; //flush out the messages
- }
-
- return result;
- }
-}
-
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java b/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java
deleted file mode 100644
index 78bf7b47dc5e..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.tomcat.bayeux.request;
-
-import java.io.IOException;
-import java.util.HashMap;
-import javax.servlet.ServletException;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.tomcat.bayeux.HttpError;
-import org.apache.tomcat.bayeux.BayeuxException;
-import org.apache.tomcat.bayeux.BayeuxRequest;
-import org.apache.tomcat.bayeux.ClientImpl;
-import org.apache.tomcat.bayeux.TomcatBayeux;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.tomcat.bayeux.*;
-import org.apache.cometd.bayeux.Channel;
-
-/******************************************************************************
- * Handshake request Bayeux message.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 1.0
- *
- */
-public class MetaDisconnectRequest extends RequestBase implements BayeuxRequest {
-
- protected static HashMap responseTemplate = new HashMap();
-
- static {
- responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_DISCONNECT);
- responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
- responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap());
- }
-
- public MetaDisconnectRequest(TomcatBayeux tb, CometEvent event, JSONObject jsReq) throws JSONException {
- super(tb, event, jsReq);
- }
-
-
- /**
- * Check client request for validity.
- *
- * Per section 4.4.1 of the Bayuex spec a connect request must contain:
- * 1) The "/meta/disconnect" channel identifier.
- * 2) The clientId.
- *
- * @return HttpError This method returns null if no errors were found
- */
- public HttpError validate() {
- if(clientId==null|| (!this.getTomcatBayeux().hasClient(clientId)))
- return new HttpError(400,"Client Id not valid.", null);
-// if (! (Bayeux.TRANSPORT_LONG_POLL.equals(conType) || Bayeux.TRANSPORT_CALLBACK_POLL.equals(conType)))
-// return new HttpError(400,"Unsupported connection type.",null);
- return null;//no error
- }
-
- /**
- * Disconnect a client session.
- */
- public int process(int prevops) throws BayeuxException {
- super.process(prevops);
- response = (HashMap)responseTemplate.clone();
- ClientImpl client = (ClientImpl)getTomcatBayeux().getClient(clientId);
- HttpError error = validate();
- if (error == null) {
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("reconnect", "retry");
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("interval", getReconnectInterval());
- }else {
- getTomcatBayeux().remove(client);
- response.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
- response.put(Bayeux.ERROR_FIELD, error.toString());
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("reconnect", "none");
- if (client==null) client = TomcatBayeux.getErrorClient();
- }
- response.put(Bayeux.CLIENT_FIELD, client.getId());
- try {
- JSONObject obj = new JSONObject(response);
- addToDeliveryQueue(client, obj);
- } catch (ServletException x) {
- throw new BayeuxException(x);
- } catch (IOException x) {
- throw new BayeuxException(x);
- }
- return 0;
- }
-}
-
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java b/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java
deleted file mode 100644
index 593cfef0ffd3..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.tomcat.bayeux.request;
-
-import java.io.IOException;
-import java.util.HashMap;
-import javax.servlet.ServletException;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.tomcat.bayeux.HttpError;
-import org.apache.tomcat.bayeux.BayeuxException;
-import org.apache.tomcat.bayeux.BayeuxRequest;
-import org.apache.tomcat.bayeux.ClientImpl;
-import org.apache.tomcat.bayeux.TomcatBayeux;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.tomcat.bayeux.*;
-
-/******************************************************************************
- * Handshake request Bayeux message.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 1.0
- *
- */
-public class MetaHandshakeRequest extends RequestBase implements BayeuxRequest {
-
- protected static HashMap responseTemplate = new HashMap();
-
- static {
- responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_HANDSHAKE);
- responseTemplate.put(Bayeux.VERSION_FIELD,"1.0");
- responseTemplate.put(Bayeux.SUPP_CONNECTION_TYPE_FIELD,new String[] { Bayeux.TRANSPORT_LONG_POLL, Bayeux.TRANSPORT_CALLBACK_POLL });
- responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
- responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap());
- }
-
- public MetaHandshakeRequest(TomcatBayeux tomcatBayeux, CometEvent event, JSONObject jsReq) throws JSONException {
- super(tomcatBayeux, event, jsReq);
- }
-
-
- public String getVersion() { return version; }
- public String getMinimumVersion() { return minVersion; }
-
-
- /**
- * Check client request for validity.
- *
- * Per section 4.1.1 of the Bayuex spec a handshake request must contain:
- * 1) The "/meta/handshake" channel identifier.
- * 2) The version of the protocol supported by the client
- * 3) The client's supported connection types.
- *
- * @return HttpError This method returns null if no errors were found
- */
- public HttpError validate() {
- boolean error = (version==null || version.length()==0);
- if (!error) error = suppConnTypesFlag==0;
- if (error) return new HttpError(400,"Invalid handshake request, supportedConnectionType field missing.",null);
- else return null;
- }
-
- /**
- * Generate and return a client identifier. Return a list of
- * supported connection types. Must be a subset of or identical to
- * the list of types supported by the client. See section 4.1.2 of
- * the Bayuex specification.
- */
- public int process(int prevops) throws BayeuxException {
- super.process(prevops);
- response = (HashMap)responseTemplate.clone();
- ClientImpl client = null;
- HttpError error = validate();
- if (error == null) {
- client = (ClientImpl) getTomcatBayeux().newClient("http-", null, false,getEvent());
- clientId = client.getId();
- client.setSupportedConnTypes(suppConnTypesFlag);
- client.setUseJsonFiltered(getExt().get(Bayeux.JSON_COMMENT_FILTERED_FIELD) != null);
- response.put(Bayeux.CLIENT_FIELD, client.getId());
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.RECONNECT_FIELD, Bayeux.RETRY_RESPONSE);
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.INTERVAL_FIELD, getReconnectInterval());
- }else {
- response.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
- response.put(Bayeux.ERROR_FIELD, error.toString());
- client = TomcatBayeux.getErrorClient();
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.RECONNECT_FIELD, Bayeux.NONE_RESPONSE);
- }
- try {
- JSONObject obj = new JSONObject(response);
- addToDeliveryQueue(client, obj);
- } catch (ServletException x) {
- throw new BayeuxException(x);
- } catch (IOException x) {
- throw new BayeuxException(x);
- }
- return 0;
- }
-}
-
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java b/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java
deleted file mode 100644
index af42d097cee7..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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.tomcat.bayeux.request;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import javax.servlet.ServletException;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.tomcat.bayeux.HttpError;
-import org.apache.tomcat.bayeux.BayeuxException;
-import org.apache.tomcat.bayeux.BayeuxRequest;
-import org.apache.tomcat.bayeux.ChannelImpl;
-import org.apache.tomcat.bayeux.ClientImpl;
-import org.apache.tomcat.bayeux.TomcatBayeux;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Channel;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.tomcat.bayeux.*;
-
-/******************************************************************************
- * Handshake request Bayeux message.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 1.0
- */
-public class MetaSubscribeRequest extends RequestBase implements BayeuxRequest {
-
- protected static HashMap responseTemplate = new HashMap();
-
- static {
- responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_SUBSCRIBE);
- responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
- responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap());
- }
-
- public MetaSubscribeRequest(TomcatBayeux tb, CometEvent event, JSONObject jsReq) throws JSONException {
- super(tb, event, jsReq);
- }
-
-
- /**
- * Check client request for validity.
- *
- * Per section 4.5.1 of the Bayuex spec a connect request must contain:
- * 1) The "/meta/subscribe" channel identifier.
- * 2) The clientId.
- * 3) The subscription. This is the name of the channel of interest,
- * or a pattern.
- *
- * @return HttpError This method returns null if no errors were found
- */
- public HttpError validate() {
- if(clientId==null|| (!this.getTomcatBayeux().hasClient(clientId)))
- return new HttpError(400,"Client Id not valid.", null);
- if (subscription==null||subscription.length()==0)
- return new HttpError(400,"Subscription missing.",null);
- return null;//no error
- }
-
- /**
- * Register interest for one or more channels. Per section 2.2.1 of the
- * Bayeux spec, a pattern may be specified. Assign client to matching
- * channels and inverse client to channel reference.
- */
- public int process(int prevops) throws BayeuxException {
- super.process(prevops);
- response = (HashMap)this.responseTemplate.clone();
- ClientImpl client = (ClientImpl)getTomcatBayeux().getClient(clientId);
- HttpError error = validate();
- if (error == null) {
- boolean wildcard = subscription.indexOf('*')!=-1;
- boolean subscribed = false;
- if (wildcard) {
- List channels = getTomcatBayeux().getChannels();
- Iterator it = channels.iterator();
- while (it.hasNext()) {
- ChannelImpl ch = (ChannelImpl)it.next();
- if (ch.matches(subscription)) {
- ch.subscribe(client);
- subscribed = true;
- }
- }
- }else {
- ChannelImpl ch = (ChannelImpl)getTomcatBayeux().getChannel(subscription,true);
- ch.subscribe(client);
- subscribed = true;
- }
- response.put(Bayeux.SUCCESSFUL_FIELD, Boolean.valueOf(subscribed));
- response.put(Bayeux.SUBSCRIPTION_FIELD,subscription);
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("reconnect", "retry");
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("interval", getReconnectInterval());
- }else {
- response.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
- response.put(Bayeux.ERROR_FIELD, error.toString());
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("reconnect", "handshake");
- if (client==null) client = TomcatBayeux.getErrorClient();
- }
- response.put(Bayeux.CLIENT_FIELD, client.getId());
- response.put(Bayeux.TIMESTAMP_FIELD,getTimeStamp());
- try {
- JSONObject obj = new JSONObject(response);
- addToDeliveryQueue(client, obj);
- } catch (ServletException x) {
- throw new BayeuxException(x);
- } catch (IOException x) {
- throw new BayeuxException(x);
- }
- return 0;
- }
-}
-
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java b/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java
deleted file mode 100644
index 62e4c8f4f1a9..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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.tomcat.bayeux.request;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import javax.servlet.ServletException;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.tomcat.bayeux.HttpError;
-import org.apache.tomcat.bayeux.BayeuxException;
-import org.apache.tomcat.bayeux.BayeuxRequest;
-import org.apache.tomcat.bayeux.ChannelImpl;
-import org.apache.tomcat.bayeux.ClientImpl;
-import org.apache.tomcat.bayeux.TomcatBayeux;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Channel;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.tomcat.bayeux.*;
-
-/******************************************************************************
- * Handshake request Bayeux message.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 1.0
- *
- */
-public class MetaUnsubscribeRequest extends RequestBase implements BayeuxRequest {
-
- protected static HashMap responseTemplate = new HashMap();
-
- static {
- responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_UNSUBSCRIBE);
- responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
- responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap());
- }
-
- public MetaUnsubscribeRequest(TomcatBayeux tb, CometEvent event, JSONObject jsReq) throws JSONException {
- super(tb, event, jsReq);
- }
-
-
- /**
- * Check client request for validity.
- *
- * Per section 4.6.1 of the Bayuex spec a connect request must contain:
- * 1) The "/meta/unsubscribe" channel identifier.
- * 2) The clientId.
- * 3) The subscription. This is the name of the channel of interest,
- * or a pattern.
- *
- * @return HttpError This method returns null if no errors were found
- */
- public HttpError validate() {
- if(clientId==null|| (!this.getTomcatBayeux().hasClient(clientId)))
- return new HttpError(400,"Client Id not valid.", null);
- if (subscription==null||subscription.length()==0)
- return new HttpError(400,"Subscription missing.",null);
- return null;//no error
- }
-
- /**
- * De-register interest for one or more channels. Per section 2.2.1 of the
- * Bayeux spec, a pattern may be specified. Sever relationships.
- */
- public int process(int prevops) throws BayeuxException {
- super.process(prevops);
- response = (HashMap)responseTemplate.clone();
- ClientImpl client = (ClientImpl)getTomcatBayeux().getClient(clientId);
- HttpError error = validate();
- if (error == null) {
- boolean wildcard = subscription.indexOf('*')!=-1;
- boolean unsubscribed = false;
- if (wildcard) {
- List channels = getTomcatBayeux().getChannels();
- Iterator it = channels.iterator();
- while (it.hasNext()) {
- ChannelImpl ch = (ChannelImpl)it.next();
- if (ch.matches(subscription)) {
- ch.unsubscribe(client);
- unsubscribed = true;
- }
- }
- }else {
- ChannelImpl ch = (ChannelImpl)getTomcatBayeux().getChannel(subscription,true);
- ch.unsubscribe(client);
- unsubscribed = true;
- }
- response.put(Bayeux.SUCCESSFUL_FIELD, Boolean.valueOf(unsubscribed));
- response.put(Bayeux.SUBSCRIPTION_FIELD,subscription);
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("reconnect", "retry");
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("interval", getReconnectInterval());
- }else {
- response.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
- response.put(Bayeux.ERROR_FIELD, error.toString());
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put("reconnect", "handshake");
- if (client==null) client = TomcatBayeux.getErrorClient();
- }
- response.put(Bayeux.CLIENT_FIELD, client.getId());
- response.put(Bayeux.TIMESTAMP_FIELD,getTimeStamp());
- try {
- JSONObject obj = new JSONObject(response);
- addToDeliveryQueue(client, obj);
- } catch (ServletException x) {
- throw new BayeuxException(x);
- } catch (IOException x) {
- throw new BayeuxException(x);
- }
- return 0;
- }
-}
-
diff --git a/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java b/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java
deleted file mode 100644
index 0b1a03472be9..000000000000
--- a/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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.tomcat.bayeux.request;
-
-import java.io.IOException;
-import java.util.HashMap;
-import javax.servlet.ServletException;
-
-import org.apache.catalina.comet.CometEvent;
-import org.apache.tomcat.bayeux.HttpError;
-import org.apache.tomcat.bayeux.BayeuxException;
-import org.apache.tomcat.bayeux.ChannelImpl;
-import org.apache.tomcat.bayeux.ClientImpl;
-import org.apache.tomcat.bayeux.MessageImpl;
-import org.apache.tomcat.bayeux.RequestBase;
-import org.apache.tomcat.bayeux.TomcatBayeux;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-import org.apache.juli.logging.Log;
-import org.apache.juli.logging.LogFactory;
-
-/******************************************************************************
- * Handshake request Bayeux message.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 1.0
- *
- */
-public class PublishRequest extends RequestBase {
-
- private static final Log log = LogFactory.getLog(PublishRequest.class);
-
- protected static HashMap responseTemplate = new HashMap();
-
- static {
- responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
- responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap());
- }
-
- JSONObject msgData = null;
-
- public PublishRequest(TomcatBayeux tb, CometEvent event, JSONObject jsReq) throws JSONException {
- super(tb, event, jsReq);
- }
-
-
- /**
- * Check client request for validity.
- *
- * Per section 5.1.1 of the Bayuex spec a connect request must contain:
- * 1) The channel identifier of the channel for publication.
- * 2) The data to send.
- *
- * @return HttpError This method returns null if no errors were found
- */
- @Override
- public HttpError validate() {
- if(channel==null|| (!this.getTomcatBayeux().hasChannel(channel)))
- return new HttpError(400,"Channel Id not valid.", null);
- if(data==null || data.length()==0)
- return new HttpError(400,"Message data missing.", null);
- try {
- this.msgData = new JSONObject(data);
- }catch (JSONException x) {
- return new HttpError(400,"Invalid JSON object in data attribute.",x);
- }
- if(clientId==null|| (!this.getTomcatBayeux().hasClient(clientId)))
- return new HttpError(400,"Client Id not valid.", null);
- return null;//no error
- }
-
- /**
- * Send the event message to all registered subscribers.
- */
- @Override
- public int process(int prevops) throws BayeuxException {
- super.process(prevops);
- response = (HashMap)responseTemplate.clone();
- ClientImpl client = clientId!=null?(ClientImpl)getTomcatBayeux().getClient(clientId):
- (ClientImpl)event.getHttpServletRequest().getAttribute("client");
- boolean success = false;
- HttpError error = validate();
- if (error == null) {
- ChannelImpl chimpl = (ChannelImpl)getTomcatBayeux().getChannel(channel,false);
- MessageImpl mimpl = (MessageImpl)getTomcatBayeux().newMessage(client);
-
- try {
- String[] keys = JSONObject.getNames(msgData);
- for (int i = 0; i < keys.length; i++) {
- mimpl.put(keys[i], msgData.get(keys[i]));
- }
- success = true;
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.RECONNECT_FIELD, Bayeux.RETRY_RESPONSE);
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.INTERVAL_FIELD, getReconnectInterval());
- }catch (JSONException x) {
- if (log.isErrorEnabled()) log.error("Unable to parse:"+msgData,x);
- throw new BayeuxException(x);
- }
- chimpl.publish(mimpl);
- }
- if(!success) {
- response.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
- response.put(Bayeux.ERROR_FIELD, error.toString());
- ((HashMap) response.get(Bayeux.ADVICE_FIELD)).put(Bayeux.RECONNECT_FIELD, Bayeux.HANDSHAKE_RESPONSE);
- if (client==null) client = TomcatBayeux.getErrorClient();
- }
- response.put(Bayeux.CHANNEL_FIELD,channel);
- response.put(Bayeux.CLIENT_FIELD, client.getId());
- try {
- JSONObject obj = new JSONObject(response);
- addToDeliveryQueue(client, obj);
- } catch (ServletException x) {
- throw new BayeuxException(x);
- } catch (IOException x) {
- throw new BayeuxException(x);
- }
-
- if (success && client!=null && client.hasMessages()) {
- //send out messages
- flushMessages(client);
- }
-
- return 0;
- }
-}
-
diff --git a/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java b/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java
deleted file mode 100644
index fbd19fdf3f46..000000000000
--- a/modules/bayeux/test/org/apache/cometd/bayeux/samples/BayeuxStockTicker.java
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * 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.cometd.bayeux.samples;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextAttributeListener;
-import javax.servlet.ServletContextAttributeEvent;
-import org.apache.cometd.bayeux.Bayeux;
-
-import java.text.DecimalFormat;
-import java.util.List;
-import java.util.Random;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.Listener;
-import org.apache.cometd.bayeux.Message;
-import org.apache.cometd.bayeux.Channel;
-
-public class BayeuxStockTicker implements ServletContextListener,
- ServletContextAttributeListener, Listener {
-
- static AtomicInteger counter = new AtomicInteger(0);
- protected int id;
- protected Bayeux b;
- protected Client c;
- protected boolean alive = true;
- protected boolean initialized = false;
- protected TickerThread tt = new TickerThread();
-
- public BayeuxStockTicker() {
- id = counter.incrementAndGet();
- System.out.println("new listener created with id:" + id);
- }
-
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- alive = false;
- tt.run = false;
- tt.interrupt();
- }
-
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- }
-
- public void attributeAdded(ServletContextAttributeEvent scae) {
- if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
- if (initialized) return;
- initialized = true;
- System.out.println("Starting stock ticker server client!");
- b = (Bayeux) scae.getValue();
- c = b.newClient("stock-ticker-", this);
- tt.start();
- }
- }
-
- public void attributeRemoved(ServletContextAttributeEvent scae) {
- if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
- initialized = false;
- b = (Bayeux) scae.getValue();
- List chs = b.getChannels();
- for (Channel ch : chs) {
- ch.unsubscribe(c);
- }
- }
- }
-
- public void attributeReplaced(
- ServletContextAttributeEvent servletContextAttributeEvent) {
- }
-
- public void removed(boolean timeout) {
- System.out.println("Client removed.");
- }
-
- public void deliver(Message[] msgs) {
- for (int i = 0; msgs != null && i < msgs.length; i++) {
- Message msg = msgs[i];
- System.out.println("[stock ticker server client ]received message:" + msg);
- }
- }
-
- public class TickerThread extends Thread {
- public boolean run = true;
-
- public TickerThread() {
- setName("Ticker Thread");
- }
-
- public void run() {
- try {
-
- Stock[] stocks = new Stock[] {
- new Stock("GOOG", 435.43),
- new Stock("YHOO", 27.88),
- new Stock("ASF", 1015.55), };
- for (Stock s : stocks) {
- Channel ch = b.getChannel("/stock/"+s.getSymbol(), true);
- ch.subscribe(c);
-
- }
- Random r = new Random(System.currentTimeMillis());
- while (run) {
- for (int j = 0; j < 1; j++) {
- int i = r.nextInt() % 3;
- if (i < 0)
- i = i * (-1);
- Stock stock = stocks[i];
- double change = r.nextDouble();
- boolean plus = r.nextBoolean();
- if (plus) {
- stock.setValue(stock.getValue() + change);
- } else {
- stock.setValue(stock.getValue() - change);
- }
- Channel ch = b.getChannel("/stock/"+stock.getSymbol(), true);
- Message m = b.newMessage(c);
- m.put("stock", stock.toString());
- m.put("symbol", stock.getSymbol());
- m.put("price", stock.getValueAsString());
- m.put("change", stock.getLastChangeAsString());
- ch.publish(m);
- System.out.println("Bayeux Stock: "+stock.getSymbol()+" Price: "+stock.getValueAsString()+" Change: "+stock.getLastChangeAsString());
- }
- Thread.sleep(850);
- }
- } catch (InterruptedException ix) {
-
- } catch (Exception x) {
- x.printStackTrace();
- }
- }
- }
-
- public static class Stock {
- protected static DecimalFormat df = new DecimalFormat("0.00");
- protected String symbol = "";
- protected double value = 0.0d;
- protected double lastchange = 0.0d;
- protected int cnt = 0;
-
- public Stock(String symbol, double initvalue) {
- this.symbol = symbol;
- this.value = initvalue;
- }
-
- public void setCnt(int c) {
- this.cnt = c;
- }
-
- public int getCnt() {
- return cnt;
- }
-
- public String getSymbol() {
- return symbol;
- }
-
- public double getValue() {
- return value;
- }
-
- public void setValue(double value) {
- double old = this.value;
- this.value = value;
- this.lastchange = value - old;
- }
-
- public String getValueAsString() {
- return df.format(value);
- }
-
- public double getLastChange() {
- return this.lastchange;
- }
-
- public void setLastChange(double lastchange) {
- this.lastchange = lastchange;
- }
-
- public String getLastChangeAsString() {
- return df.format(lastchange);
- }
-
- public int hashCode() {
- return symbol.hashCode();
- }
-
- public boolean equals(Object other) {
- if (other instanceof Stock) {
- return this.symbol.equals(((Stock) other).symbol);
- } else {
- return false;
- }
- }
-
- public String toString(){
- StringBuilder buf = new StringBuilder("STOCK#");
- buf.append(getSymbol());
- buf.append("#");
- buf.append(getValueAsString());
- buf.append("#");
- buf.append(getLastChangeAsString());
- buf.append("#");
- buf.append(String.valueOf(getCnt()));
- return buf.toString();
-
- }
-
- public Object clone() {
- Stock s = new Stock(this.getSymbol(), this.getValue());
- s.setLastChange(this.getLastChange());
- s.setCnt(this.cnt);
- return s;
- }
- }
-
-}
\ No newline at end of file
diff --git a/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java b/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java
deleted file mode 100644
index a4b38734b028..000000000000
--- a/modules/bayeux/test/org/apache/cometd/bayeux/samples/EchoChatClient.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * 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.cometd.bayeux.samples;
-
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-import javax.servlet.ServletContextAttributeListener;
-import javax.servlet.ServletContextAttributeEvent;
-import org.apache.cometd.bayeux.Bayeux;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.cometd.bayeux.Client;
-import org.apache.cometd.bayeux.Listener;
-import org.apache.cometd.bayeux.Message;
-import org.apache.cometd.bayeux.Channel;
-
-public class EchoChatClient implements ServletContextListener, ServletContextAttributeListener, Listener {
-
- static AtomicInteger counter = new AtomicInteger(0);
- protected int id;
- protected Bayeux b;
- protected Client c;
- protected boolean alive = true;
- protected TimestampThread tt = new TimestampThread();
-
- public EchoChatClient() {
- id = counter.incrementAndGet();
- System.out.println("new listener created with id:"+id);
- }
-
- public void contextDestroyed(ServletContextEvent servletContextEvent) {
- alive = false;
- tt.interrupt();
- }
-
- public void contextInitialized(ServletContextEvent servletContextEvent) {
- }
-
- public void attributeAdded(ServletContextAttributeEvent scae) {
- if (scae.getName().equals(Bayeux.DOJOX_COMETD_BAYEUX)) {
- System.out.println("Starting echo chat client!");
- b = (Bayeux)scae.getValue();
- c = b.newClient("echochat-",this);
- Channel ch = b.getChannel("/chat/demo",true);
- ch.subscribe(c);
- tt.start();
- }
- }
-
- public void attributeRemoved(ServletContextAttributeEvent servletContextAttributeEvent) {
- }
-
- public void attributeReplaced(ServletContextAttributeEvent servletContextAttributeEvent) {
- }
-
- public void removed(boolean timeout) {
- System.out.println("Client removed.");
- }
-
- public void deliver(Message[] msgs) {
- for (int i=0; msgs!=null && i
-
-
- Cometd Test WebApp
-
-
- cometd
- org.apache.tomcat.bayeux.BayeuxServlet
-
- timeout
- 120000000
-
-
- reconnectInterval
- 250
-
- 1
-
-
-
- cometd
- /cometd/*
-
-
-
- org.apache.cometd.bayeux.samples.EchoChatClient
-
-
- org.apache.cometd.bayeux.samples.BayeuxStockTicker
-
-
-
-
-
diff --git a/modules/bayeux/webapps/cometd/examples/simplechat/cometdchat.htm b/modules/bayeux/webapps/cometd/examples/simplechat/cometdchat.htm
deleted file mode 100644
index 0f30cad1be71..000000000000
--- a/modules/bayeux/webapps/cometd/examples/simplechat/cometdchat.htm
+++ /dev/null
@@ -1,130 +0,0 @@
-
-
-Comet Simple Chat Application
-
-
-
-
-
-
-
-
-
-
-
-
-