Package org.apache.ftpserver.listener

Examples of org.apache.ftpserver.listener.Listener


        ListenerFactory listenerFactory = new ListenerFactory();
        listenerFactory.setPort(0);
       
        // let's create two listeners on the same port, second should not start
    
        Listener defaultListener = listenerFactory.createListener();
        Listener secondListener = listenerFactory.createListener();
       
       
        serverFactory.addListener("default", defaultListener);
        serverFactory.addListener("second", secondListener);
       
        FtpServer server = serverFactory.createServer();
       
        try {
            server.start();
           
            // Windows seems to allow for both listeners to bind on the same port...
            //fail("Must throw FtpServerConfigurationException");
        } catch(FtpServerConfigurationException e) {
            if(e.getCause() instanceof BindException) {
                // OK!
               
                // we failed to start, make sure things are shut down correctly
                assertTrue(defaultListener.isStopped());
                assertTrue(secondListener.isStopped());
                assertTrue(server.isStopped());
            } else {
                throw e;
            }
        }
View Full Code Here


        Map<String, Listener> listeners = server.getServerContext()
                .getListeners();
        assertEquals(3, listeners.size());

        Listener listener = listeners.get("listener0");
        assertNotNull(listener);
        assertTrue(listener instanceof NioListener);
        assertEquals(2222, ((NioListener) listener).getPort());
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
                .getServerAddress()));
        assertEquals(100, ((NioListener) listener)
                .getDataConnectionConfiguration().getIdleTime());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isActiveEnabled());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isImplicitSsl());
       
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
            .getDataConnectionConfiguration().getActiveLocalAddress()) );
        assertEquals("123-125", ((NioListener) listener)
                .getDataConnectionConfiguration().getPassivePorts());
        assertEquals(false, ((NioListener) listener)
                .getDataConnectionConfiguration().isPassiveIpCheck());
       
        RemoteIpFilter filter = (RemoteIpFilter) listener.getSessionFilter();
        assertEquals(3, filter.size());
        assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.3.0"), 16)));
        assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.4.0"), 16)));
        assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.3.4"), 32)));
        listener = listeners.get("listener1");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2223, listener.getPort());

        listener = listeners.get("listener2");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2224, listener.getPort());

        CommandFactory cf = server.getCommandFactory();
        assertTrue(cf.getCommand("FOO") instanceof HELP);
        assertTrue(cf.getCommand("FOO2") instanceof STAT);
View Full Code Here

        ListenerFactory listenerFactory = new ListenerFactory();
        listenerFactory.setPort(TestUtil.findFreePort());
       
        // let's create two listeners on the same port, second should not start
    
        Listener defaultListener = listenerFactory.createListener();
        Listener secondListener = listenerFactory.createListener();
       
       
        serverFactory.addListener("default", defaultListener);
        serverFactory.addListener("second", secondListener);
       
        FtpServer server = serverFactory.createServer();
       
        try {
            server.start();
           
            // Windows seems to allow for both listeners to bind on the same port...
            //fail("Must throw FtpServerConfigurationException");
        } catch(FtpServerConfigurationException e) {
            if(e.getCause() instanceof BindException) {
                // OK!
               
                // we failed to start, make sure things are shut down correctly
                assertTrue(defaultListener.isStopped());
                assertTrue(secondListener.isStopped());
                assertTrue(server.isStopped());
            } else {
                throw e;
            }
        }
View Full Code Here

        Map<String, Listener> listeners = server.getServerContext()
                .getListeners();
        assertEquals(3, listeners.size());

        Listener listener = listeners.get("listener0");
        assertNotNull(listener);
        assertTrue(listener instanceof NioListener);
        assertEquals(2222, ((NioListener) listener).getPort());
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
                .getServerAddress()));
        assertEquals(100, ((NioListener) listener)
                .getDataConnectionConfiguration().getIdleTime());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isActiveEnabled());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isImplicitSsl());
       
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
            .getDataConnectionConfiguration().getActiveLocalAddress()) );
        assertEquals("123-125", ((NioListener) listener)
                .getDataConnectionConfiguration().getPassivePorts());

        List<Subnet> subnets = ((NioListener) listener).getBlockedSubnets();
        assertEquals(3, subnets.size());
        assertEquals(new Subnet(InetAddress.getByName("1.2.3.0"), 16), subnets
                .get(0));
        assertEquals(new Subnet(InetAddress.getByName("1.2.4.0"), 16), subnets
                .get(1));
        assertEquals(new Subnet(InetAddress.getByName("1.2.3.4"), 32), subnets
                .get(2));

        listener = listeners.get("listener1");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2223, listener.getPort());

        listener = listeners.get("listener2");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2224, listener.getPort());

        CommandFactory cf = server.getCommandFactory();
        assertTrue(cf.getCommand("FOO") instanceof HELP);
        assertTrue(cf.getCommand("FOO2") instanceof STAT);
View Full Code Here

   */
  public void dispose() {

    Iterator<Listener> listenerIter = listeners.values().iterator();
    while (listenerIter.hasNext()) {
      Listener listener = listenerIter.next();
      listener.stop();
    }
  }
