Christian Dräger
12/28/2020, 10:44 AM// lets assume i have some basic crud repository like:
interface MyFunkyRepository : CrudRepository<MyFunkyEntity, String>
@Entity(name = "funky")
@Table(name = "funky")
class MyFunkyEntity(
@Id
var id: String = UUID.randomUUID().toString(),
@Column(name = "title", nullable = false)
var title: String,
@Column(name = "description", nullable = false)
var description: String,
)
// and i have a service that is using the repository
@Service
class MyFunkyService(
private val myFunkyRepository: MyFunkyRepository,
) {
fun funkyAmount() = myFunkyRepository.count()
fun addFunkiness(f: MyFunkyEntity) = myFunkyRepository.save(f)
}
// now i would like to write a little internal DSL to add entries to the repository by using the service
@DslMarker
annotation class MyFunkyDsl
@MyFunkyDsl
fun <T> addFunkyStuff(init: MyFunkyEntity.() -> T): T {
// TODO: somehow inject MyFunkyService and store fields set by init callback
}
// so i could just use 'addFunkyStuff' lambda anywhere in my code like this:
class UseDslExample {
fun someFunction() {
addFunkyStuff {
title = "xyz"
description = "abcd"
}
}
}
is this possible in any way or what could be an alternative approach to write an DSL for a use-case like that?wakingrufus
12/30/2020, 3:08 PMNikky
01/06/2021, 12:00 PMspring:=
rsocket:
server:
port: 8080
transport: websocket
mapping-path: "rsocket"
in a way that it shares the port with the existing http server ?
we cannot expose additional ports and this would force us to switch to a different platform or deployment optionPhilipp Mayer
01/06/2021, 8:46 PM@Configuration
class?
Usually, one would define it as follows:
@ConstructorBinding
@ConfigurationProperties(prefix = "rooms")
class RoomConfigurationProperties(val filePath: String)
But due to modularization, I have a configuration class for the whole module (speak: maven module) whichs looks similiar to that:
@Configuration
@ComponentScan
class RoomConfig {
@Bean
@ConfigurationProperties(prefix = "rooms")
fun properties(filePath: String) = RoomConfigurationProperties(filePath)
/*...*/
}
However, since the filepath is a constructor parameter, I of course have to supply it and I'm not sure how. Any hint would be appreciated, I unfortunately didn't find what I was looking for in the docs.gotoOla
01/08/2021, 2:39 PMkqr
01/09/2021, 12:13 AMSourabh Rawat
01/10/2021, 6:37 AMWARNING: A HTTP GET method, public final java.lang.Object com.example.demo.FooController.bar(java.lang.String,kotlin.coroutines.Continuation), should not consume any entity.
WARNING: Parameter 1 of type kotlin.coroutines.Continuation<? super java.lang.String> from public final java.lang.Object com.example.demo.FooController.foobar(kotlin.coroutines.Continuation<? super java.lang.String>) is not resolvable to a concrete type.
WARNING: A HTTP GET method, public final java.lang.Object com.example.demo.FooController.foobar(kotlin.coroutines.Continuation), should not consume any entity.
2021-01-10 11:51:30.715 ERROR 20636 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[.[.e.demo.JerseyConfig] : Servlet.service() for servlet [com.example.demo.JerseyConfig] in context with path [] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException: null
at kotlinx.coroutines.CoroutineScopeKt.coroutineScope(CoroutineScope.kt:193) ~[kotlinx-coroutines-core-jvm-1.4.2.jar:na]
at com.example.demo.FooController.bar(FooController.kt:36) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
Code:
@GET
@Path("{name}")
@Produces(MediaType.APPLICATION_JSON)
suspend fun bar(@PathParam("name") name: String): Bar = coroutineScope {
val foo = async { Bar(name) }
foo.await()
}
Dariusz Kuc
01/17/2021, 2:59 AMval rawBodyContent = serverRequest.bodyToMono(String::class.java).awaitFirst()
val jsonNode = objectMapper.readTree(rawBodyContent)
if (jsonNode.isArray) {
objectMapper.convertValue(jsonNode, object: TypeReference<List<MyItem>>() {})
} else {
objectMapper.treeToValue(jsonNode, MyItem::class.java)
}
marzelwidmer
01/19/2021, 5:12 AMandy.burdett
01/19/2021, 6:43 PMhttp {
httpBasic {}
authorizeRequests {
authorize("/greetings/**", hasAuthority("ROLE_ADMIN"))
authorize("/**", permitAll)
}
}
Dariusz Kuc
01/21/2021, 3:53 PMSlackbot
01/22/2021, 1:54 PMxii
01/28/2021, 4:25 PMImran/Malic
01/28/2021, 5:06 PMMockBean
bjonnh
02/01/2021, 3:51 AMdodalovic
02/05/2021, 10:45 AMbootBuildImage
and GitHub Actions to the AWS ECS ?
Thanks in advance!Alexis Cala Martínez
02/05/2021, 6:30 PMmarzelwidmer
02/07/2021, 8:34 AMFunction,Supplier,Consumer
do I need maybe also the spring-cloud-function-kotlin
for this ? I try to migrate my sample application to the new API
@SpringBootApplication
class ProducerApplication
fun main(args: Array<String>) {
runApplication<ProducerApplication>(*args)
}
@RestController
@RequestMapping(value = ["/producer"])
class ProducerController(private val producerMessagingService: ProducerMessagingService) {
private val log = LoggerFactory.getLogger(javaClass)
@PostMapping(value = ["{message}"])
fun message(@PathVariable message: String) {
<http://log.info|log.info>("------------> Receive message {} <-------------", message)
producerMessagingService.sendMessage(message)
}
}
@Service
class ProducerMessagingService(private val producerSource: ProducerSource) {
fun sendMessage(message: String) = producerSource.producerChannel().send(MessageBuilder.withPayload(message).build())
}
interface ProducerSource {
@Output(value = "producerOutput")
fun producerChannel(): MessageChannel
}
@Configuration
@EnableBinding(value = [ProducerSource::class])
class MessagingConfig
Mar Mar
02/13/2021, 4:51 AMantonarhipov
02/16/2021, 3:21 PMDenis Sazonov
02/17/2021, 6:29 AMgotoOla
02/17/2021, 7:15 PMgotoOla
02/22/2021, 1:13 PM`fun springSecurityFilterChain(http: ServerHttpSecurity): SecurityWebFilterChain? =
http.csrf().disable().authorizeExchange()
.anyExchange().permitAll()
.and()
.oauth2Client()
.and()
.oauth2ResourceServer { it.opaqueToken(withDefaults()) }
.build()
and my Principal gets populated with the fields from the token as a BearerTokenAuthentication (I'm guessing this happens within the oauth2ResourceServer-block?)
I'd like to add a layer where I can map the given role to some permissions specifically for my back end service. How should one go about this?
I've tried implementing an AuthoritiesExtractor and PrincipalExtractor and exposed them as @Components but they never seem to be called (I am using webflux with spring 2.2.6.RELEASE)
I guess I could do a roleToPermissionService and call that immediately from the controller but it feels a bit non-springy123
02/23/2021, 12:47 PMigor.wojda
02/23/2021, 10:06 PMinit
bean as top-level function? (now this bean does not run)
@SpringBootApplication
class TestServerApplication
fun main(args: Array<String>) {
runApplication<TestServerApplication>(*args)
}
@Bean
fun init(repository: StreamRepository) = ApplicationRunner { _ ->
// Do sth on app start
}
This makes a bean run, but this solution involves a lot of nesting, so wonder if this is necessary 🤔
@SpringBootApplication
class InboxionServerApplication {
companion object {
@JvmStatic
fun main(args: Array<String>) {
runApplication<InboxionServerApplication>(*args)
}
}
@Bean
fun init(repository: StreamRepository) = ApplicationRunner { _ ->
// Do sth on app start
}
}
Christian Dräger
03/08/2021, 10:16 PMsubprojects {
tasks {
withType<KotlinCompile> {
dependsOn(ktlintFormat)
kotlinOptions {
jvmTarget = "1.8"
apiVersion = "1.5"
languageVersion = "1.5"
freeCompilerArgs = listOf("-Xjsr305=strict")
}
}
when running the app via gradle everything works fine but having intellij showing up errors all the time isn’t nice for the workflow ^^
any hint what could be the problem here?iamkdblue
03/09/2021, 3:12 PMgotoOla
03/10/2021, 12:27 PMval reactorContext = coroutineContext[ReactorContext.Key]!!.context.asCoroutineContext()
but if I try to write a unit-test for this I fail with a nullpointerException since I guess the coroutineContext[ReactorContext.Key] is populated from the context given by spring/the controller layer? ?Alfred Lopez
03/10/2021, 4:01 PM123
03/12/2021, 5:07 PMA
and A_Log
with relations:
@Entity data class A (val log: A_Log)
@Entity data class A_Log(val a: A, val price: Int)
And a method which persists them:
@Transactional fun persist(val dto: PriceDto) {
val a: A = A(???)
val log: A_Log = (a, price = dto.price)
// persist methods
}
I think the problem is clear, any way to solve this egg-or-chicken problem except making fields nullable and using (!!
) elsewhere in code?