co.cask.common.http.HttpRequest.getURL()方法的使用及代码示例

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

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

HttpRequest.getURL介绍

暂无

代码示例

代码示例来源:origin: caskdata/cdap

/**
  * Create a generic error message about a failure to make a specified request.
  *
  * @param request the request made
  * @param body the request body if it should be in the error message
  * @return a generic error message about the failure
  */
 public String createErrorMessage(HttpRequest request, @Nullable String body) {
  String headers = request.getHeaders() == null ?
   "null" : Joiner.on(",").withKeyValueSeparator("=").join(request.getHeaders().entries());
  return String.format("Error making request to %s service at %s while doing %s with headers %s%s.",
             discoverableServiceName, request.getURL(), request.getMethod(),
             headers, body == null ? "" : " and body " + body);
 }
}

代码示例来源:origin: co.cask.cdap/cdap-common

/**
  * Create a generic error message about a failure to make a specified request.
  *
  * @param request the request made
  * @param body the request body if it should be in the error message
  * @return a generic error message about the failure
  */
 public String createErrorMessage(HttpRequest request, @Nullable String body) {
  String headers = request.getHeaders() == null ?
   "null" : Joiner.on(",").withKeyValueSeparator("=").join(request.getHeaders().entries());
  return String.format("Error making request to %s service at %s while doing %s with headers %s%s.",
             discoverableServiceName, request.getURL(), request.getMethod(),
             headers, body == null ? "" : " and body " + body);
 }
}

代码示例来源:origin: co.cask.cdap/cdap-notifications-api

private HttpResponse execute(HttpRequest request) throws NotificationFeedException {
  try {
   return remoteClient.execute(request);
  } catch (IOException e) {
   throw new NotificationFeedException(
    String.format("Error connecting to Notification Feed Service at %s while doing %s",
           request.getURL(), request.getMethod()));
  }
 }
}

代码示例来源:origin: co.cask.cdap/cdap-data-fabric

private HttpResponse doRequest(HttpRequest.Builder requestBuilder) throws DatasetManagementException {
 HttpRequest request = addUserIdHeader(requestBuilder).build();
 try {
  LOG.trace("Executing {} {}", request.getMethod(), request.getURL().getPath());
  HttpResponse response = remoteClient.execute(request);
  LOG.trace("Executed {} {}", request.getMethod(), request.getURL().getPath());
  return response;
 } catch (ServiceUnavailableException e) { // thrown by RemoteClient in case of ConnectException
  logThreadDump();
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw e;
 } catch (SocketTimeoutException e) { // passed through by RemoteClient
  logThreadDump();
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw new DatasetManagementException(remoteClient.createErrorMessage(request, null), e);
 } catch (IOException e) { // other network exceptions
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw new DatasetManagementException(remoteClient.createErrorMessage(request, null), e);
 } catch (Throwable e) { // anything unexpected
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw e;
 }
}

代码示例来源:origin: cdapio/cdap

private HttpResponse doRequest(HttpRequest.Builder requestBuilder) throws DatasetManagementException {
 HttpRequest request = addUserIdHeader(requestBuilder).build();
 try {
  LOG.trace("Executing {} {}", request.getMethod(), request.getURL().getPath());
  HttpResponse response = remoteClient.execute(request);
  LOG.trace("Executed {} {}", request.getMethod(), request.getURL().getPath());
  return response;
 } catch (ServiceUnavailableException e) { // thrown by RemoteClient in case of ConnectException
  logThreadDump();
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw e;
 } catch (SocketTimeoutException e) { // passed through by RemoteClient
  logThreadDump();
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw new DatasetManagementException(remoteClient.createErrorMessage(request, null), e);
 } catch (IOException e) { // other network exceptions
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw new DatasetManagementException(remoteClient.createErrorMessage(request, null), e);
 } catch (Throwable e) { // anything unexpected
  LOG.trace("Caught exception for {} {}", request.getMethod(), request.getURL().getPath(), e);
  throw e;
 }
}

代码示例来源:origin: cdapio/cdap

private HttpResponse executeRequest(ImpersonationRequest impersonationRequest) throws IOException {
 HttpRequest request = remoteClient.requestBuilder(HttpMethod.POST, "impersonation/credentials")
  .withBody(GSON.toJson(impersonationRequest))
  .build();
 HttpResponse response = remoteClient.execute(request);
 if (response.getResponseCode() == HttpURLConnection.HTTP_OK) {
  return response;
 }
 throw new IOException(String.format("%s Response: %s.", createErrorMessage(request.getURL()), response));
}

相关文章