com.squareup.okhttp.HttpUrl类的使用及代码示例

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

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

HttpUrl介绍

暂无

代码示例

代码示例来源:origin: Javen205/IJPay

@Override
public String get(String url, Map<String, String> queryParas) {
  com.squareup.okhttp.HttpUrl.Builder urlBuilder = com.squareup.okhttp.HttpUrl.parse(url).newBuilder();
  for (Entry<String, String> entry : queryParas.entrySet()) {
    urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
  }
  com.squareup.okhttp.HttpUrl httpUrl = urlBuilder.build();
  com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder().url(httpUrl).get().build();
  return exec(request);
}

代码示例来源:origin: google/data-transfer-project

@Test
public void testExport() throws Exception {
 server.enqueue(new MockResponse().setBody(CALENDARS_RESPONSE));
 server.enqueue(new MockResponse().setBody(CALENDAR1_EVENTS_RESPONSE));
 server.enqueue(new MockResponse().setBody(CALENDAR2_EVENTS_RESPONSE));
 server.start();
 HttpUrl baseUrl = server.url("");
 MicrosoftCalendarExporter exporter =
   new MicrosoftCalendarExporter(baseUrl.toString(), client, mapper, transformerService);
 ExportResult<CalendarContainerResource> resource = exporter
   .export(UUID.randomUUID(), token, Optional.empty());
 CalendarContainerResource calendarResource = resource.getExportedData();
 Assert.assertEquals(2, calendarResource.getCalendars().size());
 Assert.assertFalse(
   calendarResource
     .getCalendars()
     .stream()
     .anyMatch(c -> "Calendar1".equals(c.getId()) && "Calendar2".equals(c.getId())));
 Assert.assertEquals(2, calendarResource.getEvents().size());
 Assert.assertFalse(
   calendarResource
     .getEvents()
     .stream()
     .anyMatch(
       e ->
         "Test Appointment 1".equals(e.getTitle())
           && "Test Appointment 2".equals(e.getTitle())));
}

代码示例来源:origin: com.netflix.spinnaker.clouddriver/clouddriver-artifacts

public InputStream download(Artifact artifact) throws IOException {
 HttpUrl.Builder fileUrl;
 try {
  // reference should use the Gitlab raw file download url: https://docs.gitlab.com/ee/api/repository_files.html#get-raw-file-from-repository
  fileUrl = HttpUrl.parse(artifact.getReference()).newBuilder();
 } catch (Exception e) {
  throw new IllegalArgumentException("Malformed gitlab content URL in 'reference'. Read more here https://www.spinnaker.io/reference/artifacts/types/gitlab-file/: " + e.getMessage(), e);
 }
 String version = artifact.getVersion();
 if (StringUtils.isEmpty(version)) {
  log.info("No version specified for artifact {}, using 'master'.", version);
  version = "master";
 }
 fileUrl.addQueryParameter("ref", version);
 Request fileRequest = requestBuilder
  .url(fileUrl.build().toString())
  .build();
 try {
  Response downloadResponse = okHttpClient.newCall(fileRequest).execute();
  return downloadResponse.body().byteStream();
 } catch (IOException e) {
  throw new com.netflix.spinnaker.clouddriver.artifacts.gitlab.GitlabArtifactCredentials.FailedDownloadException("Unable to download the contents of artifact " + artifact + ": " + e.getMessage(), e);
 }
}

代码示例来源:origin: org.sonarsource.sonarqube/sonar-batch

@VisibleForTesting
void logSuccess(@Nullable String taskId) {
 if (taskId == null) {
  LOG.info("ANALYSIS SUCCESSFUL");
 } else {
  Map<String, String> metadata = new LinkedHashMap<>();
  String effectiveKey = projectReactor.getRoot().getKeyWithBranch();
  metadata.put("projectKey", effectiveKey);
  metadata.put("serverUrl", publicUrl());
  URL dashboardUrl = HttpUrl.parse(publicUrl()).newBuilder()
   .addPathSegment("dashboard").addPathSegment("index").addPathSegment(effectiveKey)
   .build()
   .url();
  metadata.put("dashboardUrl", dashboardUrl.toExternalForm());
  URL taskUrl = HttpUrl.parse(publicUrl()).newBuilder()
   .addPathSegment("api").addPathSegment("ce").addPathSegment("task")
   .addQueryParameter("id", taskId)
   .build()
   .url();
  metadata.put("ceTaskId", taskId);
  metadata.put("ceTaskUrl", taskUrl.toExternalForm());
  LOG.info("ANALYSIS SUCCESSFUL, you can browse {}", dashboardUrl);
  LOG.info("Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report");
  LOG.info("More about the report processing at {}", taskUrl);
  dumpMetadata(metadata);
 }
}

