org.eclipse.jetty.client.api.Request.send()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中org.eclipse.jetty.client.api.Request.send方法的一些代码示例,展示了Request.send的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.send方法的具体详情如下:
包路径:org.eclipse.jetty.client.api.Request
类名称:Request
方法名:send

Request.send介绍

[英]Sends this request and returns the response.

This method should be used when a simple blocking semantic is needed, and when it is known that the response content can be buffered without exceeding memory constraints.

For example, this method is not appropriate to download big files from a server; consider using #send(Response.CompleteListener) instead, passing your own Response.Listener or a utility listener such as InputStreamResponseListener.

The method returns when the Response.CompleteListener is fired.
[中]发送此请求并返回响应。
当需要简单的阻塞语义时,以及当知道响应内容可以在不超过内存约束的情况下进行缓冲时,应该使用这种方法。
例如,这种方法不适合从服务器下载大文件;考虑使用“发送”(Real.Sealelististor),而不是通过自己的响应。侦听器或实用侦听器,如InputStreamResponseListener。
该方法在收到响应时返回。CompleteListener被解雇了。

代码示例

代码示例来源:origin: spring-projects/spring-framework

private void executeReceiveRequest(URI url, HttpHeaders headers, SockJsResponseListener listener) {
  if (logger.isTraceEnabled()) {
    logger.trace("Starting XHR receive request, url=" + url);
  }
  Request httpRequest = this.httpClient.newRequest(url).method(HttpMethod.POST);
  addHttpHeaders(httpRequest, headers);
  httpRequest.send(listener);
}

代码示例来源:origin: spring-projects/spring-framework

protected ResponseEntity<String> executeRequest(URI url, HttpMethod method,
    HttpHeaders headers, @Nullable String body) {
  Request httpRequest = this.httpClient.newRequest(url).method(method);
  addHttpHeaders(httpRequest, headers);
  if (body != null) {
    httpRequest.content(new StringContentProvider(body));
  }
  ContentResponse response;
  try {
    response = httpRequest.send();
  }
  catch (Exception ex) {
    throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
  }
  HttpStatus status = HttpStatus.valueOf(response.getStatus());
  HttpHeaders responseHeaders = toHttpHeaders(response.getHeaders());
  return (response.getContent() != null ?
      new ResponseEntity<>(response.getContentAsString(), responseHeaders, status) :
      new ResponseEntity<>(responseHeaders, status));
}

代码示例来源:origin: konsoletyper/teavm

