Search in sources :

Example 1 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class DistributionConfigImpl method setStartLocator.

public void setStartLocator(String value) {
    startLocatorPort = 0;
    if (value == null) {
        value = DEFAULT_START_LOCATOR;
    } else {
        // bug 37938 - allow just a port
        boolean alldigits = true;
        for (int i = 0; i < value.length(); i++) {
            char c = value.charAt(i);
            if (!Character.isDigit(c)) {
                alldigits = false;
                break;
            }
        }
        if (value.length() > 0 && alldigits) {
            try {
                int port = Integer.parseInt(value);
                if (port < 0 || port > 65535) {
                    throw new GemFireConfigException("Illegal port specified for start-locator");
                }
                startLocatorPort = port;
            } catch (NumberFormatException e) {
                throw new GemFireConfigException("Illegal port specified for start-locator", e);
            }
        } else {
        }
    }
    this.startLocator = value;
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException)

Example 2 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class ConnectionFactoryImpl method createClientToServerConnection.

public Connection createClientToServerConnection(ServerLocation location, boolean forQueue) throws GemFireSecurityException {
    ConnectionImpl connection = new ConnectionImpl(this.ds, this.cancelCriterion);
    FailureTracker failureTracker = blackList.getFailureTracker(location);
    boolean initialized = false;
    try {
        HandShake connHandShake = new HandShake(handshake);
        connection.connect(endpointManager, location, connHandShake, socketBufferSize, handShakeTimeout, readTimeout, getCommMode(forQueue), this.gatewaySender, this.socketCreator);
        failureTracker.reset();
        connection.setHandShake(connHandShake);
        authenticateIfRequired(connection);
        initialized = true;
    } catch (GemFireConfigException e) {
        throw e;
    } catch (CancelException e) {
        // propagate this up, don't retry
        throw e;
    } catch (GemFireSecurityException e) {
        // propagate this up, don't retry
        throw e;
    } catch (GatewayConfigurationException e) {
        // propagate this up, don't retry
        throw e;
    } catch (ServerRefusedConnectionException src) {
        // propagate this up, don't retry
        logger.warn(LocalizedMessage.create(LocalizedStrings.AutoConnectionSourceImpl_COULD_NOT_CREATE_A_NEW_CONNECTION_TO_SERVER_0, src.getMessage()));
        testFailedConnectionToServer = true;
        throw src;
    } catch (Exception e) {
        if (e.getMessage() != null && (e.getMessage().equals("Connection refused") || e.getMessage().equals("Connection reset"))) {
            // print an exception
            if (logger.isDebugEnabled()) {
                logger.debug("Unable to connect to {}: connection refused", location);
            }
        } else {
            // print a warning with the exception stack trace
            logger.warn(LocalizedMessage.create(LocalizedStrings.ConnectException_COULD_NOT_CONNECT_TO_0, location), e);
        }
        testFailedConnectionToServer = true;
    } finally {
        if (!initialized) {
            connection.destroy();
            failureTracker.addFailure();
            connection = null;
        }
    }
    return connection;
}
Also used : HandShake(org.apache.geode.internal.cache.tier.sockets.HandShake) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) FailureTracker(org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) GemFireConfigException(org.apache.geode.GemFireConfigException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) CancelException(org.apache.geode.CancelException) ServerRefusedConnectionException(org.apache.geode.cache.client.ServerRefusedConnectionException) GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) GemFireConfigException(org.apache.geode.GemFireConfigException) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Example 3 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class HandShake method handshakeWithServer.

/**
   * Client-side handshake with a Server
   */
