|
17 | 17 | package org.springframework.web.socket.adapter;
|
18 | 18 |
|
19 | 19 | import java.nio.ByteBuffer;
|
20 |
| - |
21 | 20 | import javax.websocket.DecodeException;
|
22 | 21 | import javax.websocket.Decoder;
|
23 | 22 | import javax.websocket.EncodeException;
|
|
65 | 64 | *
|
66 | 65 | * @author Phillip Webb
|
67 | 66 | * @since 4.0
|
68 |
| - * |
69 |
| - * @param <T> The type being converted to (for Encoder) or from (for Decoder) |
70 |
| - * @param <M> The WebSocket message type ({@link String} or {@link ByteBuffer}) |
71 |
| - * |
| 67 | + * @param <T> the type being converted to (for Encoder) or from (for Decoder) |
| 68 | + * @param <M> the WebSocket message type ({@link String} or {@link ByteBuffer}) |
72 | 69 | * @see ConvertingEncoderDecoderSupport.BinaryEncoder
|
73 | 70 | * @see ConvertingEncoderDecoderSupport.BinaryDecoder
|
74 | 71 | * @see ConvertingEncoderDecoderSupport.TextEncoder
|
@@ -107,15 +104,13 @@ public void destroy() {
|
107 | 104 | */
|
108 | 105 | protected ConversionService getConversionService() {
|
109 | 106 | ApplicationContext applicationContext = getApplicationContext();
|
110 |
| - Assert.state(applicationContext != null, |
111 |
| - "Unable to locate the Spring ApplicationContext"); |
| 107 | + Assert.state(applicationContext != null, "Unable to locate the Spring ApplicationContext"); |
112 | 108 | try {
|
113 | 109 | return applicationContext.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class);
|
114 | 110 | }
|
115 | 111 | catch (BeansException ex) {
|
116 |
| - throw new IllegalStateException( |
117 |
| - "Unable to find ConversionService, please configure a '" |
118 |
| - + CONVERSION_SERVICE_BEAN_NAME + "' or override getConversionService()", ex); |
| 112 | + throw new IllegalStateException("Unable to find ConversionService: please configure a '" + |
| 113 | + CONVERSION_SERVICE_BEAN_NAME + "' or override the getConversionService() method", ex); |
119 | 114 | }
|
120 | 115 | }
|
121 | 116 |
|
@@ -148,8 +143,12 @@ protected TypeDescriptor getMessageType() {
|
148 | 143 | }
|
149 | 144 |
|
150 | 145 | private Class<?>[] resolveTypeArguments() {
|
151 |
| - return GenericTypeResolver.resolveTypeArguments(getClass(), |
152 |
| - ConvertingEncoderDecoderSupport.class); |
| 146 | + Class<?>[] resolved = GenericTypeResolver.resolveTypeArguments(getClass(), ConvertingEncoderDecoderSupport.class); |
| 147 | + if (resolved == null) { |
| 148 | + throw new IllegalStateException("ConvertingEncoderDecoderSupport's generic types T and M " + |
| 149 | + "need to be substituted in subclass: " + getClass()); |
| 150 | + } |
| 151 | + return resolved; |
153 | 152 | }
|
154 | 153 |
|
155 | 154 | /**
|
@@ -185,63 +184,56 @@ public T decode(M message) throws DecodeException {
|
185 | 184 | }
|
186 | 185 | catch (ConversionException ex) {
|
187 | 186 | if (message instanceof String) {
|
188 |
| - throw new DecodeException((String) message, "Unable to decode " + |
189 |
| - "websocket message using ConversionService", ex); |
| 187 | + throw new DecodeException((String) message, |
| 188 | + "Unable to decode websocket message using ConversionService", ex); |
190 | 189 | }
|
191 | 190 | if (message instanceof ByteBuffer) {
|
192 |
| - throw new DecodeException((ByteBuffer) message, "Unable to decode " + |
193 |
| - "websocket message using ConversionService", ex); |
| 191 | + throw new DecodeException((ByteBuffer) message, |
| 192 | + "Unable to decode websocket message using ConversionService", ex); |
194 | 193 | }
|
195 | 194 | throw ex;
|
196 | 195 | }
|
197 | 196 | }
|
198 | 197 |
|
199 | 198 |
|
200 | 199 | /**
|
201 |
| - * A Binary {@link javax.websocket.Encoder.Binary javax.websocket.Encoder} that |
202 |
| - * delegates to Spring's conversion service. See |
203 |
| - * {@link ConvertingEncoderDecoderSupport} for details. |
204 |
| - * |
205 |
| - * @param <T> The type that this Encoder can convert to. |
| 200 | + * A binary {@link javax.websocket.Encoder.Binary javax.websocket.Encoder} that delegates |
| 201 | + * to Spring's conversion service. See {@link ConvertingEncoderDecoderSupport} for details. |
| 202 | + * @param <T> the type that this Encoder can convert to |
206 | 203 | */
|
207 |
| - public static abstract class BinaryEncoder<T> extends |
208 |
| - ConvertingEncoderDecoderSupport<T, ByteBuffer> implements Encoder.Binary<T> { |
| 204 | + public static abstract class BinaryEncoder<T> extends ConvertingEncoderDecoderSupport<T, ByteBuffer> |
| 205 | + implements Encoder.Binary<T> { |
209 | 206 | }
|
210 | 207 |
|
211 | 208 |
|
212 | 209 | /**
|
213 |
| - * A Binary {@link javax.websocket.Encoder.Binary javax.websocket.Encoder} that delegates |
214 |
| - * to Spring's conversion service. See {@link ConvertingEncoderDecoderSupport} for |
215 |
| - * details. |
216 |
| - * |
217 |
| - * @param <T> The type that this Decoder can convert from. |
| 210 | + * A binary {@link javax.websocket.Encoder.Binary javax.websocket.Encoder} that delegates |
| 211 | + * to Spring's conversion service. See {@link ConvertingEncoderDecoderSupport} for details. |
| 212 | + * @param <T> the type that this Decoder can convert from |
218 | 213 | */
|
219 |
| - public static abstract class BinaryDecoder<T> extends |
220 |
| - ConvertingEncoderDecoderSupport<T, ByteBuffer> implements Decoder.Binary<T> { |
| 214 | + public static abstract class BinaryDecoder<T> extends ConvertingEncoderDecoderSupport<T, ByteBuffer> |
| 215 | + implements Decoder.Binary<T> { |
221 | 216 | }
|
222 | 217 |
|
223 | 218 |
|
224 | 219 | /**
|
225 |
| - * A Text {@link javax.websocket.Encoder.Text javax.websocket.Encoder} that delegates |
| 220 | + * A text {@link javax.websocket.Encoder.Text javax.websocket.Encoder} that delegates |
226 | 221 | * to Spring's conversion service. See {@link ConvertingEncoderDecoderSupport} for
|
227 | 222 | * details.
|
228 |
| - * |
229 |
| - * @param <T> The type that this Encoder can convert to. |
| 223 | + * @param <T> the type that this Encoder can convert to |
230 | 224 | */
|
231 |
| - public static abstract class TextEncoder<T> extends |
232 |
| - ConvertingEncoderDecoderSupport<T, String> implements Encoder.Text<T> { |
| 225 | + public static abstract class TextEncoder<T> extends ConvertingEncoderDecoderSupport<T, String> |
| 226 | + implements Encoder.Text<T> { |
233 | 227 | }
|
234 | 228 |
|
235 | 229 |
|
236 | 230 | /**
|
237 | 231 | * A Text {@link javax.websocket.Encoder.Text javax.websocket.Encoder} that delegates
|
238 |
| - * to Spring's conversion service. See {@link ConvertingEncoderDecoderSupport} for |
239 |
| - * details. |
240 |
| - * |
241 |
| - * @param <T> The type that this Decoder can convert from. |
| 232 | + * to Spring's conversion service. See {@link ConvertingEncoderDecoderSupport} for details. |
| 233 | + * @param <T> the type that this Decoder can convert from |
242 | 234 | */
|
243 |
| - public static abstract class TextDecoder<T> extends |
244 |
| - ConvertingEncoderDecoderSupport<T, String> implements Decoder.Text<T> { |
| 235 | + public static abstract class TextDecoder<T> extends ConvertingEncoderDecoderSupport<T, String> |
| 236 | + implements Decoder.Text<T> { |
245 | 237 | }
|
246 | 238 |
|
247 | 239 | }
|
0 commit comments