Package org.apache.james.protocols.netty

Examples of org.apache.james.protocols.netty.NettyServer


    LMTPProtocolHandlerChain chain = new LMTPProtocolHandlerChain();
    chain.add(0, new ElasticInboxDeliveryHandler(backend));
    chain.add(0, new ValidRcptHandler());
    chain.wireExtensibleHandlers();

    server = new NettyServer(new SMTPProtocol(chain, new LMTPServerConfig(), logger));
    server.setListenAddresses(new InetSocketAddress(Configurator.getLmtpPort()));
    server.setMaxConcurrentConnections(Configurator.getLmtpMaxConnections());
    server.setTimeout(LMTPServerConfig.CONNECTION_TIMEOUT);
    server.setUseExecutionHandler(true, 16);
    server.bind();
View Full Code Here


  {
    Logger logger = new POP3ProtocolLogger();

    POP3ProtocolHandlerChain chain = new POP3ProtocolHandlerChain(new AuthHandler(backend));

    server = new NettyServer(new POP3Protocol(chain, new POP3ServerConfig(), logger));
    server.setListenAddresses(new InetSocketAddress(Configurator.getPop3Port()));
    server.setMaxConcurrentConnections(Configurator.getPop3MaxConnections());
    server.setTimeout(POP3ServerConfig.CONNECTION_TIMEOUT);
    server.setUseExecutionHandler(true, 16);
    server.bind();
View Full Code Here

    @Override
    public void testMailWithoutBrackets() throws Exception {
        TestMessageHook hook = new TestMessageHook();
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            server = new NettyServer(createProtocol(hook));
            server.setListenAddresses(address);
            server.bind();
           
            SMTPClient client = createClient();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
           
            client.helo("localhost");
            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

            client.mail(SENDER);
            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
           
            client.quit();
            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
            client.disconnect();

            Iterator<MailEnvelope> queued = hook.getQueued().iterator();
            assertFalse(queued.hasNext());

        } finally {
            if (server != null) {
                server.unbind();
            }
        }
       
    }
View Full Code Here

    @Override
    public void testRcptWithoutBrackets() throws Exception {
        TestMessageHook hook = new TestMessageHook();
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            server = new NettyServer(createProtocol(hook));
            server.setListenAddresses(address);
            server.bind();
           
            SMTPClient client = createClient();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));
           
            client.helo("localhost");
            assertTrue(SMTPReply.isPositiveCompletion(client.getReplyCode()));

            client.setSender(SENDER);
            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));

            client.rcpt(RCPT1);
            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
            client.quit();
            assertTrue("Reply="+ client.getReplyString(), SMTPReply.isPositiveCompletion(client.getReplyCode()));
            client.disconnect();

            Iterator<MailEnvelope> queued = hook.getQueued().iterator();
            assertFalse(queued.hasNext());

        } finally {
            if (server != null) {
                server.unbind();
            }
        }
    }
View Full Code Here

    }
    @Test
    public void testInvalidAuth() throws Exception {
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            server = new NettyServer(createProtocol(new TestPassCmdHandler()));
            server.setListenAddresses(address);
            server.bind();
           
            POP3Client client =  new POP3Client();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertFalse(client.login("invalid", "invalid"));
          
            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
        }
       
    }
View Full Code Here

   
    @Test
    public void testEmptyInbox() throws Exception {
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            String identifier = "id";
            TestPassCmdHandler handler = new TestPassCmdHandler();
           
            handler.add("valid", new MockMailbox(identifier));
            server = new NettyServer(createProtocol(handler));
            server.setListenAddresses(address);
            server.bind();
           
            POP3Client client =  new POP3Client();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            POP3MessageInfo[] info = client.listMessages();
            assertEquals(0, info.length);
           
            info = client.listUniqueIdentifiers();
            assertEquals(0, info.length);
            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
        }
       
    }
