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


Java ClientUpgradeRequest.setHeader方法代码示例

本文整理汇总了Java中org.eclipse.jetty.websocket.client.ClientUpgradeRequest.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java ClientUpgradeRequest.setHeader方法的具体用法?Java ClientUpgradeRequest.setHeader怎么用?Java ClientUpgradeRequest.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jetty.websocket.client.ClientUpgradeRequest的用法示例。


在下文中一共展示了ClientUpgradeRequest.setHeader方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: connect

import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //导入方法依赖的package包/类
public void connect(boolean isReconnect) {
    if (client == null) {
        client = new org.eclipse.jetty.websocket.client.WebSocketClient();
    }
    // For debug usage
    // client.setConnectTimeout(SDKConstants.ONE_HOUR);
    try {
        if (!client.isStarted()) {
            client.start();
        }
        ClientUpgradeRequest request = new ClientUpgradeRequest();
        request.setSubProtocols(subProtocol);
        setLoadBalanceKey(request);
        if (token != null) {
            request.setHeader(SDKConstants.CUPID_INTERACTION_HEADER_TOKEN, token);
        }
        if (isReconnect) {
            request.setHeader(SDKConstants.CUPID_INTERACTION_HEADER_RECONNECT,
                    String.valueOf(System.currentTimeMillis()));
        }
        LOG.info(subProtocol + " - Connecting to : " + destUri);
        Future<Session> future = client.connect(interactionSocket, destUri, request);
        Session session = future.get(5l, TimeUnit.SECONDS);
        if (!isReconnect && SDKConstants.CUPID_INTERACTION_SUB_PROTOCOL_CLIENT.equals(subProtocol)) {
            // will be used for reconnect
            token = session.getUpgradeResponse().getHeader(SDKConstants.CUPID_INTERACTION_HEADER_TOKEN);
            routeInfo =
                    session.getUpgradeResponse()
                            .getHeader(SDKConstants.CUPID_INTERACTION_HEADER_ROUTE_INFO);
        }
        extractLoadBalanceKey(session);
        LOG.info(subProtocol + " - Connected!");
    } catch (Throwable t) {
        String errMsg = subProtocol + " - Websocket connect failed";
        LOG.error(errMsg, t);
        close();
    }
}
 
开发者ID:aliyun,项目名称:aliyun-cupid-sdk,代码行数:39,代码来源:WebSocketClient.java

示例6: connect

import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //导入方法依赖的package包/类
public void connect() throws Exception {
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    request.setHeader("Cookie", "CurseAuthToken=" + URLEncoder.encode(getAuthToken()));
    WebSocketClient client = new WebSocketClient(new SslContextFactory());
    TwitchNotificationSocket socket = new TwitchNotificationSocket(this);
    client.start();
    URI destUri = new URI("wss://notifications-eu-v1.curseapp.net/");
    System.out.println("Connecting to " + destUri);
    client.connect(socket, destUri, request);
}
 
开发者ID:renepreuss,项目名称:TwitchMessenger,代码行数:11,代码来源:TwitchMessenger.java

示例7: doHandshakeInternal