public ServerQueueStatus handshakeWithServer(Connection conn, ServerLocation location, byte communicationMode) throws IOException, AuthenticationRequiredException, AuthenticationFailedException, ServerRefusedConnectionException {
    try {
        ServerQueueStatus serverQStatus = null;
        Socket sock = conn.getSocket();
        DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
        final InputStream in = sock.getInputStream();
        DataInputStream dis = new DataInputStream(in);
        DistributedMember member = getIDForSocket(sock);
        // if running in a loner system, use the new port number in the ID to
        // help differentiate from other clients
        DM dm = ((InternalDistributedSystem) this.system).getDistributionManager();
        InternalDistributedMember idm = dm.getDistributionManagerId();
        synchronized (idm) {
            if (idm.getPort() == 0 && dm instanceof LonerDistributionManager) {
                int port = sock.getLocalPort();
                ((LonerDistributionManager) dm).updateLonerPort(port);
                updateProxyID(dm.getDistributionManagerId());
            }
        }
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {
            this.credentials = getCredentials(member);
        }
        byte intermediateAcceptanceCode = write(dos, dis, communicationMode, REPLY_OK, this.clientReadTimeout, null, this.credentials, member, false);
        String authInit = this.system.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT);
        if (communicationMode != Acceptor.GATEWAY_TO_GATEWAY && intermediateAcceptanceCode != REPLY_AUTH_NOT_REQUIRED && (authInit != null && authInit.length() != 0)) {
            location.compareAndSetRequiresCredentials(true);
        }
        // Read the acceptance code
        byte acceptanceCode = dis.readByte();
        if (acceptanceCode == (byte) 21 && !(sock instanceof SSLSocket)) {
            // SSL
            throw new AuthenticationRequiredException(LocalizedStrings.HandShake_SERVER_EXPECTING_SSL_CONNECTION.toLocalizedString());
        }
        if (acceptanceCode == REPLY_SERVER_IS_LOCATOR) {
            throw new GemFireConfigException("Improperly configured client detected.  " + "Server at " + location + " is actually a locator.  Use addPoolLocator to configure locators.");
        }
        // Successful handshake for GATEWAY_TO_GATEWAY mode sets the peer version in connection
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && !(acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_REQUIRED || acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_FAILED)) {
            short wanSiteVersion = Version.readOrdinal(dis);
            conn.setWanSiteVersion(wanSiteVersion);
            // establish a versioned stream for the other site, if necessary
            if (wanSiteVersion < Version.CURRENT_ORDINAL) {
                dis = new VersionedDataInputStream(dis, Version.fromOrdinalOrCurrent(wanSiteVersion));
            }
        }
        // No need to check for return value since DataInputStream already throws
        // EOFException in case of EOF
        byte epType = dis.readByte();
        int qSize = dis.readInt();
        // Read the server member
        member = readServerMember(dis);
        serverQStatus = new ServerQueueStatus(epType, qSize, member);
        // Read the message (if any)
        readMessage(dis, dos, acceptanceCode, member);
        // DSes with different values of this. It shoule be a member variable.
        if (communicationMode != Acceptor.GATEWAY_TO_GATEWAY && currentClientVersion.compareTo(Version.GFE_61) >= 0) {
            deltaEnabledOnServer = dis.readBoolean();
        }
        // validate that the remote side has a different distributed system id.
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && Version.GFE_66.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_66) >= 0) {
            int remoteDistributedSystemId = in.read();
            int localDistributedSystemId = ((InternalDistributedSystem) system).getDistributionManager().getDistributedSystemId();
            if (localDistributedSystemId >= 0 && localDistributedSystemId == remoteDistributedSystemId) {
                throw new GatewayConfigurationException("Remote WAN site's distributed system id " + remoteDistributedSystemId + " matches this sites distributed system id " + localDistributedSystemId);
            }
        }
        // Read the PDX registry size from the remote size
        if (communicationMode == Acceptor.GATEWAY_TO_GATEWAY && Version.GFE_80.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_80) >= 0) {
            int remotePdxSize = dis.readInt();
            serverQStatus.setPdxSize(remotePdxSize);
        }
        return serverQStatus;
    } catch (IOException ex) {
        CancelCriterion stopper = this.system.getCancelCriterion();
        stopper.checkCancelInProgress(null);
        throw ex;
    }
}
Also used : GatewayConfigurationException(org.apache.geode.cache.GatewayConfigurationException) DataOutputStream(java.io.DataOutputStream) VersionedDataOutputStream(org.apache.geode.internal.VersionedDataOutputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) SSLSocket(javax.net.ssl.SSLSocket) CancelCriterion(org.apache.geode.CancelCriterion) DM(org.apache.geode.distributed.internal.DM) AuthenticationRequiredException(org.apache.geode.security.AuthenticationRequiredException) IOException(java.io.IOException) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GemFireConfigException(org.apache.geode.GemFireConfigException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) LonerDistributionManager(org.apache.geode.distributed.internal.LonerDistributionManager) SSLSocket(javax.net.ssl.SSLSocket) Socket(java.net.Socket) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream)

Example 4 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class SocketCreator method connect.

/**
   * Return a client socket, timing out if unable to connect and timeout > 0 (millis). The parameter
   * <i>timeout</i> is ignored if SSL is being used, as there is no timeout argument in the ssl
   * socket factory
   */
