Java Code Examples for org.apache.qpid.proton.engine.Transport#bind()

The following examples show how to use org.apache.qpid.proton.engine.Transport#bind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventImplTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTransportWithDeliveryContext()
{
    Transport transport = Transport.Factory.create();
    Connection connection = Connection.Factory.create();
    transport.bind(connection);

    Session session = connection.session();
    Sender sender = session.sender("mySender");

    Delivery delivery = sender.delivery("tag".getBytes());

    EventImpl event = createEvent(delivery, Event.Type.DELIVERY);

    assertNotNull("No transport returned", event.getTransport());
    assertSame("Incorrect transport returned", transport, event.getTransport());
}
 
Example 2
Source File: SimpleTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void test()
{
    Connection connection1 = Proton.connection();
    Connection connection2 = Proton.connection();;
    Transport transport1 = Proton.transport();
    transport1.bind(connection1);

    Transport transport2 = Proton.transport();
    transport2.bind(connection2);

    assertEquals(EndpointState.UNINITIALIZED, connection1.getLocalState());
    assertEquals(EndpointState.UNINITIALIZED, connection1.getRemoteState());

    connection1.open();
    connection2.open();
}
 
Example 3
Source File: Driver.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
public void selected() throws IOException {
    SocketChannel sock = socket.accept();
    System.out.println("ACCEPTED: " + sock);
    Connection conn = Connection.Factory.create();
    conn.collect(collector);
    Transport transport = Transport.Factory.create();
    Sasl sasl = transport.sasl();
    sasl.setMechanisms("ANONYMOUS");
    sasl.server();
    sasl.done(Sasl.PN_SASL_OK);
    transport.bind(conn);
    new ChannelHandler(sock, SelectionKey.OP_READ, transport);
}
 
Example 4
Source File: Driver.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private static Transport makeTransport(Connection conn) {
    Transport transport = Transport.Factory.create();
    Sasl sasl = transport.sasl();
    sasl.setMechanisms("ANONYMOUS");
    sasl.client();
    transport.bind(conn);
    return transport;
}
 
Example 5
Source File: IOHandler.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
private void handleOpen(Reactor reactor, Event event) {
    Connection connection = event.getConnection();
    if (connection.getRemoteState() != EndpointState.UNINITIALIZED) {
        return;
    }
    // Outgoing Reactor connections set the virtual host automatically using the
    // following rules:
    String vhost = connection.getHostname();
    if (vhost == null) {
        // setHostname never called, use the host from the connection's
        // socket address as the default virtual host:
        String conAddr = reactor.getConnectionAddress(connection);
        if (conAddr != null) {
            Address addr = new Address(conAddr);
            connection.setHostname(addr.getHost());
        }
    } else if (vhost.isEmpty()) {
        // setHostname called explictly with a null string. This allows
        // the application to completely avoid sending a virtual host
        // name
        connection.setHostname(null);
    } else {
        // setHostname set by application - use it.
    }
    Transport transport = Proton.transport();

    int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize();
    if (maxFrameSizeOption != 0) {
        transport.setMaxFrameSize(maxFrameSizeOption);
    }

    if (reactor.getOptions().isEnableSaslByDefault()) {
        Sasl sasl = transport.sasl();
        sasl.client();
        sasl.setMechanisms("ANONYMOUS");
    }

    transport.bind(connection);
}
 
Example 6
Source File: EventImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportWithConnectionContext()
{
    Transport transport = Transport.Factory.create();
    Connection connection = Connection.Factory.create();
    transport.bind(connection);

    EventImpl event = createEvent(connection, Event.Type.CONNECTION_BOUND);

    assertNotNull("No transport returned", event.getTransport());
    assertSame("Incorrect transport returned", transport, event.getTransport());
}
 
Example 7
Source File: EventImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportWithTransportContext()
{
    Transport transport = Transport.Factory.create();
    Connection connection = Connection.Factory.create();
    transport.bind(connection);

    EventImpl event = createEvent(transport, Event.Type.TRANSPORT);

    assertNotNull("No transport returned", event.getTransport());
    assertSame("Incorrect transport returned", transport, event.getTransport());
}
 
