Hitesh Chopra
09/02/2021, 2:43 PMlandon burch
09/03/2021, 4:43 PMHitesh Chopra
09/04/2021, 7:28 AMVasily Scherbakov
09/04/2021, 9:06 AMclass MainView : KComposite() {
private val apiClient: ScenarioServiceClient = ScenarioServiceClientImpl("<http://localhost:5000>");
private val root = ui {
verticalLayout {
horizontalLayout {
div{
addClassName("centered-content")
apiClient.getAvailableScenarios()
.forEach { scenario -> scenarioItemView(scenario) }
}
}
}
}
This is how i use ktor:
class ScenarioServiceClientImpl(private val baseUrl: String) : ScenarioServiceClient {
private val restClient: HttpClient = HttpClient(Apache)
override suspend fun getAvailableScenarios() : List<ScenarioViewModel>{
val scenarios = restClient.get<List<ScenarioViewModel>>("${baseUrl}/scenarios")}}
May be there is some way to invoke api call without suspend?Evgeny Berezovsky
09/05/2021, 10:22 PMdefaultRequest
uses header(HttpHeaders.ContentType, ContentType.Application.Json)
When sending via submitFormWithBinaryData
, it returns the error kotlinx. serialization. SerializationException: Serializer for class 'MultipartFormDataContent' is not found
I tried to change header
for the request to send an image with contentType
, but I get another error io.ktor. http.UnsafeHeaderException: Header(s) [Content-Type] are controlled by the engine and cannot be set explicitly
Judging by https://youtrack.jetbrains.com/issue/KTOR-620, I can't do this
Setting contentType
for MultipartFormDataContent
does not give anything
How can I send a request with a serializable class of type AddImageToMessage (val messageId: Int)
and attach an image to this request?Didier Villevalois
09/06/2021, 3:34 PMAF_UNIX
instead of AF_INET
). However, I think I would need to do some (problematic?) refactoring first.
◦ AConnectedSocket
and ABoundSocket
both use NetworkAddress
for their remoteAddress
and localAddress
which is problematic, because too restrictive. Presumably, I would have to introduce some super-class to NetworkAddress
and another sibling to NetworkAddress
(say UnixAddress
). This refactoring could ripple a lot.
◦ Rename TCPSocketNative
to ByteStreamSocketNative
as its implementation would be used as is for both TCP byte-stream sockets and IPC byte-stream sockets. (Same for TCPServerSocketNative
)
◦ Adapt the first two lines of both connect()
and bind()
(in ConnectUtilsNative.kt
) to also handle the UnixAddress
. The rest of the code would (more or less) stay as is.
That's all for now. I am quite ready to jump on the wagon, as there won't be much work to do (and I desperately need this 🤪). Please guide me on how I should proceed. Thanks in advance.Paul Woitaschek
09/06/2021, 8:12 PMURLBuilder
to create urls in a type safe way. However suddenly lots of warnings popped up that the whole parameters api is marked as internal.
(ParametersBuilder is public) but functions like append
belong to StringValuesBuilder
and are marked as InternalAPI
.
Is there really no public api to create an url with parameters?darkmoon_uk
09/07/2021, 4:18 AMBarry Fawthrop
09/07/2021, 7:37 PMViktor Petrovski
09/08/2021, 8:16 AMval status = HttpClient().use { client ->
// ...
}
should be preferred to
client.get("<https://ktor.io/>")
So there is no need to call the .close()
functionBarry Fawthrop
09/08/2021, 10:34 PMPiotr Krzemiński
09/09/2021, 8:56 AMJeff
09/09/2021, 9:04 AMREQUEST https://....... failed with exception: io.ktor.client.features.HttpRequestTimeoutException: Request timeout has been expired [url=https://......., request_timeout=15000 ms]
Trevor Stone
09/09/2021, 5:05 PMJan
09/10/2021, 10:56 AMBart
09/11/2021, 2:42 PMFun main(arqs: Array<String>): Unity = io.ktor.server.jetty.EngineMain.main(arqs)
If I understand correctly i need to create certificate before server in fun main.
So its should goes like this:
fun main(arts: Array<String>{
<My certificate code>
Unity = io.ktor.server.jetty.EngineMain.main(arqs)
}
As it cant be done like this, how it can be configured? Examples that i find are created for embeddedServer so i can't use it.Didier Villevalois
09/11/2021, 4:59 PMIsaacMart
09/13/2021, 3:40 AM@Entity(tableName = "requests")
public class Request extends BaseObservable implements Parcelable {
@PrimaryKey(autoGenerate = true)
private int request_id;// Document_id
private String r_clients_id;
private int r_tasker_id;
private User user;// Type converter
private String requested_skill;
private String time_stamp;
}
Same model for my ktor project
class Request(
val request_id: Int,
val r_clients_id: Int,
val r_tasker_id: Int,
val user: User,
val requested_skill: String,
val time_stamp: String,
val arrival_date: String,
): Serializable, Principal
Here is where am facing the challenge. I really don't know how to insert or reference the Type converter class in my object class.
object Requests : Table() {
val requestId: Column<Int> = integer("request_id").autoIncrement().primaryKey()
val rClientId: Column<Int> = integer("r_clients_id").references(Users.userId)
val rTaskerId: Column<Int> = integer("r_tasker_id").references(Taskers.taskerId)
val user: Column<User> = ?????????????????????????
val requestedSkill = varchar("requested_skill", 128)
val timeStamp = varchar("time_stamp", 64)
val arrivalDate = varchar("arrival_date", 64)
}
Arnab
09/13/2021, 7:04 AMgraphql
route in my ktor app. I want that route to be authenticated, but I don't want there to be any authentication on Introspection
queries. Is that possible?natario1
09/13/2021, 2:10 PMinstall(Auth) { bearer { ... } }
? We're having serious issues after logout/re-login, because apparently ktor keeps the old token in memory (loadTokens / refreshTokens not called). Using ktor client 1.6.0.Jose A.
09/14/2021, 11:59 AMpost {
val targetChannel = FileOutputStream(Files.createTempFile("job-", ".json").toFile()).channel
val originChannel = newChannel(call.receiveStream())
originChannel.use {
targetChannel.use {
targetChannel.transferFrom(originChannel, 0L, 100000)
}
}
...
FileOutputStream, etc. are blocking calls. Is there a nonblocking API to write to files so I can use receiveChannel()
?Jeff Lockhart
09/15/2021, 6:50 PMappend()
or appendAll()
functions to add headers to a request.
For example, the example in the documentation:
val response: HttpResponse = client.get("<https://ktor.io/>") {
headers {
append(HttpHeaders.Accept, "text/html") // warning
append(HttpHeaders.Authorization, "token") // warning
append(HttpHeaders.UserAgent, "ktor client") // warning
}
}
Is there a new pattern that should be used for this? Why is StringValuesBuilder
marked @InternalAPI
now? Using ktor 1.6.3.subashz
09/15/2021, 6:51 PMget("/test") {
call.respond("hello")
sendNotification() // does this function call execute properly
}
Danish Ansari
09/16/2021, 6:40 AMPeter Mandeljc
09/16/2021, 9:56 AMOsmium
09/16/2021, 10:00 AMIsaacMart
09/17/2021, 3:52 AMoverride suspend fun getAllRequestsById(user_id: Int): List<Request> {
return DatabaseFactory.dbQuery {
Requests.select { Requests.rClientId.eq(user_id) or Requests.rTaskerId.eq(user_id) }.mapNotNull { rowToRequest(it) } // Suspension functions can be called only within coroutine body
}
}
Here is my rowToRequest() function
private suspend fun rowToRequest(row: ResultRow?): Request? {
if (row == null) {
return null
}
return userRepository.getUser(row[Requests.user])?.let {user ->
taskerRepository.getTasker(row[Requests.tasker])?.let { tasker ->
Request(
row[Requests.requestId],
row[Requests.rClientId],
row[Requests.rTaskerId],
user,
tasker,
row[Requests.requestedSkill],
row[Requests.timeStamp],
row[Requests.arrivalDate],
row[Requests.arrivalTime],
row[Requests.taskDescription],
row[Requests.task1ImgUrl],
row[Requests.task2ImgUrl],
row[Requests.task3ImgUrl],
row[Requests.task4ImgUrl],
row[Requests.notificationStatus],
row[Requests.viewHolderNotificationType],
row[Requests.receiptNo],
row[Requests.taskStatus],
row[Requests.isNotificationSeen],
row[Requests.dateOfAcceptance],
row[Requests.dateOfDecline],
row[Requests.dateOfExpire],
row[Requests.convenienceFee],
row[Requests.paymentDate],
row[Requests.paidAmount],
row[Requests.paymentOption],
row[Requests.paymentStatus],
row[Requests.clientRatingStar],
row[Requests.clientRatingFeedback],
row[Requests.feedbackDate],
)
}
}
}
benkuly
09/17/2021, 10:58 AMByteReadChannel
, but then the Content-Length
-header is not set. Setting it manually throws:
Header(s) [Content-Length] are controlled by the engine and cannot be set explicitly
io.ktor.http.UnsafeHeaderException: Header(s) [Content-Length] are controlled by the engine and cannot be set explicitly
Cristian Rosa
09/19/2021, 12:34 PM@Composable
fun MainScreen() {
val ktorServer = embeddedServer(Jetty, port = 8080,) {
...module declaration....
}
Column(Modifier.fillMaxSize(), Arrangement.spacedBy(5.dp)) {
Button(modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = {
ktorServer.start(wait = false)
}
) {
Text("START")
}
Button(modifier = Modifier.align(Alignment.CenterHorizontally),
onClick = {
ktorServer.stop(5000, 6000, TimeUnit.MILLISECONDS)
}
) {
Text("STOP")
}
}
}
At the moment
• “start” button click works as expected and the server run properly
• “stop” doesn’t take any action at all!!!!
The only way, I figure out to stop the server is by shutdown-url, but in this way the all app is closed
(I would like to keep the compose windows open with the change of re-start server again)
Using EngineMain like this:
scope.launch(Dispatchers.Default) {
val args = arrayOf<String>()
EngineMain.main(args)
}
Again I can run the server but don’t know how to stop it.Big Chungus
09/19/2021, 2:17 PMBig Chungus
09/19/2021, 2:17 PMhfhbd
09/19/2021, 2:18 PMBig Chungus
09/19/2021, 2:19 PMhfhbd
09/20/2021, 9:40 AM2.0.0-eap
Big Chungus
09/20/2021, 11:11 AM