Search in sources :

Example 6 with WebSocketImpl

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

the class AmqpFeedbackReceivedHandler method onConnectionBound.

@Override
public void onConnectionBound(Event event) {
    // Codes_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]
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPFEEDBACKRECEIVEDHANDLER_12_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
    Transport transport = event.getConnection().getTransport();
    if (transport != null) {
        if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) {
            WebSocketImpl webSocket = new WebSocketImpl();
            webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null);
            ((TransportInternal) transport).addTransportLayer(webSocket);
        }
        Sasl sasl = transport.sasl();
        sasl.plain(this.userName, this.sasToken);
        SslDomain domain = makeDomain(SslDomain.Mode.CLIENT);
        domain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
        Ssl ssl = transport.ssl(domain);
    }
}
Also used : WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal)

Example 7 with WebSocketImpl

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

the class AmqpFileUploadNotificationReceivedHandler method onConnectionBound.

@Override
public void onConnectionBound(Event event) {
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_019: [The event handler shall set the SASL PLAIN authentication on the Transport using the given user name and sas token]
    // Codes_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_010: [The event handler shall set ANONYMUS_PEER authentication mode on the domain of the Transport]
    Transport transport = event.getConnection().getTransport();
    if (transport != null) {
        if (this.iotHubServiceClientProtocol == IotHubServiceClientProtocol.AMQPS_WS) {
            // Codes_SRS_SERVICE_SDK_JAVA_AMQPFILEUPLOADNOTIFICATIONRECEIVEDHANDLER_25_020: [** The event handler shall not initialize WebSocket if the protocol is AMQP **]
            WebSocketImpl webSocket = new WebSocketImpl();
            webSocket.configure(this.webSocketHostName, WEBSOCKET_PATH, 0, WEBSOCKET_SUB_PROTOCOL, null, null);
            ((TransportInternal) transport).addTransportLayer(webSocket);
        }
        Sasl sasl = transport.sasl();
        sasl.plain(this.userName, this.sasToken);
        SslDomain domain = makeDomain(SslDomain.Mode.CLIENT);
        domain.setPeerAuthentication(SslDomain.VerifyMode.ANONYMOUS_PEER);
        Ssl ssl = transport.ssl(domain);
    }
}
Also used : WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) TransportInternal(org.apache.qpid.proton.engine.impl.TransportInternal)

Example 8 with WebSocketImpl

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

the class AmqpsIotHubConnectionTest method onConnectionBoundWebSockets.

// Tests_SRS_AMQPSIOTHUBCONNECTION_15_030: [The event handler shall get the Transport (Proton) object from the event.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_031: [The event handler shall set the SASL_PLAIN authentication on the transport using the given user name and sas token.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_15_032: [The event handler shall set VERIFY_PEER authentication mode on the domain of the Transport.]
// Tests_SRS_AMQPSIOTHUBCONNECTION_25_049: [The event handler shall set the SSL Context to IOTHub SSL context containing valid certificates.]
@Test
public void onConnectionBoundWebSockets() throws IOException {
    baseExpectations();
    new NonStrictExpectations() {

        {
            mockEvent.getConnection();
            result = mockConnection;
            mockConnection.getTransport();
            result = mockTransportInternal;
            new WebSocketImpl();
            result = mockWebSocket;
            mockWebSocket.configure(anyString, anyString, anyInt, anyString, (Map<String, String>) any, (WebSocketHandler) any);
            mockTransportInternal.addTransportLayer(mockWebSocket);
            mockTransportInternal.sasl();
            result = mockSasl;
            mockSasl.plain(anyString, anyString);
            mockSslDomain.setSslContext(mockIotHubSSLContext.getIotHubSSlContext());
            mockSslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
            mockTransportInternal.ssl(mockSslDomain);
        }
    };
    final AmqpsIotHubConnection connection = new AmqpsIotHubConnection(mockConfig, false);
    Deencapsulation.setField(connection, "useWebSockets", true);
    connection.onConnectionBound(mockEvent);
    new Verifications() {

        {
            mockEvent.getConnection();
            times = 1;
            mockConnection.getTransport();
            times = 1;
            mockWebSocket.configure(hostName + ":" + amqpPort, "/$iothub/websocket", 0, "AMQPWSB10", null, null);
            times = 1;
            mockTransportInternal.addTransportLayer(mockWebSocket);
            times = 1;
            mockTransportInternal.sasl();
            times = 1;
            mockSasl.plain(deviceId + "@sas." + hubName, anyString);
            times = 1;
            mockSslDomain.setSslContext(mockIotHubSSLContext.getIotHubSSlContext());
            times = 1;
            mockSslDomain.setPeerAuthentication(SslDomain.VerifyMode.VERIFY_PEER);
            times = 1;
            mockTransportInternal.ssl(mockSslDomain);
            times = 1;
        }
    };
}
Also used : AmqpsIotHubConnection(com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection) WebSocketImpl(com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl) Test(org.junit.Test)

Aggregations

WebSocketImpl (com.microsoft.azure.sdk.iot.deps.ws.impl.WebSocketImpl)8 TransportInternal (org.apache.qpid.proton.engine.impl.TransportInternal)4 Test (org.junit.Test)4 IotHubServiceClientProtocol (com.microsoft.azure.sdk.iot.service.IotHubServiceClientProtocol)3 Expectations (mockit.Expectations)3 AmqpsIotHubConnection (com.microsoft.azure.sdk.iot.device.transport.amqps.AmqpsIotHubConnection)1 AmqpFeedbackReceivedHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpFeedbackReceivedHandler)1 AmqpSendHandler (com.microsoft.azure.sdk.iot.service.transport.amqps.AmqpSendHandler)1