java类javax.websocket.Decoder的实例源码

PojoMessageHandlerWholeBinary.java 文件源码 项目:tomcat7 阅读 26 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeText.java 文件源码 项目:tomcat7 阅读 21 收藏 0 点赞 0 评论 0
@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;
}
DefaultServerEndpointConfig.java 文件源码 项目:lams 阅读 28 收藏 0 点赞 0 评论 0
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;
    }
}
PojoMessageHandlerWholeBinary.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 27 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeText.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 31 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeBinary.java 文件源码 项目:lazycat 阅读 29 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeText.java 文件源码 项目:lazycat 阅读 29 收藏 0 点赞 0 评论 0
@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;
}
UndertowRequestUpgradeStrategy.java 文件源码 项目:spring4-understanding 阅读 29 收藏 0 点赞 0 评论 0
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);
    }
}
ServerContainerInitializeListener.java 文件源码 项目:che 阅读 32 收藏 0 点赞 0 评论 0
protected ServerEndpointConfig createWsServerEndpointConfig(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 + websocketEndPoint)
          .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;
}
ServerContainerInitializeListener.java 文件源码 项目:che 阅读 31 收藏 0 点赞 0 评论 0
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;
}
PojoMessageHandlerWholeBinary.java 文件源码 项目:class-guard 阅读 43 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeText.java 文件源码 项目:class-guard 阅读 26 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeBinary.java 文件源码 项目:apache-tomcat-7.0.57 阅读 22 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeText.java 文件源码 项目:apache-tomcat-7.0.57 阅读 23 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeBinary.java 文件源码 项目:apache-tomcat-7.0.57 阅读 25 收藏 0 点赞 0 评论 0
@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;
}
PojoMessageHandlerWholeText.java 文件源码 项目:apache-tomcat-7.0.57 阅读 30 收藏 0 点赞 0 评论 0
@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;
}
AnnotatedEndpointMeta.java 文件源码 项目:ameba-container-grizzly 阅读 25 收藏 0 点赞 0 评论 0
@Override
protected ServerEndpointConfig buildServerEndpointConfig(String path, WebSocket wseAnnotation,
                                                         Class<?> annotatedClass, String[] subProtocols,
                                                         List<Class<? extends Encoder>> encoderClasses,
                                                         List<Class<? extends Decoder>> decoderClasses) {
    int max = getMaxSessions(annotatedClass);
    if (max != -1) {
        TyrusServerEndpointConfig.Builder builder =
                TyrusServerEndpointConfig.Builder
                        .create(annotatedClass, path)
                        .encoders(encoderClasses)
                        .decoders(decoderClasses)
                        .subprotocols(Arrays.asList(subProtocols));
        if (!ServerEndpointConfig.Configurator.class.equals(wseAnnotation.configurator())) {
            builder = builder.configurator(Injections.getOrCreate(manager, wseAnnotation.configurator()));
        }
        return builder.maxSessions(max).build();
    }
    return super.buildServerEndpointConfig(path, wseAnnotation, annotatedClass,
            subProtocols, encoderClasses, decoderClasses);
}
PojoEndpointClient.java 文件源码 项目:tomcat7 阅读 29 收藏 0 点赞 0 评论 0
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());
}
Util.java 文件源码 项目:tomcat7 阅读 30 收藏 0 点赞 0 评论 0
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;
}
Util.java 文件源码 项目:tomcat7 阅读 31 收藏 0 点赞 0 评论 0
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;
}
DefaultServerEndpointConfig.java 文件源码 项目:tomcat7 阅读 23 收藏 0 点赞 0 评论 0
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;
}
PojoEndpointClient.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 29 收藏 0 点赞 0 评论 0
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());
}
Util.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 26 收藏 0 点赞 0 评论 0
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;
}
Util.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 33 收藏 0 点赞 0 评论 0
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;
}
DefaultServerEndpointConfig.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 34 收藏 0 点赞 0 评论 0
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;
}
MeetupRSVPsWebSocketClientSession.java 文件源码 项目:redis-websocket-javaee 阅读 89 收藏 0 点赞 0 评论 0
@PostConstruct
public void init(){
    try {
        WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
        List<Class<? extends Decoder>> decoders = new ArrayList<>();
        decoders.add(MeetupRSVPJSONDecoder.class);
        session = webSocketContainer.connectToServer(new MeetupRSVPsWebSocketClient(),
                ClientEndpointConfig.Builder.create().decoders(decoders).build(),
                URI.create("ws://stream.meetup.com/2/rsvps"));
    } catch (DeploymentException | IOException ex) {
        Logger.getLogger(MeetupRSVPsWebSocketClientSession.class.getName()).log(Level.SEVERE, null, ex);
    }

}
Util.java 文件源码 项目:lazycat 阅读 35 收藏 0 点赞 0 评论 0
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;
}
Util.java 文件源码 项目:lazycat 阅读 32 收藏 0 点赞 0 评论 0
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;
}
DefaultServerEndpointConfig.java 文件源码 项目:lazycat 阅读 25 收藏 0 点赞 0 评论 0
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;
}
ConvertingEncoderDecoderSupportTests.java 文件源码 项目:spring4-understanding 阅读 27 收藏 0 点赞 0 评论 0
@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);
}


问题


面经


文章

微信
公众号

扫码关注公众号