Search in sources :

Example 6 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class LocalServerConnection method authenticate.

public synchronized void authenticate() throws ConnectionException, CommunicationException {
    Object previousSecurityContext = workContext.getSecurityHelper().associateSecurityContext(workContext.getSession().getSecurityContext());
    try {
        logoff();
    } finally {
        workContext.getSecurityHelper().associateSecurityContext(previousSecurityContext);
    }
    workContext.setSecurityContext(previousSecurityContext);
    try {
        this.result = this.getService(ILogon.class).logon(this.connectionProperties);
        AuthenticationType type = (AuthenticationType) this.result.getProperty(ILogon.AUTH_TYPE);
        if (type != null) {
            // server has issued an additional challenge
            if (type == AuthenticationType.GSS) {
                try {
                    this.result = MakeGSS.authenticate(this.getService(ILogon.class), this.connectionProperties);
                } catch (LogonException e) {
                    if (!passthrough) {
                        throw new LogonException(RuntimePlugin.Event.TEIID40150, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40150));
                    }
                    throw e;
                }
            } else {
                throw new LogonException(JDBCPlugin.Event.TEIID20034, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20034, type));
            }
        }
    } catch (LogonException e) {
        // to give to the user
        throw new ConnectionException(e);
    } catch (TeiidComponentException e) {
        if (e.getCause() instanceof CommunicationException) {
            throw (CommunicationException) e.getCause();
        }
        throw new CommunicationException(RuntimePlugin.Event.TEIID40069, e);
    }
}
Also used : CommunicationException(org.teiid.net.CommunicationException) LogonException(org.teiid.client.security.LogonException) TeiidComponentException(org.teiid.core.TeiidComponentException) ConnectionException(org.teiid.net.ConnectionException) AuthenticationType(org.teiid.net.socket.AuthenticationType)

Example 7 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class TestSocketServerConnection method createConnection.

private SocketServerConnection createConnection(final Throwable t, final HostInfo hostInfo, Properties p) throws CommunicationException, ConnectionException {
    ServerDiscovery discovery = new UrlServerDiscovery(new TeiidURL(hostInfo.getHostName(), hostInfo.getPortNumber(), false));
    SocketServerInstanceFactory instanceFactory = new SocketServerInstanceFactory() {

        FakeILogon logon = new FakeILogon(t);

        @Override
        public SocketServerInstance getServerInstance(HostInfo info) throws CommunicationException, IOException {
            SocketServerInstance instance = Mockito.mock(SocketServerInstance.class);
            Mockito.stub(instance.getCryptor()).toReturn(new NullCryptor());
            Mockito.stub(instance.getHostInfo()).toReturn(hostInfo);
            Mockito.stub(instance.getService(ILogon.class)).toReturn(logon);
            Mockito.stub(instance.getServerVersion()).toReturn("07.03");
            if (t != null) {
                try {
                    Mockito.doAnswer(new Answer<Void>() {

                        @Override
                        public Void answer(InvocationOnMock invocation) throws Throwable {
                            if (logon.t == null) {
                                return null;
                            }
                            throw logon.t;
                        }
                    }).when(instance).send((Message) Mockito.anyObject(), (ResultsReceiver<Object>) Mockito.anyObject(), (Serializable) Mockito.anyObject());
                } catch (Exception e) {
                }
            }
            Mockito.stub(instance.isOpen()).toReturn(true);
            return instance;
        }

        @Override
        public void connected(SocketServerInstance instance, SessionToken session) {
        }

        @Override
        public void disconnected(SocketServerInstance instance, SessionToken session) {
        }
    };
    SocketServerConnection connection = new SocketServerConnection(instanceFactory, false, discovery, p);
    return connection;
}
Also used : SessionToken(org.teiid.client.security.SessionToken) TeiidURL(org.teiid.net.TeiidURL) NullCryptor(org.teiid.core.crypto.NullCryptor) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) CommunicationException(org.teiid.net.CommunicationException) IOException(java.io.IOException) LogonException(org.teiid.client.security.LogonException) ConnectionException(org.teiid.net.ConnectionException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) HostInfo(org.teiid.net.HostInfo)

Example 8 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class SocketServerConnection method selectServerInstance.

/**
 * Implements a sticky random selection policy
 * TODO: make this customizable
 * TODO: put more information on hostinfo as to process response time, last successful connect, etc.
 * @throws ConnectionException
 */
