com.ning.http.client.uri.Uri.toString()方法的使用及代码示例

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

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

Uri.toString介绍

暂无

代码示例

代码示例来源:origin: com.ning/async-http-client

private static Request newRequest(final HttpTransactionContext ctx,
    final Uri newUri, final HttpResponsePacket response,
    final Realm realm, boolean asGet) {
  final Request prototype = ctx.getAhcRequest();
  final FluentCaseInsensitiveStringsMap prototypeHeaders =
      prototype.getHeaders();
  
  prototypeHeaders.remove(Header.Host.toString());
  prototypeHeaders.remove(Header.ContentLength.toString());
  
  if (asGet)
    prototypeHeaders.remove(Header.ContentType.toString());
  if (realm != null && realm.getScheme() == AuthScheme.NTLM) {
    prototypeHeaders.remove(Header.Authorization.toString());
    prototypeHeaders.remove(Header.ProxyAuthorization.toString());
  }
  
  final RequestBuilder builder = new RequestBuilder(prototype);
  if (asGet) {
    builder.setMethod("GET");
  }
  builder.setUrl(newUri.toString());
  for (String cookieStr : response.getHeaders().values(Header.SetCookie)) {
    builder.addOrReplaceCookie(CookieDecoder.decode(cookieStr));
  }
      
  return builder.build();
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public String onCompleted(Response response) throws Exception {
  return response.getUri().toString();
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public String onCompleted(Response response) throws Exception {
  return response.getUri().toString();
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public String onCompleted(Response response) throws Exception {
  return response.getUri().toString();
}

代码示例来源:origin: javaee/grizzly-ahc

private String getBaseUrl(Uri uri) {
  String url = uri.toString();
  int port = uri.getPort();
  if (port == -1) {
    port = getPort(uri);
    url = url.substring(0, url.length() - 1) + ":" + port;
  }
  return url.substring(0, url.lastIndexOf(":") + String.valueOf(port).length() + 1);
}

代码示例来源:origin: javaee/grizzly-ahc

private String getBaseUrl(Uri uri) {
  String url = uri.toString();
  int port = uri.getPort();
  if (port == -1) {
    port = getPort(uri);
    url = url.substring(0, url.length() - 1) + ":" + port;
  }
  return url.substring(0, url.lastIndexOf(":") + String.valueOf(port).length() + 1);
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public STATE onStatusReceived(final HttpResponseStatus status) throws Exception {
  if (!status.getUri().toString().equals("http://127.0.0.1:" + port1 + "/?a=")) {
    throw new IOException(status.getUri().toString());
  }
  return super.onStatusReceived(status);
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public STATE onStatusReceived(final HttpResponseStatus status) throws Exception {
  if (!status.getUri().toString().equals("http://127.0.0.1:" + port1 + "/?a=b&c&d=e")) {
    throw new IOException("failed to parse the query properly");
  }
  return super.onStatusReceived(status);
}

代码示例来源:origin: javaee/grizzly-ahc

@Override
public STATE onStatusReceived(final HttpResponseStatus status) throws Exception {
  if (!status.getUri().toString().equals("http://127.0.0.1:" + port1 + "/?a=b&c=&d=e")) {
    throw new IOException("failed to parse the query properly");
  }
  return super.onStatusReceived(status);
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
public void absolutePathRedirectTest() throws Throwable {
  isSet.getAndSet(false);
  AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
  try (AsyncHttpClient client = getAsyncHttpClient(cg)) {
    String redirectTarget = "/bar/test";
    String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();
    Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
    assertNotNull(response);
    assertEquals(response.getStatusCode(), 200);
    assertEquals(response.getUri().toString(), destinationUrl);
    log.debug("{} was redirected to {}", redirectTarget, destinationUrl);
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
  public void relativePathRedirectTest() throws Throwable {
    isSet.getAndSet(false);

    AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder().setFollowRedirect(true).build();
    try (AsyncHttpClient client = getAsyncHttpClient(cg)) {
      String redirectTarget = "bar/test1";
      String destinationUrl = new URI(getTargetUrl()).resolve(redirectTarget).toString();

      Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", redirectTarget).execute().get();
      assertNotNull(response);
      assertEquals(response.getStatusCode(), 200);
      assertEquals(response.getUri().toString(), destinationUrl);

      log.debug("{} was redirected to {}", redirectTarget, destinationUrl);
    }
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
  public void relativeLocationUrl() throws Throwable {
    isSet.getAndSet(false);

    try (AsyncHttpClient client = getAsyncHttpClient(null)) {
      Response response = client.preparePost(getTargetUrl()).setFollowRedirects(true).setHeader("X-redirect", "/foo/test").execute().get();
      assertNotNull(response);
      assertEquals(response.getStatusCode(), 200);
      assertEquals(response.getUri().toString(), getTargetUrl());
    }
  }
}

代码示例来源:origin: javaee/grizzly-ahc

@Test(groups = { "standalone", "default_provider" })
  public void relativeLocationUrl() throws Throwable {
    isSet.getAndSet(false);

    AsyncHttpClientConfig cg = new AsyncHttpClientConfig.Builder()//
        .setMaxRedirects(5)//
        .setFollowRedirect(true)//
        .setAcceptAnyCertificate(true)//
        .build();
    try (AsyncHttpClient client = getAsyncHttpClient(cg)) {
      Response response = client.prepareGet(getTargetUrl()).setHeader("X-redirect", "/foo/test").execute().get();
      assertNotNull(response);
      assertEquals(response.getStatusCode(), 200);
      assertEquals(response.getUri().toString(), getTargetUrl());
    }
  }
}

代码示例来源:origin: org.glassfish.grizzly/grizzly-http-client

private static Request newRequest(final HttpTransactionContext ctx,
    final Uri newUri, final HttpResponsePacket response,
    final Realm realm, boolean asGet) {
  final Request prototype = ctx.getAhcRequest();
  final FluentCaseInsensitiveStringsMap prototypeHeaders =
      prototype.getHeaders();
  
  prototypeHeaders.remove(Header.Host.toString());
  prototypeHeaders.remove(Header.ContentLength.toString());
  
  if (asGet)
    prototypeHeaders.remove(Header.ContentType.toString());
  if (realm != null && realm.getScheme() == AuthScheme.NTLM) {
    prototypeHeaders.remove(Header.Authorization.toString());
    prototypeHeaders.remove(Header.ProxyAuthorization.toString());
  }
  
  final RequestBuilder builder = new RequestBuilder(prototype);
  if (asGet) {
    builder.setMethod("GET");
  }
  builder.setUrl(newUri.toString());
  for (String cookieStr : response.getHeaders().values(Header.SetCookie)) {
    builder.addOrReplaceCookie(CookieDecoder.decode(cookieStr));
  }
      
  return builder.build();
}

代码示例来源:origin: javaee/grizzly-ahc

private static Request newRequest(final HttpTransactionContext ctx,
    final Uri newUri, final HttpResponsePacket response,
    final Realm realm, boolean asGet) {
  final Request prototype = ctx.getAhcRequest();
  final FluentCaseInsensitiveStringsMap prototypeHeaders =
      prototype.getHeaders();
  
  prototypeHeaders.remove(Header.Host.toString());
  prototypeHeaders.remove(Header.ContentLength.toString());
  
  if (asGet)
    prototypeHeaders.remove(Header.ContentType.toString());
  if (realm != null && realm.getScheme() == AuthScheme.NTLM) {
    prototypeHeaders.remove(Header.Authorization.toString());
    prototypeHeaders.remove(Header.ProxyAuthorization.toString());
  }
  
  final RequestBuilder builder = new RequestBuilder(prototype);
  if (asGet) {
    builder.setMethod("GET");
  }
  builder.setUrl(newUri.toString());
  for (String cookieStr : response.getHeaders().values(Header.SetCookie)) {
    builder.addOrReplaceCookie(CookieDecoder.decode(cookieStr));
  }
      
  return builder.build();
}

相关文章