19
19
import java .lang .reflect .Method ;
20
20
import java .util .Collections ;
21
21
import java .util .List ;
22
- import java .util .function .BiFunction ;
23
22
24
23
import org .springframework .context .ApplicationContext ;
25
24
import org .springframework .core .MethodParameter ;
26
- import org .springframework .lang .Nullable ;
27
25
import org .springframework .messaging .Message ;
28
26
import org .springframework .messaging .ReactiveMessageHandler ;
29
27
import org .springframework .messaging .handler .CompositeMessageCondition ;
30
28
import org .springframework .messaging .handler .DestinationPatternsMessageCondition ;
31
29
import org .springframework .messaging .handler .invocation .reactive .HandlerMethodArgumentResolver ;
32
30
import org .springframework .messaging .handler .invocation .reactive .SyncHandlerMethodArgumentResolver ;
33
- import org .springframework .messaging .rsocket .RSocketRequester ;
34
- import org .springframework .messaging .rsocket .RSocketStrategies ;
35
- import org .springframework .messaging .rsocket .annotation .support .DefaultMetadataExtractor ;
36
- import org .springframework .messaging .rsocket .annotation .support .MetadataExtractor ;
31
+ import org .springframework .messaging .rsocket .annotation .support .RSocketFrameTypeMessageCondition ;
37
32
import org .springframework .messaging .rsocket .annotation .support .RSocketMessageHandler ;
38
- import org .springframework .util .Assert ;
39
- import org .springframework .util .MimeType ;
40
- import org .springframework .util .MimeTypeUtils ;
41
33
import org .springframework .util .ReflectionUtils ;
42
- import org .springframework .util .StringUtils ;
43
-
44
- import io .rsocket .ConnectionSetupPayload ;
45
- import io .rsocket .RSocket ;
46
34
47
35
/**
48
36
* The {@link RSocketMessageHandler} extension for Spring Integration needs.
@@ -60,63 +48,10 @@ class IntegrationRSocketMessageHandler extends RSocketMessageHandler {
60
48
private static final Method HANDLE_MESSAGE_METHOD =
61
49
ReflectionUtils .findMethod (ReactiveMessageHandler .class , "handleMessage" , Message .class );
62
50
63
- @ Nullable
64
- private MimeType defaultDataMimeType ;
65
-
66
- private MimeType defaultMetadataMimeType = IntegrationRSocket .COMPOSITE_METADATA ;
67
-
68
- private MetadataExtractor metadataExtractor ;
69
-
70
51
IntegrationRSocketMessageHandler () {
71
52
setHandlerPredicate ((clazz ) -> false );
72
53
}
73
54
74
- /**
75
- * Configure the default content type to use for data payloads.
76
- * <p>By default this is not set. However a server acceptor will use the
77
- * content type from the {@link io.rsocket.ConnectionSetupPayload}, so this is typically
78
- * required for clients but can also be used on servers as a fallback.
79
- * @param defaultDataMimeType the MimeType to use
80
- */
81
- @ Override
82
- public void setDefaultDataMimeType (@ Nullable MimeType defaultDataMimeType ) {
83
- super .setDefaultDataMimeType (defaultDataMimeType );
84
- this .defaultDataMimeType = defaultDataMimeType ;
85
- }
86
-
87
-
88
- /**
89
- * Configure the default {@code MimeType} for payload data if the
90
- * {@code SETUP} frame did not specify one.
91
- * <p>By default this is set to {@code "message/x.rsocket.composite-metadata.v0"}
92
- * @param mimeType the MimeType to use
93
- */
94
- @ Override
95
- public void setDefaultMetadataMimeType (MimeType mimeType ) {
96
- super .setDefaultMetadataMimeType (mimeType );
97
- this .defaultMetadataMimeType = mimeType ;
98
- }
99
-
100
- /**
101
- * Configure a {@link MetadataExtractor} to extract the route and possibly
102
- * other metadata from the first payload of incoming requests.
103
- * <p>By default this is a {@link DefaultMetadataExtractor} with the
104
- * configured {@link RSocketStrategies} (and decoders), extracting a route
105
- * from {@code "message/x.rsocket.routing.v0"} or {@code "text/plain"}
106
- * metadata entries.
107
- * @param extractor the extractor to use
108
- */
109
- @ Override
110
- public void setMetadataExtractor (MetadataExtractor extractor ) {
111
- super .setMetadataExtractor (extractor );
112
- this .metadataExtractor = extractor ;
113
- }
114
-
115
- @ Override
116
- public BiFunction <ConnectionSetupPayload , RSocket , RSocket > clientAcceptor () {
117
- return this ::createRSocket ;
118
- }
119
-
120
55
public boolean detectEndpoints () {
121
56
ApplicationContext applicationContext = getApplicationContext ();
122
57
if (applicationContext != null && getHandlerMethods ().isEmpty ()) {
@@ -135,6 +70,7 @@ public boolean detectEndpoints() {
135
70
public void addEndpoint (IntegrationRSocketEndpoint endpoint ) {
136
71
registerHandlerMethod (endpoint , HANDLE_MESSAGE_METHOD ,
137
72
new CompositeMessageCondition (
73
+ RSocketFrameTypeMessageCondition .REQUEST_CONDITION ,
138
74
new DestinationPatternsMessageCondition (endpoint .getPath (), getRouteMatcher ())));
139
75
}
140
76
@@ -143,36 +79,6 @@ protected List<? extends HandlerMethodArgumentResolver> initArgumentResolvers()
143
79
return Collections .singletonList (new MessageHandlerMethodArgumentResolver ());
144
80
}
145
81
146
- @ Override
147
- public void afterPropertiesSet () {
148
- super .afterPropertiesSet ();
149
- if (this .metadataExtractor == null ) {
150
- DefaultMetadataExtractor extractor = new DefaultMetadataExtractor (getRSocketStrategies ()); // NOSONAR
151
- extractor .metadataToExtract (MimeTypeUtils .TEXT_PLAIN , String .class , MetadataExtractor .ROUTE_KEY );
152
- this .metadataExtractor = extractor ;
153
- }
154
- }
155
-
156
- protected IntegrationRSocket createRSocket (ConnectionSetupPayload setupPayload , RSocket rsocket ) {
157
- String mimeType = setupPayload .dataMimeType ();
158
- MimeType dataMimeType =
159
- StringUtils .hasText (mimeType )
160
- ? MimeTypeUtils .parseMimeType (mimeType )
161
- : this .defaultDataMimeType ;
162
- Assert .notNull (dataMimeType , "No `dataMimeType` in ConnectionSetupPayload and no default value" );
163
- mimeType = setupPayload .metadataMimeType ();
164
- MimeType metaMimeType =
165
- StringUtils .hasText (mimeType )
166
- ? MimeTypeUtils .parseMimeType (mimeType )
167
- : this .defaultMetadataMimeType ;
168
- Assert .notNull (dataMimeType , "No `metadataMimeType` in ConnectionSetupPayload and no default value" );
169
- RSocketStrategies rSocketStrategies = getRSocketStrategies ();
170
- Assert .notNull (rSocketStrategies , "No `rSocketStrategies` provided" );
171
- RSocketRequester requester = RSocketRequester .wrap (rsocket , dataMimeType , metaMimeType , rSocketStrategies );
172
- return new IntegrationRSocket (this , getRouteMatcher (), requester , dataMimeType , metaMimeType ,
173
- this .metadataExtractor , rSocketStrategies .dataBufferFactory ());
174
- }
175
-
176
82
private static final class MessageHandlerMethodArgumentResolver implements SyncHandlerMethodArgumentResolver {
177
83
178
84
@ Override
0 commit comments