Jetty
  1. Jetty
  2. JETTY-483

org.mortbay.jetty.EofException thrown when handshake between BayeuxClient and servlet based on SSL

    Details

    • Type: Bug Bug
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.1.6rc1
    • Fix Version/s: 7.0.0pre4, 6.1.12.rc2
    • Component/s: Bayeux
    • Labels:
      None
    • Environment:
      Winxp
    • Number of attachments :
      1

      Description

      I always meet this problem. Actually, when I use Http , not Https, and SelectChannelConnector , it is no problem to publish event from server to client or request from client to server. But when I start a servlet with SslSelectChannelConnector and then start client to connect it , the "WARN: Handshake:org.mortbay.jetty.EofException" always thrown. Maybe it is not a bug for Bayeux, but could u tell me how to resolve it?
      The fllowing is the output of console:
      [main] : CometdSSLClient------Beginning to start Client...
      2007-12-19 10:32:38.746::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
      [main] : CometdSSLClient------Start BayeuxClient:null
      [main] : CometdSSLClient------Start Client successfully!
      [main] : CometdSSLClient------clientPublish toChannel:/noticiation/tier3 data:

      {"user":"test","action":"register_client"}

      msgId:0
      2007-12-19 10:32:38.011::WARN: Handshake:org.mortbay.jetty.EofException
      org.mortbay.jetty.EofException
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:303)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
      at org.mortbay.jetty.client.HttpConnection.handle(HttpConnection.java:238)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
      at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)
      The below is a part of my sourcecodes in client and servlet, and I have attched the BayeuxClient.java in attachment.
      Server side:
      ...
      public void startCometdSSLServlet() {
      try {
      Logger.log(Logger.LOG_NORMAL, "Beginning to start CometdSSLServlet...");
      String sUserDir = System.getProperty("user.dir");
      Server server = new Server();

      SelectChannelConnector connector;
      if (_sslEnabled.equalsIgnoreCase("Y"))

      { //the connector is for SSL connection connector = new SslSelectChannelConnector(); ((SslSelectChannelConnector)connector).setKeystore(_sKeystore); ((SslSelectChannelConnector)connector).setPassword(_sPwd); ((SslSelectChannelConnector)connector).setKeyPassword(_sKeyPwd); ((SslSelectChannelConnector)connector).setNeedClientAuth(_sEnableClientAuth.equals("Y") ? true : false); //((SslSelectChannelConnector)connector).setPort(_sPort); }

      else

      { connector = new SelectChannelConnector(); }


      connector.setPort(_sPort);
      server.addConnector(connector);
      //System.setProperty("javax.net.ssl.trustStore", _sKeystore);

      Context context = new Context(server, "/", Context.NO_SECURITY | Context.NO_SESSIONS);
      context.setResourceBase(sUserDir + "/myweb/");

      ContinuationCometdServlet cometd_servlet = new ContinuationCometdServlet();
      ServletHolder cometd_holder = new ServletHolder(cometd_servlet);
      //cometd_holder.setInitParameter("filters","/WEB-INF/filters.json");
      cometd_holder.setInitParameter("timeout", "240000");
      cometd_holder.setInitParameter("interval", "0");
      cometd_holder.setInitParameter("multiFrameInterval", "1500");
      //cometd_holder.setInitParameter("JSONCommented","true");
      //context.addServlet(cometd_holder, "/cometd/*");
      context.addServlet(cometd_holder, "/myweb/*");
      context.addServlet("servlet.DefaultHttpServlet", "/");

      _listener = new BayeuxCometdStartupListener();
      context.addEventListener(_listener);
      server.start();

      AbstractBayeux bayeux = cometd_servlet.getBayeux();
      bayeux.setSecurityPolicy(new AbstractBayeux.DefaultPolicy() {
      public boolean canHandshake(Map message) {
      System.err.println("BayeuxServlet-------------------canHandshake(Message)");
      // if (_testHandshakeFailure < 0)

      { // _testHandshakeFailure++; // return false; // }

      return true;
      }
      });
      Logger.log(Logger.LOG_NORMAL, "CometdSSLServlet start successfully!");
      } catch (Exception ex)

      { Logger.log(Logger.LOG_ERR, "CometdSSLServlet starts error!"); ex.printStackTrace(); }

      }

      public void pushEvent(Map<String, Object> msg)

      { _listener.pushDebugEvent(msg); }

      public static void main(String[] args) {
      CometdSSLServlet cometServlet = CometdSSLServlet.getInstance();
      cometServlet.startCometdSSLServlet();
      int i = 0;
      while (true) {
      try

      { Map<String, Object> msg = new HashMap<String, Object>(); msg.put("eventId", "" + i); msg.put("eventType", "system"); msg.put("content", "test" + i); cometServlet.pushEvent(msg); i++; Thread.sleep(5000); }

      catch (InterruptedException ex)

      { ex.printStackTrace(); }

      }
      }
      ...

      client side:
      .....
      private void start() {
      Logger.log(Logger.LOG_NORMAL, "CometdSSLClient------Beginning to start Client...");
      try {
      try

      { startHttpClient(); }

      catch (Exception ex)

      { Logger.log(Logger.LOG_ERR, "CometdSSLClient------Start HttpClient error"); ex.printStackTrace(); }

      startBayeuxClient();
      } catch (IOException ex)

      { Logger.log(Logger.LOG_ERR, "CometdSSLClient------Start BayeuxClient error"); ex.printStackTrace(); }

      Logger.log(Logger.LOG_NORMAL, "CometdSSLClient------Start Client successfully!");
      }

      private void startHttpClient() throws Exception

      { _httpClient = new HttpClient(); _httpClient.setConnectorType(HttpClient.CONNECTOR_SELECT_CHANNEL); _httpClient.setMaxConnectionsPerAddress(MAX_CONNECTION_PERADDRESS); BoundedThreadPool pool = new BoundedThreadPool(); pool.setMaxThreads(MAX_THREAD); //pool.setDaemon(true); pool.setName("COMETDCLIENT_HREADPOOL"); _httpClient.setThreadPool(pool); _httpClient.start(); }

      private void startBayeuxClient() throws IOException {
      _bClient = new BayeuxClient(_httpClient, _address, _uri, _isHttps);
      Listener listener = new Listener() {

      public void deliver(Client fromClient, Client toClient, Map<String, Object> msg) {
      Logger.log(Logger.LOG_DEBUG, "CometdSSLClient------------Get Time:" + (new Date()));
      Logger.log(Logger.LOG_DEBUG, "CometdSSLClient------------FromClient:" + fromClient + " toClient:" + toClient.getId() + " Message:" + msg);
      Object data = (Object) msg.get(AbstractBayeux.DATA_FIELD);
      //filtered the "/meta/channel" connection information and only keep "/service/channel" and "/notification/channel" message.
      if (data != null)

      { //Event event = EventConstructor.constructEvent(msg); //dispatch Event to every components registered in the event dispatcher via different event filter. //dispatch(event); }

      }

      public void removed(String clientId, boolean timeout) {
      }
      };
      _bClient.setListener(listener);
      _bClient.subscribe(Configurator.CLIENT_NOTIFICATIONCHANNEL);
      _bClient.start();
      Logger.log(Logger.LOG_NORMAL, "CometdSSLClient------Start BayeuxClient:" + _bClient.getId());
      }

      private void clientPublish(String toChannel, JSON.Literal jsonMsg, String msgId) {
      synchronized (_bClient)

      { Logger.log(Logger.LOG_DEBUG, "CometdSSLClient------clientPublish toChannel:" + toChannel + " data:" + jsonMsg + " msgId:" + msgId); _bClient.publish(toChannel, jsonMsg, msgId); }

      }

      /**

      • @param clientType
      • please see CometdConfigurator.CLIENT_NOTIFICATION, CometdConfigurator.CLIENT_SERVICE
      • */
        public void registerClient(String clientType)

        Unknown macro: { // TODO }

      public static void main(String[] args) {
      CometdSSLClient sslClient = CometdSSLClient.getInstance();
      sslClient.start();
      sslClient.registerClient(Configurator.CLIENT_NOTIFICATIONCHANNEL);
      }
      ......

        Activity

        Hide
        Greg Wilkins added a comment -

        Can you send me the actual diffs of the classes you have changed.

        thanks

        Show
        Greg Wilkins added a comment - Can you send me the actual diffs of the classes you have changed. thanks
        Hide
        scg added a comment -

        Hi, Greg
        I have sent you the modified BayeuxClient and original one in your mail box. Actually, I only modified the file a little bit. In the BayeuxClient constructor method, I added a boolean parameter - isHttps and defined a gloable parameter _isHttps, and then set HttpExchange.ContentExchange setScheme() to be HttpSchemes.HTTPS_BUFFER instead of HttpSchemes.HTTP_BUFFER in according to the _isHttps value.
        In my first post , I attached the client side codes about how to create&start the client , subscribe my event channel for pushing the event data from server to client, and publish message from cleint to server.

        BTW, as my fist post said, if based on http protocol , all of these are running normally.

        Thanks a lot.

        Show
        scg added a comment - Hi, Greg I have sent you the modified BayeuxClient and original one in your mail box. Actually, I only modified the file a little bit. In the BayeuxClient constructor method, I added a boolean parameter - isHttps and defined a gloable parameter _isHttps, and then set HttpExchange.ContentExchange setScheme() to be HttpSchemes.HTTPS_BUFFER instead of HttpSchemes.HTTP_BUFFER in according to the _isHttps value. In my first post , I attached the client side codes about how to create&start the client , subscribe my event channel for pushing the event data from server to client, and publish message from cleint to server. BTW, as my fist post said, if based on http protocol , all of these are running normally. Thanks a lot.
        Hide
        Greg Wilkins added a comment -

        Up for grabs

        Show
        Greg Wilkins added a comment - Up for grabs
        Hide
        Greg Wilkins added a comment -

        This has been fixed in Jetty 7.
        We hope to back port this to jetty 6 soon.

        Show
        Greg Wilkins added a comment - This has been fixed in Jetty 7. We hope to back port this to jetty 6 soon.
        Hide
        Greg Wilkins added a comment -

        I believe this is now backported to jetty-6

        Show
        Greg Wilkins added a comment - I believe this is now backported to jetty-6

          People

          • Assignee:
            Greg Wilkins
            Reporter:
            scg
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: