org.eclipse.jetty.client.HttpClient.newRequest()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(245)

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

HttpClient.newRequest介绍

[英]Creates a new request with the specified absolute URI in string format.
[中]以字符串格式创建具有指定绝对URI的新请求。

代码示例

代码示例来源: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

@Override
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
    Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
  if (!uri.isAbsolute()) {
    return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri));
  }
  if (!this.httpClient.isStarted()) {
    try {
      this.httpClient.start();
    }
    catch (Exception ex) {
      return Mono.error(ex);
    }
  }
  JettyClientHttpRequest clientHttpRequest = new JettyClientHttpRequest(
      this.httpClient.newRequest(uri).method(method.toString()), this.bufferFactory);
  return requestCallback.apply(clientHttpRequest).then(Mono.from(
      clientHttpRequest.getReactiveRequest().response((response, chunks) -> {
        Flux<DataBuffer> content = Flux.from(chunks).map(this::toDataBuffer);
        return Mono.just(new JettyClientHttpResponse(response, content));
      })));
}

代码示例来源: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

Request proxyReq = httpClient.newRequest(sb.toString());
proxyReq.method(req.getMethod());
copyRequestHeaders(req, proxyReq::header);

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

.newRequest(rewriteURI(request, server.getScheme(), server.getHost()))
.method(HttpMethod.DELETE)
.timeout(CANCELLATION_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);

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

private Request translateRequest(final ClientRequest clientRequest) {
  final URI uri = clientRequest.getUri();
  final Request request = client.newRequest(uri);
  request.method(clientRequest.getMethod());
  request.followRedirects(clientRequest.resolveProperty(ClientProperties.FOLLOW_REDIRECTS, true));
  final Object readTimeout = clientRequest.getConfiguration().getProperties().get(ClientProperties.READ_TIMEOUT);
  if (readTimeout != null && readTimeout instanceof Integer && (Integer) readTimeout > 0) {
    request.timeout((Integer) readTimeout, TimeUnit.MILLISECONDS);
  }
  return request;
}

代码示例来源:origin: org.springframework/spring-web

@Override
public Mono<ClientHttpResponse> connect(HttpMethod method, URI uri,
    Function<? super ClientHttpRequest, Mono<Void>> requestCallback) {
  if (!uri.isAbsolute()) {
    return Mono.error(new IllegalArgumentException("URI is not absolute: " + uri));
  }
  if (!this.httpClient.isStarted()) {
    try {
      this.httpClient.start();
    }
    catch (Exception ex) {
      return Mono.error(ex);
    }
  }
  JettyClientHttpRequest clientHttpRequest = new JettyClientHttpRequest(
      this.httpClient.newRequest(uri).method(method.toString()), this.bufferFactory);
  return requestCallback.apply(clientHttpRequest).then(Mono.from(
      clientHttpRequest.getReactiveRequest().response((response, chunks) -> {
        Flux<DataBuffer> content = Flux.from(chunks).map(this::toDataBuffer);
        return Mono.just(new JettyClientHttpResponse(response, content));
      })));
}

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

Request request = httpClient.newRequest(param);
request.method(HttpMethod.GET);
request.timeout(5000, TimeUnit.MILLISECONDS);

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

Request request = httpClient.newRequest(param);
request.method(HttpMethod.GET);
request.timeout(5000, TimeUnit.MILLISECONDS);

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

public Request newRequest(HttpClient httpClient) {
  Request request = httpClient.newRequest(uri);
  request.content(contentProvider).method(method);
  for (String key : headers.keySet()) {
    if (! "User-Agent".equals(key)) {
      request.header(key, headers.get(key));
    }
  }
  return request;
}

代码示例来源: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

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

代码示例来源: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

@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

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

final Request request = client.newRequest(invocation.getUri());
final CompletableFuture<T> future = new RequestFuture<T>(request);

代码示例来源:origin: org.springframework/spring-websocket

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: org.infinispan/infinispan-server-rest

@Test
public void shouldReturnJsonWithDefaultConfig() throws Exception {
 putStringValueInCache("textCache", "test", "Hey!");
 ContentResponse getResponse = client
    .newRequest(String.format("http://localhost:%d/rest/%s/%s", restServer().getPort(), "textCache", "test"))
    .method(HttpMethod.GET)
    .header("Accept", "application/json")
    .send();
 ResponseAssertion.assertThat(getResponse).isOk();
 ResponseAssertion.assertThat(getResponse).hasReturnedText("\"Hey!\"");
}

相关文章

HttpClient类方法