本文整理了Java中com.amazonaws.Request.getEndpoint
方法的一些代码示例,展示了Request.getEndpoint
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getEndpoint
方法的具体详情如下:
包路径:com.amazonaws.Request
类名称:Request
方法名:getEndpoint
[英]Returns the service endpoint (ex: "https://ec2.amazonaws.com") to which this request should be sent.
[中]返回服务端点(例如:https://ec2.amazonaws.com),该请求应发送到该地址。
代码示例来源:origin: aws/aws-sdk-java
private static String getProtocol(Request<?> request) {
if (request == null || request.getEndpoint() == null) {
return null;
}
return request.getEndpoint().getScheme();
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public void beforeRequest(Request<?> request) {
URI endpoint = request.getEndpoint();
// If the request is using a non-standard endpoint, then
// alter it to use the corresponding, standard endpoint
if (nonstandardEndpointMap.containsKey(endpoint.getHost())) {
String newHost = nonstandardEndpointMap.get(endpoint.getHost());
String newEndpoint = endpoint.toString().replaceFirst(endpoint.getHost(), newHost);
request.setEndpoint(URI.create(newEndpoint));
}
}
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public void beforeRequest(Request<?> request) {
if (!request.getHeaders().containsKey(X_AMZ_ACCOUNT_ID)) {
throw new SdkClientException("Account ID must be specified for all requests");
}
String accountId = request.getHeaders().remove(X_AMZ_ACCOUNT_ID);
URI endpoint = request.getEndpoint();
String host = resolveHost(request, accountId);
try {
request.setEndpoint(new URI(endpoint.getScheme(), endpoint.getUserInfo(),
host, endpoint.getPort(), endpoint.getPath(), endpoint.getQuery(), endpoint.getFragment()));
} catch (URISyntaxException e) {
throw new SdkClientException(
String.format("Endpoint was invalid, account id (%s) is likely incorrect", accountId), e);
}
}
代码示例来源:origin: aws/aws-sdk-java
private String resolveHost(Request<?> request, String accountId) {
if (isDualstackEnabled(request) && isFipsEnabled(request)) {
throw new SdkClientException("Cannot use both Dual-Stack endpoints and FIPS endpoints");
}
String host = request.getEndpoint().getHost();
if (isDualstackEnabled(request)) {
if (!host.contains(ENDPOINT_PREFIX)) {
throw new SdkClientException(String.format("The Dual-Stack option cannot be used with custom endpoints (%s)",
request.getEndpoint()));
}
host = host.replace(ENDPOINT_PREFIX, String.format("%s.%s", ENDPOINT_PREFIX, "dualstack"));
} else if (isFipsEnabled(request)) {
if (!host.contains(ENDPOINT_PREFIX)) {
throw new SdkClientException(String.format("The FIPS option cannot be used with custom endpoints (%s)",
request.getEndpoint()));
}
host = host.replace(ENDPOINT_PREFIX, String.format("%s-%s", ENDPOINT_PREFIX, "fips"));
}
return String.format("%s.%s", accountId, host);
}
代码示例来源:origin: aws/aws-sdk-java
/**
* <p>Returns true if the region required for signing could not be computed from the client or the request.</p>
* <p>
* This is the case when the standard endpoint is in use and neither an explicit region nor a signer override
* have been provided by the user.
* </p>
*/
private boolean noExplicitRegionProvided(final Request<?> request) {
return isStandardEndpoint(request.getEndpoint()) &&
getSignerRegion() == null;
}
代码示例来源: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
/**
* <p>
* Populates the specified request with the specified Multi-Factor
* Authentication (MFA) details. This includes the MFA header with device serial
* number and generated token. Since all requests which include the MFA
* header must be sent over HTTPS, this operation also configures the request object to
* use HTTPS instead of HTTP.
* </p>
*
* @param request
* The request to populate.
* @param mfa
* The Multi-Factor Authentication information.
*/
private void populateRequestWithMfaDetails(Request<?> request, MultiFactorAuthentication mfa) {
if (mfa == null) return;
String endpoint = request.getEndpoint().toString();
if (endpoint.startsWith("http://")) {
String httpsEndpoint = endpoint.replace("http://", "https://");
request.setEndpoint(URI.create(httpsEndpoint));
log.info("Overriding current endpoint to use HTTPS " +
"as required by S3 for requests containing an MFA header");
}
request.addHeader(Headers.S3_MFA,
mfa.getDeviceSerialNumber() + " " + mfa.getToken());
}
代码示例来源: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
StringBuilder url = new StringBuilder(request.getEndpoint().toString());
url.append(urlPath);
代码示例来源:origin: aws/aws-sdk-java
private void doPutMedia(PutMediaRequest request,
PutMediaResponseHandler responseHandler,
List<ChannelHandler> requestHandlers) {
request.getRequestClientOptions().appendUserAgent(USER_AGENT);
Request<PutMediaRequest> marshalled = marshall(request);
applyUserAgent(request, marshalled);
signer.sign(marshalled, resolveCredentials(request));
try {
Bootstrap b = new Bootstrap()
.group(group)
.channel(NioSocketChannel.class)
.remoteAddress(marshalled.getEndpoint().getHost(), getPort(marshalled.getEndpoint()))
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectionTimeoutInMillis)
.handler(new PutMediaHandlerInitializer(getSslContext(marshalled.getEndpoint()),
createHandlers(responseHandler, marshalled, requestHandlers)));
invoke(marshalled, b, responseHandler);
} catch (InterruptedException e) {
throw handleInterruptedException(e);
}
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Configures the headers in the specified Apache HTTP request.
*/
private void addHeadersToRequest(HttpRequestBase httpRequest, Request<?> request) {
httpRequest.addHeader(HttpHeaders.HOST, getHostHeaderValue(request.getEndpoint()));
// Copy over any other headers already in our request
for (Entry<String, String> entry : request.getHeaders().entrySet()) {
/*
* HttpClient4 fills in the Content-Length header and complains if
* it's already present, so we skip it here. We also skip the Host
* header to avoid sending it twice, which will interfere with some
* signing schemes.
*/
if (!(ignoreHeaders.contains(entry.getKey()))) {
httpRequest.addHeader(entry.getKey(), entry.getValue());
}
}
/* Set content type and encoding */
if (httpRequest.getHeaders(HttpHeaders.CONTENT_TYPE) == null || httpRequest
.getHeaders
(HttpHeaders.CONTENT_TYPE).length == 0) {
httpRequest.addHeader(HttpHeaders.CONTENT_TYPE,
"application/x-www-form-urlencoded; " +
"charset=" + DEFAULT_ENCODING.toLowerCase());
}
}
代码示例来源:origin: aws/aws-sdk-java
private AuthRetryParameters redirectToRegionInHeader(Request<?> request, HttpResponse response) {
final String region = getServingRegionHeader(response);
AWSS3V4Signer v4Signer = buildSigV4Signer(region);
endpointResolver.resolveRequestEndpoint(request, region);
return buildRetryParams(v4Signer, request.getEndpoint());
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public void beforeRequest(Request<?> request) {
if (!requestClassToPreSign.isInstance(request.getOriginalRequest())) return;
if (request.getParameters().containsKey(PARAM_PRESIGNED_URL)) return;
PresignableRequest presignableRequest = adaptRequest(requestClassToPreSign.cast(
request.getOriginalRequest()));
String sourceRegion = presignableRequest.getSourceRegion();
if (sourceRegion == null) return;
String destinationRegion = AwsHostNameUtils.parseRegion(request.getEndpoint().getHost(),
SERVICE_NAME);
Request<?> requestToPresign = presignableRequest.marshall();
requestToPresign.getParameters().remove(PARAM_SOURCE_REGION);
requestToPresign.getParameters().put(PARAM_DESTINATION_REGION, Arrays.asList(destinationRegion));
requestToPresign.setEndpoint(createEndpoint(sourceRegion, SERVICE_NAME));
requestToPresign.setHttpMethod(HttpMethodName.GET);
AWSCredentials credentials = request.getHandlerContext(HandlerContextKey.AWS_CREDENTIALS);
requestToPresign = presignRequest(requestToPresign, credentials, sourceRegion);
final String presignedUrl = generateUrl(requestToPresign);
presignableRequest.setPreSignedUrl(presignedUrl);
request.addParameter(PARAM_PRESIGNED_URL, presignedUrl);
// Remove the unmodeled params to stop them getting onto the wire
request.getParameters().remove(PARAM_SOURCE_REGION);
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public Signer getSigner(SignerProviderContext context) {
Request<?> request = context.getRequest();
if (request == null || shouldUseDefaultSigner(request.getOriginalRequest())) {
if (context.isRedirect()) {
return awsClient.getSignerByURI(context.getUri());
}
return defaultSigner;
}
SignerTypeAware signerTypeAware = (SignerTypeAware) request.getOriginalRequest();
SignerParams params = new SignerParams(awsClient.getServiceName(), getSigningRegionForRequestURI(request.getEndpoint()));
return SignerFactory.createSigner(signerTypeAware.getSignerType(), params);
}
代码示例来源: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/aws-sdk-java
public URL presign(Request<?> request, Date expirationDate) {
final Presigner presigner = (Presigner) signerProvider.getSigner(SignerProviderContext.builder()
.withIsRedirect(false)
.withRequest(request)
.withUri(request.getEndpoint())
.build());
if (request.getOriginalRequest() != null) {
addCustomQueryParams(request);
addCustomHeaders(request);
}
final AWSCredentialsProvider credentialsProvider = resolveCredentials(request);
presigner.presignRequest(request, credentialsProvider.getCredentials(), expirationDate);
return RuntimeHttpUtils.convertRequestToUrl(request, true, false);
}
代码示例来源:origin: aws/aws-sdk-java
URI uri = clientOptions.isAccelerateModeEnabled() ? endpoint : request.getEndpoint();
final Signer signer = getSignerByURI(uri);
代码示例来源:origin: aws/aws-sdk-java
URI endPointDestination = request.getEndpoint();
String destinationRegion = originalCopySnapshotRequest
.getDestinationRegion() != null ? originalCopySnapshotRequest
代码示例来源:origin: aws/aws-sdk-java
String fqdn = extractFqdn(request.getEndpoint());
TimingInfo timingInfo = metrics == null ? null : metrics.getTimingInfo();
内容来源于网络,如有侵权,请联系作者删除!