Skip to content

Commit f16e785

Browse files
committed
More logs
1 parent b579fb4 commit f16e785

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/main/java/org/jenkinsci/plugins/webhookconnector/WebsocketHandler.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.eclipse.jetty.websocket.api.Session;
66
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
77
import org.eclipse.jetty.websocket.client.WebSocketClient;
8+
import org.eclipse.jetty.util.ssl.SslContextFactory;
89

910
import java.net.URI;
1011
import java.util.concurrent.Future;
@@ -44,27 +45,36 @@ public long getRecurrencePeriod() {
4445
* The WebhookReceiver handles what happens when an event comes in.
4546
*/
4647
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";
5052
String destUri = System.getenv("WEBHOOK_SUBSCRIPTION");
5153
if (destUri == null) {
5254
destUri = "ws://localhost:8888/subscribe/testing";
5355
}
5456

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+
5565
WebhookReceiver socket = new WebhookReceiver();
5666
try
5767
{
5868
client.start();
5969
URI echoUri = new URI(destUri);
6070
ClientUpgradeRequest request = new ClientUpgradeRequest();
6171
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);
6373

6474
try {
6575
fs.get(5, TimeUnit.SECONDS);
6676
} 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() + ")");
6878
Thread.sleep(5000);
6979
return;
7080
}

0 commit comments

Comments
 (0)