Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
WebSocket Client Class Object Information
How to get WebSocket Client object class information? I am using the Java EE 2 SDK distribution package.
✍: FYIcenter.com
If you are using the Java EE 2 SDK distribution package,
you can follow this tutorial to get WebSocket Client object class information:
1. Write a test Java class annotated as @ClientEndpoint:
@ClientEndpoint
public class WebSocketClassInfo {
2. Create a WebSocketContainer instance from the ContainerProvider class:
WebSocketContainer c = ContainerProvider.getWebSocketContainer();
3. Create a Session instance by calling connectToServer() on the WebSocketContainer instance with a working WebSocket server URI:
URI u = new URI("wss://echo.websocket.org");
Session s = c.connectToServer(WebSocketClassInfo.class, u);
4. Print out object class information to see what the implementation classes of the WebSocket API:
System.out.println(" URI: "+u.getClass().getName());
System.out.println(" Container: "+c.getClass().getName());
System.out.println(" Session: "+s.getClass().getName());
Here is the entir test program, WebSocketClassInfo.java:
// Copyright (c) 2016 FYIcenter.com
import java.net.URI;
import javax.websocket.ClientEndpoint;
import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
@ClientEndpoint
public class WebSocketClassInfo {
public static void main(String[] args) throws Exception {
WebSocketContainer c = ContainerProvider.getWebSocketContainer();
URI u = new URI("wss://echo.websocket.org");
Session s = c.connectToServer(WebSocketClassInfo.class, u);
System.out.println("WebSocket class info:");
System.out.println(" URI: "+u.getClass().getName());
System.out.println(" Container: "+c.getClass().getName());
System.out.println(" Session: "+s.getClass().getName());
}
}
You can compile and run the above example in a command window with Java SE JDK 8 and the tyrus-standalone-client.jar from Java EE 7 SDK:
>\fyicenter\jdk-1.8.0\bin\javac -cp \fyicenter\glassfish4\mq\lib\tyrus-standalone-client.jar WebSocketClassInfo.java >\fyicenter\jdk-1.8.0\bin\java -cp .;\fyicenter\glassfish4\mq\lib\tyrus-standalone-client.jar WebSocketClassInfo WebSocket class info: URI: java.net.URI Container: org.glassfish.tyrus.client.ClientManager Session: org.glassfish.tyrus.core.TyrusSession
⇒ WebSocketEchoClient.java - WebSocket Echo Client
⇐ Using WebSocket API in Java Programs
2018-01-16, ∼1605🔥, 0💬
Popular Posts:
Apache Commons CLI Source Code Files are provided in the source package file commons-cli-1.5.0-sourc. ..
JDK 11 java.sql.rowset.jmod is the JMOD file for JDK 11 SQL Rowset module. JDK 11 SQL Rowset module ...
How to download and install Apache ZooKeeper Source Package? Apache ZooKeeper is an open-source serv...
What Is javax.websocket-api-1.1. jar?javax.websocket-api-1.1. jaris the JAR file for Java API for We...
What Is mail.jar of JavaMail 1.4.2? I got the JAR file from javamail-1.4.2.zip. mail.jar in javamail...