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);
}
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);
}
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);
}
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);
}
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);
}
}
}
Aggregations