com.ksc.network.slb.KSCSLBClient Maven / Gradle / Ivy
package com.ksc.network.slb;
import java.util.ArrayList;
import java.util.List;
import org.w3c.dom.Node;
import com.ksc.ClientConfiguration;
import com.ksc.ClientConfigurationFactory;
import com.ksc.KscServiceException;
import com.ksc.KscWebServiceClient;
import com.ksc.KscWebServiceRequest;
import com.ksc.KscWebServiceResponse;
import com.ksc.Request;
import com.ksc.Response;
import com.ksc.auth.AWSCredentialsProvider;
import com.ksc.auth.DefaultAWSCredentialsProviderChain;
import com.ksc.auth.credentials.AWSCredentials;
import com.ksc.http.DefaultErrorResponseHandler;
import com.ksc.http.ExecutionContext;
import com.ksc.http.HttpResponseHandler;
import com.ksc.http.StaxResponseHandler;
import com.ksc.internal.StaticCredentialsProvider;
import com.ksc.metrics.RequestMetricCollector;
import com.ksc.network.slb.model.ConfigureHealthCheckRequest;
import com.ksc.network.slb.model.ConfigureHealthCheckResult;
import com.ksc.network.slb.model.CreateListenersRequest;
import com.ksc.network.slb.model.CreateListenersResult;
import com.ksc.network.slb.model.CreateLoadBalancerRequest;
import com.ksc.network.slb.model.CreateLoadBalancerResult;
import com.ksc.network.slb.model.DeleteHealthCheckRequest;
import com.ksc.network.slb.model.DeleteHealthCheckResult;
import com.ksc.network.slb.model.DeleteListenersRequest;
import com.ksc.network.slb.model.DeleteListenersResult;
import com.ksc.network.slb.model.DeleteLoadBalancerRequest;
import com.ksc.network.slb.model.DeleteLoadBalancerResult;
import com.ksc.network.slb.model.DeregisterInstancesFromListenerRequest;
import com.ksc.network.slb.model.DeregisterInstancesFromListenerResult;
import com.ksc.network.slb.model.DescribeHealthChecksRequest;
import com.ksc.network.slb.model.DescribeHealthChecksResult;
import com.ksc.network.slb.model.DescribeInstancesWithListenerRequest;
import com.ksc.network.slb.model.DescribeInstancesWithListenerResult;
import com.ksc.network.slb.model.DescribeListenersRequest;
import com.ksc.network.slb.model.DescribeListenersResult;
import com.ksc.network.slb.model.DescribeLoadBalancersRequest;
import com.ksc.network.slb.model.DescribeLoadBalancersResult;
import com.ksc.network.slb.model.ModifyHealthCheckRequest;
import com.ksc.network.slb.model.ModifyHealthCheckResult;
import com.ksc.network.slb.model.ModifyInstancesWithListenerRequest;
import com.ksc.network.slb.model.ModifyInstancesWithListenerResult;
import com.ksc.network.slb.model.ModifyListenersRequest;
import com.ksc.network.slb.model.ModifyListenersResult;
import com.ksc.network.slb.model.ModifyLoadBalancerRequest;
import com.ksc.network.slb.model.ModifyLoadBalancerResult;
import com.ksc.network.slb.model.RegisterInstancesWithListenerRequest;
import com.ksc.network.slb.model.RegisterInstancesWithListenerResult;
import com.ksc.network.slb.model.transform.ConfigureHealthCheckRequestMarshaller;
import com.ksc.network.slb.model.transform.ConfigureHealthCheckResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.CreateListenersRequestMarshaller;
import com.ksc.network.slb.model.transform.CreateListenersResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.CreateLoadBalancerRequestMarshaller;
import com.ksc.network.slb.model.transform.CreateLoadBalancerResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DeleteHealthCheckRequestMarshaller;
import com.ksc.network.slb.model.transform.DeleteHealthCheckResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DeleteListenersRequestMarshaller;
import com.ksc.network.slb.model.transform.DeleteListenersResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DeleteLoadBalancerRequestMarshaller;
import com.ksc.network.slb.model.transform.DeleteLoadBalancerResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DeregisterInstancesFromListenerRequestMarshaller;
import com.ksc.network.slb.model.transform.DeregisterInstancesFromListenerResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DescribeHealthChecksRequestMarshaller;
import com.ksc.network.slb.model.transform.DescribeHealthChecksResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DescribeInstancesWithListenerRequestMarshaller;
import com.ksc.network.slb.model.transform.DescribeInstancesWithListenerResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DescribeListenersRequestMarshaller;
import com.ksc.network.slb.model.transform.DescribeListenersResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.DescribeLoadBalancersRequestMarshaller;
import com.ksc.network.slb.model.transform.DescribeLoadBalancersResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.ModifyHealthCheckRequestMarshaller;
import com.ksc.network.slb.model.transform.ModifyHealthCheckResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.ModifyInstancesWithListenerRequestMarshaller;
import com.ksc.network.slb.model.transform.ModifyInstancesWithListenerResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.ModifyListenersRequestMarshaller;
import com.ksc.network.slb.model.transform.ModifyListenersResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.ModifyLoadBalancerRequestMarshaller;
import com.ksc.network.slb.model.transform.ModifyLoadBalancerResultStaxUnmarshaller;
import com.ksc.network.slb.model.transform.RegisterInstancesWithListenerRequestMarshaller;
import com.ksc.network.slb.model.transform.RegisterInstancesWithListenerResultStaxUnmarshaller;
import com.ksc.transform.LegacyErrorUnmarshaller;
import com.ksc.transform.StandardErrorUnmarshaller;
import com.ksc.transform.Unmarshaller;
import com.ksc.util.CredentialUtils;
import com.ksc.util.KscRequestMetrics;
import com.ksc.util.KscRequestMetrics.Field;
public class KSCSLBClient extends KscWebServiceClient implements KSCSLB{
/** Provider for AWS credentials. */
private AWSCredentialsProvider kscCredentialsProvider;
/** Default signing name for the service. */
private static final String DEFAULT_SIGNING_NAME = "slb";
/** The region metadata service name for computing region endpoints. */
private static final String DEFAULT_ENDPOINT_PREFIX = "slb";
/**
* Client configuration factory providing ClientConfigurations tailored to
* this client
*/
protected static final ClientConfigurationFactory configFactory = new ClientConfigurationFactory();
/**
* List of exception unmarshallers for all modeled exceptions
*/
protected final List> exceptionUnmarshallers = new ArrayList>();
/**
* Constructs a new client to invoke service methods on SLB. A credentials
* provider chain will be used that searches for credentials in this order:
*
* - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
* - Java System Properties - aws.accessKeyId and aws.secretKey
* - Instance profile credentials delivered through the SLB metadata
* service
*
*
*
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @see DefaultAWSCredentialsProviderChain
*/
public KSCSLBClient() {
this(new DefaultAWSCredentialsProviderChain(), configFactory.getConfig());
}
/**
* Constructs a new client to invoke service methods on SLB. A credentials
* provider chain will be used that searches for credentials in this order:
*
* - Environment Variables - AWS_ACCESS_KEY_ID and AWS_SECRET_KEY
* - Java System Properties - aws.accessKeyId and aws.secretKey
* - Instance profile credentials delivered through the SLB metadata
* service
*
*
*
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param clientConfiguration
* The client configuration options controlling how this client
* connects to KSC (ex: proxy settings, retry counts, etc.).
*
* @see DefaultAWSCredentialsProviderChain
*/
public KSCSLBClient(ClientConfiguration clientConfiguration) {
this(new DefaultAWSCredentialsProviderChain(), clientConfiguration);
}
/**
* Constructs a new client to invoke service methods on SLB using the
* specified AWS account credentials.
*
*
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param awsCredentials
* The AWS credentials (access key ID and secret key) to use when
* authenticating with AWS services.
*/
public KSCSLBClient(AWSCredentials awsCredentials) {
this(awsCredentials, configFactory.getConfig());
}
/**
* Constructs a new client to invoke service methods on SLB using the
* specified AWS account credentials and client configuration options.
*
*
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param awsCredentials
* The AWS credentials (access key ID and secret key) to use when
* authenticating with AWS services.
* @param clientConfiguration
* The client configuration options controlling how this client
* connects to SLB (ex: proxy settings, retry counts, etc.).
*/
public KSCSLBClient(AWSCredentials awsCredentials, ClientConfiguration clientConfiguration) {
super(clientConfiguration);
this.kscCredentialsProvider = new StaticCredentialsProvider(awsCredentials);
init();
}
/**
* Constructs a new client to invoke service methods on SLB using the
* specified AWS account credentials provider.
*
*
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param awsCredentialsProvider
* The AWS credentials provider which will provide credentials to
* authenticate requests with KSC services.
*/
public KSCSLBClient(AWSCredentialsProvider awsCredentialsProvider) {
this(awsCredentialsProvider, configFactory.getConfig());
}
/**
* Constructs a new client to invoke service methods on SLB using the
* specified AWS account credentials provider and client configuration
* options.
*
*
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param awsCredentialsProvider
* The AWS credentials provider which will provide credentials to
* authenticate requests with KSC services.
* @param clientConfiguration
* The client configuration options controlling how this client
* connects to SLB (ex: proxy settings, retry counts, etc.).
*/
public KSCSLBClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration) {
this(awsCredentialsProvider, clientConfiguration, null);
}
/**
* Constructs a new client to invoke service methods on SLB using the
* specified KSC account credentials provider, client configuration options,
* and request metric collector.
*
*
* All service calls made using this new client object are blocking, and
* will not return until the service call completes.
*
* @param awsCredentialsProvider
* The AWS credentials provider which will provide credentials to
* authenticate requests with KSC services.
* @param clientConfiguration
* The client configuration options controlling how this client
* connects to SLB (ex: proxy settings, retry counts, etc.).
* @param requestMetricCollector
* optional request metric collector
*/
public KSCSLBClient(AWSCredentialsProvider awsCredentialsProvider, ClientConfiguration clientConfiguration,
RequestMetricCollector requestMetricCollector) {
super(clientConfiguration, requestMetricCollector);
this.kscCredentialsProvider = awsCredentialsProvider;
init();
}
@Override
public DescribeLoadBalancersResult describeLoadBalancers(DescribeLoadBalancersRequest describeLoadBalancersRequest) {
ExecutionContext executionContext = createExecutionContext(describeLoadBalancersRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DescribeLoadBalancersRequestMarshaller()
.marshall(describeLoadBalancersRequest);
// Binds the request metrics to the current request.
request.setKscRequestMetrics(kscRequestMetrics);
} finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DescribeLoadBalancersResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public CreateLoadBalancerResult createLoadBalancer(CreateLoadBalancerRequest createLoadBalancerRequest) {
ExecutionContext executionContext = createExecutionContext(createLoadBalancerRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new CreateLoadBalancerRequestMarshaller()
.marshall(createLoadBalancerRequest);
// Binds the request metrics to the current request.
request.setKscRequestMetrics(kscRequestMetrics);
} finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new CreateLoadBalancerResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public DeleteLoadBalancerResult deleteLoadBalancer(DeleteLoadBalancerRequest deleteLoadBalancerRequest) {
ExecutionContext executionContext = createExecutionContext(deleteLoadBalancerRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DeleteLoadBalancerRequestMarshaller()
.marshall(deleteLoadBalancerRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DeleteLoadBalancerResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public ModifyLoadBalancerResult modifyLoadBalancer(ModifyLoadBalancerRequest modifyLoadBalancerRequest) {
ExecutionContext executionContext = createExecutionContext(modifyLoadBalancerRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new ModifyLoadBalancerRequestMarshaller().marshall(modifyLoadBalancerRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new ModifyLoadBalancerResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
}finally {
endClientExecution(kscRequestMetrics,request,response);
}
}
@Override
public CreateListenersResult createListeners(CreateListenersRequest createListenersRequest) {
ExecutionContext executionContext = createExecutionContext(createListenersRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new CreateListenersRequestMarshaller()
.marshall(createListenersRequest);
// Binds the request metrics to the current request.
request.setKscRequestMetrics(kscRequestMetrics);
} finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new CreateListenersResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public ModifyListenersResult modifyListeners(ModifyListenersRequest modifyListenersRequest) {
ExecutionContext executionContext = createExecutionContext(modifyListenersRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new ModifyListenersRequestMarshaller().marshall(modifyListenersRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new ModifyListenersResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
}finally {
endClientExecution(kscRequestMetrics,request,response);
}
}
@Override
public DeleteListenersResult deleteListeners(DeleteListenersRequest deleteListenersRequest) {
ExecutionContext executionContext = createExecutionContext(deleteListenersRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DeleteListenersRequestMarshaller()
.marshall(deleteListenersRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DeleteListenersResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public DescribeListenersResult describeListeners(DescribeListenersRequest describeListenersRequest) {
ExecutionContext executionContext = createExecutionContext(describeListenersRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DescribeListenersRequestMarshaller()
.marshall(describeListenersRequest);
// Binds the request metrics to the current request.
request.setKscRequestMetrics(kscRequestMetrics);
} finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DescribeListenersResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public ConfigureHealthCheckResult configureHealthCheck(ConfigureHealthCheckRequest configureHealthCheckRequest) {
ExecutionContext executionContext = createExecutionContext(configureHealthCheckRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new ConfigureHealthCheckRequestMarshaller()
.marshall(configureHealthCheckRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new ConfigureHealthCheckResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public ModifyHealthCheckResult modifyHealthCheck(ModifyHealthCheckRequest modifyHealthCheckRequest) {
ExecutionContext executionContext = createExecutionContext(modifyHealthCheckRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new ModifyHealthCheckRequestMarshaller().marshall(modifyHealthCheckRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new ModifyHealthCheckResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
}finally {
endClientExecution(kscRequestMetrics,request,response);
}
}
@Override
public DeleteHealthCheckResult deleteHealthCheck(DeleteHealthCheckRequest deleteHealthCheckRequest) {
ExecutionContext executionContext = createExecutionContext(deleteHealthCheckRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DeleteHealthCheckRequestMarshaller()
.marshall(deleteHealthCheckRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DeleteHealthCheckResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public DescribeHealthChecksResult describeHealthChecks(DescribeHealthChecksRequest describeHealthChecksRequest) {
ExecutionContext executionContext = createExecutionContext(describeHealthChecksRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DescribeHealthChecksRequestMarshaller()
.marshall(describeHealthChecksRequest);
// Binds the request metrics to the current request.
request.setKscRequestMetrics(kscRequestMetrics);
} finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DescribeHealthChecksResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public RegisterInstancesWithListenerResult registerInstancesWithListener(RegisterInstancesWithListenerRequest registerInstancesWithListenerRequest) {
ExecutionContext executionContext = createExecutionContext(registerInstancesWithListenerRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new RegisterInstancesWithListenerRequestMarshaller()
.marshall(registerInstancesWithListenerRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new RegisterInstancesWithListenerResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
@Override
public ModifyInstancesWithListenerResult modifyInstancesWithListener(ModifyInstancesWithListenerRequest modifyInstancesWithListenerRequest) {
ExecutionContext executionContext = createExecutionContext(modifyInstancesWithListenerRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new ModifyInstancesWithListenerRequestMarshaller().marshall(modifyInstancesWithListenerRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new ModifyInstancesWithListenerResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
}finally {
endClientExecution(kscRequestMetrics,request,response);
}
}
@Override
public DeregisterInstancesFromListenerResult deregisterInstancesFromListener(DeregisterInstancesFromListenerRequest deregisterInstancesFromListenerRequest) {
ExecutionContext executionContext = createExecutionContext(deregisterInstancesFromListenerRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DeregisterInstancesFromListenerRequestMarshaller().marshall(deregisterInstancesFromListenerRequest);
request.setKscRequestMetrics(kscRequestMetrics);
}finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DeregisterInstancesFromListenerResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
}finally {
endClientExecution(kscRequestMetrics,request,response);
}
}
@Override
public DescribeInstancesWithListenerResult describeInstancesWithListener(DescribeInstancesWithListenerRequest describeInstancesWithListenerRequest) {
ExecutionContext executionContext = createExecutionContext(describeInstancesWithListenerRequest);
KscRequestMetrics kscRequestMetrics = executionContext.getKscRequestMetrics();
kscRequestMetrics.startEvent(Field.ClientExecuteTime);
Request request = null;
Response response = null;
try {
kscRequestMetrics.startEvent(Field.RequestMarshallTime);
try {
request = new DescribeInstancesWithListenerRequestMarshaller()
.marshall(describeInstancesWithListenerRequest);
// Binds the request metrics to the current request.
request.setKscRequestMetrics(kscRequestMetrics);
} finally {
kscRequestMetrics.endEvent(Field.RequestMarshallTime);
}
StaxResponseHandler responseHandler = new StaxResponseHandler(
new DescribeInstancesWithListenerResultStaxUnmarshaller());
response = invoke(request, responseHandler, executionContext);
return response.getKscResponse();
} finally {
endClientExecution(kscRequestMetrics, request, response);
}
}
private void init() {
exceptionUnmarshallers.add(new StandardErrorUnmarshaller());
exceptionUnmarshallers.add(new LegacyErrorUnmarshaller());
setServiceNameIntern(DEFAULT_SIGNING_NAME);
setEndpointPrefix(DEFAULT_ENDPOINT_PREFIX);
// calling this.setEndPoint(...) will also modify the signer accordingly
setEndpoint("http://slb.cn-beijing-6.api.ksyun.com");
}
/**
* Normal invoke with authentication. Credentials are required and may be
* overriden at the request level.
**/
private Response invoke(Request request,
HttpResponseHandler> responseHandler, ExecutionContext executionContext) {
executionContext.setCredentialsProvider(
CredentialUtils.getCredentialsProvider(request.getOriginalRequest(), kscCredentialsProvider));
return doInvoke(request, responseHandler, executionContext);
}
/**
* Invoke the request using the http client. Assumes credentials (or lack
* thereof) have been configured in the ExecutionContext beforehand.
**/
private Response doInvoke(Request request,
HttpResponseHandler> responseHandler, ExecutionContext executionContext) {
request.setEndpoint(endpoint);
request.setTimeOffset(timeOffset);
DefaultErrorResponseHandler errorResponseHandler = new DefaultErrorResponseHandler(exceptionUnmarshallers);
return client.execute(request, responseHandler, errorResponseHandler, executionContext);
}
}