Search in sources :

Example 1 with RSocketRequester

use of org.springframework.messaging.rsocket.RSocketRequester in project spring-framework by spring-projects.

the class RSocketMessageHandler method createResponder.

private MessagingRSocket createResponder(ConnectionSetupPayload setupPayload, RSocket rsocket) {
    String str = setupPayload.dataMimeType();
    MimeType dataMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultDataMimeType;
    Assert.notNull(dataMimeType, "No `dataMimeType` in ConnectionSetupPayload and no default value");
    Assert.isTrue(isDataMimeTypeSupported(dataMimeType), "Data MimeType '" + dataMimeType + "' not supported");
    str = setupPayload.metadataMimeType();
    MimeType metaMimeType = StringUtils.hasText(str) ? MimeTypeUtils.parseMimeType(str) : this.defaultMetadataMimeType;
    Assert.notNull(metaMimeType, "No `metadataMimeType` in ConnectionSetupPayload and no default value");
    RSocketRequester requester = RSocketRequester.wrap(rsocket, dataMimeType, metaMimeType, this.strategies);
    return new MessagingRSocket(dataMimeType, metaMimeType, getMetadataExtractor(), requester, this, obtainRouteMatcher(), this.strategies);
}
Also used : RSocketRequester(org.springframework.messaging.rsocket.RSocketRequester) MimeType(org.springframework.util.MimeType) WellKnownMimeType(io.rsocket.metadata.WellKnownMimeType)

Example 2 with RSocketRequester

use of org.springframework.messaging.rsocket.RSocketRequester in project spring-framework by spring-projects.

the class RSocketRequesterMethodArgumentResolver method resolveArgument.

@Override
public Mono<Object> resolveArgument(MethodParameter parameter, Message<?> message) {
    Object headerValue = message.getHeaders().get(RSOCKET_REQUESTER_HEADER);
    Assert.notNull(headerValue, "Missing '" + RSOCKET_REQUESTER_HEADER + "'");
    Assert.isInstanceOf(RSocketRequester.class, headerValue, "Expected header value of type RSocketRequester");
    RSocketRequester requester = (RSocketRequester) headerValue;
    Class<?> type = parameter.getParameterType();
    if (RSocketRequester.class.equals(type)) {
        return Mono.just(requester);
    } else if (RSocket.class.isAssignableFrom(type)) {
        return Mono.justOrEmpty(requester.rsocket());
    } else {
        return Mono.error(new IllegalArgumentException("Unexpected parameter type: " + parameter));
    }
}
Also used : RSocketRequester(org.springframework.messaging.rsocket.RSocketRequester) RSocket(io.rsocket.RSocket)

Aggregations

RSocketRequester (org.springframework.messaging.rsocket.RSocketRequester)2 RSocket (io.rsocket.RSocket)1 WellKnownMimeType (io.rsocket.metadata.WellKnownMimeType)1 MimeType (org.springframework.util.MimeType)1