View Full Code Here

        assertEquals(125, server.getConnectionConfig().getLoginFailureDelay());
       
        Map<String, Listener> listeners = server.getServerContext().getListeners();
        assertEquals(3, listeners.size());
       
        Listener listener = listeners.get("listener0");
        assertNotNull(listener);
        assertTrue(listener instanceof NioListener);
        assertEquals(2222, ((NioListener)listener).getPort());
        assertEquals(true, ((NioListener)listener).getDataConnectionConfiguration().isActiveEnabled());
        assertEquals(InetAddress.getByName("1.2.3.4"), ((NioListener)listener).getDataConnectionConfiguration().getActiveLocalAddress());
        assertEquals("123-125", ((NioListener)listener).getDataConnectionConfiguration().getPassivePorts());
       
        List<Subnet> subnets = ((NioListener)listener).getBlockedSubnets();
        assertEquals(3, subnets.size());
        assertEquals(new Subnet(InetAddress.getByName("1.2.3.0"), 16), subnets.get(0));
        assertEquals(new Subnet(InetAddress.getByName("1.2.4.0"), 16), subnets.get(1));
        assertEquals(new Subnet(InetAddress.getByName("1.2.3.4"), 32), subnets.get(2));
       
        DefaultSslConfiguration ssl = (DefaultSslConfiguration) listener.getSslConfiguration();
        assertEquals(new File("/tmp/tmp.jks"), ssl.getKeystoreFile());
        assertEquals("password", ssl.getKeystorePassword());

        // make sure the data connection got the same config
        ssl = (DefaultSslConfiguration) listener.getDataConnectionConfiguration().getSslConfiguration();
        assertEquals(new File("/tmp/tmp.jks"), ssl.getKeystoreFile());
        assertEquals("password", ssl.getKeystorePassword());

       
        listener = listeners.get("listener1");
View Full Code Here

        ListenerFactory listenerFactory = new ListenerFactory();
        listenerFactory.setPort(TestUtil.findFreePort());
       
        // let's create two listeners on the same port, second should not start
    
        Listener defaultListener = listenerFactory.createListener();
        Listener secondListener = listenerFactory.createListener();
       
       
        serverFactory.addListener("default", defaultListener);
        serverFactory.addListener("second", secondListener);
       
        FtpServer server = serverFactory.createServer();
       
        try {
            server.start();
           
            // Windows seems to allow for both listeners to bind on the same port...
            //fail("Must throw FtpServerConfigurationException");
        } catch(FtpServerConfigurationException e) {
            if(e.getCause() instanceof BindException) {
                // OK!
               
                // we failed to start, make sure things are shut down correctly
                assertTrue(defaultListener.isStopped());
                assertTrue(secondListener.isStopped());
                assertTrue(server.isStopped());
            } else {
                throw e;
            }
        }
View Full Code Here

        Map<String, Listener> listeners = server.getServerContext()
                .getListeners();
        assertEquals(3, listeners.size());

        Listener listener = listeners.get("listener0");
        assertNotNull(listener);
        assertTrue(listener instanceof NioListener);
        assertEquals(2222, ((NioListener) listener).getPort());
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
                .getServerAddress()));
        assertEquals(100, ((NioListener) listener)
                .getDataConnectionConfiguration().getIdleTime());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isActiveEnabled());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isImplicitSsl());
       
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
            .getDataConnectionConfiguration().getActiveLocalAddress()) );
        assertEquals("123-125", ((NioListener) listener)
                .getDataConnectionConfiguration().getPassivePorts());

        DefaultIpFilter filter = (DefaultIpFilter) listener.getIpFilter();
        assertEquals(3, filter.size());
        assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.3.0"), 16)));
        assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.4.0"), 16)));
        assertTrue(filter.contains(new Subnet(InetAddress.getByName("1.2.3.4"), 32)));
        listener = listeners.get("listener1");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2223, listener.getPort());

        listener = listeners.get("listener2");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2224, listener.getPort());

        CommandFactory cf = server.getCommandFactory();
        assertTrue(cf.getCommand("FOO") instanceof HELP);
        assertTrue(cf.getCommand("FOO2") instanceof STAT);
View Full Code Here

        Map<String, Listener> listeners = server.getServerContext()
                .getListeners();
        assertEquals(3, listeners.size());

        Listener listener = listeners.get("listener0");
        assertNotNull(listener);
        assertTrue(listener instanceof NioListener);
        assertEquals(2222, ((NioListener) listener).getPort());
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
                .getServerAddress()));
        assertEquals(100, ((NioListener) listener)
                .getDataConnectionConfiguration().getIdleTime());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isActiveEnabled());
        assertTrue(((NioListener) listener)
                .getDataConnectionConfiguration().isImplicitSsl());
       
        assertEquals(InetAddress.getByName("1.2.3.4"), InetAddress.getByName(((NioListener) listener)
            .getDataConnectionConfiguration().getActiveLocalAddress()) );
        assertEquals("123-125", ((NioListener) listener)
                .getDataConnectionConfiguration().getPassivePorts());

        List<Subnet> subnets = ((NioListener) listener).getBlockedSubnets();
        assertEquals(3, subnets.size());
        assertEquals(new Subnet(InetAddress.getByName("1.2.3.0"), 16), subnets
                .get(0));
        assertEquals(new Subnet(InetAddress.getByName("1.2.4.0"), 16), subnets
                .get(1));
        assertEquals(new Subnet(InetAddress.getByName("1.2.3.4"), 32), subnets
                .get(2));

        listener = listeners.get("listener1");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2223, listener.getPort());

        listener = listeners.get("listener2");
        assertNotNull(listener);
        assertTrue(listener instanceof MyCustomListener);
        assertEquals(2224, listener.getPort());

        CommandFactory cf = server.getCommandFactory();
        assertTrue(cf.getCommand("FOO") instanceof HELP);
        assertTrue(cf.getCommand("FOO2") instanceof STAT);
View Full Code Here

     */
    public void dispose() {

        Iterator<Listener> listenerIter = listeners.values().iterator();
        while (listenerIter.hasNext()) {
            Listener listener = listenerIter.next();
            listener.stop();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.ftpserver.listener.Listener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.