org.apache.cxf.jaxrs.client.WebClient.getCurrentURI()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(16.4k)|赞(0)|评价(0)|浏览(190)

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

WebClient.getCurrentURI介绍

暂无

代码示例

代码示例来源:origin: apache/cxf

public HttpRequestProperties(WebClient wc, String httpMethod) {
  this(wc.getCurrentURI(), httpMethod);
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-security-oauth2

public HttpRequestProperties(WebClient wc, String httpMethod) {
  this(wc.getCurrentURI(), httpMethod);
}

代码示例来源:origin: apache/cxf

private void initTargetClientIfNeeded(Map<String, Object> configProps) {
  URI uri = uriBuilder.build();
  if (targetClient == null) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(uri.toString());
    Boolean threadSafe = getBooleanValue(configProps.get(THREAD_SAFE_CLIENT_PROP));
    if (threadSafe == null) {
      threadSafe = DEFAULT_THREAD_SAFETY_CLIENT_STATUS;
    }
    bean.setThreadSafe(threadSafe);
    if (threadSafe) {
      Integer cleanupPeriod = getIntValue(configProps.get(THREAD_SAFE_CLIENT_STATE_CLEANUP_PROP));
      if (cleanupPeriod == null) {
        cleanupPeriod = THREAD_SAFE_CLIENT_STATE_CLEANUP_PERIOD;
      }
      if (cleanupPeriod != null) {
        bean.setSecondsToKeepState(cleanupPeriod);
      }
    }
    targetClient = bean.createWebClient();
    ClientImpl.this.baseClients.add(targetClient);
  } else if (!targetClient.getCurrentURI().equals(uri)) {
    targetClient.to(uri.toString(), false);
  }
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-client

private void initTargetClientIfNeeded(Map<String, Object> configProps) {
  URI uri = uriBuilder.build();
  if (targetClient == null) {
    JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
    bean.setAddress(uri.toString());
    Boolean threadSafe = getBooleanValue(configProps.get(THREAD_SAFE_CLIENT_PROP));
    if (threadSafe == null) {
      threadSafe = DEFAULT_THREAD_SAFETY_CLIENT_STATUS;
    }
    bean.setThreadSafe(threadSafe);
    if (threadSafe) {
      Integer cleanupPeriod = getIntValue(configProps.get(THREAD_SAFE_CLIENT_STATE_CLEANUP_PROP));
      if (cleanupPeriod == null) {
        cleanupPeriod = THREAD_SAFE_CLIENT_STATE_CLEANUP_PERIOD;
      }
      if (cleanupPeriod != null) {
        bean.setSecondsToKeepState(cleanupPeriod);
      }
    }
    targetClient = bean.createWebClient();
    ClientImpl.this.baseClients.add(targetClient);
  } else if (!targetClient.getCurrentURI().equals(uri)) {
    targetClient.to(uri.toString(), false);
  }
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

private Message finalizeMessage(String httpMethod, 
                MultivaluedMap<String, String> headers, 
                Object body, 
                Class<?> requestClass,
                Type inGenericType,
                Class<?> responseClass, 
                Type outGenericType,
                Exchange exchange,
                Map<String, Object> invContext) {
//CHECKSTYLE:ON    
  URI uri = getCurrentURI();
  Message m = createMessage(body, httpMethod, headers, uri, exchange, 
      invContext, false);
  setSupportOnewayResponseProperty(m);
  Map<String, Object> reqContext = getRequestContext(m);
  reqContext.put(Message.HTTP_REQUEST_METHOD, httpMethod);
  reqContext.put(REQUEST_CLASS, requestClass);
  reqContext.put(REQUEST_TYPE, inGenericType);
  reqContext.put(RESPONSE_CLASS, responseClass);
  reqContext.put(RESPONSE_TYPE, outGenericType);
  
  m.getInterceptorChain().add(bodyWriter);
 
  setPlainOperationNameProperty(m, httpMethod + ":" + uri.toString());
  return m;
}

代码示例来源:origin: apache/cxf

Map<String, Object> invContext) {
URI uri = getCurrentURI();
Message m = createMessage(body, httpMethod, headers, uri, exchange,
    invContext, false);

代码示例来源:origin: apache/cxf

/**
 * Goes back
 * @param fast if true then goes back to baseURI otherwise to a previous path segment
 * @return updated WebClient
 */
public WebClient back(boolean fast) {
  getState().setTemplates(null);
  if (fast) {
    getCurrentBuilder().replacePath(getBaseURI().getPath());
  } else {
    URI uri = getCurrentURI();
    if (uri == getBaseURI()) {
      return this;
    }
    List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false);
    getCurrentBuilder().replacePath(null);
    for (int i = 0; i < segments.size() - 1; i++) {
      getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i)));
    }
  }
  return this;
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider);
  final Future<Response> f = client.async().get();
  final Response r = f.get(1, TimeUnit.SECONDS);
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSender.getAllSpans().size(), equalTo(3));
  assertThat(TestSender.getAllSpans().get(0).getOperationName(), equalTo("Get Books"));
  assertThat(TestSender.getAllSpans().get(1).getOperationName(), equalTo("GET /bookstore/books"));
  assertThat(TestSender.getAllSpans().get(2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
}

代码示例来源:origin: org.apache.cxf/cxf-rt-rs-client

/**
 * Goes back
 * @param fast if true then goes back to baseURI otherwise to a previous path segment
 * @return updated WebClient
 */
public WebClient back(boolean fast) {
  getState().setTemplates(null);
  if (fast) {
    getCurrentBuilder().replacePath(getBaseURI().getPath());
  } else {
    URI uri = getCurrentURI();
    if (uri == getBaseURI()) {
      return this;
    }
    List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false);
    getCurrentBuilder().replacePath(null);
    for (int i = 0; i < segments.size() - 1; i++) {
      getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i)));
    }
  }
  return this;
}

代码示例来源:origin: org.apache.cxf/cxf-bundle-jaxrs

/**
 * Goes back
 * @param fast if true then goes back to baseURI otherwise to a previous path segment 
 * @return updated WebClient
 */
public WebClient back(boolean fast) {
  getState().setTemplates(null);
  if (fast) {
    getCurrentBuilder().replacePath(getBaseURI().getPath());
  } else {
    URI uri = getCurrentURI();
    if (uri == getBaseURI()) {
      return this;
    }
    List<PathSegment> segments = JAXRSUtils.getPathSegments(uri.getPath(), false);
    getCurrentBuilder().replacePath(null);
    for (int i = 0; i < segments.size() - 1; i++) {
      getCurrentBuilder().path(HttpUtils.fromPathSegment(segments.get(i)));
    }
    
  }
  return this;
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpanIsCreatedWhenNotProvidedUsingAsyncClient() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
  final Future<Response> f = client.async().get();
  final Response r = f.get(1, TimeUnit.SECONDS);
  assertEquals(Status.OK.getStatusCode(), r.getStatus());
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
  assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
  assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
  assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
  assertThatTraceHeadersArePresent(r, false);
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
  // The intention is to make a calls one after another, not in parallel, to ensure the
  // thread have trace contexts cleared out.
  final Collection<Response> responses = IntStream
    .range(0, 4)
    .mapToObj(index -> client.get())
    .collect(Collectors.toList());
  for (final Response r: responses) {
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThatTraceHeadersArePresent(r, false);
  }
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(12));
  IntStream
    .range(0, 4)
    .map(index -> index * 3)
    .forEach(index -> {
      assertThat(TestSpanReporter.getAllSpans().get(index).name(),
        equalTo("get books"));
      assertThat(TestSpanReporter.getAllSpans().get(index + 1).name(),
        equalTo("get /bookstore/books"));
      assertThat(TestSpanReporter.getAllSpans().get(index + 2).name(),
        equalTo("get " + client.getCurrentURI()));
    });
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
  // The intention is to make a calls one after another, not in parallel, to ensure the
  // thread have trace contexts cleared out.
  final Collection<Response> responses = IntStream
    .range(0, 4)
    .mapToObj(index -> client.async().get())
    .map(this::get)
    .collect(Collectors.toList());
  for (final Response r: responses) {
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThatTraceHeadersArePresent(r, false);
  }
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(12));
  IntStream
    .range(0, 4)
    .map(index -> index * 3)
    .forEach(index -> {
      assertThat(TestSpanReporter.getAllSpans().get(index).name(),
        equalTo("get books"));
      assertThat(TestSpanReporter.getAllSpans().get(index + 1).name(),
        equalTo("get /bookstore/books"));
      assertThat(TestSpanReporter.getAllSpans().get(index + 2).name(),
        equalTo("get " + client.getCurrentURI()));
    });
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleClients() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider);
  // The intention is to make a calls one after another, not in parallel, to ensure the
  // thread have trace contexts cleared out.
  final Collection<Response> responses = IntStream
    .range(0, 4)
    .mapToObj(index -> client.get())
    .collect(Collectors.toList());
  for (final Response r: responses) {
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
  }
  assertThat(TestSender.getAllSpans().size(), equalTo(12));
  IntStream
    .range(0, 4)
    .map(index -> index * 3)
    .forEach(index -> {
      assertThat(TestSender.getAllSpans().get(index).getOperationName(),
        equalTo("Get Books"));
      assertThat(TestSender.getAllSpans().get(index + 1).getOperationName(),
        equalTo("GET /bookstore/books"));
      assertThat(TestSender.getAllSpans().get(index + 2).getOperationName(),
        equalTo("GET " + client.getCurrentURI()));
    });
}