import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //导入方法依赖的package包/类
@Override
public ListenableFuture<WebSocketSession> doHandshakeInternal(WebSocketHandler wsHandler,
		HttpHeaders headers, final URI uri, List<String> protocols,
		List<WebSocketExtension> extensions,  Map<String, Object> attributes) {

	final ClientUpgradeRequest request = new ClientUpgradeRequest();
	request.setSubProtocols(protocols);

	for (WebSocketExtension e : extensions) {
		request.addExtensions(new WebSocketToJettyExtensionConfigAdapter(e));
	}

	for (String header : headers.keySet()) {
		request.setHeader(header, headers.get(header));
	}

	Principal user = getUser();
	final JettyWebSocketSession wsSession = new JettyWebSocketSession(attributes, user);
	final JettyWebSocketHandlerAdapter listener = new JettyWebSocketHandlerAdapter(wsHandler, wsSession);

	Callable<WebSocketSession> connectTask = new Callable<WebSocketSession>() {
		@Override
		public WebSocketSession call() throws Exception {
			Future<Session> future = client.connect(listener, uri, request);
			future.get();
			return wsSession;
		}
	};

	if (this.taskExecutor != null) {
		return this.taskExecutor.submitListenable(connectTask);
	}
	else {
		ListenableFutureTask<WebSocketSession> task = new ListenableFutureTask<WebSocketSession>(connectTask);
		task.run();
		return task;
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:39,代码来源:JettyWebSocketClient.java

示例8: write

import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //导入方法依赖的package包/类
@Override
public void write(Batch batch) throws StageException {
  Session wsSession = null;
  try {
    WebSocketTargetSocket webSocketTargetSocket = new WebSocketTargetSocket(
        conf,
        generatorFactory,
        errorRecordHandler,
        batch
    );
    webSocketClient.start();
    URI webSocketUri = new URI(conf.resourceUrl);
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    for(HeaderBean header : conf.headers) {
      request.setHeader(header.key, header.value.get());
    }
    Future<Session> connectFuture = webSocketClient.connect(webSocketTargetSocket, webSocketUri, request);
    wsSession = connectFuture.get();
    if (!webSocketTargetSocket.awaitClose(conf.maxRequestCompletionSecs, TimeUnit.SECONDS)) {
      throw new RuntimeException("Failed to send all records in maximum wait time.");
    }
  } catch (Exception ex) {
    LOG.error(Errors.HTTP_50.getMessage(), ex.toString(), ex);
    errorRecordHandler.onError(Lists.newArrayList(batch.getRecords()), throwStageException(ex));
  } finally {
    if (wsSession != null) {
      wsSession.close();
    }
    try {
      webSocketClient.stop();
    } catch (Exception e) {
      LOG.error(Errors.HTTP_50.getMessage(), e.toString(), e);
    }
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:36,代码来源:WebSocketTarget.java

示例9: connect

import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //导入方法依赖的package包/类
@Override
public Promise<Channel> connect(final TransportContext context, final ChannelHandler handler, boolean reconnect) {
    if (context == null) {
        throw new IllegalArgumentException("Context must not be null");
    }
    if (handler == null) {
        throw new IllegalArgumentException("Handler must not be null");
    }

    final TransportOptions options = context.getTransportOptions();

    if (!options.getTryWebSockets()) {
        throw new IllegalStateException("WebSockets are not supported by the server");
    }

    // Setup request.
    final URI uri = Transports.buildConnectUri(context, this, reconnect);
    final ClientUpgradeRequest request = new ClientUpgradeRequest();
    final Map<String, Collection<String>> headers = context.getHeaders();

    for (final Map.Entry<String, Collection<String>> header : headers.entrySet()) {
        final String name = header.getKey();

        for (final String value : header.getValue()) {
            request.setHeader(name, value);
        }
    }
    request.setHeader("User-Agent", USER_AGENT);

    // Send request.
    final WebSocketListenerAdapter listener = new WebSocketListenerAdapter(handler);

    try {
        _webSocketClient.connect(listener, uri, request);
    } catch (final Exception e) {
        return Promises.newFailure(e);
    }

    return listener.getChannel();
}
 
开发者ID:mtamme,项目名称:signalr-client,代码行数:41,代码来源:WebSocketTransport.java

示例10: testSource

import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; //导入方法依赖的package包/类
@Test
public void testSource() throws Exception {
  WebSocketConfigs webSocketConfigs = new WebSocketConfigs();
  webSocketConfigs.appId = () -> "appId";
  webSocketConfigs.port = NetworkUtils.getRandomPort();
  webSocketConfigs.maxConcurrentRequests = 1;
  webSocketConfigs.tlsConfigBean.tlsEnabled = false;
  WebSocketServerPushSource source =
      new WebSocketServerPushSource(webSocketConfigs, DataFormat.JSON, new DataParserFormatConfig());
  final PushSourceRunner runner =
      new PushSourceRunner.Builder(WebSocketServerDPushSource.class, source).addOutputLane("a").build();
  runner.runInit();
  try {
    final List<Record> records = new ArrayList<>();
    runner.runProduce(Collections.<String, String>emptyMap(), 1, new PushSourceRunner.Callback() {
      @Override
      public void processBatch(StageRunner.Output output) {
        records.clear();
        records.addAll(output.getRecords().get("a"));
        runner.setStop();
      }
    });

    WebSocketClient client = new WebSocketClient();
    SimpleEchoSocket socket = new SimpleEchoSocket();
    try {
      client.start();
      URI echoUri = new URI("ws://localhost:" + webSocketConfigs.getPort());
      ClientUpgradeRequest request = new ClientUpgradeRequest();
      request.setHeader(HttpConstants.X_SDC_APPLICATION_ID_HEADER, "appId");
      Future<Session> future = client.connect(socket, echoUri, request);
      future.get();
      // wait for closed socket connection.
      socket.awaitClose(5, TimeUnit.SECONDS);
    } catch (Throwable t) {
      t.printStackTrace();
    } finally {
      try {
        client.stop();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    runner.waitOnProduce();

    Assert.assertEquals(1, records.size());
    Assert.assertEquals("value", records.get(0).get("/field1").getValue());
  } finally {
    runner.runDestroy();
  }
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:53,代码来源:TestWebSocketServerPushSource.java


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