1
2
3
4 package com.azure.messaging.eventhubs.implementation.handler;
5
6 import com.azure.core.util.logging.ClientLogger;
7 import com.microsoft.azure.proton.transport.ws.impl.WebSocketImpl;
8 import org.apache.qpid.proton.engine.Event;
9 import org.apache.qpid.proton.engine.impl.TransportInternal;
10
11
12
13
14 public class WebSocketsConnectionHandler extends ConnectionHandler {
15 static final int HTTPS_PORT = 443;
16
17
18
19 static final int MAX_FRAME_SIZE = 4 * 1024;
20
21 private static final String SOCKET_PATH = "/$servicebus/websocket";
22 private static final String PROTOCOL = "AMQPWSB10";
23
24
25
26
27
28
29
30
31 public WebSocketsConnectionHandler(final String connectionId, final String hostname) {
32 super(connectionId, hostname, new ClientLogger(WebSocketsConnectionHandler.class));
33 }
34
35 @Override
36 protected void addTransportLayers(final Event event, final TransportInternal transport) {
37 final String hostName = event.getConnection().getHostname();
38
39 final WebSocketImpl webSocket = new WebSocketImpl();
40 webSocket.configure(
41 hostName,
42 SOCKET_PATH,
43 "",
44 0,
45 PROTOCOL,
46 null,
47 null);
48
49 transport.addTransportLayer(webSocket);
50
51 logger.verbose("Adding web sockets transport layer for hostname[{}]", hostName);
52
53 super.addTransportLayers(event, transport);
54 }
55
56 @Override
57 public int getProtocolPort() {
58 return HTTPS_PORT;
59 }
60
61 @Override
62 public int getMaxFrameSize() {
63 return MAX_FRAME_SIZE;
64 }
65 }