Java 类javax.websocket.Decoder 实例源码

项目:tomcat7    文件:PojoMessageHandlerWholeBinary.java   
@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;
}
项目:tomcat7    文件:PojoMessageHandlerWholeText.java   
@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;
}
项目:lams    文件:DefaultServerEndpointConfig.java   
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;
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:PojoMessageHandlerWholeBinary.java   
@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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:PojoMessageHandlerWholeText.java   
@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;
}
项目:lazycat    文件:PojoMessageHandlerWholeBinary.java   
@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;
}
项目:lazycat    文件:PojoMessageHandlerWholeText.java   
@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;
}
项目:spring4-understanding    文件:UndertowRequestUpgradeStrategy.java   
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);
    }
}
项目:che    文件:ServerContainerInitializeListener.java   
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;
}
项目:che    文件:ServerContainerInitializeListener.java   
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;
}
项目:class-guard    文件:PojoMessageHandlerWholeBinary.java   
@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;
}
项目:class-guard    文件:PojoMessageHandlerWholeText.java   
@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;
}
项目:apache-tomcat-7.0.57    文件:PojoMessageHandlerWholeBinary.java   
@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;
}
项目:apache-tomcat-7.0.57    文件:PojoMessageHandlerWholeText.java   
@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;
}
项目:apache-tomcat-7.0.57    文件:PojoMessageHandlerWholeBinary.java   
@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;
}
项目:apache-tomcat-7.0.57    文件:PojoMessageHandlerWholeText.java   
@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;
}
项目:ameba-container-grizzly    文件:AnnotatedEndpointMeta.java   
@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);
}
项目:tomcat7    文件:PojoEndpointClient.java   
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());
}
项目:tomcat7    文件:Util.java   
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;
}
项目:tomcat7    文件:Util.java   
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;
}
项目:tomcat7    文件:DefaultServerEndpointConfig.java   
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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:PojoEndpointClient.java   
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());
}
项目:apache-tomcat-7.0.73-with-comment    文件:Util.java   
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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:Util.java   
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;
}
项目:apache-tomcat-7.0.73-with-comment    文件:DefaultServerEndpointConfig.java   
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;
}
项目:redis-websocket-javaee    文件:MeetupRSVPsWebSocketClientSession.java   
@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);
    }

}
项目:lazycat    文件:Util.java   
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;
}
项目:lazycat    文件:Util.java   
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;
}
项目:lazycat    文件:DefaultServerEndpointConfig.java   
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;
}
项目:spring4-understanding    文件:ConvertingEncoderDecoderSupportTests.java   
@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);
}
项目:spring4-understanding    文件:ConvertingEncoderDecoderSupportTests.java   
@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);
}
项目:actionbazaar    文件:ChatEndpointConfig.java   
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> endpointClasses) {
    logger.info("Checking the endpoint...");
    // Configuring the decoders
    List<Class<? extends Decoder>> decoders = new LinkedList<>();
    decoders.add(CommandMessageDecoder.class);
    // Configuring the encoders
    List<Class<? extends Encoder>> encoders = new LinkedList<>();
    encoders.add(CommandMessageEncoder.class);
    Set<ServerEndpointConfig> configs = new HashSet<>();
    configs.add(ServerEndpointConfig.Builder.create(ClientChatEndpoint.class, "/chat").decoders(decoders).encoders(encoders).build());
    configs.add(ServerEndpointConfig.Builder.create(SupportChatEndpoint.class, "/support").decoders(decoders).encoders(encoders).build());
    return configs;
}
项目:class-guard    文件:PojoEndpointClient.java   
public PojoEndpointClient(Object pojo,
        Class<? extends Decoder>[] decoders) throws DeploymentException {
    setPojo(pojo);
    setMethodMapping(
            new PojoMethodMapping(pojo.getClass(), decoders, null));
    setPathParameters(Collections.<String, String> emptyMap());
}
项目:class-guard    文件:DefaultServerEndpointConfig.java   
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;
}
项目:JavaIncrementalParser    文件:TestClient.java   
/**
 * Processes requests for both HTTP
 * <code>GET</code> and
 * <code>POST</code> methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet TestServlet</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");

        List<Class<? extends Encoder>> encoders = new ArrayList<>();
        encoders.add(MyMessageEncoder.class);
        List<Class<? extends Decoder>> decoders = new ArrayList<>();
        decoders.add(MyMessageDecoder.class);

        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        String uri = "ws://localhost:8080" + request.getContextPath() + "/websocket";
        out.println("Connecting to " + uri);
        container.connectToServer(MyClient.class, 
                ClientEndpointConfig.Builder.create()
                .encoders(encoders)
                .decoders(decoders)
                .build(),
                URI.create(uri));
        out.println("<br><br>Look in server.log for message exchange between client/server.");

        out.println("</body>");
        out.println("</html>");
    } catch (DeploymentException ex) {
        Logger.getLogger(TestClient.class.getName()).log(Level.SEVERE, null, ex);
    }
}
项目:apache-tomcat-7.0.57    文件:PojoEndpointClient.java   
public PojoEndpointClient(Object pojo,
        Class<? extends Decoder>[] decoders) throws DeploymentException {
    setPojo(pojo);
    setMethodMapping(
            new PojoMethodMapping(pojo.getClass(), decoders, null));
    setPathParameters(Collections.<String,String>emptyMap());
}
项目:apache-tomcat-7.0.57    文件:DefaultServerEndpointConfig.java   
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;
}
项目:apache-tomcat-7.0.57    文件:PojoEndpointClient.java   
public PojoEndpointClient(Object pojo,
        Class<? extends Decoder>[] decoders) throws DeploymentException {
    setPojo(pojo);
    setMethodMapping(
            new PojoMethodMapping(pojo.getClass(), decoders, null));
    setPathParameters(Collections.<String,String>emptyMap());
}
项目:apache-tomcat-7.0.57    文件:DefaultServerEndpointConfig.java   
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;
}
项目:ameba-container-grizzly    文件:AnnotatedEndpointMeta.java   
@Override
protected List<Class<? extends Decoder>> getDefaultDecoders() {
    final List<Class<? extends Decoder>> classList = Lists.newArrayList();
    classList.addAll(PrimitiveDecoders.ALL);
    classList.add(NoOpTextCoder.class);
    classList.add(NoOpByteBufferCoder.class);
    classList.add(NoOpByteArrayCoder.class);
    classList.add(ReaderDecoder.class);
    classList.add(InputStreamDecoder.class);
    return classList;
}