Hakon Grotte
11/01/2022, 11:21 AMclass ResourceProducer(
private val resourceAProducer: Producer<String, ResourceA>,
private val resourceBProducer: Producer<String, ResourceB>
) {
fun getCorrectKafkaProducer(resource: Resource): Producer<String, SpecificRecord> {
return when(someSealedClass) {
ValueA -> resourceAProducer <-- does not compile
ValueB -> resourceBProducer <-- does not compile
}
}
^-- Compiler error msg: Type mismatch: Required: Producer<String, SpecificRecord>, Found: Producer<String, ResourceA/B>
fun getSpecificRecord(resource: Resource): SpecificRecord {
return when(someSealedClass) {
ValueA -> ResourceA <-- this compiles
ValueB -> ResourceB <-- this compiles
}
}
}
Arun Sudharsan
11/01/2022, 6:29 PMPartho Paul
11/03/2022, 12:27 PMBrian Estrada
11/03/2022, 1:45 PMConcurrentHashMap
and removing items at the same time?Raphael TEYSSANDIER
11/08/2022, 11:54 AMSam Si
11/11/2022, 6:12 AMModule was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.1.
I am getting this issue and trying to figure out if anyone knows the solution for it.rrva
11/11/2022, 9:31 AMJohn Huang
11/15/2022, 7:41 PMYogeshvu
11/17/2022, 11:31 AMrocketraman
11/17/2022, 6:32 PMFencedLock
(https://docs.hazelcast.com/imdg/4.2/data-structures/fencedlock) but I wouldn't call that light-weight. Same for Zookeeper / etcd and company.Justin Strong
11/24/2022, 12:28 PMclass Articles(val sort: String? = "new") {
@Serializable
@Resource("new")
class New(val parent: Articles = Articles())
@Serializable
@Resource("{id}")
class Id(val parent: Articles = Articles(), val id: Long) {
@Serializable
@Resource("edit")
class Edit(val parent: Id)
}
}
fun Application.configureRouting() {
println("routing")
// Starting point for a Ktor app:
routing {
/*get<Articles> { article ->
// Get all articles ...
call.respondText("List of articles sorted starting from ${article.sort}")
}*/
post<Articles> { article ->
println("posty time")
// Get all articles ...
call.respondText("posty")
}
post<Articles.New> {
var headers = call.request.headers;
println(headers)
println(call.request.headers.toString())
// Show a page with fields for creating a new article ...
call.respondText("Create a new article")
}
get<Articles.New> {
// Save an article ...
println(call.request.toString())
call.respondText("An article is saved", status = HttpStatusCode.Created)
}
}
}
And here’s the TypeScript sending the requests
function sendPostRequest() {
fetch('<http://localhost:8080/articles/new>',
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
mode: 'no-cors',
method: "POST",
//body: JSON.stringify({firstName: "Jet", lastName: "woooooooooo", numba: 1})
})
.then(response => response.text())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}
function sendGetRequest() {
fetch('<http://localhost:8080/articles/new>',
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
mode: 'no-cors',
method: "GET",
})
.then(response => response.text())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}
Justin Strong
11/24/2022, 12:33 PMJustin Strong
11/24/2022, 3:25 PMCannot transform this request's content to com.company.plugins.Articles
I’ve setup content negotiation and resources as such
import io.ktor.http.*
import io.ktor.resources.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.request.*
import io.ktor.server.resources.*
import io.ktor.server.resources.Resources
import <http://io.ktor.server.resources.post|io.ktor.server.resources.post>
import io.ktor.server.response.*
import io.ktor.server.routing.*
import kotlinx.serialization.Serializable
fun Application.plugins() {
install(ContentNegotiation) {
json()
println("We have installed content negotiation with json()")
}
install(Resources)
And verified that the println shows up in the console logs. I’ve got the API setup as such:
@Serializable
@Resource("/articles")
data class Articles(val sort: String? = "new on no") {
@Serializable
@Resource("new")
class New(val parent: Articles = Articles())
@Serializable
@Resource("{id}")
class Id(val parent: Articles = Articles(), val id: Long) {
@Serializable
@Resource("edit")
class Edit(val parent: Id)
}
}
fun Application.configureRouting() {
println("routing")
// Starting point for a Ktor app:
routing {
post<Articles.New> { article ->
try {
var arty = call.receive<Articles>()
println("no excpetionsf")
} catch (e: Exception) {
println("exception")
println(e.message)
}
call.respondText("Create a new article")
}
}
}
And am making the request as such:
function sendPostRequest() {
fetch('<http://localhost:8080/articles/new>',
{
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
mode: 'no-cors',
method: "POST",
body: JSON.stringify({sort: "Jet", parent: "woooooooooo", numba: 1})
})
.then(response => response.text())
.then(data => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
}
James Chen
11/24/2022, 6:50 PMexternalServices
. This is the mock I have right now in my `testApplication`:
externalServices {
hosts("<ws://test.com>") {
install(io.ktor.server.websocket.WebSockets) {}
routing {
webSocket("/") {
this.send("hello")
}
}
}
}
My test will hang when it tries to connect to <ws://test.com>
and eventually return a io.ktor.client.network.sockets.ConnectTimeoutException: Connect timeout has expired [url=<ws://test.com>, connect_timeout=unknown ms]
error. Can externalServices
mock out ws servers? If not, are there any suggestions on how to mock a ws server for testing? Thank you!Łukasz Pięta
11/25/2022, 8:51 AM@Transactional
from them, and I use testcontainers. And I wonder if there is some library that could be used to populate database (for integration tests - Spring, Kotlin/JVM) but not in an usual way. Using plain SQL (import.sql, which is default in Spring) is fast but when I used it, it was hard to keep the data in SQL up-to-date with all the business requirements (not all of them can be database constraints). On the other hand, using the business logic entry points to populate the data regarding all the business rules can introduce an overhead. So some kind of SQL-generator for business logic would be great. How do I imagine it could work? I'll have e.g. PaymentInitDb
class which will call some business logic parts of the system (let's say PaymentFacade
). It will cause changes committed to the database, so the dump can be made. If we already have the dump, we can use it as our import.sql. Do you know if something like this exists? I'll be very grateful for help, because I probably google that wrong, because I couldn't find anything like thatRob Elliot
11/26/2022, 4:21 PMUdomomo
11/27/2022, 1:24 PMcopy
method not visible from outside.
Many people provide workarounds and I found this. Seems interesting but I don’t know how it works. This uses sealed class and seems hashCode
equals
toString
method of data class can be still used from outside, while copy
method is not. Why only copy
method is hidden by this way?
// Original data class with private constructor
data class User private constructor(val name: String, val id: Int){
companion object{
fun of(name:String, id: Int): User{
return User(if(name.isEmpty()) "Unknown" else name, id)
}
}
}
// Workaround with sealed class
sealed class User {
companion object {
fun of(name: String, id: Int): User = UserData(if (name.isEmpty()) "Unknown" else name, id)
}
abstract val name: String
abstract val id: Int
private data class UserData(override val name: String, override val id: Int) : User()
}
t3wad
12/01/2022, 3:55 PMspierce7
12/06/2022, 2:39 PMdocker-compose
becomes extremely inconvenient as soon as you want to turn off a service and run your own local dev environment.
Surely there is a tool that I just don't know about that everyone is using to manage their environments?Cody Mikol
12/07/2022, 2:30 AMGustav Elmgren
12/08/2022, 5:02 PMdata class StudentDTO(val id: Long, val name: String)
data class Student(val id: Long, val name: String)
This would probably work easier in java (for good and bad reasons), given that the ID could be null, given we use StudentDTO
as the RequestBody
in a POST
request. I don't like the approach with nullable id in the DTO. So I guess you would have to create multiple models for different scenarios?
data class CreateStudentDTO(val name: String) --> Used when parsing the request
data class ReturnStudentDTO(val id: Long, name: String) --> Used to return from the controller
data class CreateStudent(val name: String) -> Used as an argument in the service layer
data class Student(val id: Long, name: String) -> Used as a return in the service layer
Martin Gaens
12/08/2022, 10:29 PMKevin Del Castillo
12/09/2022, 4:44 PMipolyzos
12/14/2022, 7:10 AMBaidyanath
12/15/2022, 12:49 PMs4nchez
12/18/2022, 4:42 PMSaher Al-Sous
12/20/2022, 9:04 AM@Table
annotation?
Using a bean or overrides?Debanshu Datta
12/22/2022, 8:32 AMRizwan
12/22/2022, 2:32 PMJane
12/25/2022, 10:05 AM