/** * Strategy method used to obtain the {@link ConversionService}. By default this * method expects a bean named {@code 'webSocketConversionService'} in the * {@link #getApplicationContext() active ApplicationContext}. * @return the {@link ConversionService} (never null) */ protected ConversionService getConversionService() { ApplicationContext applicationContext = getApplicationContext(); Assert.state(applicationContext != null, "Unable to locate the Spring ApplicationContext"); try { return applicationContext.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class); } catch (BeansException ex) { throw new IllegalStateException("Unable to find ConversionService: please configure a '" + CONVERSION_SERVICE_BEAN_NAME + "' or override the getConversionService() method", ex); } }
/** * Determine if a given message can be decoded. * @see #decode(Object) * @see javax.websocket.Decoder.Text#willDecode(String) * @see javax.websocket.Decoder.Binary#willDecode(ByteBuffer) */ public boolean willDecode(M bytes) { return getConversionService().canConvert(getType(), getMessageType()); }
/** * Returns the type being converted. By default the type is resolved using * the generic arguments of the class. */ protected TypeDescriptor getType() { return TypeDescriptor.valueOf(resolveTypeArguments()[0]); }
/** * Encode an object to a message. * @see javax.websocket.Encoder.Text#encode(Object) * @see javax.websocket.Encoder.Binary#encode(Object) */ @SuppressWarnings("unchecked") @Nullable public M encode(T object) throws EncodeException { try { return (M) getConversionService().convert(object, getType(), getMessageType()); } catch (ConversionException ex) { throw new EncodeException(object, "Unable to encode websocket message using ConversionService", ex); } }
/** * Returns the websocket message type. By default the type is resolved using * the generic arguments of the class. */ protected TypeDescriptor getMessageType() { return TypeDescriptor.valueOf(resolveTypeArguments()[1]); }
/** * Called to initialize the encoder/decoder. * @see javax.websocket.Encoder#init(EndpointConfig) * @see javax.websocket.Decoder#init(EndpointConfig) */ public void init(EndpointConfig config) { ApplicationContext applicationContext = getApplicationContext(); if (applicationContext != null && applicationContext instanceof ConfigurableApplicationContext) { ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory(); beanFactory.autowireBean(this); } }
/** * Decode the a message into an object. * @see javax.websocket.Decoder.Text#decode(String) * @see javax.websocket.Decoder.Binary#decode(ByteBuffer) */ @SuppressWarnings("unchecked") @Nullable public T decode(M message) throws DecodeException { try { return (T) getConversionService().convert(message, getMessageType(), getType()); } catch (ConversionException ex) { if (message instanceof String) { throw new DecodeException((String) message, "Unable to decode websocket message using ConversionService", ex); } if (message instanceof ByteBuffer) { throw new DecodeException((ByteBuffer) message, "Unable to decode websocket message using ConversionService", ex); } throw ex; } }
/** * Returns the websocket message type. By default the type is resolved using * the generic arguments of the class. */ protected TypeDescriptor getMessageType() { return TypeDescriptor.valueOf(resolveTypeArguments()[1]); }
/** * Strategy method used to obtain the {@link ConversionService}. By default this * method expects a bean named {@code 'webSocketConversionService'} in the * {@link #getApplicationContext() active ApplicationContext}. * @return the {@link ConversionService} (never null) */ protected ConversionService getConversionService() { ApplicationContext applicationContext = getApplicationContext(); Assert.state(applicationContext != null, "Unable to locate the Spring ApplicationContext"); try { return applicationContext.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class); } catch (BeansException ex) { throw new IllegalStateException("Unable to find ConversionService: please configure a '" + CONVERSION_SERVICE_BEAN_NAME + "' or override the getConversionService() method", ex); } }
/** * Determine if a given message can be decoded. * @see #decode(Object) * @see javax.websocket.Decoder.Text#willDecode(String) * @see javax.websocket.Decoder.Binary#willDecode(ByteBuffer) */ public boolean willDecode(M bytes) { return getConversionService().canConvert(getType(), getMessageType()); }
/** * Returns the type being converted. By default the type is resolved using * the generic arguments of the class. */ protected TypeDescriptor getType() { return TypeDescriptor.valueOf(resolveTypeArguments()[0]); }
/** * Strategy method used to obtain the {@link ConversionService}. By default this * method expects a bean named {@code 'webSocketConversionService'} in the * {@link #getApplicationContext() active ApplicationContext}. * @return the {@link ConversionService} (never null) */ protected ConversionService getConversionService() { ApplicationContext applicationContext = getApplicationContext(); Assert.state(applicationContext != null, "Unable to locate the Spring ApplicationContext"); try { return applicationContext.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class); } catch (BeansException ex) { throw new IllegalStateException("Unable to find ConversionService: please configure a '" + CONVERSION_SERVICE_BEAN_NAME + "' or override the getConversionService() method", ex); } }
/** * @see javax.websocket.Decoder.Text#willDecode(String) * @see javax.websocket.Decoder.Binary#willDecode(ByteBuffer) */ public boolean willDecode(M bytes) { return getConversionService().canConvert(getType(), getMessageType()); }
/** * Returns the websocket message type. By default the type is resolved using * the generic arguments of the class. */ protected TypeDescriptor getMessageType() { return TypeDescriptor.valueOf(resolveTypeArguments()[1]); }
/** * Called to initialize the encoder/decoder. * @see javax.websocket.Encoder#init(EndpointConfig) * @see javax.websocket.Decoder#init(EndpointConfig) */ public void init(EndpointConfig config) { ApplicationContext applicationContext = getApplicationContext(); if (applicationContext != null && applicationContext instanceof ConfigurableApplicationContext) { ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory(); beanFactory.autowireBean(this); } }
/** * Encode an object to a message. * @see javax.websocket.Encoder.Text#encode(Object) * @see javax.websocket.Encoder.Binary#encode(Object) */ @SuppressWarnings("unchecked") @Nullable public M encode(T object) throws EncodeException { try { return (M) getConversionService().convert(object, getType(), getMessageType()); } catch (ConversionException ex) { throw new EncodeException(object, "Unable to encode websocket message using ConversionService", ex); } }
/** * Returns the type being converted. By default the type is resolved using * the generic arguments of the class. */ protected TypeDescriptor getType() { return TypeDescriptor.valueOf(resolveTypeArguments()[0]); }
/** * @see javax.websocket.Encoder#init(EndpointConfig) * @see javax.websocket.Decoder#init(EndpointConfig) */ public void init(EndpointConfig config) { ApplicationContext applicationContext = getApplicationContext(); if (applicationContext != null && applicationContext instanceof ConfigurableApplicationContext) { ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory(); beanFactory.autowireBean(this); } }
/** * @see javax.websocket.Encoder.Text#encode(Object) * @see javax.websocket.Encoder.Binary#encode(Object) */ @SuppressWarnings("unchecked") @Nullable public M encode(T object) throws EncodeException { try { return (M) getConversionService().convert(object, getType(), getMessageType()); } catch (ConversionException ex) { throw new EncodeException(object, "Unable to encode websocket message using ConversionService", ex); } }
/** * Decode the a message into an object. * @see javax.websocket.Decoder.Text#decode(String) * @see javax.websocket.Decoder.Binary#decode(ByteBuffer) */ @SuppressWarnings("unchecked") @Nullable public T decode(M message) throws DecodeException { try { return (T) getConversionService().convert(message, getMessageType(), getType()); } catch (ConversionException ex) { if (message instanceof String) { throw new DecodeException((String) message, "Unable to decode websocket message using ConversionService", ex); } if (message instanceof ByteBuffer) { throw new DecodeException((ByteBuffer) message, "Unable to decode websocket message using ConversionService", ex); } throw ex; } }