public synchronized SocketServerInstance selectServerInstance(boolean logoff) throws CommunicationException, ConnectionException {
    if (closed) {
        throw new CommunicationException(JDBCPlugin.Event.TEIID20016, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20016));
    }
    if (this.serverInstance != null && (!failOver || this.serverInstance.isOpen())) {
        return this.serverInstance;
    }
    List<HostInfo> hostKeys = new ArrayList<HostInfo>(this.serverDiscovery.getKnownHosts(logonResult, null));
    boolean discoverHosts = true;
    closeServerInstance();
    List<HostInfo> hostCopy = new ArrayList<HostInfo>(hostKeys);
    int knownHosts = hostKeys.size();
    while (hostKeys.size() > 0) {
        HostInfo hostInfo = this.serverDiscovery.selectNextInstance(hostKeys);
        Exception ex = null;
        try {
            if (!hostInfo.isResolved()) {
                InetAddress inetAddress = hostInfo.getInetAddress();
                if (!hostInfo.isResolved()) {
                    // create a resolved version
                    hostInfo = new HostInfo(hostInfo.getHostName(), new InetSocketAddress(inetAddress, hostInfo.getPortNumber()));
                }
            }
            ILogon newLogon = connect(hostInfo);
            if (this.logonResult == null) {
                try {
                    logon(newLogon, logoff);
                    this.serverDiscovery.connectionSuccessful(hostInfo);
                    if (discoverHosts) {
                        List<HostInfo> updatedHosts = this.serverDiscovery.getKnownHosts(logonResult, this.serverInstance);
                        if (updatedHosts.size() > 1 && new HashSet<HostInfo>(updatedHosts).size() > new HashSet<HostInfo>(hostCopy).size()) {
                            hostKeys = updatedHosts;
                            closeServerInstance();
                            discoverHosts = false;
                            continue;
                        }
                    }
                } catch (LogonException e) {
                    // to give to the user
                    throw new ConnectionException(e);
                } catch (TeiidComponentException e) {
                    if (e.getCause() instanceof CommunicationException) {
                        throw (CommunicationException) e.getCause();
                    }
                    throw new CommunicationException(JDBCPlugin.Event.TEIID20018, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20018));
                }
            }
            return this.serverInstance;
        } catch (IOException e) {
            ex = e;
        } catch (SingleInstanceCommunicationException e) {
            ex = e;
        }
        this.serverDiscovery.markInstanceAsBad(hostInfo);
        if (knownHosts == 1) {
            // just a single host, use the exception
            if (ex instanceof UnknownHostException) {
                throw new SingleInstanceCommunicationException(JDBCPlugin.Event.TEIID20019, ex, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20019, hostInfo.getHostName()));
            }
            throw new SingleInstanceCommunicationException(JDBCPlugin.Event.TEIID20020, ex, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20020, hostInfo.getHostName(), String.valueOf(hostInfo.getPortNumber()), ex.getMessage()));
        }
        // $NON-NLS-1$
        log.log(Level.FINE, "Unable to connect to host", ex);
    }
    throw new CommunicationException(JDBCPlugin.Event.TEIID20021, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20021, hostCopy.toString()));
}
Also used : CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) SocketException(java.net.SocketException) CommunicationException(org.teiid.net.CommunicationException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ConnectionException(org.teiid.net.ConnectionException) ILogon(org.teiid.client.security.ILogon) LogonException(org.teiid.client.security.LogonException) TeiidComponentException(org.teiid.core.TeiidComponentException) HostInfo(org.teiid.net.HostInfo) InetAddress(java.net.InetAddress) ConnectionException(org.teiid.net.ConnectionException)

Example 9 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class TransportService method start.

@Override
public void start(StartContext context) throws StartException {
    this.setVDBRepository(this.getVdbRepository());
    SessionService ss = sessionServiceInjector.getValue();
    this.setSecurityHelper(ss.getSecurityHelper());
    // create the necessary services
    // $NON-NLS-1$
    this.logon = new LogonImpl(ss, "teiid-cluster");
    DQP dqpProxy = proxyService(DQP.class, getDQP(), LogConstants.CTX_DQP);
    this.registerClientService(ILogon.class, logon, LogConstants.CTX_SECURITY);
    this.registerClientService(DQP.class, dqpProxy, LogConstants.CTX_DQP);
    this.setAuthenticationType(ss.getDefaultAuthenticationType());
    if (this.socketConfig != null) {
        /*
    		try {
				// this is to show the bound socket port in the JMX console
				SocketBinding socketBinding = getSocketBindingInjector().getValue();
				ManagedServerSocketBinding ss = (ManagedServerSocketBinding)socketBinding.getSocketBindings().getServerSocketFactory().createServerSocket(socketBinding.getName());
				socketBinding.getSocketBindings().getNamedRegistry().registerBinding(ss);
			}  catch (IOException e) {
				throw new StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50013));
			}
    		*/
        this.address = getSocketBindingInjector().getValue().getSocketAddress();
        this.socketConfig.setBindAddress(this.address.getHostName());
        this.socketConfig.setPortNumber(this.address.getPort());
        boolean sslEnabled = false;
        if (this.socketConfig.getSSLConfiguration() != null) {
            sslEnabled = this.socketConfig.getSSLConfiguration().isSslEnabled();
        }
        if (socketConfig.getProtocol() == WireProtocol.teiid) {
            this.socketListener = new SocketListener(address, this.socketConfig, this, getBufferManagerInjector().getValue());
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50012, this.transportName, address.getHostName(), String.valueOf(address.getPort()), (sslEnabled ? "ON" : "OFF")));
        } else if (socketConfig.getProtocol() == WireProtocol.pg) {
            TeiidDriver driver = new TeiidDriver();
            driver.setLocalProfile(new ConnectionProfile() {

                @Override
                public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
                    try {
                        LocalServerConnection sc = new LocalServerConnection(info, true) {

                            @Override
                            protected ClientServiceRegistry getClientServiceRegistry(String name) {
                                return TransportService.this;
                            }
                        };
                        return new ConnectionImpl(sc, info, url);
                    } catch (CommunicationException e) {
                        throw TeiidSQLException.create(e);
                    } catch (ConnectionException e) {
                        throw TeiidSQLException.create(e);
                    }
                }
            });
            ODBCSocketListener odbc = new ODBCSocketListener(address, this.socketConfig, this, getBufferManagerInjector().getValue(), getMaxODBCLobSizeAllowed(), this.logon, driver);
            this.socketListener = odbc;
            // $NON-NLS-1$ //$NON-NLS-2$
            LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50037, this.transportName, address.getHostName(), String.valueOf(address.getPort()), (sslEnabled ? "ON" : "OFF")));
        } else {
            throw new StartException(IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50013));
        }
    } else {
        LogManager.logInfo(LogConstants.CTX_RUNTIME, IntegrationPlugin.Util.gs(IntegrationPlugin.Event.TEIID50038, LocalServerConnection.jndiNameForRuntime(transportName)));
    }
}
Also used : DQP(org.teiid.client.DQP) CommunicationException(org.teiid.net.CommunicationException) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) SessionService(org.teiid.dqp.service.SessionService) LogonImpl(org.teiid.transport.LogonImpl) SocketListener(org.teiid.transport.SocketListener) ODBCSocketListener(org.teiid.transport.ODBCSocketListener) TeiidDriver(org.teiid.jdbc.TeiidDriver) StartException(org.jboss.msc.service.StartException) LocalServerConnection(org.teiid.transport.LocalServerConnection) ODBCSocketListener(org.teiid.transport.ODBCSocketListener) ConnectionException(org.teiid.net.ConnectionException)

