com.amazonaws.Request.getResourcePath()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(176)

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

Request.getResourcePath介绍

[英]Returns the path to the resource being requested.
[中]返回被请求资源的路径。

代码示例

代码示例来源:origin: aws/aws-sdk-java

private static String uriFrom(Request<?> sdkRequest) {
  StringBuilder uriBuilder = new StringBuilder(sdkRequest.getEndpoint().toString());
  if (!StringUtils.isNullOrEmpty(sdkRequest.getResourcePath())) {
    uriBuilder.append(sdkRequest.getResourcePath());
  }
  QueryStringEncoder encoder = new QueryStringEncoder(uriBuilder.toString());
  for (Map.Entry<String, List<String>> param : sdkRequest.getParameters().entrySet()) {
    for (String value : param.getValue()) {
      encoder.addParam(param.getKey(), value);
    }
  }
  return encoder.toString();
}

代码示例来源:origin: aws/aws-sdk-java

private String generateUrl(Request<?> request) {
  URI endpoint = request.getEndpoint();
  String uri = SdkHttpUtils.appendUri(endpoint.toString(),
      request.getResourcePath(), true);
  String encodedParams = SdkHttpUtils.encodeParameters(request);
  if (encodedParams != null && !encodedParams.isEmpty()) {
    uri += "?" + encodedParams;
  }
  return uri;
}

代码示例来源:origin: aws/aws-sdk-java

private String generateUrl(Request<?> request) {
  URI endpoint = request.getEndpoint();
  String uri = SdkHttpUtils.appendUri(endpoint.toString(),
      request.getResourcePath(), true);
  String encodedParams = SdkHttpUtils.encodeParameters(request);
  if (encodedParams != null) {
    uri += "?" + encodedParams;
  }
  return uri;
}

代码示例来源:origin: aws/aws-sdk-java

