Skip to content

Commit e38295d

Browse files
committed
- Added config property for a WoT base URL, which will be used for the URLs of the forms of properties, actions, and events.
- The server is bound to '0.0.0.0' by default, ensuring it is accessible within the cluster (aligning with Spring Boot’s default behavior). - Adjusted server configuration properties to ensure proper setup of the WebSocket server.
1 parent b5ac202 commit e38295d

File tree

7 files changed

+60
-20
lines changed

7 files changed

+60
-20
lines changed

kotlin-wot-binding-http/src/main/kotlin/http/HttpProtocolServer.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ open class HttpProtocolServer(
4444
private val wait: Boolean = false,
4545
private val bindHost: String = "0.0.0.0",
4646
private val bindPort: Int = 8080,
47-
private val createServer: (host: String, port: Int, servient: Servient) -> EmbeddedServer<*, *> = ::defaultServer
47+
private val createServer: (host: String, port: Int, servient: Servient) -> EmbeddedServer<*, *> = ::defaultServer,
48+
thingDescriptionBaseUrl: String = "localhost"
4849
) : ProtocolServer {
4950
val things: MutableMap<String, ExposedThing> = mutableMapOf()
5051
var started = false
5152
private var server: EmbeddedServer<*, *>? = null
52-
private var actualAddresses: List<String> = listOf("http://$bindHost:$bindPort")
53+
private var actualAddresses: List<String> = listOf("http://$thingDescriptionBaseUrl:$bindPort")
5354

5455
companion object {
5556
private val log = LoggerFactory.getLogger(HttpProtocolServer::class.java)

kotlin-wot-binding-http/src/test/kotlin/http/HttpProtocolServerTest.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ class HttpProtocolServerTest {
395395
// Assert
396396
assertTrue(exposedThing.forms.isNotEmpty(), "Expected forms to be added to thing")
397397

398-
val expectedHref = "http://0.0.0.0:8080/${exposedThing.id}/all/properties"
398+
val expectedHref = "http://localhost:8080/${exposedThing.id}/all/properties"
399399
val form = exposedThing.forms.find { it.href == expectedHref }
400400
assertNotNull(form, "Expected form for reading all properties to be added")
401401
assertEquals(CONTENT_TYPE, form.contentType)
@@ -406,7 +406,7 @@ class HttpProtocolServerTest {
406406
fun `exposeProperties should add forms for read write properties`() {
407407
// Arrange
408408
server.started = true
409-
val address = "http://0.0.0.0:8080"
409+
val address = "http://localhost:8080"
410410
// Act
411411
server.exposeProperties(exposedThing, address, CONTENT_TYPE)
412412

@@ -422,7 +422,7 @@ class HttpProtocolServerTest {
422422
fun `exposeActions should add form for action`() {
423423
// Arrange
424424
server.started = true
425-
val address = "http://0.0.0.0:8080"
425+
val address = "http://localhost:8080"
426426
// Act
427427
server.exposeActions(exposedThing, address, CONTENT_TYPE)
428428

@@ -439,7 +439,7 @@ class HttpProtocolServerTest {
439439
fun `exposeEvents should add form for event`() {
440440
// Arrange
441441
server.started = true
442-
val address = "http://0.0.0.0:8080"
442+
val address = "http://localhost:8080"
443443
// Act
444444
server.exposeEvents(exposedThing, address, CONTENT_TYPE)
445445

kotlin-wot-binding-websocket/src/main/kotlin/websocket/WebSocketProtocolServer.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ class WebSocketProtocolServer(
4040
private val wait: Boolean = false,
4141
private val bindHost: String = "0.0.0.0",
4242
private val bindPort: Int = 8080,
43-
private val createServer: (host: String, port: Int, servient: Servient) -> EmbeddedServer<*, *> = ::defaultWebSocketServer
43+
private val createServer: (host: String, port: Int, servient: Servient) -> EmbeddedServer<*, *> = ::defaultWebSocketServer,
44+
thingDescriptionBaseUrl: String = "localhost"
4445
) : ProtocolServer {
4546
private val things: MutableMap<String, ExposedThing> = mutableMapOf()
4647

4748
var started = false
4849
private var server: EmbeddedServer<*, *>? = null
49-
private var actualAddresses: List<String> = listOf("ws://$bindHost:$bindPort")
50+
private var actualAddresses: List<String> = listOf("ws://$thingDescriptionBaseUrl:$bindPort")
5051

5152
companion object {
5253
private val log = LoggerFactory.getLogger(WebSocketProtocolServer::class.java)

kotlin-wot-integration-tests/src/main/resources/application.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ arc:
88
url: https://gpt4-uk.openai.azure.com
99

1010
wot:
11+
baseUrl: my-base-url
1112
servient:
1213
security:
1314
credentials:
@@ -18,10 +19,10 @@ wot:
1819
server:
1920
enabled: true
2021
host: localhost
21-
port: 8080
22+
port: 8181
2223
http:
2324
server:
24-
enabled: false
25+
enabled: true
2526
host: localhost
2627
port: 8080
2728
mqtt:

kotlin-wot-spring-boot-starter/src/main/kotlin/spring/HttpProperties.kt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@ package ai.ancf.lmos.wot.spring
33
import org.springframework.boot.context.properties.ConfigurationProperties
44
import org.springframework.validation.annotation.Validated
55

6-
@ConfigurationProperties(prefix = "wot.servient.http.server", ignoreUnknownFields = true)
7-
@Validated
8-
data class HttpServerProperties(
6+
open class ServerProperties (
97
var enabled: Boolean = true,
10-
var host: String = "localhost",
8+
var host: String = "0.0.0.0",
119
var port: Int = 8080
12-
)
10+
)
11+
12+
@ConfigurationProperties(prefix = "wot.servient.http.server", ignoreUnknownFields = true)
13+
@Validated
14+
class HttpServerProperties : ServerProperties()
15+
16+
@ConfigurationProperties(prefix = "wot.servient.websocket.server", ignoreUnknownFields = true)
17+
@Validated
18+
class WebsocketProperties : ServerProperties()

kotlin-wot-spring-boot-starter/src/main/kotlin/spring/ServientAutoConfiguration.kt

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ import org.springframework.context.annotation.Configuration
2222

2323

2424
@AutoConfiguration
25-
@EnableConfigurationProperties(CredentialsProperties::class, HttpServerProperties::class, MqttServerProperties::class, MqttClientProperties::class)
25+
@EnableConfigurationProperties(
26+
CredentialsProperties::class,
27+
WotProperties::class,
28+
HttpServerProperties::class,
29+
WebsocketProperties::class,
30+
MqttServerProperties::class,
31+
MqttClientProperties::class
32+
)
2633
class ServientAutoConfiguration {
2734

2835
@Bean
@@ -55,8 +62,15 @@ class ServientAutoConfiguration {
5562
havingValue = "true",
5663
matchIfMissing = true // By default, enable the server
5764
)
58-
fun webSocketProtocolServer(httpServerProperties: HttpServerProperties): WebSocketProtocolServer {
59-
return WebSocketProtocolServer(bindHost = httpServerProperties.host, bindPort = httpServerProperties.port)
65+
fun webSocketProtocolServer(
66+
websocketProperties: WebsocketProperties,
67+
wotProperties: WotProperties
68+
): WebSocketProtocolServer {
69+
return WebSocketProtocolServer(
70+
bindHost = websocketProperties.host,
71+
bindPort = websocketProperties.port,
72+
thingDescriptionBaseUrl = wotProperties.baseUrl
73+
)
6074
}
6175

6276
@Bean
@@ -82,8 +96,15 @@ class ServientAutoConfiguration {
8296
havingValue = "true",
8397
matchIfMissing = true // By default, enable the server
8498
)
85-
fun httpProtocolServer(httpServerProperties: HttpServerProperties): HttpProtocolServer {
86-
return HttpProtocolServer(bindHost = httpServerProperties.host, bindPort = httpServerProperties.port)
99+
fun httpProtocolServer(
100+
httpServerProperties: HttpServerProperties,
101+
wotProperties: WotProperties
102+
): HttpProtocolServer {
103+
return HttpProtocolServer(
104+
bindHost = httpServerProperties.host,
105+
bindPort = httpServerProperties.port,
106+
thingDescriptionBaseUrl = wotProperties.baseUrl
107+
)
87108
}
88109

89110
@Bean
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ai.ancf.lmos.wot.spring
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties
4+
import org.springframework.validation.annotation.Validated
5+
6+
@ConfigurationProperties(prefix = "wot", ignoreUnknownFields = true)
7+
@Validated
8+
data class WotProperties(
9+
var baseUrl: String = "localhost"
10+
)

0 commit comments

Comments
 (0)