Package javax.management.remote.message

Examples of javax.management.remote.message.Message


      HandshakeBeginMessage begin =
    new HandshakeBeginMessage(serverProfiles, serverVersion);
      mc.writeMessage(begin);

      while (true) {
    Message msg = mc.readMessage();
    if (msg instanceof HandshakeErrorMessage) {
        // Throw exception and let GenericConnectorServer
        // close the connection
        //
        sendError = false;
        HandshakeErrorMessage error = (HandshakeErrorMessage) msg;
        AdminClient.throwExceptionOnError(error);
    } else if (msg instanceof HandshakeEndMessage) {
        HandshakeEndMessage cend = (HandshakeEndMessage) msg;
        Object ccontext = cend.getContext();
        if (logger.traceOn()) {
      logger.trace("connectionOpen",
             ">>>>> Handshake End <<<<<");
      logger.trace("connectionOpen",
             "Client Context Object [ " +
             ccontext + " ]");
        }
        Object scontext = (Object) env.get("jmx.remote.context");
        // If MessageConnection is an instance of SocketConnectionIf
        // then set the authenticated subject.
        if (mc instanceof SocketConnectionIf) {
      ((SocketConnectionIf)mc).setSubject(subject);
        }
        String connectionId = mc.getConnectionId();
        // If the environment includes an authenticator, check
        // that it accepts the connection id, and replace the
        // Subject by whatever it returns.
        JMXAuthenticator authenticator =
      (JMXAuthenticator) env.get("jmx.remote.authenticator");
        if (authenticator != null) {
      Object[] credentials = {connectionId, subject};
      subject = authenticator.authenticate(credentials);
      if (mc instanceof SocketConnectionIf) {
          ((SocketConnectionIf)mc).setSubject(subject);
      }
      connectionId = mc.getConnectionId();
        }
        if (logger.traceOn()) {
      logger.trace("connectionOpen",
             "Server Context Object [ " +
             scontext + " ]");
      logger.trace("connectionOpen",
             "Server Connection Id [ " +
             connectionId + " ]");
        }

        // Check that the negotiated profiles are acceptable for
        // the server's defined security policy. This method is
        // called just before the initial handshake is completed
        // with a HandshakeEndMessage sent from the server to the
        // client. If the method throws an exception, then a
        // HandshakeErrorMessage will be sent instead.
        //
        List profileNames = getProfilesByName(mc);
        CheckProfiles np = (CheckProfiles)
      env.get("com.sun.jmx.remote.profile.checker");
        if (np != null) {
      np.checkProfiles(env,
           profileNames,
           ccontext,
           connectionId);
        } else {
      checkProfilesForEquality(serverProfiles,
             profileNames);
        }

        HandshakeEndMessage send =
      new HandshakeEndMessage(scontext, connectionId);
        mc.writeMessage(send);
        break;
    } else if (msg instanceof VersionMessage) {
        VersionMessage cjmxmp = (VersionMessage) msg;
        String clientVersion = cjmxmp.getVersion();
        if (clientVersion.equals(serverVersion)) {
      VersionMessage sjmxmp =
          new VersionMessage(serverVersion);
      mc.writeMessage(sjmxmp);
        } else {
      throw new IOException("Protocol version " +
                "mismatch: Client [" +
                clientVersion +
                "] vs. Server [" +
                serverVersion + "]");
        }
    } else if (msg instanceof ProfileMessage) {
        ProfileMessage pm = (ProfileMessage) msg;
        String pn = pm.getProfileName();
        ProfileServer p = (ProfileServer) getProfile(mc, pn);
        if (p == null) {
      p = ProfileServerFactory.createProfile(pn, env);
      if (logger.traceOn()) {
          logger.trace("connectionOpen",
           ">>>>> Profile " +
           p.getClass().getName() +
           " <<<<<");
      }
      p.initialize(mc, subject);
      putProfile(mc, p);
        }
        p.consumeMessage(pm);
        pm = p.produceMessage();
        mc.writeMessage(pm);
        if (p.isComplete()) {
      subject = p.activate();
        }
    } else {
        throw new IOException("Unexpected message: " +
            msg.getClass().getName());
    }
      }
      putSubject(mc, subject);
  } catch (Exception e) {
      if (sendError) {
View Full Code Here


        try {

            // Begin Handshake
            //
            HandshakeBeginMessage begin = null;
            Message msg = mc.readMessage();
            if (msg instanceof HandshakeBeginMessage) {
                begin = (HandshakeBeginMessage) msg;
            } else if (msg instanceof HandshakeErrorMessage) {
                // Throw exception and let GenericConnector
                // close the connection
                //
                sendError = false;
                error = (HandshakeErrorMessage) msg;
                throwExceptionOnError(error);
            } else {
                throw new IOException("Unexpected message: " +
                                      msg.getClass().getName());
            }

            String serverProfiles = begin.getProfiles();
            String serverVersion = begin.getVersion();
      if (logger.traceOn()) {
    logger.trace("connectionOpen", ">>>>> Handshake Begin <<<<<");
    logger.trace("connectionOpen", "Server Supported Profiles [ " +
           serverProfiles + " ]");
    logger.trace("connectionOpen", "Server JMXMP Version [ " +
           serverVersion + " ]");
      }

            // Negotiate JMXMP protocol version
            //
            String clientVersion = "1.0";
            if (!clientVersion.equals(serverVersion)) {
                if (clientVersion.compareTo(serverVersion) > 0) {
                    throw new IOException("The client is already using the " +
                                          "lowest JMXMP protocol version [" +
                                          clientVersion + "]");
                } else {
                    VersionMessage cjmxmp = new VersionMessage(clientVersion);
                    mc.writeMessage(cjmxmp);
                    msg = mc.readMessage();
                    if (msg instanceof VersionMessage) {
                        VersionMessage sjmxmp = (VersionMessage) msg;
                        if (!clientVersion.equals(sjmxmp.getVersion())) {
                            throw new IOException("Protocol version " +
                                                  "mismatch: Client [" +
                                                  clientVersion +
                                                  "] vs. Server [" +
                                                  sjmxmp.getVersion() + "]");
                        }
                    } else if (msg instanceof HandshakeErrorMessage) {
                        // Throw exception and let GenericConnector
                        // close the connection
                        //
                        sendError = false;
                        error = (HandshakeErrorMessage) msg;
                        throwExceptionOnError(error);
                    } else {
                        throw new IOException("Unexpected message: " +
                                              msg.getClass().getName());
                    }
                }
            }

            // Execute client selected profiles
            //
            List profileList = selectProfiles(serverProfiles);
            for (Iterator i = profileList.iterator(); i.hasNext(); ) {
                String profile = (String) i.next();
    ProfileClient p =
        ProfileClientFactory.createProfile(profile, env);
    if (logger.traceOn()) {
        logger.trace("connectionOpen",
         ">>>>> Profile " +
         p.getClass().getName() +
         " <<<<<");
    }
    ProfileMessage pm = null;
    p.initialize(mc);
    while (!p.isComplete()) {
        pm = p.produceMessage();
        mc.writeMessage(pm);
        msg = mc.readMessage();
        if (msg instanceof ProfileMessage) {
      p.consumeMessage((ProfileMessage)msg);
        } else if (msg instanceof HandshakeErrorMessage) {
      // Throw exception and let GenericConnector
      // close the connection
      //
      sendError = false;
      error = (HandshakeErrorMessage) msg;
      throwExceptionOnError(error);
        } else {
      throw new IOException("Unexpected message: " +
                msg.getClass().getName());
        }
    }
    p.activate();
    profilesList.add(p);
      }

            // Send client handshake end
            //
            Object ccontext = (Object) env.get("jmx.remote.context");
            HandshakeEndMessage cend = new HandshakeEndMessage(ccontext, null);
      if (logger.traceOn()) {
    logger.trace("connectionOpen",
           ">>>>> Handshake End <<<<<");
    logger.trace("connectionOpen",
           "Client Context Object [ " + ccontext + " ]");
      }
            mc.writeMessage(cend);

            // Wait for server handshake end
            //
            HandshakeEndMessage send = null;
            msg = mc.readMessage();
            if (msg instanceof HandshakeEndMessage) {
                send = (HandshakeEndMessage) msg;
            } else if (msg instanceof HandshakeErrorMessage) {
                // Throw exception and let GenericConnector
                // close the connection
                //
                sendError = false;
                error = (HandshakeErrorMessage) msg;
                throwExceptionOnError(error);
            } else {
                throw new IOException("Unexpected message: " +
                                      msg.getClass().getName());
            }
            Object scontext = send.getContext();
            connectionId = send.getConnectionId();
      if (logger.traceOn()) {
    logger.trace("connectionOpen",
View Full Code Here

TOP

Related Classes of javax.management.remote.message.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.