String resourcePath = request.getResourcePath();
if (resourcePath != null) {
  String newResourcePath = resourcePath.replace("{jobType}", "archive-retrievals");

代码示例来源:origin: aws/aws-sdk-java

boolean urlEncode) {
String resourcePath = urlEncode ?
    SdkHttpUtils.urlEncode(request.getResourcePath(), true)
    : request.getResourcePath();

代码示例来源:origin: aws/aws-sdk-java

boolean urlEncode) {
String resourcePath = urlEncode ?
    SdkHttpUtils.urlEncode(request.getResourcePath(), true)
    : request.getResourcePath();

代码示例来源:origin: aws/aws-sdk-java

@Override
public void marshall(T val, JsonMarshallerContext context, MarshallingInfo<T> marshallingInfo) {
  context.request().setResourcePath(
      pathMarshaller.marshall(context.request().getResourcePath(), marshallingInfo.marshallLocationName(),
                  converter.convert(val)));
}

代码示例来源:origin: aws/aws-sdk-java

@Override
public HttpRequestBase create(final Request<?> request,
               final HttpClientSettings settings)
    throws
    FakeIOException {
  URI endpoint = request.getEndpoint();
  /*
   * HttpClient cannot handle url in pattern of "http://host//path", so we
   * have to escape the double-slash between endpoint and resource-path
   * into "/%2F"
   */
  String uri = SdkHttpUtils.appendUri(endpoint.toString(), request
      .getResourcePath(), true);
  String encodedParams = SdkHttpUtils.encodeParameters(request);
  /*
   * For all non-POST requests, and any POST requests that already have a
   * payload, we put the encoded params directly in the URI, otherwise,
   * we'll put them in the POST request's payload.
   */
  boolean requestHasNoPayload = request.getContent() != null;
  boolean requestIsPost = request.getHttpMethod() == HttpMethodName.POST;
  boolean putParamsInUri = !requestIsPost || requestHasNoPayload;
  if (encodedParams != null && putParamsInUri) {
    uri += "?" + encodedParams;
  }
  final HttpRequestBase base = createApacheRequest(request, uri, encodedParams);
  addHeadersToRequest(base, request);
  addRequestConfig(base, request, settings);
  return base;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

/**
 * Returns the path to the resource being requested.
 *
 * @return The path to the resource being requested.
 */
public String getPath() {
  return request.getResourcePath();
}

代码示例来源:origin: aws-amplify/aws-sdk-android

private String getCanonicalizedResourcePath(Request<?> request) {
  String resourcePath = "";
  if (request.getEndpoint().getPath() != null) {
    resourcePath += request.getEndpoint().getPath();
  }
  if (request.getResourcePath() != null) {
    if (resourcePath.length() > 0 &&
        !resourcePath.endsWith("/") &&
        !request.getResourcePath().startsWith("/")) {
      resourcePath += "/";
    }
    resourcePath += request.getResourcePath();
  } else if (!resourcePath.endsWith("/")) {
    resourcePath += "/";
  }
  if (!resourcePath.startsWith("/")) {
    resourcePath = "/" + resourcePath;
  }
  if (resourcePath.startsWith("//")) {
    resourcePath = resourcePath.substring(1);
  }
  return resourcePath;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

private String generateUrl(Request<?> request) {
  URI endpoint = request.getEndpoint();
  String uri = HttpUtils.appendUri(endpoint.toString(),
      request.getResourcePath(), true);
  String encodedParams = HttpUtils.encodeParameters(request);
  if (encodedParams != null) {
    uri += "?" + encodedParams;
  }
  return uri;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

boolean removeLeadingSlashInResourcePath,
  boolean urlEncode) {
String resourcePath = urlEncode ? HttpUtils.urlEncode(request.getResourcePath(), true)
    : request.getResourcePath();

代码示例来源:origin: aws-amplify/aws-sdk-android

request.addHeader(name, String.valueOf(arg));
} else if ("path".equals(location)) {
  String path = request.getResourcePath();
  path = path.replaceAll("\\{" + name + "\\}", String.valueOf(arg));
  request.setResourcePath(path);

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

@Override
public void marshall(T val, JsonMarshallerContext context, MarshallingInfo<T> marshallingInfo) {
  context.request().setResourcePath(
      pathMarshaller.marshall(context.request().getResourcePath(), marshallingInfo.marshallLocationName(),
                  converter.convert(val)));
}

代码示例来源:origin: aws-amplify/aws-sdk-android

protected String getCanonicalRequest(Request<?> request, String contentSha256) {
  /* This would url-encode the resource path for the first time */
  final String path = HttpUtils.appendUri(request.getEndpoint().getPath(),
      request.getResourcePath());
  final String canonicalRequest =
      request.getHttpMethod().toString() + "\n" +
          /*
           * This would optionally double url-encode the resource
           * path
           */
          getCanonicalizedResourcePath(path, doubleUrlEncode) + "\n" +
          getCanonicalizedQueryString(request) + "\n" +
          getCanonicalizedHeaderString(request) + "\n" +
          getSignedHeadersString(request) + "\n" +
          contentSha256;
  log.debug("AWS4 Canonical Request: '\"" + canonicalRequest + "\"");
  return canonicalRequest;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreatePutObjectRequestWithSpecialCharacterKeys() {
  final String bucketName = "bucket";
  final String key = "key%^!@#*()";
  final File file = new File(key);
  final HttpMethodName method = HttpMethodName.PUT;
  final PutObjectRequest originalRequest = new PutObjectRequest(bucketName, key, file);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals(String.format("%s.s3.amazonaws.com", bucketName),
      request.getEndpoint().getHost());
  assertEquals(method, request.getHttpMethod());
  assertTrue(request.getResourcePath().contains(key));
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateGetObjectRequestWithSpecialCharacterKeys() {
  final String bucketName = "bucket";
  final String key = "key%^!@#*()";
  final HttpMethodName method = HttpMethodName.GET;
  final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals(String.format("%s.s3.amazonaws.com", bucketName),
      request.getEndpoint().getHost());
  assertEquals(method, request.getHttpMethod());
  assertTrue(request.getResourcePath().contains(key));
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateRequestNonDNS() {
  final String bucketName = "bucket.with.dot";
  final String key = "key";
  final File file = new File(key);
  final HttpMethodName method = HttpMethodName.PUT;
  final PutObjectRequest originalRequest = new PutObjectRequest(bucketName, key, file);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  assertEquals("s3.amazonaws.com", request.getEndpoint().getHost());
  assertEquals(String.format("%s/%s", bucketName, key), request.getResourcePath());
  assertEquals(method, request.getHttpMethod());
}

代码示例来源:origin: com.amazonaws/aws-java-sdk-core

@Override
public HttpRequestBase create(final Request<?> request,
               final HttpClientSettings settings)
    throws
    FakeIOException {
  URI endpoint = request.getEndpoint();
  /*
   * HttpClient cannot handle url in pattern of "http://host//path", so we
   * have to escape the double-slash between endpoint and resource-path
   * into "/%2F"
   */
  String uri = SdkHttpUtils.appendUri(endpoint.toString(), request
      .getResourcePath(), true);
  String encodedParams = SdkHttpUtils.encodeParameters(request);
  /*
   * For all non-POST requests, and any POST requests that already have a
   * payload, we put the encoded params directly in the URI, otherwise,
   * we'll put them in the POST request's payload.
   */
  boolean requestHasNoPayload = request.getContent() != null;
  boolean requestIsPost = request.getHttpMethod() == HttpMethodName.POST;
  boolean putParamsInUri = !requestIsPost || requestHasNoPayload;
  if (encodedParams != null && putParamsInUri) {
    uri += "?" + encodedParams;
  }
  final HttpRequestBase base = createApacheRequest(request, uri, encodedParams);
  addHeadersToRequest(base, request);
  addRequestConfig(base, request, settings);
  return base;
}

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
public void testCreateSignerWithSpecialCharacterKeys() {
  s3.setS3ClientOptions(accelerateOption);
  final Regions region = Regions.US_WEST_2;
  s3.setRegion(Region.getRegion(region));
  final String bucketName = "bucket";
  final String key = "key%^!@#*()";
  final HttpMethodName method = HttpMethodName.GET;
  final GetObjectRequest originalRequest = new GetObjectRequest(bucketName, key);
  final Request<?> request = s3.createRequest(bucketName, key, originalRequest, method);
  final Signer signer = s3.createSigner(request, bucketName, key);
  assertTrue(signer instanceof AWSS3V4Signer);
  signer.sign(request, creds);
  final String authorization = request.getHeaders().get("Authorization");
  assertNotNull(authorization);
  final String regionName = authorization.split("/")[2];
  assertEquals(region.getName(), regionName);
  assertTrue(request.getResourcePath().contains(key));
}

相关文章