|
5 | 5 | import org.eclipse.jetty.websocket.api.Session;
|
6 | 6 | import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
|
7 | 7 | import org.eclipse.jetty.websocket.client.WebSocketClient;
|
| 8 | +import org.eclipse.jetty.util.ssl.SslContextFactory; |
8 | 9 |
|
9 | 10 | import java.net.URI;
|
10 | 11 | import java.util.concurrent.Future;
|
@@ -44,27 +45,36 @@ public long getRecurrencePeriod() {
|
44 | 45 | * The WebhookReceiver handles what happens when an event comes in.
|
45 | 46 | */
|
46 | 47 | private static void listen() {
|
47 |
| - WebSocketClient client = new WebSocketClient(); |
48 |
| - //String destUri = "wss://cloudbees-hooksocket.beescloud.com/ws?tenant=java"; |
49 |
| - //String destUri = "ws://172.18.128.252:33048/ws?tenant=java"; |
| 48 | + final WebSocketClient client; |
| 49 | + |
| 50 | + //String destUri = "wss://cloudbees-hooksocket.beescloud.com/subscribe/testing"; |
| 51 | + //String destUri = "ws://172.18.128.252:33048/ws?tenant=testing"; |
50 | 52 | String destUri = System.getenv("WEBHOOK_SUBSCRIPTION");
|
51 | 53 | if (destUri == null) {
|
52 | 54 | destUri = "ws://localhost:8888/subscribe/testing";
|
53 | 55 | }
|
54 | 56 |
|
| 57 | + if (destUri.startsWith("wss://")) { |
| 58 | + SslContextFactory sslContextFactory = new SslContextFactory(); |
| 59 | + sslContextFactory.setTrustAll(true); |
| 60 | + client = new WebSocketClient(sslContextFactory); |
| 61 | + } else { |
| 62 | + client = new WebSocketClient(); |
| 63 | + } |
| 64 | + |
55 | 65 | WebhookReceiver socket = new WebhookReceiver();
|
56 | 66 | try
|
57 | 67 | {
|
58 | 68 | client.start();
|
59 | 69 | URI echoUri = new URI(destUri);
|
60 | 70 | ClientUpgradeRequest request = new ClientUpgradeRequest();
|
61 | 71 | Future<Session> fs = client.connect(socket,echoUri,request);
|
62 |
| - System.out.printf("Attempting to subscribe for webhooks to : %s%n",echoUri); |
| 72 | + System.out.printf("Attempting to subscribe to webhooks at : %s%n", echoUri); |
63 | 73 |
|
64 | 74 | try {
|
65 | 75 | fs.get(5, TimeUnit.SECONDS);
|
66 | 76 | } catch (Exception e) {
|
67 |
| - System.out.println("Failure to connect. Will try again shortly.. " + e.getMessage()); |
| 77 | + System.out.println("Failed to connect - will retry shortly (" + e.getMessage() + ")"); |
68 | 78 | Thread.sleep(5000);
|
69 | 79 | return;
|
70 | 80 | }
|
|
0 commit comments