Skip to content

Commit

Permalink
Added the ability to configure userproperties on the websocket throug…
Browse files Browse the repository at this point in the history
…h a subclass
  • Loading branch information
timhamoni committed Dec 12, 2024
1 parent c272b06 commit 339a518
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
package org.kie.server.controller.websocket.client;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -102,6 +104,7 @@ public KieServerSetup connect(KieServerInfo serverInfo) {
"kieserver"))
.password(KeyStoreHelperUtil.loadControllerPassword(config))
.token(config.getConfigItemValue(KieServerConstants.CFG_KIE_CONTROLLER_TOKEN))
.userProperties(getUserProperties())
.build());
CountDownLatch waitLatch = new CountDownLatch(1);

Expand Down Expand Up @@ -186,4 +189,8 @@ public void setRegistry(KieServerRegistry registry) {
public KieServerRegistry getRegistry() {
return this.context;
}

protected Map<String, Object> getUserProperties() {
return new HashMap<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void init(final WebSocketClientConfiguration clientConfig) {
.encoders(clientConfig.getEncoders())
.decoders(clientConfig.getDecoders())
.build();
this.config.getUserProperties().putAll(clientConfig.getUserProperties());
this.endpoint = URI.create(clientConfig.getControllerUrl());
session = container.connectToServer(this, this.config, this.endpoint);
LOGGER.info("New Web Socket Session with id: {}, started", session.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.websocket.Decoder;
import javax.websocket.Encoder;

Expand All @@ -43,6 +44,8 @@ static Builder builder() {

List<Class<? extends Decoder>> getDecoders();

Map<String, Object> getUserProperties();

class Builder {

private WebSocketClientConfigurationImpl config = new WebSocketClientConfigurationImpl();
Expand Down Expand Up @@ -87,6 +90,11 @@ public Builder decoders(final Class<? extends Decoder>... decoders) {
return this;
}

public Builder userProperties(final Map<String, Object> userProperties) {
config.setUserProperties(userProperties);
return this;
}

public WebSocketClientConfiguration build() {
return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package org.kie.server.controller.websocket.common.config;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.websocket.Decoder;
import javax.websocket.Encoder;

Expand All @@ -38,6 +40,8 @@ public class WebSocketClientConfigurationImpl implements WebSocketClientConfigur

private List<Class<? extends Decoder>> decoders;

private Map<String, Object> userProperties;

protected WebSocketClientConfigurationImpl() {
}

Expand Down Expand Up @@ -113,6 +117,15 @@ public void setDecoders(List<Class<? extends Decoder>> decoders) {
this.decoders = decoders;
}

@Override
public Map<String, Object> getUserProperties() {
return userProperties;
}

public void setUserProperties(Map<String, Object> userProperties) {
this.userProperties = userProperties;
}

@Override
public String toString() {
return "WebSocketClientConfigurationImpl{" +
Expand All @@ -124,6 +137,7 @@ public String toString() {
", asyncSendTimeout=" + asyncSendTimeout +
", encoders=" + encoders +
", decoders=" + decoders +
", userProperties=" + userProperties +
'}';
}
}

0 comments on commit 339a518

Please sign in to comment.