javax.websocket.Decoder Java Examples
The following examples show how to use
javax.websocket.Decoder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Util.java From Tomcat8-Source-Read with MIT License | 6 votes |
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.getConstructor().newInstance(); } catch (ReflectiveOperationException e) { throw new DeploymentException( sm.getString("pojoMethodMapping.invalidDecoder", decoderClazz.getName()), e); } DecoderEntry entry = new DecoderEntry( Util.getDecoderType(decoderClazz), decoderClazz); result.add(entry); } } return result; }
Example #2
Source File: UndertowRequestUpgradeStrategy.java From spring4-understanding with Apache License 2.0 | 6 votes |
private ConfiguredServerEndpoint createConfiguredServerEndpoint(String selectedProtocol, List<Extension> selectedExtensions, Endpoint endpoint, HttpServletRequest servletRequest) { String path = servletRequest.getRequestURI(); // shouldn't matter ServerEndpointRegistration endpointRegistration = new ServerEndpointRegistration(path, endpoint); endpointRegistration.setSubprotocols(Arrays.asList(selectedProtocol)); endpointRegistration.setExtensions(selectedExtensions); EncodingFactory encodingFactory = new EncodingFactory( Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(), Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap(), Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(), Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap()); try { return (endpointConstructorWithEndpointFactory ? endpointConstructor.newInstance(endpointRegistration, new EndpointInstanceFactory(endpoint), null, encodingFactory, null) : endpointConstructor.newInstance(endpointRegistration, new EndpointInstanceFactory(endpoint), null, encodingFactory)); } catch (Exception ex) { throw new HandshakeFailureException("Failed to instantiate ConfiguredServerEndpoint", ex); } }
Example #3
Source File: DefaultServerEndpointConfig.java From lams with GNU General Public License v2.0 | 6 votes |
DefaultServerEndpointConfig(Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, ServerEndpointConfig.Configurator serverEndpointConfigurator) { this.path = path; this.endpointClass = endpointClass; this.subprotocols = Collections.unmodifiableList(subprotocols); this.extensions = Collections.unmodifiableList(extensions); this.encoders = Collections.unmodifiableList(encoders); this.decoders = Collections.unmodifiableList(decoders); if (serverEndpointConfigurator == null) { this.serverEndpointConfigurator = ServerEndpointConfig.Configurator.fetchContainerDefaultConfigurator(); } else{ this.serverEndpointConfigurator = serverEndpointConfigurator; } }
Example #4
Source File: Encoding.java From quarkus-http with Apache License 2.0 | 6 votes |
public Object decodeBinary(final Class<?> targetType, final byte[] bytes) throws DecodeException { List<InstanceHandle<? extends Decoder>> decoders = binaryDecoders.get(targetType); if (decoders != null) { for (InstanceHandle<? extends Decoder> decoderHandle : decoders) { Decoder decoder = decoderHandle.getInstance(); if (decoder instanceof Decoder.Binary) { if (((Decoder.Binary) decoder).willDecode(ByteBuffer.wrap(bytes))) { return ((Decoder.Binary) decoder).decode(ByteBuffer.wrap(bytes)); } } else { try { return ((Decoder.BinaryStream) decoder).decode(new ByteArrayInputStream(bytes)); } catch (IOException e) { throw new DecodeException(ByteBuffer.wrap(bytes), "Could not decode binary", e); } } } } throw new DecodeException(ByteBuffer.wrap(bytes), "Could not decode binary"); }
Example #5
Source File: PojoMessageHandlerWholeText.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override protected Object decode(String message) throws DecodeException { // Handle primitives if (primitiveType != null) { return Util.coerceToType(primitiveType, message); } // Handle full decoders for (Decoder decoder : decoders) { if (decoder instanceof Text) { if (((Text<?>) decoder).willDecode(message)) { return ((Text<?>) decoder).decode(message); } } else { StringReader r = new StringReader(message); try { return ((TextStream<?>) decoder).decode(r); } catch (IOException ioe) { throw new DecodeException(message, sm.getString( "pojoMessageHandlerWhole.decodeIoFail"), ioe); } } } return null; }
Example #6
Source File: PojoMessageHandlerWholeBinary.java From Tomcat7.0.67 with Apache License 2.0 | 6 votes |
@Override protected Object decode(ByteBuffer message) throws DecodeException { for (Decoder decoder : decoders) { if (decoder instanceof Binary) { if (((Binary<?>) decoder).willDecode(message)) { return ((Binary<?>) decoder).decode(message); } } else { byte[] array = new byte[message.limit() - message.position()]; message.get(array); ByteArrayInputStream bais = new ByteArrayInputStream(array); try { return ((BinaryStream<?>) decoder).decode(bais); } catch (IOException ioe) { throw new DecodeException(message, sm.getString( "pojoMessageHandlerWhole.decodeIoFail"), ioe); } } } return null; }
Example #7
Source File: PojoMessageHandlerWholeBinary.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override protected Object decode(ByteBuffer message) throws DecodeException { for (Decoder decoder : decoders) { if (decoder instanceof Binary) { if (((Binary<?>) decoder).willDecode(message)) { return ((Binary<?>) decoder).decode(message); } } else { byte[] array = new byte[message.limit() - message.position()]; message.get(array); ByteArrayInputStream bais = new ByteArrayInputStream(array); try { return ((BinaryStream<?>) decoder).decode(bais); } catch (IOException ioe) { throw new DecodeException(message, sm.getString( "pojoMessageHandlerWhole.decodeIoFail"), ioe); } } } return null; }
Example #8
Source File: PojoMessageHandlerWholeText.java From Tomcat8-Source-Read with MIT License | 6 votes |
@Override protected Object decode(String message) throws DecodeException { // Handle primitives if (primitiveType != null) { return Util.coerceToType(primitiveType, message); } // Handle full decoders for (Decoder decoder : decoders) { if (decoder instanceof Text) { if (((Text<?>) decoder).willDecode(message)) { return ((Text<?>) decoder).decode(message); } } else { StringReader r = new StringReader(message); try { return ((TextStream<?>) decoder).decode(r); } catch (IOException ioe) { throw new DecodeException(message, sm.getString( "pojoMessageHandlerWhole.decodeIoFail"), ioe); } } } return null; }
Example #9
Source File: PojoMessageHandlerWholeText.java From tomcatsrc with Apache License 2.0 | 6 votes |
@Override protected Object decode(String message) throws DecodeException { // Handle primitives if (primitiveType != null) { return Util.coerceToType(primitiveType, message); } // Handle full decoders for (Decoder decoder : decoders) { if (decoder instanceof Text) { if (((Text<?>) decoder).willDecode(message)) { return ((Text<?>) decoder).decode(message); } } else { StringReader r = new StringReader(message); try { return ((TextStream<?>) decoder).decode(r); } catch (IOException ioe) { throw new DecodeException(message, sm.getString( "pojoMessageHandlerWhole.decodeIoFail"), ioe); } } } return null; }
Example #10
Source File: DefaultServerEndpointConfig.java From Tomcat8-Source-Read with MIT License | 5 votes |
DefaultServerEndpointConfig( Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, Configurator serverEndpointConfigurator) { this.endpointClass = endpointClass; this.path = path; this.subprotocols = subprotocols; this.extensions = extensions; this.encoders = encoders; this.decoders = decoders; this.serverEndpointConfigurator = serverEndpointConfigurator; }
Example #11
Source File: DefaultServerEndpointConfig.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
DefaultServerEndpointConfig( Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, Configurator serverEndpointConfigurator) { this.endpointClass = endpointClass; this.path = path; this.subprotocols = subprotocols; this.extensions = extensions; this.encoders = encoders; this.decoders = decoders; this.serverEndpointConfigurator = serverEndpointConfigurator; }
Example #12
Source File: ConvertingEncoderDecoderSupportTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void decodeFromTextCannotConvert() throws Exception { setup(NoConvertersConfig.class); Decoder.Text<MyType> decoder = new MyTextDecoder(); assertThat(decoder.willDecode(CONVERTED_TEXT), is(false)); thown.expect(DecodeException.class); thown.expectCause(isA(ConverterNotFoundException.class)); decoder.decode(CONVERTED_TEXT); }
Example #13
Source File: DefaultServerEndpointConfig.java From tomcatsrc with Apache License 2.0 | 5 votes |
DefaultServerEndpointConfig( Class<?> endpointClass, String path, List<String> subprotocols, List<Extension> extensions, List<Class<? extends Encoder>> encoders, List<Class<? extends Decoder>> decoders, Configurator serverEndpointConfigurator) { this.endpointClass = endpointClass; this.path = path; this.subprotocols = subprotocols; this.extensions = extensions; this.encoders = encoders; this.decoders = decoders; this.serverEndpointConfigurator = serverEndpointConfigurator; }
Example #14
Source File: Util.java From Tomcat8-Source-Read with MIT License | 5 votes |
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target, EndpointConfig endpointConfig, boolean binary) { DecoderMatch decoderMatch = matchDecoders(target, endpointConfig); if (binary) { if (decoderMatch.getBinaryDecoders().size() > 0) { return decoderMatch.getBinaryDecoders(); } } else if (decoderMatch.getTextDecoders().size() > 0) { return decoderMatch.getTextDecoders(); } return null; }
Example #15
Source File: Util.java From Tomcat8-Source-Read with MIT License | 5 votes |
private static DecoderMatch matchDecoders(Class<?> target, EndpointConfig endpointConfig) { DecoderMatch decoderMatch; try { List<Class<? extends Decoder>> decoders = endpointConfig.getDecoders(); List<DecoderEntry> decoderEntries = getDecoders(decoders); decoderMatch = new DecoderMatch(target, decoderEntries); } catch (DeploymentException e) { throw new IllegalArgumentException(e); } return decoderMatch; }
Example #16
Source File: ConvertingEncoderDecoderSupportTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void decodeFromBinaryCannotConvert() throws Exception { setup(NoConvertersConfig.class); Decoder.Binary<MyType> decoder = new MyBinaryDecoder(); assertThat(decoder.willDecode(CONVERTED_BYTES), is(false)); thown.expect(DecodeException.class); thown.expectCause(isA(ConverterNotFoundException.class)); decoder.decode(CONVERTED_BYTES); }
Example #17
Source File: ConvertingEncoderDecoderSupportTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void decodeFromTextCannotConvert() throws Exception { setup(NoConvertersConfig.class); Decoder.Text<MyType> decoder = new MyTextDecoder(); assertThat(decoder.willDecode(CONVERTED_TEXT), is(false)); assertThatExceptionOfType(DecodeException.class).isThrownBy(() -> decoder.decode(CONVERTED_TEXT)) .withCauseInstanceOf(ConverterNotFoundException.class); }
Example #18
Source File: Util.java From tomcatsrc with Apache License 2.0 | 5 votes |
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target, EndpointConfig endpointConfig, boolean binary) { DecoderMatch decoderMatch = matchDecoders(target, endpointConfig); if (binary) { if (decoderMatch.getBinaryDecoders().size() > 0) { return decoderMatch.getBinaryDecoders(); } } else if (decoderMatch.getTextDecoders().size() > 0) { return decoderMatch.getTextDecoders(); } return null; }
Example #19
Source File: ConvertingEncoderDecoderSupportTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void decodeFromTextCannotConvert() throws Exception { setup(NoConvertersConfig.class); Decoder.Text<MyType> decoder = new MyTextDecoder(); assertThat(decoder.willDecode(CONVERTED_TEXT), is(false)); thown.expect(DecodeException.class); thown.expectCause(isA(ConverterNotFoundException.class)); decoder.decode(CONVERTED_TEXT); }
Example #20
Source File: ServerContainerInitializeListener.java From everrest with Eclipse Public License 2.0 | 5 votes |
protected ServerEndpointConfig createServerEndpointConfig(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(WSConnectionImpl.class, "/ws") .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; }
Example #21
Source File: Util.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private static DecoderMatch matchDecoders(Class<?> target, EndpointConfig endpointConfig) { DecoderMatch decoderMatch; try { List<Class<? extends Decoder>> decoders = endpointConfig.getDecoders(); List<DecoderEntry> decoderEntries = getDecoders(decoders); decoderMatch = new DecoderMatch(target, decoderEntries); } catch (DeploymentException e) { throw new IllegalArgumentException(e); } return decoderMatch; }
Example #22
Source File: DecoderUtils.java From quarkus-http with Apache License 2.0 | 5 votes |
/** * Gets a decoder for a given type. * * @param type The type * @param endpointConfiguration The endpoint configuration * @return A list of decoders, or null if no decoders exist */ public static List<Decoder> getDecodersForType(final Class<?> type, final EndpointConfig endpointConfiguration) { // final List<Decoder> decoders = new ArrayList<>(); // for (final Decoder decoder : endpointConfiguration.getDecoders()) { // final Class<?> clazz = ClassUtils.getDecoderType(decoder.getClass()); // if (type.isAssignableFrom(clazz)) { // decoders.add(decoder); // } // } // if (!decoders.isEmpty()) { // return decoders; // } return null; }
Example #23
Source File: Util.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
private static List<Class<? extends Decoder>> matchDecoders(Class<?> target, EndpointConfig endpointConfig, boolean binary) { DecoderMatch decoderMatch = matchDecoders(target, endpointConfig); if (binary) { if (decoderMatch.getBinaryDecoders().size() > 0) { return decoderMatch.getBinaryDecoders(); } } else if (decoderMatch.getTextDecoders().size() > 0) { return decoderMatch.getTextDecoders(); } return null; }
Example #24
Source File: ClassUtils.java From quarkus-http with Apache License 2.0 | 5 votes |
/** * Returns the Object type for which the {@link Encoder} can be used. */ public static Class<?> getDecoderType(Class<? extends Decoder> clazz) { Method[] methods = clazz.getMethods(); for (Method m : methods) { if ("decode".equals(m.getName()) && !m.isBridge()) { return m.getReturnType(); } } throw JsrWebSocketMessages.MESSAGES.couldNotDetermineDecoderTypeFor(clazz); }
Example #25
Source File: PojoEndpointClient.java From Tomcat8-Source-Read with MIT License | 5 votes |
public PojoEndpointClient(Object pojo, List<Class<? extends Decoder>> decoders) throws DeploymentException { setPojo(pojo); setMethodMapping( new PojoMethodMapping(pojo.getClass(), decoders, null)); setPathParameters(Collections.<String,String>emptyMap()); }
Example #26
Source File: PojoEndpointClient.java From Tomcat7.0.67 with Apache License 2.0 | 5 votes |
public PojoEndpointClient(Object pojo, List<Class<? extends Decoder>> decoders) throws DeploymentException { setPojo(pojo); setMethodMapping( new PojoMethodMapping(pojo.getClass(), decoders, null)); setPathParameters(Collections.<String,String>emptyMap()); }
Example #27
Source File: TimelyEndpointConfig.java From timely with Apache License 2.0 | 4 votes |
@Override public List<Class<? extends Decoder>> getDecoders() { return Collections.emptyList(); }
Example #28
Source File: DecoderEntry.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
public Class<? extends Decoder> getDecoderClazz() { return decoderClazz; }
Example #29
Source File: DecoderEntry.java From Tomcat7.0.67 with Apache License 2.0 | 4 votes |
public DecoderEntry(Class<?> clazz, Class<? extends Decoder> decoderClazz) { this.clazz = clazz; this.decoderClazz = decoderClazz; }
Example #30
Source File: PojoMessageHandlerWholeBinary.java From tomcatsrc with Apache License 2.0 | 4 votes |
@Override protected void onClose() { for (Decoder decoder : decoders) { decoder.destroy(); } }