use of javax.websocket.Decoder in project undertow by undertow-io.
the class EncodingFactory method createFactory.
public static EncodingFactory createFactory(final ClassIntrospecter classIntrospecter, final List<Class<? extends Decoder>> decoders, final List<Class<? extends Encoder>> encoders) throws DeploymentException {
final Map<Class<?>, List<InstanceFactory<? extends Encoder>>> binaryEncoders = new HashMap<>();
final Map<Class<?>, List<InstanceFactory<? extends Decoder>>> binaryDecoders = new HashMap<>();
final Map<Class<?>, List<InstanceFactory<? extends Encoder>>> textEncoders = new HashMap<>();
final Map<Class<?>, List<InstanceFactory<? extends Decoder>>> textDecoders = new HashMap<>();
for (Class<? extends Decoder> decoder : decoders) {
if (Decoder.Binary.class.isAssignableFrom(decoder)) {
try {
Method method = decoder.getMethod("decode", ByteBuffer.class);
final Class<?> type = resolveReturnType(method, decoder);
List<InstanceFactory<? extends Decoder>> list = binaryDecoders.get(type);
if (list == null) {
binaryDecoders.put(type, list = new ArrayList<>());
}
list.add(classIntrospecter.createInstanceFactory(decoder));
} catch (NoSuchMethodException e) {
throw JsrWebSocketMessages.MESSAGES.couldNotDetermineTypeOfDecodeMethodForClass(decoder, e);
}
} else if (Decoder.BinaryStream.class.isAssignableFrom(decoder)) {
try {
Method method = decoder.getMethod("decode", InputStream.class);
final Class<?> type = resolveReturnType(method, decoder);
List<InstanceFactory<? extends Decoder>> list = binaryDecoders.get(type);
if (list == null) {
binaryDecoders.put(type, list = new ArrayList<>());
}
list.add(classIntrospecter.createInstanceFactory(decoder));
} catch (NoSuchMethodException e) {
throw JsrWebSocketMessages.MESSAGES.couldNotDetermineTypeOfDecodeMethodForClass(decoder, e);
}
} else if (Decoder.Text.class.isAssignableFrom(decoder)) {
try {
Method method = decoder.getMethod("decode", String.class);
final Class<?> type = resolveReturnType(method, decoder);
List<InstanceFactory<? extends Decoder>> list = textDecoders.get(type);
if (list == null) {
textDecoders.put(type, list = new ArrayList<>());
}
list.add(classIntrospecter.createInstanceFactory(decoder));
} catch (NoSuchMethodException e) {
throw JsrWebSocketMessages.MESSAGES.couldNotDetermineTypeOfDecodeMethodForClass(decoder, e);
}
} else if (Decoder.TextStream.class.isAssignableFrom(decoder)) {
try {
Method method = decoder.getMethod("decode", Reader.class);
final Class<?> type = resolveReturnType(method, decoder);
List<InstanceFactory<? extends Decoder>> list = textDecoders.get(type);
if (list == null) {
textDecoders.put(type, list = new ArrayList<>());
}
list.add(createInstanceFactory(classIntrospecter, decoder));
} catch (NoSuchMethodException e) {
throw JsrWebSocketMessages.MESSAGES.couldNotDetermineTypeOfDecodeMethodForClass(decoder, e);
}
} else {
throw JsrWebSocketMessages.MESSAGES.didNotImplementKnownDecoderSubclass(decoder);
}
}
for (Class<? extends Encoder> encoder : encoders) {
if (Encoder.Binary.class.isAssignableFrom(encoder)) {
final Class<?> type = findEncodeMethod(encoder, ByteBuffer.class);
List<InstanceFactory<? extends Encoder>> list = binaryEncoders.get(type);
if (list == null) {
binaryEncoders.put(type, list = new ArrayList<>());
}
list.add(createInstanceFactory(classIntrospecter, encoder));
} else if (Encoder.BinaryStream.class.isAssignableFrom(encoder)) {
final Class<?> type = findEncodeMethod(encoder, void.class, OutputStream.class);
List<InstanceFactory<? extends Encoder>> list = binaryEncoders.get(type);
if (list == null) {
binaryEncoders.put(type, list = new ArrayList<>());
}
list.add(createInstanceFactory(classIntrospecter, encoder));
} else if (Encoder.Text.class.isAssignableFrom(encoder)) {
final Class<?> type = findEncodeMethod(encoder, String.class);
List<InstanceFactory<? extends Encoder>> list = textEncoders.get(type);
if (list == null) {
textEncoders.put(type, list = new ArrayList<>());
}
list.add(createInstanceFactory(classIntrospecter, encoder));
} else if (Encoder.TextStream.class.isAssignableFrom(encoder)) {
final Class<?> type = findEncodeMethod(encoder, void.class, Writer.class);
List<InstanceFactory<? extends Encoder>> list = textEncoders.get(type);
if (list == null) {
textEncoders.put(type, list = new ArrayList<>());
}
list.add(createInstanceFactory(classIntrospecter, encoder));
}
}
return new EncodingFactory(binaryEncoders, binaryDecoders, textEncoders, textDecoders);
}
use of javax.websocket.Decoder in project tomcat by apache.
the class Util method getDecoders.
public static List<DecoderEntry> getDecoders(List<Class<? extends Decoder>> decoderClazzes) throws DeploymentException {
List<DecoderEntry> result = new ArrayList<>();
if (decoderClazzes != null) {
for (Class<? extends Decoder> decoderClazz : decoderClazzes) {
// Need to instantiate decoder to ensure it is valid and that
// deployment can be failed if it is not
@SuppressWarnings("unused") Decoder instance;
try {
instance = decoderClazz.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new DeploymentException(sm.getString("pojoMethodMapping.invalidDecoder", decoderClazz.getName()), e);
}
DecoderEntry entry = new DecoderEntry(Util.getDecoderType(decoderClazz), decoderClazz);
result.add(entry);
}
}
return result;
}
use of javax.websocket.Decoder in project che by eclipse.
the class ServerContainerInitializeListener method createEventbusServerEndpointConfig.
protected ServerEndpointConfig createEventbusServerEndpointConfig(ServletContext servletContext) {
final List<Class<? extends Encoder>> encoders = new LinkedList<>();
final List<Class<? extends Decoder>> decoders = new LinkedList<>();
encoders.add(OutputMessageEncoder.class);
decoders.add(InputMessageDecoder.class);
final ServerEndpointConfig endpointConfig = create(CheWSConnection.class, websocketContext + eventBusEndPoint).configurator(createConfigurator()).encoders(encoders).decoders(decoders).build();
endpointConfig.getUserProperties().put(EVERREST_PROCESSOR_ATTRIBUTE, getEverrestProcessor(servletContext));
endpointConfig.getUserProperties().put(EVERREST_CONFIG_ATTRIBUTE, getEverrestConfiguration(servletContext));
endpointConfig.getUserProperties().put(EXECUTOR_ATTRIBUTE, createExecutor(servletContext));
return endpointConfig;
}
use of javax.websocket.Decoder in project jetty.project by eclipse.
the class TextWholeMessage method messageComplete.
@SuppressWarnings("unchecked")
@Override
public void messageComplete() {
finished = true;
DecoderFactory.Wrapper decoder = msgWrapper.getDecoder();
Decoder.Text<Object> textDecoder = (Decoder.Text<Object>) decoder.getDecoder();
try {
Object obj = textDecoder.decode(utf.toString());
wholeHandler.onMessage(obj);
} catch (DecodeException e) {
throw new WebSocketException("Unable to decode text data", e);
}
}
Aggregations