代码示例来源:origin: greenaddress/GreenBits

@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
  try {
    HttpUrl.Builder url = HttpUrl.get(details.uri).newBuilder();
    if (services != 0)
      url.addQueryParameter("srvmask", Long.toString(services));
    Request.Builder request = new Request.Builder();
    request.url(url.build());
    request.addHeader("User-Agent", VersionMessage.LIBRARY_SUBVER); // TODO Add main version.
    log.info("Requesting seeds from {}", url);
    Response response = client.newCall(request.build()).execute();
    if (!response.isSuccessful())
      throw new PeerDiscoveryException("HTTP request failed: " + response.code() + " " + response.message());
    InputStream stream = response.body().byteStream();
    GZIPInputStream zip = new GZIPInputStream(stream);
    PeerSeedProtos.SignedPeerSeeds proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
    stream.close();
    return protoToAddrs(proto);
  } catch (PeerDiscoveryException e1) {
    throw e1;
  } catch (Exception e) {
    throw new PeerDiscoveryException(e);
  }
}

代码示例来源:origin: liferay/liferay-mobile-sdk

@Override
public String encodeURL(String url) {
  return HttpUrl.parse(url).toString();
}

代码示例来源:origin: io.paradoxical/cassieq-client

static CassieqCredentials signedQueryString(String queryAuth) {
  final Map<String, String> queryAuthParams =
      Splitter.on('&')
          .omitEmptyStrings()
          .withKeyValueSeparator('=')
          .split(queryAuth);
  return request -> {
    final HttpUrl httpUrl = request.httpUrl();
    HttpUrl.Builder newUrlBuilder = httpUrl.newBuilder();
    for (Map.Entry<String, String> entry : queryAuthParams.entrySet()) {
      newUrlBuilder = newUrlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
    }
    return request.newBuilder()
           .url(newUrlBuilder.build())
           .build();
  };
}

代码示例来源:origin: com.squareup.okhttp/mockwebserver

/**
 * Returns a URL for connecting to this server.
 * @param path the request path, such as "/".
 */
@Deprecated
public URL getUrl(String path) {
 return url(path).url();
}

代码示例来源:origin: zalando/logbook

@Override
public Optional<Integer> getPort() {
  final int port = request.httpUrl().port();
  final int defaultPort = defaultPort(request.httpUrl().scheme());
  return port == defaultPort ? Optional.empty() : Optional.of(port);
}

代码示例来源:origin: com.squareup.okhttp/okhttp-urlconnection

@Override public final Permission getPermission() throws IOException {
 URL url = getURL();
 String hostName = url.getHost();
 int hostPort = url.getPort() != -1
   ? url.getPort()
   : HttpUrl.defaultPort(url.getProtocol());
 if (usingProxy()) {
  InetSocketAddress proxyAddress = (InetSocketAddress) client.getProxy().address();
  hostName = proxyAddress.getHostName();
  hostPort = proxyAddress.getPort();
 }
 return new SocketPermission(hostName + ":" + hostPort, "connect, resolve");
}

代码示例来源:origin: com.netflix.spinnaker.clouddriver/clouddriver-artifacts

public InputStream download(Artifact artifact) throws IOException {
 HttpUrl.Builder metadataUrlBuilder;
 try {
  metadataUrlBuilder = HttpUrl.parse(artifact.getReference()).newBuilder();
 } catch (Exception e) {
  throw new IllegalArgumentException("Malformed github content URL in 'reference'. Read more here https://www.spinnaker.io/reference/artifacts/types/github-file/: " + e.getMessage(), e);
  .url(metadataUrlBuilder.build().toString())
  .build();

代码示例来源:origin: cash.bitcoinj/bitcoinj-core

@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
  try {
    HttpUrl.Builder url = HttpUrl.get(details.uri).newBuilder();
    if (services != 0)
      url.addQueryParameter("srvmask", Long.toString(services));
    Request.Builder request = new Request.Builder();
    request.url(url.build());
    request.addHeader("User-Agent", VersionMessage.LIBRARY_SUBVER); // TODO Add main version.
    log.info("Requesting seeds from {}", url);
    Response response = client.newCall(request.build()).execute();
    if (!response.isSuccessful())
      throw new PeerDiscoveryException("HTTP request failed: " + response.code() + " " + response.message());
    InputStream stream = response.body().byteStream();
    GZIPInputStream zip = new GZIPInputStream(stream);
    PeerSeedProtos.SignedPeerSeeds proto;
    try {
      proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
    } finally {
      zip.close(); // will close InputStream as well
    }
    return protoToAddrs(proto);
  } catch (PeerDiscoveryException e1) {
    throw e1;
  } catch (Exception e) {
    throw new PeerDiscoveryException(e);
  }
}

代码示例来源:origin: PaNaVTEC/Clean-Contacts

private HttpUrl composeUrl(Chain chain) {
  return chain.request().httpUrl()
     .newBuilder()
     .addQueryParameter("seed", "panavtec")
     .build();
 }
}

