Exemplo n.º 1
0
  /**
   * Connect the socket. Called by MIOPListener.
   *
   * @param profile
   * @param time_out unused, we use SO_TIMEOUT
   */
  @Override
  public void connect(Profile profile, long time_out) {
    if (!is_connected()) {
      if (profile instanceof MIOPProfile) {
        this.profile = (MIOPProfile) profile;
      } else {
        throw new org.omg.CORBA.BAD_PARAM(
            "attempt to connect an MIOP connection "
                + "to a non-MIOP profile: "
                + profile.getClass());
      }

      try {
        socket = new MulticastSocket(((MIOPProfile) profile).getUIPMCProfile().the_port);

        socket.setSoTimeout(socketTimeout);
        socket.setTimeToLive(timeToLive);
        socket.joinGroup(((MIOPProfile) profile).getGroupInetAddress());

        connection_info = socket.toString();
      } catch (Exception e) {
        if (socket != null) {
          socket.close();
        }
        throw new RuntimeException("Can't create multicast socket: " + profile);
      }

      connected = true;

      groupListener.start();
    }
  }
  /** Select IOP profile that matches protocol */
  public Profile selectProfile(List profiles, ClientConnectionManager ccm) {
    final Iterator iter = profiles.iterator();

    while (iter.hasNext()) {
      final Profile profile = (Profile) iter.next();
      final int profileTag = profile.tag();

      for (int i = 0; i < protocols.length; i++) {
        final int tagToMatch = protocols[i].protocol_type;

        if (profileTag == tagToMatch) {
          return profile;
        }

        if (profileTag == TAG_INTERNET_IOP.value && profile instanceof IIOPProfile) {
          // Special case check for IIOP profile supporting SSL
          IIOPProfile iiopProfile = (IIOPProfile) profile;
          if ((tagToMatch == ORBConstants.JAC_SSL_PROFILE_ID) && (iiopProfile.getSSL() != null)) {
            return profile;
          }

          // Special case check for IIOP profile not supporting SSL
          if ((tagToMatch == ORBConstants.JAC_NOSSL_PROFILE_ID)
              && ((iiopProfile.getSSL() == null)
                  ||
                  // SSL port contains a valid value but further check is required
                  // see if protection is enabled.
                  (((iiopProfile.getSSL()).target_requires & org.omg.Security.NoProtection.value)
                      != 0))) {
            return profile;
          }
        }
      }
    }

    return null;
  }