Skip to content

Commit 9e2baf1

Browse files
committed
Update Kotlin example service.
1 parent aa59584 commit 9e2baf1

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

httprpc-test/src/main/kotlin/org/httprpc/test/KotlinService.kt renamed to httprpc-test/src/main/kotlin/org/httprpc/test/SystemInfoService.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,34 @@ package org.httprpc.test
1616

1717
import org.httprpc.RequestMethod
1818
import org.httprpc.WebService
19+
import java.net.InetAddress
1920
import javax.servlet.annotation.WebServlet
2021

2122
/**
22-
* Kotlin example service.
23+
* System info service.
2324
*/
24-
@WebServlet(urlPatterns = ["/kotlin/*"], loadOnStartup = 1)
25-
class KotlinService : WebService() {
25+
@WebServlet(urlPatterns = ["/system-info/*"], loadOnStartup = 1)
26+
class SystemInfoService : WebService() {
2627
@RequestMethod("GET")
27-
fun sayHello(): String {
28-
return "Hello from Kotlin"
28+
fun getSystemInfo(): SystemInfo {
29+
val localHost = InetAddress.getLocalHost()
30+
val runtime = Runtime.getRuntime()
31+
32+
return SystemInfo(
33+
localHost.hostName,
34+
localHost.hostAddress,
35+
runtime.availableProcessors(),
36+
runtime.freeMemory(),
37+
runtime.totalMemory()
38+
)
2939
}
40+
}
41+
42+
class SystemInfo(
43+
val hostName: String,
44+
val hostAddress: String,
45+
val availableProcessors: Int,
46+
val freeMemory: Long,
47+
val totalMemory: Long
48+
) {
3049
}

httprpc-test/src/main/webapp/index.jsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@
104104

105105
<hr/>
106106

107-
<a href="${pageContext.request.contextPath}/kotlin?api">Kotlin (API)</a><br/>
107+
<a href="${pageContext.request.contextPath}/system-info?api">System Info (API)</a><br/>
108108
<br/>
109-
<a href="${pageContext.request.contextPath}/kotlin">Kotlin</a><br/>
109+
<a href="${pageContext.request.contextPath}/system-info">System Info</a><br/>
110110

111111
<hr/>
112112

0 commit comments

Comments
 (0)