代码示例来源:origin: apache/cxf

@Test
public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
  final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider);
  try (Scope span = tracer.buildSpan("test span").startActive(true)) {
    final Response r = client.get();
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(TestSender.getAllSpans().size(), equalTo(3));
    assertThat(TestSender.getAllSpans().get(0).getOperationName(), equalTo("Get Books"));
    assertThat(TestSender.getAllSpans().get(0).getReferences(), not(empty()));
    assertThat(TestSender.getAllSpans().get(1).getReferences(), not(empty()));
    assertThat(TestSender.getAllSpans().get(1).getOperationName(), equalTo("GET /bookstore/books"));
    assertThat(TestSender.getAllSpans().get(2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
    assertThat(TestSender.getAllSpans().get(2).getReferences(), not(empty()));
  }
  // Await till flush happens, usually every second
  await().atMost(Duration.ONE_SECOND).until(()-> TestSender.getAllSpans().size() == 4);
  assertThat(TestSender.getAllSpans().size(), equalTo(4));
  assertThat(TestSender.getAllSpans().get(3).getOperationName(), equalTo("test span"));
  assertThat(TestSender.getAllSpans().get(3).getReferences(), empty());
}

代码示例来源:origin: apache/cxf

@Test
public void testThatNewSpansAreCreatedWhenNotProvidedUsingMultipleAsyncClients() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider);
  // The intention is to make a calls one after another, not in parallel, to ensure the
  // thread have trace contexts cleared out.
  final Collection<Response> responses = IntStream
    .range(0, 4)
    .mapToObj(index -> client.async().get())
    .map(this::get)
    .collect(Collectors.toList());
  for (final Response r: responses) {
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
  }
  assertThat(TestSender.getAllSpans().size(), equalTo(12));
  IntStream
    .range(0, 4)
    .map(index -> index * 3)
    .forEach(index -> {
      assertThat(TestSender.getAllSpans().get(index).getOperationName(),
        equalTo("Get Books"));
      assertThat(TestSender.getAllSpans().get(index + 1).getOperationName(),
        equalTo("GET /bookstore/books"));
      assertThat(TestSender.getAllSpans().get(index + 2).getOperationName(),
        equalTo("GET " + client.getCurrentURI()));
    });
}

代码示例来源:origin: apache/cxf

@Test
public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", openTracingClientProvider);
  try (Scope scope = tracer.buildSpan("test span").startActive(true)) {
    final Future<Response> f = client.async().get();
    final Response r = f.get(1, TimeUnit.HOURS);
    assertEquals(Status.OK.getStatusCode(), r.getStatus());
    assertThat(tracer.activeSpan().context(), equalTo(scope.span().context()));
    assertThat(TestSender.getAllSpans().size(), equalTo(3));
    assertThat(TestSender.getAllSpans().get(0).getOperationName(), equalTo("Get Books"));
    assertThat(TestSender.getAllSpans().get(0).getReferences(), not(empty()));
    assertThat(TestSender.getAllSpans().get(1).getOperationName(), equalTo("GET /bookstore/books"));
    assertThat(TestSender.getAllSpans().get(1).getReferences(), not(empty()));
    assertThat(TestSender.getAllSpans().get(2).getOperationName(), equalTo("GET " + client.getCurrentURI()));
    assertThat(TestSender.getAllSpans().get(2).getReferences(), not(empty()));
  }
  // Await till flush happens, usually every second
  await().atMost(Duration.ONE_SECOND).until(()-> TestSender.getAllSpans().size() == 4);
  assertThat(TestSender.getAllSpans().size(), equalTo(4));
  assertThat(TestSender.getAllSpans().get(3).getOperationName(), equalTo("test span"));
  assertThat(TestSender.getAllSpans().get(3).getReferences(), empty());
}

代码示例来源:origin: apache/cxf

@Test
public void testThatProvidedSpanIsNotClosedWhenActive() throws MalformedURLException {
  final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
  final Span span = brave.tracer().nextSpan().name("test span").start();
  try {
    try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
      final Response r = client.get();
      assertEquals(Status.OK.getStatusCode(), r.getStatus());
      assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
      assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
      assertThat(TestSpanReporter.getAllSpans().get(0).parentId(), not(nullValue()));
      assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
      assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
      assertThatTraceHeadersArePresent(r, true);
    }
  } finally {
    span.finish();
  }
  // Await till flush happens, usually a second is enough
  await().atMost(Duration.ONE_SECOND).until(()-> TestSpanReporter.getAllSpans().size() == 4);
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
  assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}

代码示例来源:origin: apache/cxf

@Test
public void testGetBookRelativeUriAutoRedirect() throws Exception {
  String address = "http://localhost:" + PORT + "/bookstore/redirect/relative?loop=false";
  WebClient wc = WebClient.create(address);
  assertEquals(address, wc.getCurrentURI().toString());
  WebClient.getConfig(wc).getRequestContext().put("http.redirect.relative.uri", "true");
  WebClient.getConfig(wc).getHttpConduit().getClient().setAutoRedirect(true);
  Response r = wc.get();
  Book book = r.readEntity(Book.class);
  assertEquals(124L, book.getId());
  String newAddress = "http://localhost:" + PORT + "/bookstore/redirect/relative?redirect=true";
  assertEquals(newAddress, wc.getCurrentURI().toString());
}

代码示例来源:origin: apache/cxf

@Test
public void testThatProvidedSpanIsNotDetachedWhenActiveUsingAsyncClient() throws Exception {
  final WebClient client = createWebClient("/bookstore/books", braveClientProvider);
  final Span span = brave.tracer().nextSpan().name("test span").start();
  try {
    try (SpanInScope scope = brave.tracer().withSpanInScope(span)) {
      final Future<Response> f = client.async().get();
      final Response r = f.get(1, TimeUnit.SECONDS);
      assertEquals(Status.OK.getStatusCode(), r.getStatus());
      assertThat(brave.tracer().currentSpan().context().spanId(), equalTo(span.context().spanId()));
      assertThat(TestSpanReporter.getAllSpans().size(), equalTo(3));
      assertThat(TestSpanReporter.getAllSpans().get(0).name(), equalTo("get books"));
      assertThat(TestSpanReporter.getAllSpans().get(1).name(), equalTo("get /bookstore/books"));
      assertThat(TestSpanReporter.getAllSpans().get(2).name(), equalTo("get " + client.getCurrentURI()));
      assertThatTraceHeadersArePresent(r, true);
    }
  } finally {
    span.finish();
  }
  // Await till flush happens, usually a second is enough
  await().atMost(Duration.ONE_SECOND).until(()-> TestSpanReporter.getAllSpans().size() == 4);
  assertThat(TestSpanReporter.getAllSpans().size(), equalTo(4));
  assertThat(TestSpanReporter.getAllSpans().get(3).name(), equalTo("test span"));
}

相关文章

WebClient类方法