Example 10 with ConnectionException

use of org.teiid.net.ConnectionException in project teiid by teiid.

the class TestJDBCSocketTransport method testSyncTimeout.

/**
 * Tests to ensure that a SynchronousTtl/synchTimeout does
 * not cause a cancel.
 * TODO: had to increase the values since the test would fail on slow machine runs
 * @throws Exception
 */
@Test
public void testSyncTimeout() throws Exception {
    TeiidDriver td = new TeiidDriver();
    td.setSocketProfile(new ConnectionProfile() {

        @Override
        public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
            SocketServerConnectionFactory sscf = new SocketServerConnectionFactory();
            sscf.initialize(info);
            try {
                return new ConnectionImpl(sscf.getConnection(info), info, url);
            } catch (CommunicationException e) {
                throw TeiidSQLException.create(e);
            } catch (ConnectionException e) {
                throw TeiidSQLException.create(e);
            }
        }
    });
    Properties p = new Properties();
    p.setProperty("user", "testuser");
    p.setProperty("password", "testpassword");
    ConnectorManagerRepository cmr = server.getConnectorManagerRepository();
    AutoGenDataService agds = new AutoGenDataService() {

        @Override
        public Object getConnectionFactory() throws TranslatorException {
            return null;
        }
    };
    // wait longer than the synch ttl/soTimeout, we should still succeed
    agds.setSleep(2000);
    cmr.addConnectorManager("source", agds);
    try {
        conn = td.connect("jdbc:teiid:parts@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), p);
        Statement s = conn.createStatement();
        assertTrue(s.execute("select * from parts"));
    } finally {
        server.setConnectorManagerRepository(cmr);
    }
}
Also used : SocketServerConnectionFactory(org.teiid.net.socket.SocketServerConnectionFactory) CommunicationException(org.teiid.net.CommunicationException) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) TeiidDriver(org.teiid.jdbc.TeiidDriver) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService) ConnectionException(org.teiid.net.ConnectionException) Test(org.junit.Test)

Aggregations

ConnectionException (org.teiid.net.ConnectionException)10 CommunicationException (org.teiid.net.CommunicationException)7 IOException (java.io.IOException)4 LogonException (org.teiid.client.security.LogonException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 TeiidException (org.teiid.core.TeiidException)4 UnknownHostException (java.net.UnknownHostException)3 InvalidSessionException (org.teiid.client.security.InvalidSessionException)3 MalformedURLException (java.net.MalformedURLException)2 SocketException (java.net.SocketException)2 Properties (java.util.Properties)2 Test (org.junit.Test)2 ILogon (org.teiid.client.security.ILogon)2 ConnectionImpl (org.teiid.jdbc.ConnectionImpl)2 ConnectionProfile (org.teiid.jdbc.ConnectionProfile)2 TeiidDriver (org.teiid.jdbc.TeiidDriver)2 HostInfo (org.teiid.net.HostInfo)2 TeiidURL (org.teiid.net.TeiidURL)2 Method (java.lang.reflect.Method)1 ConnectException (java.net.ConnectException)1