Skip to content

Commit b9cb0c7

Browse files
committed
Added eraseStackTraces param to lpfcpServer and lpfcp route.
1 parent bb80c2c commit b9cb0c7

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
## The first release of the LPFCP Java library! 🎉🎉🎉
1+
### Improvements
2+
`core` module:
3+
- Made JSON library (`org.json`) an `api` dependency
4+
- Disabled types auto-boxing when working with Java primitives
5+
6+
`ktor` module:
7+
- Updated Ktor to version `3.1.3`
8+
- `Ktor.LPFCPServer` now holds the entire embedded server instead of `NettyApplicationEngine`
9+
- Added `eraseStackTraces` param to `lpfcpServer` and `lpfcp` route.
10+
When it is set — all stack traces are automatically erased from responses to a client.
11+
This will help to hide internal server implementations from users.
12+
### Other
13+
- Updated dependencies' versions
214

core/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
dependencies {
2-
api("io.github.likespro:commons-core-mit:3.0.2")
3-
implementation("io.github.likespro:commons-reflection:3.0.2")
4-
implementation("io.github.likespro:commons-network:3.0.2")
2+
api("io.github.likespro:commons-core-mit:3.1.0")
3+
implementation("io.github.likespro:commons-reflection:3.1.0")
4+
implementation("io.github.likespro:commons-network:3.1.0")
55

66
api("org.json:json:20250107")
77

ktor/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ dependencies {
44

55
implementation("org.json:json:20250107")
66

7-
implementation("io.github.likespro:commons-reflection:3.0.2")
7+
implementation("io.github.likespro:commons-reflection:3.1.0")
88

99
implementation(project(":core"))
1010
}

ktor/src/main/java/eth/likespro/lpfcp/ktor/Ktor.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package eth.likespro.lpfcp.ktor
1111
import eth.likespro.commons.reflection.ObjectEncoding.encodeObject
1212
import eth.likespro.lpfcp.LPFCP.ExposedFunction
1313
import eth.likespro.lpfcp.LPFCP.processRequest
14-
import io.ktor.server.application.*
1514
import io.ktor.server.engine.*
1615
import io.ktor.server.netty.*
1716
import io.ktor.server.request.*
@@ -50,9 +49,9 @@ object Ktor {
5049
* @param processor The object containing the functions to be invoked with [ExposedFunction] annotation.
5150
* @param port The port on which the server will listen to (default is `8080`).
5251
*/
53-
fun lpfcpServer(processor: Any, port: Int = 8080) = LPFCPServer(embeddedServer(Netty, port) {
52+
fun lpfcpServer(processor: Any, port: Int = 8080, eraseStackTraces: Boolean = false) = LPFCPServer(embeddedServer(Netty, port) {
5453
routing {
55-
lpfcp(processor)
54+
lpfcp(processor, eraseStackTraces = eraseStackTraces)
5655
}
5756
})
5857

@@ -62,10 +61,12 @@ object Ktor {
6261
* @param processor The object containing the functions to be invoked with [ExposedFunction] annotation.
6362
* @param path The path for the LPFCP endpoint (default is "/lpfcp").
6463
*/
65-
fun Route.lpfcp(processor: Any, path: String = "/lpfcp") {
64+
fun Route.lpfcp(processor: Any, path: String = "/lpfcp", eraseStackTraces: Boolean = false) {
6665
post(path) {
6766
val request = JSONObject(call.receiveText())
68-
call.respond(processRequest(request, processor).encodeObject())
67+
call.respond(processRequest(request, processor).apply {
68+
if(eraseStackTraces) eraseStackTrace()
69+
}.encodeObject())
6970
}
7071
}
7172
}

ktor/src/test/java/eth/likespro/lpfcp/ktor/KtorTestsJava.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Integer divideSafely(int a, int b) {
5858
public static Ktor.LPFCPServer server;
5959

6060
@BeforeAll static void setupKtorServer() {
61-
server = Ktor.INSTANCE.lpfcpServer(calculator, 8080).start(false);
61+
server = Ktor.INSTANCE.lpfcpServer(calculator, 8080, false).start(false);
6262
}
6363

6464
@AfterAll static void teardownKtorServer() {

0 commit comments

Comments
 (0)