Example 8
Source File: EventImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportWithSessionContext()
{
    Transport transport = Transport.Factory.create();
    Connection connection = Connection.Factory.create();
    transport.bind(connection);

    Session session = connection.session();

    EventImpl event = createEvent(session, Event.Type.SESSION_INIT);

    assertNotNull("No transport returned", event.getTransport());
    assertSame("Incorrect transport returned", transport, event.getTransport());
}
 
Example 9
Source File: EventImplTest.java    From qpid-proton-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTransportWithLinkContext()
{
    Transport transport = Transport.Factory.create();
    Connection connection = Connection.Factory.create();
    transport.bind(connection);

    Session session = connection.session();
    Link link = session.receiver("myReceiver");

    EventImpl event = createEvent(link, Event.Type.LINK_INIT);

    assertNotNull("No transport returned", event.getTransport());
    assertSame("Incorrect transport returned", transport, event.getTransport());
}
 
Example 10
Source File: AcceptorImpl.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Selectable selectable) {
    Reactor reactor = selectable.getReactor();
    try {
        SocketChannel socketChannel = ((ServerSocketChannel)selectable.getChannel()).accept();
        if (socketChannel == null) {
            throw new ReactorInternalException("Selectable readable, but no socket to accept");
        }
        Handler handler = BaseHandler.getHandler(AcceptorImpl.this);
        if (handler == null) {
            handler = reactor.getHandler();
        }
        Connection conn = reactor.connection(handler);
        Record conn_recs = conn.attachments();
        conn_recs.set(CONNECTION_ACCEPTOR_KEY, Acceptor.class, AcceptorImpl.this);
        InetSocketAddress peerAddr = (InetSocketAddress)socketChannel.getRemoteAddress();
        if (peerAddr != null) {
            Address addr = new Address();
            addr.setHost(peerAddr.getHostString());
            addr.setPort(Integer.toString(peerAddr.getPort()));
            conn_recs.set(ReactorImpl.CONNECTION_PEER_ADDRESS_KEY, Address.class, addr);
        }
        Transport trans = Proton.transport();

        int maxFrameSizeOption = reactor.getOptions().getMaxFrameSize();
        if (maxFrameSizeOption != 0) {
            trans.setMaxFrameSize(maxFrameSizeOption);
        }

        if(reactor.getOptions().isEnableSaslByDefault()) {
            Sasl sasl = trans.sasl();
            sasl.server();
            sasl.setMechanisms("ANONYMOUS");
            sasl.done(SaslOutcome.PN_SASL_OK);
        }
        trans.bind(conn);
        IOHandler.selectableTransport(reactor, socketChannel.socket(), trans);
    } catch(IOException ioException) {
        sel.error();
    }
}
 
