protected void connect(Socket socket) throws IOException { super.connect(socket); reader = new BufferedReader(new InputStreamReader(serverIn)); }
protected void connect (Socket socket) throws IOException { super.connect (socket); reader = new BufferedReader (new InputStreamReader (serverIn)); } public void disconnect () throws IOException {
protected void connect (Socket socket) throws IOException { super.connect (socket); reader = new BufferedReader (new InputStreamReader (serverIn)); } public void disconnect () throws IOException {
protected void connect (Socket socket) throws IOException { super.connect (socket); reader = new BufferedReader (new InputStreamReader (serverIn)); } public void disconnect () throws IOException {
/** * Issues a disconnect followed by a connect * @exception IOException */ public void reconnect() throws IOException { disconnect(); connect(); } public void setLogger (Logger logger, String realm) {
/** * Accepts connection * @exception IOException */ public void accept(ServerSocket s) throws IOException { // if (serverPort > 0) // s = new ServerSocket (serverPort); // else // serverPort = s.getLocalPort(); Socket ss = s.accept(); this.name = ss.getInetAddress().getHostAddress()+":"+ss.getPort(); connect(ss); // Warning - closing here breaks ISOServer, we need an // accept that keep ServerSocket open. // s.close(); }
public BaseChannel getChannel(InputStream in, OutputStream out, ClientRequestDetails requestDetails) throws IOException { BaseChannel c = (BaseChannel) channel.clone(); FakeSocket s = new FakeSocket(in, out); s.setRequest(requestDetails); c.connect(s); return c; }
@Test public void testDisconnectWithDefaultSoLingerOption() throws Exception { Socket socket = mockSocket(); when(socketFactory.createSocket(anyString(), anyInt())).thenReturn(socket); BaseChannel rawChannel = new RawChannel(); rawChannel.setSocketFactory(socketFactory); rawChannel.connect(); rawChannel.disconnect(); verify(socket).setSoLinger(true, 5); verify(socket).shutdownOutput(); verify(socket).close(); assertTrue(rawChannel.isSoLingerOn()); assertEquals(5, rawChannel.getSoLingerSeconds()); }
@Test public void testDisconnectWithCustomSoLingerOption() throws Exception { Socket socket = mockSocket(); when(socketFactory.createSocket(anyString(), anyInt())).thenReturn(socket); BaseChannel rawChannel = new RawChannel(); rawChannel.setSocketFactory(socketFactory); rawChannel.setSoLinger(true, 0); rawChannel.connect(); rawChannel.disconnect(); verify(socket).setSoLinger(true, 0); verify(socket).close(); verify(socket, never()).shutdownOutput(); // this does not make sense when sending a TCP RST down the socket assertTrue(rawChannel.isSoLingerOn()); assertEquals(0, rawChannel.getSoLingerSeconds()); }
/** * Connects client ISOChannel to server * @exception IOException */ public void connect () throws IOException { LogEvent evt = new LogEvent (this, "connect"); try { if (serverSocket != null) { accept(serverSocket); evt.addMessage ("local port "+serverSocket.getLocalPort() +" remote host "+socket.getInetAddress()); } else { connect(newSocket (hosts, ports, evt)); } applyTimeout(); Logger.log (evt); } catch (ConnectException e) { Logger.log (new LogEvent (this, "connection-refused", getHost()+":"+getPort()) ); } catch (IOException e) { evt.addMessage (e.getMessage ()); Logger.log (evt); throw e; } }
@Test public void testConnectThrowsNullPointerException() throws Throwable { BaseChannel bASE24TCPChannel = new BASE24TCPChannel(); Socket socket = new Socket(); bASE24TCPChannel.setTimeout(-1); try { bASE24TCPChannel.connect(socket); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertNull("(BASE24TCPChannel) bASE24TCPChannel.serverIn", ((BASE24TCPChannel) bASE24TCPChannel).serverIn); assertNull("(BASE24TCPChannel) bASE24TCPChannel.serverOut", ((BASE24TCPChannel) bASE24TCPChannel).serverOut); assertSame("(BASE24TCPChannel) bASE24TCPChannel.getSocket()", socket, bASE24TCPChannel.getSocket()); assertEquals("(BASE24TCPChannel) bASE24TCPChannel.cnt.length", 3, ((BASE24TCPChannel) bASE24TCPChannel).cnt.length); assertFalse("(BASE24TCPChannel) bASE24TCPChannel.usable", ((BASE24TCPChannel) bASE24TCPChannel).usable); assertNull("(BASE24TCPChannel) bASE24TCPChannel.logger", ((BASE24TCPChannel) bASE24TCPChannel).logger); assertNull("(BASE24TCPChannel) bASE24TCPChannel.originalRealm", ((BASE24TCPChannel) bASE24TCPChannel).originalRealm); assertNull("(BASE24TCPChannel) bASE24TCPChannel.realm", ((BASE24TCPChannel) bASE24TCPChannel).realm); assertNull("socket.getChannel()", socket.getChannel()); } }
@Test public void testConnectThrowsNullPointerException1() throws Throwable { Socket socket = new Socket(Proxy.NO_PROXY); BaseChannel gZIPChannel = new GZIPChannel(); gZIPChannel.setTimeout(1); try { gZIPChannel.connect(socket); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull("ex.getMessage()", ex.getMessage()); assertNull("(GZIPChannel) gZIPChannel.serverIn", ((GZIPChannel) gZIPChannel).serverIn); assertNull("(GZIPChannel) gZIPChannel.serverOut", ((GZIPChannel) gZIPChannel).serverOut); assertSame("(GZIPChannel) gZIPChannel.getSocket()", socket, gZIPChannel.getSocket()); assertEquals("(GZIPChannel) gZIPChannel.cnt.length", 3, ((GZIPChannel) gZIPChannel).cnt.length); assertFalse("(GZIPChannel) gZIPChannel.usable", ((GZIPChannel) gZIPChannel).usable); assertNull("(GZIPChannel) gZIPChannel.logger", ((GZIPChannel) gZIPChannel).logger); assertNull("(GZIPChannel) gZIPChannel.originalRealm", ((GZIPChannel) gZIPChannel).originalRealm); assertNull("(GZIPChannel) gZIPChannel.realm", ((GZIPChannel) gZIPChannel).realm); assertNull("socket.getChannel()", socket.getChannel()); } }