Search in sources :

Example 1 with WebSocketImpl

use of com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpFileUploadNotificationReceivedHandlerTest method onConnectionBoundCallFlowAndInitOkAmqps.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_010: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_018: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBoundCallFlowAndInitOkAmqps() {
    // Arrange
    final String hostName = "aaa";
    final String userName = "bbb";
    final String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    Object amqpReceiveHandler = Deencapsulation.newInstance(AmqpFileUploadNotificationReceivedHandler.class, hostName, userName, sasToken, iotHubServiceClientProtocol, amqpFeedbackReceivedEvent, mockedProxyOptions, mockedSslContext);
    // Assert
    new Expectations() {

        {
            event.getConnection();
            result = connection;
            connection.getTransport();
            result = transportInternal;
            new ProxyImpl();
            result = mockedProxyImpl;
            new ProxyHandlerImpl();
            result = mockedProxyHandlerImpl;
            mockedProxyImpl.configure(anyString, (Map<String, String>) any, mockedProxyHandlerImpl, transportInternal);
            transportInternal.addTransportLayer(mockedProxyImpl);
            new WebSocketImpl(anyInt);
            result = webSocket;
            webSocket.configure(anyString, anyString, anyString, 443, anyString, null, null);
            transportInternal.addTransportLayer(webSocket);
            Proton.sslDomain();
            result = sslDomain;
            sslDomain.init(SslDomain.Mode.CLIENT);
            sslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
            transportInternal.ssl(sslDomain);
        }
    };
    // Act
    Deencapsulation.invoke(amqpReceiveHandler, "onConnectionBound", event);
}
Also used : Expectations(mockit.Expectations) ProxyHandlerImpl(com.microsoft.azure.proton.transport.proxy.impl.ProxyHandlerImpl) ProxyImpl(com.microsoft.azure.proton.transport.proxy.impl.ProxyImpl) WebSocketImpl(com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 2 with WebSocketImpl

use of com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpsIotHubConnection method addWebSocketLayer.

private void addWebSocketLayer(Transport transport) {
    log.debug("Adding websocket layer to amqp transport");
    WebSocketImpl webSocket = new WebSocketImpl(MAX_MESSAGE_PAYLOAD_SIZE);
    webSocket.configure(this.hostName, WEB_SOCKET_PATH, WEB_SOCKET_QUERY, WEB_SOCKET_PORT, WEB_SOCKET_SUB_PROTOCOL, null, null);
    ((TransportInternal) transport).addTransportLayer(webSocket);
}
Also used : WebSocketImpl(com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal)

Example 3 with WebSocketImpl

use of com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpFeedbackReceivedHandlerTest method onConnectionBound_call_flow_and_init_ok_amqps.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_010: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_018: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqps() {
    // Arrange
    final String hostName = "aaa";
    final String userName = "bbb";
    final String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    AmqpFeedbackReceivedHandler amqpReceiveHandler = new AmqpFeedbackReceivedHandler(hostName, userName, sasToken, iotHubServiceClientProtocol, null);
    // Assert
    new Expectations() {

        {
            event.getConnection();
            result = connection;
            connection.getTransport();
            result = transportInternal;
            new WebSocketImpl(anyInt);
            result = webSocket;
            webSocket.configure(anyString, anyString, anyString, 443, anyString, null, null);
            transportInternal.addTransportLayer(webSocket);
            Proton.sslDomain();
            result = sslDomain;
            sslDomain.init(SslDomain.Mode.CLIENT);
            sslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
            transportInternal.ssl(sslDomain);
        }
    };
    // Act
    amqpReceiveHandler.onConnectionBound(event);
}
Also used : Expectations(mockit.Expectations) WebSocketImpl(com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl) AmqpFeedbackReceivedHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 4 with WebSocketImpl

use of com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpSendHandlerTest method onConnectionBound_call_flow_and_init_ok_amqp_ws.

// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_009: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_010: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport]
// Tests_SRS_SERVICE_SDK_JAVA_AMQPSENDHANDLER_12_024: [The event handler shall initialize WebSocket if the protocol is AMQP_WS]
@Test
public void onConnectionBound_call_flow_and_init_ok_amqp_ws() throws IOException, CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
    // Arrange
    String hostName = "aaa";
    String userName = "bbb";
    String sasToken = "ccc";
    IotHubServiceClientProtocol iotHubServiceClientProtocol = IotHubServiceClientProtocol.AMQPS_WS;
    AmqpSendHandler amqpSendHandler = new AmqpSendHandler(hostName, userName, sasToken, iotHubServiceClientProtocol);
    // Assert
    new Expectations() {

        {
            event.getConnection();
            result = connection;
            connection.getTransport();
            result = transportInternal;
            new WebSocketImpl(anyInt);
            result = webSocket;
            webSocket.configure(anyString, anyString, anyString, 443, anyString, null, null);
            transportInternal.addTransportLayer(webSocket);
            Proton.sslDomain();
            result = sslDomain;
            sslDomain.init(SslDomain.Mode.CLIENT);
            sslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
            transportInternal.ssl(sslDomain);
            new IotHubSSLContext();
            result = mockedIotHubSSLContext;
        }
    };
    // Act
    amqpSendHandler.onConnectionBound(event);
}
Also used : Expectations(mockit.Expectations) IotHubSSLContext(com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext) AmqpSendHandler(com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler) WebSocketImpl(com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl) IotHubServiceClientProtocol(com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol) Test(org.junit.Test)

Example 5 with WebSocketImpl

use of com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl in project azure-iot-sdk-java by Azure.

the class AmqpConnectionHandler method onConnectionBound.

/**
 * Event handler for the connection bound event
 * @param event The proton event object
 */
@Override
public void onConnectionBound(Event event) {
    Transport transport = event.getConnection().getTransport();
    if (transport != null) {
        if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) {
            WebSocketImpl webSocket = new WebSocketImpl(MAX_MESSAGE_PAYLOAD_SIZE);
            webSocket.configure(this.hostName, WEB_SOCKET_PATH, WEB_SOCKET_QUERY, AMQPS_WS_PORT, WEB_SOCKET_SUB_PROTOCOL, null, null);
            ((TransportInternal) transport).addTransportLayer(webSocket);
        }
        // Note that this does not mean that the connection will not be authenticated. This simply defers authentication
        // to the claims based security model that IoT Hub implements wherein the client sends the authentication token
        // over the CBS link rather than doing a sasl.plain(username, password) call at this point.
        transport.sasl().setMechanisms("ANONYMOUS");
        SslDomain domain = makeDomain();
        domain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
        transport.ssl(domain);
        if (this.proxyOptions != null) {
            addProxyLayer(transport, this.hostName);
        }
    }
}
Also used : SslDomain(org.apache.qpid.proton.engine.SslDomain) WebSocketImpl(com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal) Transport(org.apache.qpid.proton.engine.Transport)

Aggregations

WebSocketImpl (com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl)6 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)3 Expectations (mockit.Expectations)3 TransportInternal (org.apache.qpid.proton.engine.impl.TransportInternal)3 Test (org.junit.Test)3 ProxyHandlerImpl (com.microsoft.azure.proton.transport.proxy.impl.ProxyHandlerImpl)1 ProxyImpl (com.microsoft.azure.proton.transport.proxy.impl.ProxyImpl)1 IotHubSSLContext (com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext)1 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)1 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)1 SslDomain (org.apache.qpid.proton.engine.SslDomain)1 Transport (org.apache.qpid.proton.engine.Transport)1