Roy Nard
12/09/2019, 2:49 PMpdegand
12/10/2019, 2:37 PMwebClient.get()...awaitExchange().awaitBody()
and webClient.get()...retrieve().awaitBody()
?Anders Mikkelsen
12/10/2019, 2:46 PMAnders Mikkelsen
12/10/2019, 2:46 PMpdegand
12/10/2019, 2:49 PMretrieve().awaitBody()
Anders Mikkelsen
12/10/2019, 2:50 PMAnders Mikkelsen
12/10/2019, 2:51 PMpdegand
12/10/2019, 2:58 PMpdegand
12/10/2019, 3:03 PMweblient().get()...awaitExchange().awaitBody()
call.
I have setup a MockWebServer from OkHttp and for a first try, I just want to see if I can get the String of the body, so I did something like
@Test
fun myTest() = runBlockingTest {
val mockResponse = MockResponse().apply { setBody("foo") }
mockServer.enqueue(mockResponse)
val string = webclient.get().uri(mockServer.url("/").toString).awaitExchange().awaitBody()
assertThat(string).isEqualTo("foo")
}
But the test is crashing with IllegaleStateException : This job has not completed yet
pdegand
12/10/2019, 3:04 PMrunBlockingTest
, if I switch to runBlocking
the issue is gone and the test passes, but I would like to understand a bit why it’s not working with runBlockingTest
Anders Mikkelsen
12/10/2019, 3:17 PMpdegand
12/10/2019, 3:24 PMpdegand
12/10/2019, 3:24 PMAnders Mikkelsen
12/10/2019, 5:34 PMGerard Klijs
12/10/2019, 7:16 PM.cancel()
but they are only really stopped once the connection with the client is broken.
https://github.com/ExpediaGroup/graphql-kotlin/pull/510Philipp Mayer
12/16/2019, 3:56 PMfun main(args: Array<String>) {
runApplication<SomeApplicationName>(*args)
}
//<https://docs.spring.io/spring/docs/4.2.x/spring-framework-reference/html/cors.html>
@Configuration
@EnableWebMvc
class CorsConfig: WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**")
}
}
Philipp Mayer
12/16/2019, 4:01 PM@Configuration
class CorsConfig : WebMvcConfigurer {
override fun addCorsMappings(registry: CorsRegistry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD")
.allowCredentials(true)
}
}
@Bean
fun cors(): FilterRegistrationBean<CorsFilter> {
val source = UrlBasedCorsConfigurationSource()
val config = CorsConfiguration()
config.setAllowCredentials(true)
config.setAllowedOrigins(Collections.singletonList("*"))
config.setAllowedMethods(Collections.singletonList("*"))
config.setAllowedHeaders(Collections.singletonList("*"))
source.registerCorsConfiguration("/**", config)
val bean = FilterRegistrationBean(CorsFilter(source))
bean.setOrder(0)
return bean
}
leodeng
12/16/2019, 4:22 PMleodeng
12/16/2019, 4:24 PMleodeng
12/16/2019, 4:24 PMPhilipp Mayer
12/17/2019, 7:00 AMDave Jensen
12/18/2019, 7:15 PMDave Jensen
12/18/2019, 7:19 PMDave Jensen
12/24/2019, 5:09 AMCrudRepository.findByIdOrNull
not documented?Dave Jensen
12/24/2019, 5:22 AMbjonnh
01/10/2020, 5:17 PMPhilipp Mayer
01/12/2020, 6:36 PMfun routes(indexController: IndexController) = router {
GET("/index", indexController::getIndex)
GET("/uptime", indexController::getUptime)
}
controller:
@Suppress("UNUSED_PARAMETER")
class IndexController(private val indexTemplate: IndexTemplate) {
fun getIndex(req: ServerRequest) = ok().render("index", indexTemplate.index)
and the HTML:
import kotlinx.html.div
import kotlinx.html.dom.create
import kotlinx.html.p
import org.w3c.dom.Document
class IndexTemplate(document: Document) {
val index = document.create.div {
p { +"Hello" }
p { +"you" }
}
}
However, I can't find the way to respond with html.
Unfortunately, sources about the usage of kotlinxhtml and spring are really rare (understandable ofc)thiagoretondar
01/13/2020, 11:31 AMsuspend fun
?jordigarcl
01/13/2020, 12:21 PMapplicationEventPublished.publish(event)
in a kotlin coroutine is a good alternative to Spring’s @Async
method for asynchronous processing of events.
This is a Spring Boot application (No Webflux), so the Controller would have to implement CoroutineScope
to avoid using GlobalScope.Dave Jensen
01/14/2020, 5:42 PM