View Full Code Here

   
    @Test
    public void testInboxWithMessages() throws Exception {
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            String identifier = "id";
            TestPassCmdHandler handler = new TestPassCmdHandler();
           
            handler.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = new NettyServer(createProtocol(handler));
            server.setListenAddresses(address);
            server.bind();
           
            POP3Client client =  new POP3Client();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            POP3MessageInfo[] info = client.listMessages();
            assertEquals(2, info.length);
            assertEquals((int) MESSAGE1.meta.getSize(), info[0].size);
            assertEquals((int) MESSAGE2.meta.getSize(), info[1].size);
            assertEquals(1, info[0].number);
            assertEquals(2, info[1].number);

            POP3MessageInfo mInfo = client.listMessage(1);
            assertEquals((int) MESSAGE1.meta.getSize(), mInfo.size);
            assertEquals(1, mInfo.number);

            // try to retrieve message that not exist
            mInfo = client.listMessage(10);
            assertNull(mInfo);

            info = client.listUniqueIdentifiers();
            assertEquals(2, info.length);
            assertEquals(identifier + "-" + MESSAGE1.meta.getUid(), info[0].identifier);
            assertEquals(identifier + "-" + MESSAGE2.meta.getUid(), info[1].identifier);
            assertEquals(1, info[0].number);
            assertEquals(2, info[1].number);

            mInfo = client.listUniqueIdentifier(1);
            assertEquals(identifier + "-" + MESSAGE1.meta.getUid(), mInfo.identifier);
            assertEquals(1, mInfo.number);

            // try to retrieve message that not exist
            mInfo = client.listUniqueIdentifier(10);
            assertNull(mInfo);
           
            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
        }
       
    }
View Full Code Here

   
    @Test
    public void testRetr() throws Exception {
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            String identifier = "id";
            TestPassCmdHandler factory = new TestPassCmdHandler();
           
            factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = new NettyServer(createProtocol(factory));
            server.setListenAddresses(address);
            server.bind();
           
            POP3Client client =  new POP3Client();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            Reader reader = client.retrieveMessage(1);
            assertNotNull(reader);
            checkMessage(MESSAGE1, reader);
            reader.close();
           
            // does not exist
            reader = client.retrieveMessage(10);
            assertNull(reader);
           
           
            // delete and check for the message again, should now be deleted
            assertTrue(client.deleteMessage(1));
            reader = client.retrieveMessage(1);
            assertNull(reader);

           
            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
        }
       
    }
View Full Code Here

   
    @Test
    public void testTop() throws Exception {
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            String identifier = "id";
            TestPassCmdHandler factory = new TestPassCmdHandler();
           
            factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = new NettyServer(createProtocol(factory));
            server.setListenAddresses(address);
            server.bind();
           
            POP3Client client =  new POP3Client();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            Reader reader = client.retrieveMessageTop(1, 1000);
            assertNotNull(reader);
            checkMessage(MESSAGE1, reader);
            reader.close();
           
            reader = client.retrieveMessageTop(2, 1);
            assertNotNull(reader);
            checkMessage(MESSAGE2, reader,1);
            reader.close();
           
            // does not exist
            reader = client.retrieveMessageTop(10,100);
            assertNull(reader);
           
            // delete and check for the message again, should now be deleted
            assertTrue(client.deleteMessage(1));
            reader = client.retrieveMessageTop(1, 1000);
            assertNull(reader);

            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
        }
       
    }
View Full Code Here

   
    @Test
    public void testDele() throws Exception {
        InetSocketAddress address = new InetSocketAddress("127.0.0.1", TestUtils.getFreePort());
       
        NettyServer server = null;
        try {
            String identifier = "id";
            TestPassCmdHandler factory = new TestPassCmdHandler();
           
            factory.add("valid", new MockMailbox(identifier, MESSAGE1, MESSAGE2));
            server = new NettyServer(createProtocol(factory));
            server.setListenAddresses(address);
            server.bind();
           
            POP3Client client =  new POP3Client();
            client.connect(address.getAddress().getHostAddress(), address.getPort());
           
            assertTrue(client.login("valid", "valid"));
            POP3MessageInfo[] info = client.listMessages();
            assertEquals(2, info.length);
           
            assertTrue(client.deleteMessage(1));
            info = client.listMessages();
            assertEquals(1, info.length);

           
            assertFalse(client.deleteMessage(1));
            info = client.listMessages();
            assertEquals(1, info.length);
           
           
            assertTrue(client.deleteMessage(2));
            info = client.listMessages();
            assertEquals(0, info.length);
           
            // logout so the messages get expunged
            assertTrue(client.logout());

            client.connect(address.getAddress().getHostAddress(), address.getPort());
 
            assertTrue(client.login("valid", "valid"));
            info = client.listMessages();
            assertEquals(0, info.length);

            assertTrue(client.logout());
          
        } finally {
            if (server != null) {
                server.unbind();
            }
        }
       
    }
View Full Code Here

TOP

Related Classes of org.apache.james.protocols.netty.NettyServer

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.