private synchronized ResultsFuture<?> isOpen() throws CommunicationException, InvalidSessionException, TeiidComponentException { if (this.closed) { throw new CommunicationException(JDBCPlugin.Event.TEIID20023, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20023)); } return logon.ping(); }
private void logoff() { if (derived) { return; //not the right place to kill the session } try { //make a best effort to send the logoff Future<?> writeFuture = this.getService(ILogon.class).logoff(); if (writeFuture != null) { writeFuture.get(5000, TimeUnit.MILLISECONDS); } } catch (Exception e) { //ignore } }
@Test public void testSuccessfulHandshake() throws Exception { final FakeObjectChannel channel = new FakeObjectChannel(Arrays.asList(new Handshake(), new SocketTimeoutException())); SocketServerInstanceImpl instance = createInstance(channel); //no remote server is hooked up, so this will timeout ILogon logon = instance.getService(ILogon.class); try { logon.logon(new Properties()); fail("Exception expected"); //$NON-NLS-1$ } catch (SingleInstanceCommunicationException e) { assertTrue(e.getCause() instanceof TimeoutException); } }
private ILogon connectSession() throws CommunicationException, ConnectionException { ILogon newLogon = this.serverInstance.getService(ILogon.class); if (this.logonResult != null) { try { newLogon.assertIdentity(logonResult.getSessionToken()); } catch (TeiidException e) { // session is no longer valid disconnect(); } } if (this.logonResult == null) { try { logon(newLogon); } catch (LogonException e) { // Propagate the original message as it contains the message we want // 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 newLogon; }
logger.fine("Sending Service Token to Server (GSS Authentication Token)"); //$NON-NLS-1$ result = logon.neogitiateGssLogin(this.props, outToken, true); inToken = (byte[])result.getProperty(ILogon.KRB5TOKEN);
private void logon(ILogon newLogon) throws LogonException, TeiidComponentException, CommunicationException { SocketServerInstance instance = this.serverInstance; updateConnectionProperties(connProps, instance.getLocalAddress(), true, this.connectionFactory); LogonResult newResult = null; // - if gss if (connProps.contains(TeiidURL.CONNECTION.JAAS_NAME)) { newResult = MakeGSS.authenticate(newLogon, connProps); } else { newResult = newLogon.logon(connProps); } AuthenticationType type = (AuthenticationType) newResult.getProperty(ILogon.AUTH_TYPE); if (type != null) { //server has issued an additional challenge if (type == AuthenticationType.GSS) { newResult = MakeGSS.authenticate(newLogon, connProps); } else { throw new LogonException(JDBCPlugin.Event.TEIID20034, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20034, type)); } } logoff(); this.logonResult = newResult; }
private ILogon connectSession() throws CommunicationException, ConnectionException { ILogon newLogon = this.serverInstance.getService(ILogon.class); if (this.logonResult != null) { try { newLogon.assertIdentity(logonResult.getSessionToken()); } catch (TeiidException e) { // session is no longer valid disconnect(); } } if (this.logonResult == null) { try { logon(newLogon); } catch (LogonException e) { // Propagate the original message as it contains the message we want // 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 newLogon; }
logger.fine("Sending Service Token to Server (GSS Authentication Token)"); //$NON-NLS-1$ result = logon.neogitiateGssLogin(this.props, outToken, true); inToken = (byte[])result.getProperty(ILogon.KRB5TOKEN);
private synchronized ResultsFuture<?> isOpen() throws CommunicationException, InvalidSessionException, TeiidComponentException { if (this.closed) { throw new CommunicationException(JDBCPlugin.Event.TEIID20023, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20023)); } return logon.ping(); }
private void logon(ILogon newLogon) throws LogonException, TeiidComponentException, CommunicationException { SocketServerInstance instance = this.serverInstance; updateConnectionProperties(connProps, instance.getLocalAddress(), true); LogonResult newResult = null; // - if gss if (connProps.contains(TeiidURL.CONNECTION.JAAS_NAME)) { newResult = MakeGSS.authenticate(newLogon, connProps); } else { newResult = newLogon.logon(connProps); } AuthenticationType type = (AuthenticationType) newResult.getProperty(ILogon.AUTH_TYPE); if (type != null) { //server has issued an additional challenge if (type == AuthenticationType.GSS) { newResult = MakeGSS.authenticate(newLogon, connProps); } else { throw new LogonException(JDBCPlugin.Event.TEIID20034, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20034, type)); } } logoff(); this.logonResult = newResult; }
private void logoff() { if (this.logonResult == null) { return; } disconnect(); try { //make a best effort to send the logoff, and wait a small amount for a response //this will ensure a "proper" session termination on the server side, //rather than implicit closure when the socket is closed Future<?> writeFuture = this.serverInstance.getService(ILogon.class).logoff(); writeFuture.get(100, TimeUnit.MILLISECONDS); } catch (Exception e) { //ignore } }
@Override public boolean isOpen(long msToTest) { if (shutdown) { return false; } try { ResultsFuture<?> result = this.getService(ILogon.class).ping(); result.get(msToTest, TimeUnit.MILLISECONDS); } catch (Exception e) { return false; } return true; }
this.result = this.getService(ILogon.class).logon(this.connectionProperties);
private void logoff() { if (this.logonResult == null) { return; } disconnect(); try { //make a best effort to send the logoff, and wait a small amount for a response //this will ensure a "proper" session termination on the server side, //rather than implicit closure when the socket is closed Future<?> writeFuture = this.serverInstance.getService(ILogon.class).logoff(); writeFuture.get(100, TimeUnit.MILLISECONDS); } catch (Exception e) { //ignore } }
@Override protected SocketServerInstance getInstance() throws CommunicationException { if (failOver && System.currentTimeMillis() - lastPing > pingFailOverInterval) { try { ResultsFuture<?> future = selectServerInstance().getService(ILogon.class).ping(); future.get(); } catch (SingleInstanceCommunicationException e) { closeServerInstance(); } catch (CommunicationException e) { throw e; } catch (InvalidSessionException e) { disconnect(); closeServerInstance(); } catch (Exception e) { closeServerInstance(); } } lastPing = System.currentTimeMillis(); try { return selectServerInstance(); } catch (ConnectionException e) { throw new CommunicationException(e); } }
@Override public void run() { try { csr.getClientService(ILogon.class).logoff(); } catch (Exception e) { LogManager.logDetail(LogConstants.CTX_TRANSPORT, e, "Exception closing client instance"); //$NON-NLS-1$ } } });
@Override protected SocketServerInstance getInstance() throws CommunicationException { if (failOver && System.currentTimeMillis() - lastPing > pingFailOverInterval) { try { ResultsFuture<?> future = selectServerInstance().getService(ILogon.class).ping(); future.get(); } catch (SingleInstanceCommunicationException e) { closeServerInstance(); } catch (CommunicationException e) { throw e; } catch (InvalidSessionException e) { disconnect(); closeServerInstance(); } catch (Exception e) { closeServerInstance(); } } lastPing = System.currentTimeMillis(); try { return selectServerInstance(); } catch (ConnectionException e) { throw new CommunicationException(e); } }
@Test(expected=CommunicationException.class) public void testImmediateFail() throws Exception { SocketServerConnection connection = createConnection(new CommunicationException()); ILogon logon = connection.getService(ILogon.class); logon.ping(); }
/** * Since the original instance is still open, this will be a transparent retry */ @Test public void testRetry() throws Exception { SocketServerConnection connection = createConnection(new SingleInstanceCommunicationException()); connection.setFailOver(true); connection.setFailOverPingInterval(50); ILogon logon = connection.getService(ILogon.class); Thread.sleep(70); logon.ping(); }
@Test(expected=CommunicationException.class) public void testImmediateFail1() throws Exception { SocketServerConnection connection = createConnection(new CommunicationException()); connection.setFailOver(true); ILogon logon = connection.getService(ILogon.class); logon.ping(); }