Aiden Leong
04/01/2023, 9:18 AMAiden Leong
04/01/2023, 9:18 AMAiden Leong
04/01/2023, 9:22 AMjmfayard
04/05/2023, 9:08 AMRichard
04/05/2023, 9:37 PMdata class User(val name: String)
interface UserRepository {
context(UserService.Context)
fun createUser(): User
}
class RealUserRepository : UserRepository {
context(UserService.Context)
override fun createUser() = User("random-string")
}
interface UserService {
class Context private constructor()
companion object {
private val context: Context = Context() // How do I create here?
}
//extension function so it's "protected"
fun <T> UserService.withContext(block: context(Context) () -> T): T = with(context) {
block(this)
}
fun createUser(): User
}
class RealUserService : UserService {
val userRepository: UserRepository = RealUserRepository()
override fun createUser() = withContext {
userRepository.createUser()
}
}
Everything works except the initialization of the Context.
1. Is there another way to accomplish this without context receivers?
2. How do I properly initialize the companion object prop?xenomachina
04/08/2023, 2:32 AMMateusz Kolbusz
04/08/2023, 10:00 AMoverride suspend fun setTokenInvalid(refreshToken: String):Boolean {
collection.createIndex(RefreshToken::refreshToken, IndexOptions().expireAfter(7, TimeUnit.DAYS))
}
Vidar Magnusson
04/11/2023, 11:41 AMErik Dreyer
04/11/2023, 7:14 PMDaniele Segato
04/17/2023, 5:11 PMSolace Studios
04/20/2023, 3:08 AMIsak Hansson
04/20/2023, 1:04 PMAditya Mishra
04/23/2023, 10:34 AMEman
04/27/2023, 10:34 AMpost("api/auth/endpoint") {
// start - block of code that is repeated
val principal = call.principal<JWTPrincipal>()
val userId = principal?.getClaim("userId", String::class)
if (userId == null) {
call.respond(
HttpStatusCode.Forbidden,
CyrCloError(401, "User not authenticated. Please login in again")
)
return@post
}
// end
}
how can this code refactored? because i have been keep repeating that code to my other endpoints
Thanks,Solace Studios
04/28/2023, 4:20 AMkshvkantg
04/28/2023, 11:31 AMfun main() {
embeddedServer(Netty, port = 8080, host = "127.0.0.1", module = Application::module)
.start(wait = true)
}
fun Application.module() {
configureSecurity()
configureHTTP()
configureMonitoring()
configureSerialization()
configureDatabases()
configureRouting()
}
and running staus is [DefaultDispatcher-worker-1] INFO ktor.application - Responding at http://127.0.0.1:8080, same when host is "0.0.0.0" but when i redirect to http://127.0.0.1:8080 on my browser. I get an error stating "Safari cannot open the page". how can I fix this?sdeleuze
04/29/2023, 6:37 AMDamien O'Hara
04/29/2023, 9:29 AMDamien O'Hara
04/29/2023, 9:30 AMkotlin.reflect.KClass
seems to resolve without itDamien O'Hara
05/02/2023, 1:03 PMRichard
05/02/2023, 7:31 PMBack-end (JVM) Internal error: Failed to generate expression: KtCallExpression
File being compiled: (11,37) in /tmp.kt
The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.codegen.state.KotlinTypeMapper$Companion.getPackageMemberContainingClassesInfo(KotlinTypeMapper.kt:1378)
and restarts and such don't seem to helpSaher Al-Sous
05/04/2023, 6:50 PMhttps://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-fn-requestbut I'm getting internal server error
{
"timestamp": "2023-05-04T18:31:46.979+00:00",
"path": "/directory",
"status": 500,
"error": "Internal Server Error",
"requestId": "de9e7a88-1"
}
I keep getting this message in the console
2023-05-04T21:31:46.981+03:00 ERROR 47367 --- [or-http-epoll-2] a.w.r.e.AbstractErrorWebExceptionHandler : [de9e7a88-1] 500 Server Error for HTTP GET "/directory"
java.util.NoSuchElementException: No value received via onNext for awaitSingle
at kotlinx.coroutines.reactive.AwaitKt$awaitOne$2$1.onComplete(Await.kt:282) ~[kotlinx-coroutines-reactive-1.6.4.jar:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
*__checkpoint ⇢ HTTP GET "/directory" [ExceptionHandlingWebHandler]
Original Stack Trace:
at kotlinx.coroutines.reactive.AwaitKt$awaitOne$2$1.onComplete(Await.kt:282) ~[kotlinx-coroutines-reactive-1.6.4.jar:na]
at reactor.core.publisher.StrictSubscriber.onComplete(StrictSubscriber.java:123) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.FluxContextWrite$ContextWriteSubscriber.onComplete(FluxContextWrite.java:126) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2205) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.Operators$MultiSubscriptionSubscriber.onComplete(Operators.java:2205) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.MonoNext$NextSubscriber.onComplete(MonoNext.java:102) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.FluxPeek$PeekSubscriber.onComplete(FluxPeek.java:260) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.core.publisher.FluxMap$MapSubscriber.onComplete(FluxMap.java:144) ~[reactor-core-3.5.5.jar:3.5.5]
at reactor.netty.channel.FluxReceive.onInboundComplete(FluxReceive.java:413) ~[reactor-netty-core-1.1.6.jar:1.1.6]
at reactor.netty.channel.ChannelOperations.onInboundComplete(ChannelOperations.java:431) ~[reactor-netty-core-1.1.6.jar:1.1.6]
at reactor.netty.http.server.HttpServerOperations.onInboundNext(HttpServerOperations.java:663) ~[reactor-netty-http-1.1.6.jar:1.1.6]
at reactor.netty.channel.ChannelOperationsHandler.channelRead(ChannelOperationsHandler.java:113) ~[reactor-netty-core-1.1.6.jar:1.1.6]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at reactor.netty.http.server.HttpTrafficHandler.channelRead(HttpTrafficHandler.java:274) ~[reactor-netty-http-1.1.6.jar:1.1.6]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346) ~[netty-codec-4.1.91.Final.jar:4.1.91.Final]
at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333) ~[netty-codec-4.1.91.Final.jar:4.1.91.Final]
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:454) ~[netty-codec-4.1.91.Final.jar:4.1.91.Final]
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290) ~[netty-codec-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919) ~[netty-transport-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.epoll.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:800) ~[netty-transport-classes-epoll-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.epoll.EpollEventLoop.processReady(EpollEventLoop.java:499) ~[netty-transport-classes-epoll-4.1.91.Final.jar:4.1.91.Final]
at io.netty.channel.epoll.EpollEventLoop.run(EpollEventLoop.java:397) ~[netty-transport-classes-epoll-4.1.91.Final.jar:4.1.91.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.91.Final.jar:4.1.91.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.91.Final.jar:4.1.91.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.91.Final.jar:4.1.91.Final]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
2023-05-04T21:31:47.026+03:00 WARN 47367 --- [or-http-epoll-2] r.n.http.server.HttpServerOperations : [de9e7a88-1, L:/127.0.0.1:8080 - R:/127.0.0.1:42906] Decoding failed: FULL_REQUEST(decodeResult: failure(java.lang.IllegalArgumentException: text is empty (possibly HTTP/0.9)), version: HTTP/1.0, content: UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf(ridx: 0, widx: 0, cap: 0))
GET /bad-request HTTP/1.0
I tried this one as well request._bodyToMono_<SearchDirectoryDto>().awaitFirstOrNull()
but the result was null...Cru
05/05/2023, 5:13 PMDon Mitchell
05/11/2023, 7:16 PMexists
? it seems like it’s not an extension of Database or anything really but takes a query as an arg and returns an expression which implies it’s got to be a subquery. from what i can tell, we end up w the awkward double speak of
exists(
database.from(MyTable).select()
.where(MyTable.featureFlagId eq ALLOW_LEVEL_BIDDING)
).notExists
which leads me to wonder how the non extension function interacts w the extension function esp if one or both are `not`…Cies
05/11/2023, 8:00 PMgabfssilva
05/14/2023, 10:55 PMval pageNumberFlow = unboundedLongFlow(startsAt = 1)
val responseFlow: HttpResponse<String> =
pageNumberFlow
.map { page ->
get("<https://example.com>") {
query("page", "$page")
}
}
.sendAndHandle(bodyHandler = ofString, parallelism = 10)
.takeWhile { it.body() == "[]" }
With this, you can create a pagination flow with a parallelism factor of 10. All responses will be emitted sequentially, stopping the pagination once the first empty list arrives.
You may refer to the kdocs for more information.
- New Connector in Development #1 - Google Drive: The early version of the Google Drive connector is now available, probably with potential bugs (I have warned!). Initial implementation includes two APIs:
val serviceAccount: JsonNode = // provide your credentials here
val googleDriveApi = GoogleDriveApi(serviceAccount)
val files: Flow<GoogleDriveFile> =
googleDriveApi
.listFiles {
driveId = "x"
}
val fileContent: Flow<ByteArray> =
googleDriveApi.download(files.first().id)
- New Connector in Development #2 - GitHub API: I have kick-started the development of a GitHub API connector. The goal here is to enable the manipulation of an entire codebase using Kotlin flows.
- New Connector in Development #3 - OpenAI API: All the kids are trying it nowadays, so, why not? While still in its early stages and likely to have bugs, I imagine multiple possibilities such as streaming large amounts of data for model training and building documentation using data from other connectors.
- JSON Connector Fixes: Some issues were fixed in the JSON connector where non-trimmed string data was parsed incorrectly. Also, we've refined the function names for better readability and conciseness.
Not necessarily related to the version release, but:
- Added the first examples: Practical examples showcasing the capabilities of River-kt were added. Currently, we have three examples: JSON streaming (using Ktor as the HTTP server), downloading an CSV file from S3, parsing it, and saving each line to a PostgreSQL database via JDBC, and listening to an SQS queue and forwarding the requests to an HTTP API. More examples are in the oven.
- Issues for future development: I have filled the repository with issues to map the future development of other connectors. This will not only help us gather community feedback on the most requested connectors but also provide visibility into ongoing development.
Stay tuned for more updates, and thank you for your support!Marcin Krykowski
05/16/2023, 3:10 PMThiago
05/17/2023, 1:22 PMSamusev Semën
05/19/2023, 2:20 PM/callback?error=access_denied&error_description=...
And since my /callback
endpoint under authenticate
block Ktor server behaves incorrectly - essentially it runs authorization flow again (since there is no authenticated OAuth2 proncipal, user redirects back to discord authorization window).
Expected behaviour: let me handle this error and show to the user.
Any advices how to tackle this problem?Lucas León
05/20/2023, 8:02 AM<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
<executions>
<execution>
<id>kapt</id>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId><http://com.redis.om|com.redis.om></groupId>
<artifactId>redis-om-spring</artifactId>
<version>0.8.0</version>
</annotationProcessorPath>
</annotationProcessorPaths>
</configuration>
</execution>
</executions>
<configuration>
<args>
<arg>-Xjsr305=strict</arg>
</args>
<compilerPlugins>
<plugin>spring</plugin>
</compilerPlugins>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
But I’m getting this error: exception java.lang.NoSuchFieldException is never thrown in body of corresponding try statement
And this is the generated class
public final class UserInfoHash$ {
public static MetamodelField<UserInfoHash, String> _KEY;
static {
try {
_KEY = new MetamodelField<UserInfoHash, String>("__key", String.class, true);
} catch(NoSuchFieldException | SecurityException e) {
System.err.println(e.getMessage());
}
}
}
Can someone help me with this please?