Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Licensed to the Apache Software Foundation (ASF) under one or more
   * contributor license agreements.  See the NOTICE file distributed with
   * this work for additional information regarding copyright ownership.
   * The ASF licenses this file to You under the Apache License, Version 2.0
   * (the "License"); you may not use this file except in compliance with
   * the License.  You may obtain a copy of the License at
  * 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 static org.jboss.web.CoyoteMessages.MESSAGES;
Handshake request Bayeux message.

Guy A. Molinari
Filip Hanik
 public class MetaConnectRequest extends RequestBase implements BayeuxRequest {
     protected static HashMap<String,ObjectresponseTemplate = new HashMap<String,Object>();
     static {
     public MetaConnectRequest(TomcatBayeux tbHttpEvent eventJSONObject jsReqthrows JSONException {
         if (!=null && getTomcatBayeux().hasClient()) {

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.

HttpError This method returns null if no errors were found
     public HttpError validate() {
         if(==null|| (!getTomcatBayeux().hasClient()))
             return new HttpError(400, .invalidBayeuxClientId(), null);
             return new HttpError(400, .noBayeuxConnectionType(), 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 prevopsthrows BayeuxException {
         prevops = super.process(prevops);
          = (HashMap<StringObject>).clone();
         ClientImpl client = (ClientImpl)getTomcatBayeux().getClient();
         boolean success = false;
         HttpError error = validate();
         if (error == null) {
             success = true;
         }else {
            if (client==nullclient = TomcatBayeux.getErrorClient();
        try {
            JSONObject obj = new JSONObject();
        } 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 
            result = 0; //flush out the messages
        return result;
New to GrepCode? Check out our FAQ X