proxyReq.send(result -> {
  headerSender.send(result.getResponse());
  async.complete();

代码示例来源:origin: apache/incubator-druid

broadcastReq.send(completeListener);

代码示例来源:origin: jersey/jersey

jettyRequest.send(new Response.Listener.Adapter() {

代码示例来源:origin: xuxueli/xxl-job

ContentResponse response = request.send();
if (response.getStatus() != HttpStatus.OK_200) {
  XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());

代码示例来源:origin: xuxueli/xxl-job

ContentResponse response = request.send();
if (response.getStatus() != HttpStatus.OK_200) {
  XxlJobLogger.log("Http StatusCode({}) Invalid.", response.getStatus());

代码示例来源:origin: jersey/jersey

@Override
public ClientResponse apply(final ClientRequest jerseyRequest) throws ProcessingException {
  final Request jettyRequest = translateRequest(jerseyRequest);
  final Map<String, String> clientHeadersSnapshot = writeOutBoundHeaders(jerseyRequest.getHeaders(), jettyRequest);
  final ContentProvider entity = getBytesProvider(jerseyRequest);
  if (entity != null) {
    jettyRequest.content(entity);
  }
  try {
    final ContentResponse jettyResponse = jettyRequest.send();
    HeaderUtils.checkHeaderChanges(clientHeadersSnapshot, jerseyRequest.getHeaders(),
                    JettyConnector.this.getClass().getName());
    final javax.ws.rs.core.Response.StatusType status = jettyResponse.getReason() == null
        ? Statuses.from(jettyResponse.getStatus())
        : Statuses.from(jettyResponse.getStatus(), jettyResponse.getReason());
    final ClientResponse jerseyResponse = new ClientResponse(status, jerseyRequest);
    processResponseHeaders(jettyResponse.getHeaders(), jerseyResponse);
    try {
      jerseyResponse.setEntityStream(new HttpClientResponseInputStream(jettyResponse));
    } catch (final IOException e) {
      LOGGER.log(Level.SEVERE, null, e);
    }
    return jerseyResponse;
  } catch (final Exception e) {
    throw new ProcessingException(e);
  }
}

代码示例来源:origin: sixt/ja-micro

private boolean verifyRegistrationInConsul() {
  String registryServer = serviceProps.getRegistryServer();
  if (StringUtils.isBlank(registryServer)) {
    return false;
  }
  String url = "http://" + registryServer + "/v1/catalog/service/" +
      serviceProps.getServiceName();
  try {
    ContentResponse httpResponse = httpClient.newRequest(url).
        method(HttpMethod.GET).header(HttpHeader.CONTENT_TYPE, "application/json").send();
    if (httpResponse.getStatus() != 200) {
      return false;
    }
    JsonArray pods = new JsonParser().parse(httpResponse.getContentAsString()).getAsJsonArray();
    Iterator<JsonElement> iter = pods.iterator();
    while (iter.hasNext()) {
      JsonElement pod = iter.next();
      String serviceId = pod.getAsJsonObject().get("ServiceID").getAsString();
      if (serviceProps.getServiceInstanceId().equals(serviceId)) {
        return true;
      }
    }
  } catch (Exception ex) {
    logger.warn("Caught exception verifying registration", ex);
  }
  return false;
}

代码示例来源:origin: sixt/ja-micro

public void updateHealthStatus(HealthCheck.Status status) throws Exception {
  logger.trace("Updating health of {}", serviceProps.getServiceName());
  ContentResponse httpResponse = httpClient.newRequest(getHealthCheckUri(status)).method(HttpMethod.PUT).send();
  if (httpResponse.getStatus() != 200) {
    logger.warn("Received {} trying to update health", httpResponse.getStatus());
  }
}

代码示例来源:origin: sixt/ja-micro

private boolean sendRegistration(JsonObject request) {
  try {
    ContentResponse httpResponse = httpClient.newRequest(getRegistrationUri()).
        content(new StringContentProvider(request.toString())).
        method(HttpMethod.PUT).header(HttpHeader.CONTENT_TYPE, "application/json").send();
    if (httpResponse.getStatus() == 200) {
      return true;
    }
  } catch (Exception ex) {
    logger.warn("Caught exception sending registration {}", request.toString(), ex);
  }
  return false;
}

代码示例来源:origin: sixt/ja-micro

@Override
public Request newRequest(String uri) {
  Request retval = mock(Request.class);
  try {
    if (requestsTimeout || (isFirstRequestTimeout && requests.isEmpty())) {
      when(retval.send()).thenThrow(new TimeoutException());
    } else {
      when(retval.send()).thenReturn(httpResponse);
    }
    if (requestsFail && featureFlag.equals("true")) {
      when(httpResponse.getStatus()).thenReturn(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } else if (responseException != null) {
      when(httpResponse.getStatus()).thenReturn(responseException.getCategory().getHttpStatus());
    } else {
      when(httpResponse.getStatus()).thenReturn(HttpServletResponse.SC_OK);
    }
  } catch (Exception e) {
    e.printStackTrace();
  }
  when(retval.method(anyString())).thenReturn(retval);
  when(retval.content(any(ContentProvider.class))).thenReturn(retval);
  when(retval.timeout(anyLong(), any(TimeUnit.class))).thenReturn(retval);
  requests.add(uri);
  return retval;
}

代码示例来源:origin: sixt/ja-micro

while (httpResponse == null) {
  try {
    httpResponse = httpClient.newRequest(requestUrl).send();
  } catch (Exception ex) {
    if (isShutdown.get()) {

代码示例来源:origin: sixt/ja-micro

@Before
public void setup() throws Exception {
  HttpClient httpClient = mock(HttpClient.class);
  response = mock(ContentResponse.class);
  when(response.getStatus()).thenReturn(200);
  when(response.getContentAsString()).thenReturn(healthInfo);
  HttpFields headers = new HttpFields();
  headers.add(CONSUL_INDEX, "42");
  when(response.getHeaders()).thenReturn(headers);
  Request request = mock(Request.class);
  when(httpClient.newRequest(anyString())).thenReturn(request);
  when(request.send()).thenReturn(response);
  props = new ServiceProperties();
  props.addProperty(ServiceProperties.REGISTRY_SERVER_KEY, "localhost:1234");
  worker = new RegistrationMonitorWorker(httpClient, props, mock(ServiceDependencyHealthCheck.class));
  worker.setServiceName("foobar");
}

代码示例来源:origin: sixt/ja-micro

@Before
public void setup() throws InterruptedException, ExecutionException, TimeoutException {
  when(loadBalancer.getHealthyInstance()).thenReturn(createServiceEndpoint());
  when(loadBalancer.getHealthyInstanceExclude(anyListOf(ServiceEndpoint.class)))
    .thenReturn(createServiceEndpoint());
  when(rpcClient.getRetries()).thenReturn(NUMBER_OF_RETRIES);
  when(rpcClient.getTimeout()).thenReturn(0);
  httpClientWrapper.setLoadBalancer(loadBalancer);
  when(rpcClientMetrics.getMethodTimer(any(), any())).thenReturn(new GoTimer("timer"));
  when(tracer.buildSpan(any())).thenReturn(spanBuilder);
  when(spanBuilder.start()).thenReturn(span);
  when(httpClient.newRequest(any(URI.class))).thenReturn(request);
  when(httpClient.newRequest(any(String.class))).thenReturn(request);
  when(request.content(any(ContentProvider.class))).thenReturn(request);
  when(request.method(anyString())).thenReturn(request);
  when(request.timeout(anyLong(), any(TimeUnit.class))).thenReturn(request);
  when(request.send()).thenReturn(httpContentResponse);
  when(httpContentResponse.getStatus()).thenReturn(100);
  dependencyHealthCheck = mock(ServiceDependencyHealthCheck.class);
}

代码示例来源:origin: sixt/ja-micro

protected String sendRequest(String path, String data, HttpMethod method) throws Exception {
  String url = getServiceUrl(path);
  Request request = httpClient.newRequest(url).method(method).
      header(HttpHeader.CONTENT_TYPE, "application/json");
  if (data != null) {
    request.content(new StringContentProvider(data));
  }
  ContentResponse response = request.send();
  return response.getContentAsString();
}

代码示例来源:origin: resteasy/Resteasy

request.send(new Response.Listener.Adapter() {
  private ClientResponse cr;
  private JettyResponseStream stream = new JettyResponseStream();

代码示例来源:origin: allegro/hermes

private CompletableFuture<SingleMessageSendingResult> handleResponse(Request response) {
  CompletableFuture<SingleMessageSendingResult> future = new CompletableFuture<>();
  Response.CompleteListener completeListener = result -> future.complete(MessageSendingResult.of(result));
  response.send(completeListener);
  return future;
}

代码示例来源:origin: sixt/ja-micro

TimeUnit.MILLISECONDS).send();
logger.debug(logMarker, "Http send completed");
lastStatusCode = retval.getStatus();

代码示例来源:origin: allegro/hermes

private ContentResponse performHttpRequest(OAuthTokenRequest request) {
  try {
    return createHttpRequest(request).send();
  } catch (InterruptedException | TimeoutException | ExecutionException e) {
    throw new OAuthTokenRequestException("An exception occurred while performing token request", e);
  }
}

相关文章