代码示例来源:origin: JmStefanAndroid/PVCloudGroupn

Log.e(TAG, "URL:"+response.request().httpUrl().url().toString()+" result=" + resultStr);
  if (response.request().httpUrl().url().toString().contains(Contants.API.BASE_URL)) {
    try {//尝试解析为基础数据
      BaseRespMsg respMsg = mGson.fromJson(resultStr, BaseRespMsg.class);

代码示例来源:origin: blockchain/api-v1-client-java

private HttpUrl.Builder getHttpUrlBuilder(String baseURL, String resource) throws MalformedURLException {
  HttpUrl url = HttpUrl.parse(baseURL);
  if (url == null) {
   throw new MalformedURLException();
  }
  HttpUrl.Builder urlBuilder = url.newBuilder();
  urlBuilder.addPathSegment(resource);
  return urlBuilder;
}

代码示例来源:origin: google/data-transfer-project

MicrosoftCalendarImporter importer =
  new MicrosoftCalendarImporter(
    baseUrl.toString(), client, mapper, transformerService, jobStore);

代码示例来源:origin: HashEngineering/dashj

@Override
public InetSocketAddress[] getPeers(long services, long timeoutValue, TimeUnit timeoutUnit) throws PeerDiscoveryException {
  try {
    HttpUrl.Builder url = HttpUrl.get(details.uri).newBuilder();
    if (services != 0)
      url.addQueryParameter("srvmask", Long.toString(services));
    Request.Builder request = new Request.Builder();
    request.url(url.build());
    request.addHeader("User-Agent", VersionMessage.LIBRARY_SUBVER); // TODO Add main version.
    log.info("Requesting seeds from {}", url);
    Response response = client.newCall(request.build()).execute();
    if (!response.isSuccessful())
      throw new PeerDiscoveryException("HTTP request failed: " + response.code() + " " + response.message());
    InputStream stream = response.body().byteStream();
    GZIPInputStream zip = new GZIPInputStream(stream);
    PeerSeedProtos.SignedPeerSeeds proto;
    try {
      proto = PeerSeedProtos.SignedPeerSeeds.parseDelimitedFrom(zip);
    } finally {
      zip.close(); // will close InputStream as well
    }
    return protoToAddrs(proto);
  } catch (PeerDiscoveryException e1) {
    throw e1;
  } catch (Exception e) {
    throw new PeerDiscoveryException(e);
  }
}

代码示例来源:origin: org.hobsoft.microbrowser/microbrowser-tck

@Test
public void getHrefWhenLinkAndRelativeHrefReturnsAbsoluteUrl()
{
  server().enqueue(new MockResponse().setBody("<html><head>"
    + "<link rel='x' href='x'/>"
    + "</head></html>"));
  
  URL actual = newBrowser().get(url(server()))
    .getLink("x")
    .getHref();
  
  assertThat("link href", actual, is(server().url("/x").url()));
}

代码示例来源:origin: com.jfinal/jfinal-weixin

@Override
public String get(String url, Map<String, String> queryParas) {
  com.squareup.okhttp.HttpUrl.Builder urlBuilder = com.squareup.okhttp.HttpUrl.parse(url).newBuilder();
  for (Entry<String, String> entry : queryParas.entrySet()) {
    urlBuilder.addQueryParameter(entry.getKey(), entry.getValue());
  }
  com.squareup.okhttp.HttpUrl httpUrl = urlBuilder.build();
  com.squareup.okhttp.Request request = new com.squareup.okhttp.Request.Builder().url(httpUrl).get().build();
  return exec(request);
}

代码示例来源:origin: google/data-transfer-project

MicrosoftPhotosExporter exporter = new MicrosoftPhotosExporter(baseUrl.toString(), client,
  mapper, jobStore);

相关文章

微信公众号

最新文章

更多