public Socket connect(InetAddress inetadd, int port, int timeout, ConnectionWatcher optionalWatcher, boolean clientSide, int socketBufferSize, boolean sslConnection) throws IOException {
    Socket socket = null;
    SocketAddress sockaddr = new InetSocketAddress(inetadd, port);
    printConfig();
    try {
        if (sslConnection) {
            if (this.sslContext == null) {
                throw new GemFireConfigException("SSL not configured correctly, Please look at previous error");
            }
            SocketFactory sf = this.sslContext.getSocketFactory();
            socket = sf.createSocket();
            // Optionally enable SO_KEEPALIVE in the OS network protocol.
            socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE);
            // (see java.net.Socket.setReceiverBufferSize javadocs for details)
            if (socketBufferSize != -1) {
                socket.setReceiveBufferSize(socketBufferSize);
            }
            if (optionalWatcher != null) {
                optionalWatcher.beforeConnect(socket);
            }
            socket.connect(sockaddr, Math.max(timeout, 0));
            configureClientSSLSocket(socket, timeout);
            return socket;
        } else {
            if (clientSide && this.clientSocketFactory != null) {
                socket = this.clientSocketFactory.createSocket(inetadd, port);
            } else {
                socket = new Socket();
                // Optionally enable SO_KEEPALIVE in the OS network protocol.
                socket.setKeepAlive(ENABLE_TCP_KEEP_ALIVE);
                // (see java.net.Socket.setReceiverBufferSize javadocs for details)
                if (socketBufferSize != -1) {
                    socket.setReceiveBufferSize(socketBufferSize);
                }
                if (optionalWatcher != null) {
                    optionalWatcher.beforeConnect(socket);
                }
                socket.connect(sockaddr, Math.max(timeout, 0));
            }
            return socket;
        }
    } finally {
        if (optionalWatcher != null) {
            optionalWatcher.afterConnect(socket);
        }
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) InetSocketAddress(java.net.InetSocketAddress) TransportFilterSocketFactory(org.apache.geode.internal.cache.wan.TransportFilterSocketFactory) SocketFactory(javax.net.SocketFactory) ServerSocketFactory(javax.net.ServerSocketFactory) ClientSocketFactory(org.apache.geode.distributed.ClientSocketFactory) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket) ServerSocket(java.net.ServerSocket) TransportFilterServerSocket(org.apache.geode.internal.cache.wan.TransportFilterServerSocket) SSLServerSocket(javax.net.ssl.SSLServerSocket) Socket(java.net.Socket)

Example 5 with GemFireConfigException

use of org.apache.geode.GemFireConfigException in project geode by apache.

the class SocketCreator method initialize.

// -------------------------------------------------------------------------
// Initializers (change SocketCreator state)
// -------------------------------------------------------------------------
/**
   * Initialize this SocketCreator.
   * <p>
   * Caller must synchronize on the SocketCreator instance.
   */
@SuppressWarnings("hiding")
private void initialize() {
    try {
        // set p2p values...
        if (SecurableCommunicationChannel.CLUSTER.equals(sslConfig.getSecuredCommunicationChannel())) {
            if (this.sslConfig.isEnabled()) {
                System.setProperty("p2p.useSSL", "true");
                System.setProperty("p2p.oldIO", "true");
                System.setProperty("p2p.nodirectBuffers", "true");
            } else {
                System.setProperty("p2p.useSSL", "false");
            }
        }
        try {
            if (this.sslConfig.isEnabled() && sslContext == null) {
                sslContext = createAndConfigureSSLContext();
                SSLContext.setDefault(sslContext);
            }
        } catch (Exception e) {
            throw new GemFireConfigException("Error configuring GemFire ssl ", e);
        }
        // make sure TCPConduit picks up p2p properties...
        org.apache.geode.internal.tcp.TCPConduit.init();
        initializeClientSocketFactory();
        this.ready = true;
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Error t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        t.printStackTrace();
        throw t;
    } catch (RuntimeException re) {
        re.printStackTrace();
        throw re;
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) KeyStoreException(java.security.KeyStoreException) GeneralSecurityException(java.security.GeneralSecurityException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) BindException(java.net.BindException) SocketException(java.net.SocketException) SystemConnectException(org.apache.geode.SystemConnectException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) UnknownHostException(java.net.UnknownHostException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Aggregations

GemFireConfigException (org.apache.geode.GemFireConfigException)28 IOException (java.io.IOException)11 SystemConnectException (org.apache.geode.SystemConnectException)10 Properties (java.util.Properties)7 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)7 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)6 Test (org.junit.Test)6 UnknownHostException (java.net.UnknownHostException)5 CancelException (org.apache.geode.CancelException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 InetSocketAddress (java.net.InetSocketAddress)4 GemFireIOException (org.apache.geode.GemFireIOException)4 VersionedDataInputStream (org.apache.geode.internal.VersionedDataInputStream)4 MemberShunnedException (org.apache.geode.internal.tcp.MemberShunnedException)4 GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)4 InputStream (java.io.InputStream)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ServerSocket (java.net.ServerSocket)3 NetView (org.apache.geode.distributed.internal.membership.NetView)3