-
Notifications
You must be signed in to change notification settings - Fork 357
Description
环境:
server:id 'org.springframework.boot' version '2.7.2'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.security:spring-security-rsocket'
implementation 'org.springframework.security:spring-security-messaging'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-rsocket'
client:
implementation 'io.rsocket:rsocket-core:1.1.2'
implementation 'io.rsocket:rsocket-transport-netty:1.1.2'
我现在遇到的情况
- spring client jwt: connect OK
@ShellMethod
fun conn() {
val tokenMetadata = BearerTokenMetadata(token)
val uri = URI.create("ws://localhost:7002")
rSocketRequester = RSocketRequester.builder()
.setupMetadata(tokenMetadata, SIMPLE_AUTH)
.setupData("android_1234,333")
.rsocketStrategies {
it.encoder(BearerTokenAuthenticationEncoder(),ProtobufEncoder())
.decoder( ProtobufDecoder())
}
.websocket(uri)
}- spring client jwt: route OK
@ShellMethod
fun getuser() {
val tokenMetadata = BearerTokenMetadata(token)
val newBuilder = UsersPro.Users.newBuilder()
newBuilder.setAccount("123abc")
val build = newBuilder.build()
rSocketRequester!!
.route("user.get")
.metadata(tokenMetadata,SIMPLE_AUTH)
.data(build.toByteArray())
.retrieveMono(ByteArray::class.java)
.doOnSuccess {
println("ok")
}
.doOnError {
it.printStackTrace()
}
.subscribe()
}- rsocket client jwt: connect OK
fun connect() {
val uri = URI.create("ws://localhost:7002")
val transport = WebsocketClientTransport.create(uri)
val metadata = ByteBufAllocator.DEFAULT.compositeBuffer()
val bearerMetadata2 = AuthMetadataCodec.encodeMetadata(
ByteBufAllocator.DEFAULT,
WellKnownAuthType.BEARER,
Unpooled.copiedBuffer(token, CharsetUtil.UTF_8)
)
CompositeMetadataCodec.encodeAndAddMetadata(
metadata, ByteBufAllocator.DEFAULT,
WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.string,
bearerMetadata2
)
rSocket = RSocketConnector.create()
.metadataMimeType(WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.string)
.dataMimeType(WellKnownMimeType.APPLICATION_CBOR.string)
.setupPayload(DefaultPayload.create("1234,321".toByteArray(),ByteBufUtil.getBytes(metadata)))
.keepAlive(Duration.ofSeconds(30), Duration.ofMinutes(30))
.reconnect(Retry.fixedDelay(3, Duration.ofSeconds(5)).doBeforeRetry {
log.error("Retry {}", "" + it.totalRetries())
})
.connect(transport)
}- rsocket client jwt: route Error
2022-09-11 15:40:03.991 ERROR 56777 --- [actor-tcp-nio-2] Routing : Error Destination '' does not support REQUEST_RESPONSE. Supported interaction(s): [SETUP, METADATA_PUSH]
Destination '' does not support REQUEST_RESPONSE. Supported interaction(s): [SETUP, METADATA_PUSH]
Details of the error have been omitted. You can use the stacktrace command to print the full stacktrace.
val metadata = ByteBufAllocator.DEFAULT.compositeBuffer()
val routingMetadata = TaggingMetadataCodec.createRoutingMetadata(ByteBufAllocator.DEFAULT, listOf("user.get"))
CompositeMetadataCodec.encodeAndAddMetadata(
metadata, ByteBufAllocator.DEFAULT,
WellKnownMimeType.MESSAGE_RSOCKET_ROUTING,
routingMetadata.content
)
val bearerMetadata2 = AuthMetadataCodec.encodeMetadata(
ByteBufAllocator.DEFAULT,
WellKnownAuthType.BEARER,
Unpooled.copiedBuffer(token, CharsetUtil.UTF_8)
)
CompositeMetadataCodec.encodeAndAddMetadata(
metadata, ByteBufAllocator.DEFAULT,
WellKnownMimeType.MESSAGE_RSOCKET_AUTHENTICATION.string,
bearerMetadata2
)
val metaBuilder = MetaPro.Meta.newBuilder()
metaBuilder.setAppId(appId).setV(1.0).setPage(0).setPageSize(10)
val newBuilder = UsersPro.Users.newBuilder()
newBuilder.setId(id.toLong())
val build = newBuilder.build()
val res = rSocket!!
.requestResponse(DefaultPayload.create(build.toByteArray(), ByteBufUtil.getBytes(metadata)))
.doOnError {
log.error("Error {}",it.message)
}
.block()Can you give some examples? No answer found in AuthMetadataCodecTest
val block = rSocket!!.metadataPush(ByteBufPayload.create("123".toByteArray(), ByteBufUtil.getBytes(metadata))).block()
ERROR 67093 --- [ctor-http-nio-7] o.s.m.h.i.reactive.InvocableHelper : No exception handling method
org.springframework.messaging.handler.invocation.MethodArgumentResolutionException: Could not resolve method parameter at index 1 in public void RSocketRouting.connect(org.springframework.messaging.rsocket.RSocketRequester,java.lang.String): Payload content is missing: public void RSocketRouting.connect(org.springframework.messaging.rsocket.RSocketRequester,java.lang.String)
at org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver.handleMissingBody(PayloadMethodArgumentResolver.java:281)

