tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r723775 [3/5] - in /tomcat/trunk: java/org/apache/juli/ modules/bayeux/ modules/bayeux/java/org/apache/cometd/bayeux/ modules/bayeux/java/org/apache/tomcat/bayeux/ modules/bayeux/java/org/apache/tomcat/bayeux/request/ modules/bayeux/test/or...
Date Fri, 05 Dec 2008 15:57:46 GMT
Modified: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java (original)
+++ tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java Fri Dec  5 07:57:43 2008
@@ -1,176 +1,176 @@
-/*
- * 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.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<String,Client> clients = new HashMap<String,Client>();
-    
-    /**
-     * a list of all active channels
-     */
-    protected LinkedHashMap<String, Channel> channels = new LinkedHashMap<String,Channel>();
-    
-    /**
-     * 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<Client> getClients() {
-        return java.util.Arrays.asList(clients.entrySet().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<Channel> 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;
-    }
-
-}
+/*
+ * 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.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<String,Client> clients = new HashMap<String,Client>();
+    
+    /**
+     * a list of all active channels
+     */
+    protected LinkedHashMap<String, Channel> channels = new LinkedHashMap<String,Channel>();
+    
+    /**
+     * 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<Client> getClients() {
+        return java.util.Arrays.asList(clients.entrySet().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<Channel> 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;
+    }
+
+}

Propchange: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/TomcatBayeux.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java (original)
+++ tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java Fri Dec  5 07:57:43 2008
@@ -1,125 +1,125 @@
-/*
- * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
-
-    static {
-        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_CONNECT);
-        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
-        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
-    }
-
-    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<String, Object>)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;
-    }
-}
-
+/*
+ * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
+
+    static {
+        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_CONNECT);
+        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
+        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
+    }
+
+    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<String, Object>)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;
+    }
+}
+

Propchange: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaConnectRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java (original)
+++ tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java Fri Dec  5 07:57:43 2008
@@ -1,105 +1,105 @@
-/*
- * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
-
-    static {
-        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_DISCONNECT);
-        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
-        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
-    }
-
-    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<String, Object>)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;
-    }
-}
-
+/*
+ * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
+
+    static {
+        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_DISCONNECT);
+        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
+        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
+    }
+
+    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<String, Object>)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;
+    }
+}
+

Propchange: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaDisconnectRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java (original)
+++ tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java Fri Dec  5 07:57:43 2008
@@ -1,116 +1,116 @@
-/*
- * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
-    
-    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<String, Object>());
-    }
-
-    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<String, Object>)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;
-    }
-}
-
+/*
+ * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
+    
+    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<String, Object>());
+    }
+
+    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<String, Object>)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;
+    }
+}
+

Propchange: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaHandshakeRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java (original)
+++ tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java Fri Dec  5 07:57:43 2008
@@ -1,130 +1,130 @@
-/*
- * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
-
-    static {
-        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_SUBSCRIBE);
-        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
-        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
-    }
-
-    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<String, Object>)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<Channel> channels = getTomcatBayeux().getChannels();
-                Iterator<Channel> 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;
-    }
-}
-
+/*
+ * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
+
+    static {
+        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_SUBSCRIBE);
+        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
+        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
+    }
+
+    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<String, Object>)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<Channel> channels = getTomcatBayeux().getChannels();
+                Iterator<Channel> 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;
+    }
+}
+

Propchange: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaSubscribeRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java (original)
+++ tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java Fri Dec  5 07:57:43 2008
@@ -1,130 +1,130 @@
-/*
- * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
-
-    static {
-        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_UNSUBSCRIBE);
-        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
-        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
-    }
-
-    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<String, Object>)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<Channel> channels = getTomcatBayeux().getChannels();
-                Iterator<Channel> 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;
-    }
-}
-
+/*
+ * 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.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<String,Object> responseTemplate = new HashMap<String,Object>();
+
+    static {
+        responseTemplate.put(Bayeux.CHANNEL_FIELD,Bayeux.META_UNSUBSCRIBE);
+        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
+        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
+    }
+
+    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<String, Object>)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<Channel> channels = getTomcatBayeux().getChannels();
+                Iterator<Channel> 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;
+    }
+}
+

Propchange: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/MetaUnsubscribeRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java?rev=723775&r1=723774&r2=723775&view=diff
==============================================================================
--- tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java (original)
+++ tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java Fri Dec  5 07:57:43 2008
@@ -1,140 +1,140 @@
-/*
- * 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.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.MessageImpl;
-import org.apache.tomcat.bayeux.TomcatBayeux;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.apache.cometd.bayeux.Bayeux;
-import java.util.List;
-import org.apache.cometd.bayeux.Message;
-import java.util.Iterator;
-import org.apache.tomcat.bayeux.*;
-
-/******************************************************************************
- * Handshake request Bayeux message.
- *
- * @author Guy A. Molinari
- * @author Filip Hanik
- * @version 1.0
- *
- */
-public class PublishRequest extends RequestBase implements BayeuxRequest {
-
-    JSONObject msgData = null;
-
-    protected static HashMap<String,Object> responseTemplate = new HashMap<String,Object>();
-
-    static {
-        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
-        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
-    }
-
-    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
-     */
-    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.
-     */
-    public int process(int prevops) throws BayeuxException {
-        super.process(prevops);
-        response = (HashMap<String, Object>)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;
-    }
-}
-
+/*
+ * 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.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.MessageImpl;
+import org.apache.tomcat.bayeux.TomcatBayeux;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.apache.cometd.bayeux.Bayeux;
+import java.util.List;
+import org.apache.cometd.bayeux.Message;
+import java.util.Iterator;
+import org.apache.tomcat.bayeux.*;
+
+/******************************************************************************
+ * Handshake request Bayeux message.
+ *
+ * @author Guy A. Molinari
+ * @author Filip Hanik
+ * @version 1.0
+ *
+ */
+public class PublishRequest extends RequestBase implements BayeuxRequest {
+
+    JSONObject msgData = null;
+
+    protected static HashMap<String,Object> responseTemplate = new HashMap<String,Object>();
+
+    static {
+        responseTemplate.put(Bayeux.SUCCESSFUL_FIELD,Boolean.TRUE);
+        responseTemplate.put(Bayeux.ADVICE_FIELD, new HashMap<String, Object>());
+    }
+
+    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
+     */
+    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.
+     */
+    public int process(int prevops) throws BayeuxException {
+        super.process(prevops);
+        response = (HashMap<String, Object>)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;
+    }
+}
+

Propchange: tomcat/trunk/modules/bayeux/java/org/apache/tomcat/bayeux/request/PublishRequest.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message