本文整理匯總了Java中javax.websocket.Encoder類的典型用法代碼示例。如果您正苦於以下問題:Java Encoder類的具體用法?Java Encoder怎麽用?Java Encoder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Encoder類屬於javax.websocket包,在下文中一共展示了Encoder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: contextInitialized
import javax.websocket.Encoder; //導入依賴的package包/類
@Override
public void contextInitialized(ServletContextEvent sce) {
super.contextInitialized(sce);
ServerContainer sc = (ServerContainer) sce.getServletContext().getAttribute(
Constants.SERVER_CONTAINER_SERVLET_CONTEXT_ATTRIBUTE);
List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>();
encoders.add(Bug58624Encoder.class);
ServerEndpointConfig sec = ServerEndpointConfig.Builder.create(
Bug58624Endpoint.class, PATH).encoders(encoders).build();
try {
sc.addEndpoint(sec);
} catch (DeploymentException e) {
throw new RuntimeException(e);
}
}
示例2: DefaultServerEndpointConfig
import javax.websocket.Encoder; //導入依賴的package包/類
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;
}
}
示例3: createConfiguredServerEndpoint
import javax.websocket.Encoder; //導入依賴的package包/類
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);
}
}
示例4: createWsServerEndpointConfig
import javax.websocket.Encoder; //導入依賴的package包/類
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;
}
示例5: createEventbusServerEndpointConfig
import javax.websocket.Encoder; //導入依賴的package包/類
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;
}
示例6: buildServerEndpointConfig
import javax.websocket.Encoder; //導入依賴的package包/類
@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);
}
示例7: findEncoder
import javax.websocket.Encoder; //導入依賴的package包/類
private Encoder findEncoder(Object obj) {
for (EncoderEntry entry : encoderEntries) {
if (entry.getClazz().isAssignableFrom(obj.getClass())) {
return entry.getEncoder();
}
}
return null;
}
示例8: DefaultServerEndpointConfig
import javax.websocket.Encoder; //導入依賴的package包/類
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;
}
示例9: findEncoder
import javax.websocket.Encoder; //導入依賴的package包/類
private Encoder findEncoder(Object obj) {
for (EncoderEntry entry : encoderEntries) {
if (entry.getClazz().isAssignableFrom(obj.getClass())) {
return entry.getEncoder();
}
}
return null;
}
示例10: DefaultServerEndpointConfig
import javax.websocket.Encoder; //導入依賴的package包/類
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;
}
示例11: getEndpointConfigs
import javax.websocket.Encoder; //導入依賴的package包/類
@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;
}
示例12: processRequest
import javax.websocket.Encoder; //導入依賴的package包/類
/**
* 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);
}
}
示例13: EncoderEntry
import javax.websocket.Encoder; //導入依賴的package包/類
public EncoderEntry(Class<?> clazz, Encoder encoder) {
this.clazz = clazz;
this.encoder = encoder;
}
示例14: getEncoder
import javax.websocket.Encoder; //導入依賴的package包/類
public Encoder getEncoder() {
return encoder;
}
示例15: getEncoderType
import javax.websocket.Encoder; //導入依賴的package包/類
static Class<?> getEncoderType(Class<? extends Encoder> encoder) {
return Util.getGenericType(Encoder.class, encoder).getClazz();
}