Example 11
Source File: LinkTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
@Test
public void testMaxMessageSizeValue() throws Exception
{
    LOGGER.fine(bold("======== About to create transports"));

    Transport clientTransport = Proton.transport();
    getClient().setTransport(clientTransport);
    ProtocolTracerEnabler.setProtocolTracer(clientTransport, TestLoggingHelper.CLIENT_PREFIX);

    Transport serverTransport = Proton.transport();
    getServer().setTransport(serverTransport);
    ProtocolTracerEnabler.setProtocolTracer(serverTransport, "            " + TestLoggingHelper.SERVER_PREFIX);

    doOutputInputCycle();

    Connection clientConnection = Proton.connection();
    getClient().setConnection(clientConnection);
    clientTransport.bind(clientConnection);

    Connection serverConnection = Proton.connection();
    getServer().setConnection(serverConnection);
    serverTransport.bind(serverConnection);

    LOGGER.fine(bold("======== About to open connections"));
    clientConnection.open();
    serverConnection.open();

    doOutputInputCycle();

    LOGGER.fine(bold("======== About to open sessions"));
    Session clientSession = clientConnection.session();
    getClient().setSession(clientSession);
    clientSession.open();

    pumpClientToServer();

    Session serverSession = serverConnection.sessionHead(of(UNINITIALIZED), of(ACTIVE));
    getServer().setSession(serverSession);

    serverSession.open();

    pumpServerToClient();

    LOGGER.fine(bold("======== About to create receiver"));

    Source clientSource = new Source();
    getClient().setSource(clientSource);
    clientSource.setAddress(_sourceAddress);

    Target clientTarget = new Target();
    getClient().setTarget(clientTarget);
    clientTarget.setAddress(null);

    Receiver clientReceiver = clientSession.receiver("link1");
    getClient().setReceiver(clientReceiver);
    clientReceiver.setTarget(clientTarget);
    clientReceiver.setSource(clientSource);

    clientReceiver.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    clientReceiver.setSenderSettleMode(SenderSettleMode.UNSETTLED);

    // Set the local link max-message-size
    assertNull("Expected no value to be set", clientReceiver.getMaxMessageSize());
    clientReceiver.setMaxMessageSize(CLIENT_MAX_MSG_SIZE);
    assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, clientReceiver.getMaxMessageSize());

    clientReceiver.open();
    pumpClientToServer();

    LOGGER.fine(bold("======== About to set up implicitly created sender"));

    Sender serverSender = (Sender) getServer().getConnection().linkHead(of(UNINITIALIZED), of(ACTIVE));
    getServer().setSender(serverSender);

    serverSender.setReceiverSettleMode(serverSender.getRemoteReceiverSettleMode());
    serverSender.setSenderSettleMode(serverSender.getRemoteSenderSettleMode());

    org.apache.qpid.proton.amqp.transport.Source serverRemoteSource = serverSender.getRemoteSource();
    serverSender.setSource(serverRemoteSource);

    assertEquals("Expected value to be set", CLIENT_MAX_MSG_SIZE, serverSender.getRemoteMaxMessageSize());

    // Set the local link max-message-size
    assertNull("Expected no value to be set", serverSender.getMaxMessageSize());
    serverSender.setMaxMessageSize(SERVER_MAX_MSG_SIZE);
    assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, serverSender.getMaxMessageSize());

    serverSender.open();

    assertNull("Expected no value to be present yet", clientReceiver.getRemoteMaxMessageSize());

    pumpServerToClient();

    assertEquals("Expected value to be set", SERVER_MAX_MSG_SIZE, clientReceiver.getRemoteMaxMessageSize());
}
 
Example 12
Source File: SslTest.java    From qpid-proton-j with Apache License 2.0 4 votes vote down vote up
private void doMultiplePemTrustCertificatesTestImpl(String serverKeystore) throws Exception {
    Transport clientTransport = Proton.transport();
    Transport serverTransport = Proton.transport();

    TransportPumper pumper = new TransportPumper(clientTransport, serverTransport);

    Connection clientConnection = Proton.connection();
    Connection serverConnection = Proton.connection();

    SslDomain clientSslDomain = SslDomain.Factory.create();
    clientSslDomain.init(Mode.CLIENT);
    clientSslDomain.setPeerAuthentication(VerifyMode.VERIFY_PEER);
    clientSslDomain.setTrustedCaDb(CA_CERTS);
    clientTransport.ssl(clientSslDomain);

    SslDomain serverSslDomain = SslDomain.Factory.create();
    serverSslDomain.init(Mode.SERVER);
    SSLContext serverSslContext = createSslContext(serverKeystore, PASSWORD, SERVER_JKS_TRUSTSTORE, PASSWORD);
    serverSslDomain.setSslContext(serverSslContext);
    serverTransport.ssl(serverSslDomain);

    clientConnection.setContainer(CLIENT_CONTAINER);
    serverConnection.setContainer(SERVER_CONTAINER);

    clientTransport.bind(clientConnection);
    serverTransport.bind(serverConnection);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    clientConnection.open();

    assertEndpointState(clientConnection, ACTIVE, UNINITIALIZED);
    assertEndpointState(serverConnection, UNINITIALIZED, UNINITIALIZED);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    pumper.pumpAll();

    assertEndpointState(clientConnection, ACTIVE, UNINITIALIZED);
    assertEndpointState(serverConnection, UNINITIALIZED, ACTIVE);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    serverConnection.open();

    assertEndpointState(clientConnection, ACTIVE, UNINITIALIZED);
    assertEndpointState(serverConnection, ACTIVE, ACTIVE);

    assertConditions(clientTransport);
    assertConditions(serverTransport);

    pumper.pumpAll();

    assertEndpointState(clientConnection, ACTIVE, ACTIVE);
    assertEndpointState(serverConnection, ACTIVE, ACTIVE);

    assertConditions(clientTransport);
    assertConditions(serverTransport);
}