当前位置: 首页>>代码示例>>Java>>正文


Java ClientUpgradeRequest类代码示例

本文整理汇总了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);
	}
}
 
开发者ID:mattjlewis,项目名称:diozero,代码行数:19,代码来源:JsonWebSocketProtocolHandler.java

示例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){
    }
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:20,代码来源:WebSocketAbstractSampler.java

示例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);
}
 
开发者ID:gustavohbf,项目名称:robotoy,代码行数:26,代码来源:WebSocketHandlerImpl.java

示例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();
}
 
开发者ID:arielr52,项目名称:sqlsocket,代码行数:26,代码来源:WebSocketTester.java

示例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();
        }
    }
}
 
开发者ID:East196,项目名称:maker,代码行数:25,代码来源:SimpleEchoClient.java

示例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;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:17,代码来源:ZeppelinClient.java

示例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;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:25,代码来源:ZeppelinClient.java

示例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;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:20,代码来源:ZeppelinhubClient.java

示例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();
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:27,代码来源:WebSocketClientSource.java

示例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();
	}

}
 
开发者ID:h2r,项目名称:java_rosbridge,代码行数:23,代码来源:RosBridge.java

示例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();
		}
	}
}
 
开发者ID:h2r,项目名称:java_rosbridge,代码行数:25,代码来源:SimpleEchoClient.java

示例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();
}
 
开发者ID:GoogleCloudPlatform,项目名称:cloud-bigtable-examples,代码行数:17,代码来源:CoinbaseSocket.java

示例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());
}
 
开发者ID:mnxfst,项目名称:stream-analyzer,代码行数:27,代码来源:WebtrendsStreamListenerActor.java

示例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 );
	}
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:21,代码来源:HttpAgentClient.java

示例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);
}
 
开发者ID:andsel,项目名称:moquette,代码行数:17,代码来源:ServerIntegrationWebSocketTest.java


注:本文中的org.eclipse.jetty.websocket.client.ClientUpgradeRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。