本文整理匯總了Java中org.eclipse.jetty.websocket.client.ClientUpgradeRequest類的典型用法代碼示例。如果您正苦於以下問題:Java ClientUpgradeRequest類的具體用法?Java ClientUpgradeRequest怎麽用?Java ClientUpgradeRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ClientUpgradeRequest類屬於org.eclipse.jetty.websocket.client包,在下文中一共展示了ClientUpgradeRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: JsonWebSocketProtocolHandler
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
public JsonWebSocketProtocolHandler(NativeDeviceFactoryInterface deviceFactory) {
super(deviceFactory);
serialiser = GSON::toJson;
deserialiser = GSON::fromJson;
webSocketClient = new WebSocketClient();
try {
webSocketClient.start();
URI uri = new URI("ws://localhost:8080/diozero");
Logger.debug("Connecting to: {}...", uri);
session = webSocketClient.connect(this, uri, new ClientUpgradeRequest()).get();
Logger.debug("Connected to: {}", uri);
} catch (Exception e) {
throw new RuntimeIOException(e);
}
}
示例2: setConnectionHeaders
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
protected void setConnectionHeaders(ClientUpgradeRequest request, HeaderManager headerManager, CacheManager cacheManager) {
if (headerManager != null) {
CollectionProperty headers = headerManager.getHeaders();
if (headers != null) {
for (JMeterProperty jMeterProperty : headers) {
org.apache.jmeter.protocol.http.control.Header header
= (org.apache.jmeter.protocol.http.control.Header)
jMeterProperty.getObjectValue();
String n = header.getName();
if (! HTTPConstants.HEADER_CONTENT_LENGTH.equalsIgnoreCase(n)){
String v = header.getValue();
request.setHeader(n, v);
}
}
}
}
if (cacheManager != null){
}
}
示例3: onConnect
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
/**
* Callback hook for Connection open events.
*
* @param session the user session which is opened.
*/
@OnWebSocketConnect
public void onConnect(Session session) {
this.session = session;
this.futureSession = null; // don't need this anymore
this.addr = session.getRemoteAddress().getAddress();
this.remotePort = session.getRemoteAddress().getPort();
this.localAddr = session.getLocalAddress().getAddress();
this.localPort = session.getLocalAddress().getPort();
this.path = session.getUpgradeRequest().getRequestURI().getPath();
if (session.getUpgradeRequest() instanceof ClientUpgradeRequest) {
this.key = ((ClientUpgradeRequest)session.getUpgradeRequest()).getKey();
}
else {
this.key = session.getUpgradeRequest().getHeader("Sec-WebSocket-Key");
}
if (log.isLoggable(Level.INFO))
log.log(Level.INFO,"Connected with "+((addr==null)?"<null>":addr.toString())+" through local address "+localAddr.getHostAddress());
pool.addSession(this);
pool.getInclusionCallback().onStartConnection(this);
}
示例4: connect
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
@Test
public void connect() throws Exception {
final WebSocketClient client = new WebSocketClient();
client.start();
final WebSocketAdapter socket = new WebSocketAdapter() {
@Override
public void onWebSocketConnect(Session session) {
session.getRemote().sendStringByFuture("yo man!");
session.close();
}
};
client.connect(
socket,
URI.create("ws://localhost:8080/ws/"),
new ClientUpgradeRequest()
);
Thread.sleep(1000L);
client.stop();
}
示例5: main
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
public static void main(String[] args) {
String destUri = "ws://192.168.100.78:2014";
if (args.length > 0) {
destUri = args[0];
}
WebSocketClient client = new WebSocketClient();
SimpleEchoSocket socket = new SimpleEchoSocket();
try {
client.start();
URI echoUri = new URI(destUri);
ClientUpgradeRequest request = new ClientUpgradeRequest();
client.connect(socket, echoUri, request);
System.out.printf("Connecting to : %s%n", echoUri);
socket.awaitClose(5, TimeUnit.SECONDS);
} catch (Throwable t) {
t.printStackTrace();
} finally {
try {
client.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例6: openWatcherSession
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
private Session openWatcherSession() {
ClientUpgradeRequest request = new ClientUpgradeRequest();
request.setHeader(WatcherSecurityKey.HTTP_HEADER, WatcherSecurityKey.getKey());
request.setHeader(ORIGIN, "*");
WatcherWebsocket socket = WatcherWebsocket.createInstace();
Future<Session> future = null;
Session session = null;
try {
future = wsClient.connect(socket, zeppelinWebsocketUrl, request);
session = future.get();
} catch (IOException | InterruptedException | ExecutionException e) {
LOG.error("Couldn't establish websocket connection to Zeppelin ", e);
return session;
}
return session;
}
示例7: openNoteSession
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
private Session openNoteSession(String noteId, String principal, String ticket) {
ClientUpgradeRequest request = new ClientUpgradeRequest();
request.setHeader(ORIGIN, "*");
ZeppelinWebsocket socket = new ZeppelinWebsocket(noteId);
Future<Session> future = null;
Session session = null;
try {
future = wsClient.connect(socket, zeppelinWebsocketUrl, request);
session = future.get();
} catch (IOException | InterruptedException | ExecutionException e) {
LOG.error("Couldn't establish websocket connection to Zeppelin ", e);
return session;
}
if (notesConnection.containsKey(noteId)) {
session.close();
session = notesConnection.get(noteId);
} else {
String getNote = serialize(zeppelinGetNoteMsg(noteId, principal, ticket));
session.getRemote().sendStringByFuture(getNote);
notesConnection.put(noteId, session);
}
return session;
}
示例8: connect
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
private ZeppelinhubSession connect(String token) {
if (StringUtils.isBlank(token)) {
LOG.debug("Can't connect with empty token");
return ZeppelinhubSession.EMPTY;
}
ZeppelinhubSession zeppelinhubSession;
try {
ZeppelinhubWebsocket ws = ZeppelinhubWebsocket.newInstance(token);
ClientUpgradeRequest request = getConnectionRequest(token);
Future<Session> future = client.connect(ws, zeppelinhubWebsocketUrl, request);
Session session = future.get();
zeppelinhubSession = ZeppelinhubSession.createInstance(session, token);
setSession(token, zeppelinhubSession);
} catch (IOException | InterruptedException | ExecutionException e) {
LOG.info("Couldnt connect to zeppelinhub", e);
zeppelinhubSession = ZeppelinhubSession.EMPTY;
}
return zeppelinhubSession;
}
示例9: connectToWebSocket
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
private Session connectToWebSocket() throws Exception {
if (destroyed) {
return null;
}
if (!webSocketClient.isRunning()) {
webSocketClient.start();
}
URI webSocketUri = new URI(conf.resourceUrl);
ClientUpgradeRequest request = new ClientUpgradeRequest();
for (String key : conf.headers.keySet()) {
request.setHeader(key, conf.headers.get(key));
}
if (conf.authType.equals(AuthenticationType.BASIC)) {
String basicAuthHeader = WebSocketCommon.generateBasicAuthHeader(
conf.basicAuth.username.get(),
conf.basicAuth.password.get()
);
request.setHeader("Authorization", basicAuthHeader);
}
Future<Session> connectFuture = webSocketClient.connect(this, webSocketUri, request);
return connectFuture.get();
}
示例10: connect
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
/**
* Connects to the Rosbridge host at the provided URI.
* @param rosBridgeURI the URI to the ROS Bridge websocket server. Note that ROS Bridge by default uses port 9090. An example URI is: ws://localhost:9090
* @param waitForConnection if true, then this method will block until the connection is established. If false, then return immediately.
*/
public void connect(String rosBridgeURI, boolean waitForConnection){
WebSocketClient client = new WebSocketClient();
try {
client.start();
URI echoUri = new URI(rosBridgeURI);
ClientUpgradeRequest request = new ClientUpgradeRequest();
client.connect(this, echoUri, request);
System.out.printf("Connecting to : %s%n", echoUri);
if(waitForConnection){
this.waitForConnection();
}
} catch (Throwable t) {
t.printStackTrace();
}
}
示例11: main
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
public static void main(String[] args) {
String destUri = "ws://echo.websocket.org";
if (args.length > 0) {
destUri = args[0];
}
WebSocketClient client = new WebSocketClient();
SimpleEchoSocket socket = new SimpleEchoSocket();
try {
client.start();
URI echoUri = new URI(destUri);
ClientUpgradeRequest request = new ClientUpgradeRequest();
client.connect(socket, echoUri, request);
System.out.printf("Connecting to : %s%n", echoUri);
socket.awaitClose(15, TimeUnit.SECONDS);
} catch (Throwable t) {
t.printStackTrace();
} finally {
try {
client.stop();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例12: start
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
@Override
public boolean start() throws IOException {
String destUri = "wss://ws-feed.exchange.coinbase.com";
WebSocketClient client = new WebSocketClient(new SslContextFactory());
try {
LOG.info("connecting to coinbsae feed");
client.start();
URI echoUri = new URI(destUri);
ClientUpgradeRequest request = new ClientUpgradeRequest();
client.connect(this, echoUri, request);
LOG.info("done connecting");
} catch (Throwable t) {
t.printStackTrace();
}
return advance();
}
示例13: preStart
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
/**
* Establishes a connection with the webtrends stream api
* @see akka.actor.UntypedActor#preStart()
*/
public void preStart() throws Exception {
// initialize the uuid generator which is based on time and ethernet address
this.uuidGenerator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
// authenticate with the webtrends service
WebtrendsTokenRequest tokenRequest = new WebtrendsTokenRequest(this.authUrl, this.authAudience, this.authScope, this.clientId, this.clientSecret);
this.oAuthToken = tokenRequest.execute();
// initialize the webtrends stream socket client and connect the listener
this.webtrendsStreamSocketClient = new WebSocketClient();
try {
this.webtrendsStreamSocketClient.start();
ClientUpgradeRequest upgradeRequest = new ClientUpgradeRequest();
this.webtrendsStreamSocketClient.connect(this, new URI(this.eventStreamUrl), upgradeRequest);
await(5, TimeUnit.SECONDS);
} catch(Exception e) {
throw new RuntimeException("Unable to connect to web socket: " + e.getMessage(), e);
}
this.componentRegistryRef.tell(new ComponentRegistrationMessage(EVENT_SOURCE_ID, ComponentType.STREAM_LISTENER, getSelf()), getSelf());
}
示例14: openConnection
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
@Override
public void openConnection() throws IOException {
this.logger.info( getId() + " is opening a connection to the DM." );
try {
this.client = new WebSocketClient();
this.socket = new AgentWebSocket( this.messageQueue );
this.client.start();
URI dmUri = new URI( "ws://" + this.dmIp + ":" + this.dmPort + HttpConstants.DM_SOCKET_PATH );
this.logger.fine( "Connecting to " + dmUri );
ClientUpgradeRequest request = new ClientUpgradeRequest();
Future<Session> fut = this.client.connect( this.socket, dmUri, request );
this.clientSession = fut.get();
} catch( Exception e ) {
throw new IOException( e );
}
}
示例15: checkPlainConnect
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //導入依賴的package包/類
@Test
public void checkPlainConnect() throws Exception {
LOG.info("*** checkPlainConnect ***");
String destUri = "ws://localhost:" + BrokerConstants.WEBSOCKET_PORT + "/mqtt";
MQTTWebSocket socket = new MQTTWebSocket();
client.start();
URI echoUri = new URI(destUri);
ClientUpgradeRequest request = new ClientUpgradeRequest();
client.connect(socket, echoUri, request);
LOG.info("Connecting to : {}", echoUri);
boolean connected = socket.awaitConnected(4, TimeUnit.SECONDS);
LOG.info("Connected was : {}", connected);
assertTrue(connected);
}