All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.iot1clickdevices.DefaultIot1ClickDevicesClient Maven / Gradle / Ivy

Go to download

The AWS Java SDK for IoT 1Click Devices Service module holds the client classes that are used for communicating with IoT 1Click Devices Service.

There is a newer version: 2.29.39
Show newest version
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.iot1clickdevices;

import java.util.Collections;
import java.util.List;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.awscore.client.handler.AwsSyncClientHandler;
import software.amazon.awssdk.awscore.exception.AwsServiceException;
import software.amazon.awssdk.core.RequestOverrideConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientConfiguration;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.client.handler.SyncClientHandler;
import software.amazon.awssdk.core.exception.SdkClientException;
import software.amazon.awssdk.core.http.HttpResponseHandler;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.metrics.MetricCollector;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.NoOpMetricCollector;
import software.amazon.awssdk.protocols.core.ExceptionMetadata;
import software.amazon.awssdk.protocols.json.AwsJsonProtocol;
import software.amazon.awssdk.protocols.json.AwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
import software.amazon.awssdk.protocols.json.JsonOperationMetadata;
import software.amazon.awssdk.services.iot1clickdevices.model.ClaimDevicesByClaimCodeRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.ClaimDevicesByClaimCodeResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.DescribeDeviceRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.DescribeDeviceResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.FinalizeDeviceClaimRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.FinalizeDeviceClaimResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.ForbiddenException;
import software.amazon.awssdk.services.iot1clickdevices.model.GetDeviceMethodsRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.GetDeviceMethodsResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.InitiateDeviceClaimRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.InitiateDeviceClaimResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.InternalFailureException;
import software.amazon.awssdk.services.iot1clickdevices.model.InvalidRequestException;
import software.amazon.awssdk.services.iot1clickdevices.model.InvokeDeviceMethodRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.InvokeDeviceMethodResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.Iot1ClickDevicesException;
import software.amazon.awssdk.services.iot1clickdevices.model.ListDeviceEventsRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.ListDeviceEventsResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.ListDevicesRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.ListDevicesResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.ListTagsForResourceRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.ListTagsForResourceResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.PreconditionFailedException;
import software.amazon.awssdk.services.iot1clickdevices.model.RangeNotSatisfiableException;
import software.amazon.awssdk.services.iot1clickdevices.model.ResourceConflictException;
import software.amazon.awssdk.services.iot1clickdevices.model.ResourceNotFoundException;
import software.amazon.awssdk.services.iot1clickdevices.model.TagResourceRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.TagResourceResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.UnclaimDeviceRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.UnclaimDeviceResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.UntagResourceRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.UntagResourceResponse;
import software.amazon.awssdk.services.iot1clickdevices.model.UpdateDeviceStateRequest;
import software.amazon.awssdk.services.iot1clickdevices.model.UpdateDeviceStateResponse;
import software.amazon.awssdk.services.iot1clickdevices.transform.ClaimDevicesByClaimCodeRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.DescribeDeviceRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.FinalizeDeviceClaimRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.GetDeviceMethodsRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.InitiateDeviceClaimRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.InvokeDeviceMethodRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.ListDeviceEventsRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.ListDevicesRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.ListTagsForResourceRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.TagResourceRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.UnclaimDeviceRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.UntagResourceRequestMarshaller;
import software.amazon.awssdk.services.iot1clickdevices.transform.UpdateDeviceStateRequestMarshaller;
import software.amazon.awssdk.utils.Logger;

/**
 * Internal implementation of {@link Iot1ClickDevicesClient}.
 *
 * @see Iot1ClickDevicesClient#builder()
 */
@Generated("software.amazon.awssdk:codegen")
@SdkInternalApi
final class DefaultIot1ClickDevicesClient implements Iot1ClickDevicesClient {
    private static final Logger log = Logger.loggerFor(DefaultIot1ClickDevicesClient.class);

    private final SyncClientHandler clientHandler;

    private final AwsJsonProtocolFactory protocolFactory;

    private final SdkClientConfiguration clientConfiguration;

    protected DefaultIot1ClickDevicesClient(SdkClientConfiguration clientConfiguration) {
        this.clientHandler = new AwsSyncClientHandler(clientConfiguration);
        this.clientConfiguration = clientConfiguration;
        this.protocolFactory = init(AwsJsonProtocolFactory.builder()).build();
    }

    @Override
    public final String serviceName() {
        return SERVICE_NAME;
    }

    /**
     * 

* Adds device(s) to your account (i.e., claim one or more devices) if and only if you received a claim code with * the device(s). *

* * @param claimDevicesByClaimCodeRequest * @return Result of the ClaimDevicesByClaimCode operation returned by the service. * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws ForbiddenException * 403 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.ClaimDevicesByClaimCode * @see AWS API Documentation */ @Override public ClaimDevicesByClaimCodeResponse claimDevicesByClaimCode(ClaimDevicesByClaimCodeRequest claimDevicesByClaimCodeRequest) throws InvalidRequestException, InternalFailureException, ForbiddenException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ClaimDevicesByClaimCodeResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, claimDevicesByClaimCodeRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ClaimDevicesByClaimCode"); return clientHandler .execute(new ClientExecutionParams() .withOperationName("ClaimDevicesByClaimCode").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(claimDevicesByClaimCodeRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ClaimDevicesByClaimCodeRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Given a device ID, returns a DescribeDeviceResponse object describing the details of the device. *

* * @param describeDeviceRequest * @return Result of the DescribeDevice operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.DescribeDevice * @see AWS API * Documentation */ @Override public DescribeDeviceResponse describeDevice(DescribeDeviceRequest describeDeviceRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, DescribeDeviceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, describeDeviceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "DescribeDevice"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("DescribeDevice").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(describeDeviceRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new DescribeDeviceRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Given a device ID, finalizes the claim request for the associated device. *

* *

* Claiming a device consists of initiating a claim, then publishing a device event, and finalizing the claim. For a * device of type button, a device event can be published by simply clicking the device. *

*
* * @param finalizeDeviceClaimRequest * @return Result of the FinalizeDeviceClaim operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws PreconditionFailedException * 412 response * @throws ResourceConflictException * 409 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.FinalizeDeviceClaim * @see AWS * API Documentation */ @Override public FinalizeDeviceClaimResponse finalizeDeviceClaim(FinalizeDeviceClaimRequest finalizeDeviceClaimRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, PreconditionFailedException, ResourceConflictException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, FinalizeDeviceClaimResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, finalizeDeviceClaimRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "FinalizeDeviceClaim"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("FinalizeDeviceClaim").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(finalizeDeviceClaimRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new FinalizeDeviceClaimRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Given a device ID, returns the invokable methods associated with the device. *

* * @param getDeviceMethodsRequest * @return Result of the GetDeviceMethods operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.GetDeviceMethods * @see AWS API * Documentation */ @Override public GetDeviceMethodsResponse getDeviceMethods(GetDeviceMethodsRequest getDeviceMethodsRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, GetDeviceMethodsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, getDeviceMethodsRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "GetDeviceMethods"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("GetDeviceMethods").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(getDeviceMethodsRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new GetDeviceMethodsRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Given a device ID, initiates a claim request for the associated device. *

* *

* Claiming a device consists of initiating a claim, then publishing a device event, and finalizing the claim. For a * device of type button, a device event can be published by simply clicking the device. *

*
* * @param initiateDeviceClaimRequest * @return Result of the InitiateDeviceClaim operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws ResourceConflictException * 409 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.InitiateDeviceClaim * @see AWS * API Documentation */ @Override public InitiateDeviceClaimResponse initiateDeviceClaim(InitiateDeviceClaimRequest initiateDeviceClaimRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, ResourceConflictException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, InitiateDeviceClaimResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, initiateDeviceClaimRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "InitiateDeviceClaim"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("InitiateDeviceClaim").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(initiateDeviceClaimRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new InitiateDeviceClaimRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Given a device ID, issues a request to invoke a named device method (with possible parameters). See the * "Example POST" code snippet below. *

* * @param invokeDeviceMethodRequest * @return Result of the InvokeDeviceMethod operation returned by the service. * @throws InvalidRequestException * 400 response * @throws PreconditionFailedException * 412 response * @throws InternalFailureException * 500 response * @throws ResourceNotFoundException * 404 response * @throws RangeNotSatisfiableException * 416 response * @throws ResourceConflictException * 409 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.InvokeDeviceMethod * @see AWS * API Documentation */ @Override public InvokeDeviceMethodResponse invokeDeviceMethod(InvokeDeviceMethodRequest invokeDeviceMethodRequest) throws InvalidRequestException, PreconditionFailedException, InternalFailureException, ResourceNotFoundException, RangeNotSatisfiableException, ResourceConflictException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, InvokeDeviceMethodResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, invokeDeviceMethodRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "InvokeDeviceMethod"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("InvokeDeviceMethod").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(invokeDeviceMethodRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new InvokeDeviceMethodRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Using a device ID, returns a DeviceEventsResponse object containing an array of events for the device. *

* * @param listDeviceEventsRequest * @return Result of the ListDeviceEvents operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws RangeNotSatisfiableException * 416 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.ListDeviceEvents * @see AWS API * Documentation */ @Override public ListDeviceEventsResponse listDeviceEvents(ListDeviceEventsRequest listDeviceEventsRequest) throws ResourceNotFoundException, RangeNotSatisfiableException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, ListDeviceEventsResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, listDeviceEventsRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListDeviceEvents"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("ListDeviceEvents").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(listDeviceEventsRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListDeviceEventsRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Lists the 1-Click compatible devices associated with your AWS account. *

* * @param listDevicesRequest * @return Result of the ListDevices operation returned by the service. * @throws RangeNotSatisfiableException * 416 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.ListDevices * @see AWS API * Documentation */ @Override public ListDevicesResponse listDevices(ListDevicesRequest listDevicesRequest) throws RangeNotSatisfiableException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, ListDevicesResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, listDevicesRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListDevices"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("ListDevices").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(listDevicesRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListDevicesRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Lists the tags associated with the specified resource ARN. *

* * @param listTagsForResourceRequest * @return Result of the ListTagsForResource operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.ListTagsForResource * @see AWS * API Documentation */ @Override public ListTagsForResourceResponse listTagsForResource(ListTagsForResourceRequest listTagsForResourceRequest) throws ResourceNotFoundException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler( operationMetadata, ListTagsForResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, listTagsForResourceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "ListTagsForResource"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("ListTagsForResource").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(listTagsForResourceRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new ListTagsForResourceRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Adds or updates the tags associated with the resource ARN. See AWS IoT * 1-Click Service Limits for the maximum number of tags allowed per resource. *

* * @param tagResourceRequest * @return Result of the TagResource operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.TagResource * @see AWS API * Documentation */ @Override public TagResourceResponse tagResource(TagResourceRequest tagResourceRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, TagResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, tagResourceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "TagResource"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("TagResource").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(tagResourceRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new TagResourceRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Disassociates a device from your AWS account using its device ID. *

* * @param unclaimDeviceRequest * @return Result of the UnclaimDevice operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.UnclaimDevice * @see AWS API * Documentation */ @Override public UnclaimDeviceResponse unclaimDevice(UnclaimDeviceRequest unclaimDeviceRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, UnclaimDeviceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, unclaimDeviceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UnclaimDevice"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("UnclaimDevice").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(unclaimDeviceRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new UnclaimDeviceRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Using tag keys, deletes the tags (key/value pairs) associated with the specified resource ARN. *

* * @param untagResourceRequest * @return Result of the UntagResource operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.UntagResource * @see AWS API * Documentation */ @Override public UntagResourceResponse untagResource(UntagResourceRequest untagResourceRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, UntagResourceResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, untagResourceRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UntagResource"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("UntagResource").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(untagResourceRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new UntagResourceRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } /** *

* Using a Boolean value (true or false), this operation enables or disables the device given a device ID. *

* * @param updateDeviceStateRequest * @return Result of the UpdateDeviceState operation returned by the service. * @throws ResourceNotFoundException * 404 response * @throws InvalidRequestException * 400 response * @throws InternalFailureException * 500 response * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws Iot1ClickDevicesException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample Iot1ClickDevicesClient.UpdateDeviceState * @see AWS API * Documentation */ @Override public UpdateDeviceStateResponse updateDeviceState(UpdateDeviceStateRequest updateDeviceStateRequest) throws ResourceNotFoundException, InvalidRequestException, InternalFailureException, AwsServiceException, SdkClientException, Iot1ClickDevicesException { JsonOperationMetadata operationMetadata = JsonOperationMetadata.builder().hasStreamingSuccessResponse(false) .isPayloadJson(true).build(); HttpResponseHandler responseHandler = protocolFactory.createResponseHandler(operationMetadata, UpdateDeviceStateResponse::builder); HttpResponseHandler errorResponseHandler = createErrorResponseHandler(protocolFactory, operationMetadata); List metricPublishers = resolveMetricPublishers(clientConfiguration, updateDeviceStateRequest .overrideConfiguration().orElse(null)); MetricCollector apiCallMetricCollector = metricPublishers.isEmpty() ? NoOpMetricCollector.create() : MetricCollector .create("ApiCall"); try { apiCallMetricCollector.reportMetric(CoreMetric.SERVICE_ID, "IoT 1Click Devices Service"); apiCallMetricCollector.reportMetric(CoreMetric.OPERATION_NAME, "UpdateDeviceState"); return clientHandler.execute(new ClientExecutionParams() .withOperationName("UpdateDeviceState").withResponseHandler(responseHandler) .withErrorResponseHandler(errorResponseHandler).withInput(updateDeviceStateRequest) .withMetricCollector(apiCallMetricCollector) .withMarshaller(new UpdateDeviceStateRequestMarshaller(protocolFactory))); } finally { metricPublishers.forEach(p -> p.publish(apiCallMetricCollector.collect())); } } private static List resolveMetricPublishers(SdkClientConfiguration clientConfiguration, RequestOverrideConfiguration requestOverrideConfiguration) { List publishers = null; if (requestOverrideConfiguration != null) { publishers = requestOverrideConfiguration.metricPublishers(); } if (publishers == null || publishers.isEmpty()) { publishers = clientConfiguration.option(SdkClientOption.METRIC_PUBLISHERS); } if (publishers == null) { publishers = Collections.emptyList(); } return publishers; } private HttpResponseHandler createErrorResponseHandler(BaseAwsJsonProtocolFactory protocolFactory, JsonOperationMetadata operationMetadata) { return protocolFactory.createErrorResponseHandler(operationMetadata); } private > T init(T builder) { return builder .clientConfiguration(clientConfiguration) .defaultServiceExceptionSupplier(Iot1ClickDevicesException::builder) .protocol(AwsJsonProtocol.REST_JSON) .protocolVersion("1.1") .registerModeledException( ExceptionMetadata.builder().errorCode("InternalFailureException") .exceptionBuilderSupplier(InternalFailureException::builder).httpStatusCode(500).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("InvalidRequestException") .exceptionBuilderSupplier(InvalidRequestException::builder).httpStatusCode(400).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("PreconditionFailedException") .exceptionBuilderSupplier(PreconditionFailedException::builder).httpStatusCode(412).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ResourceNotFoundException") .exceptionBuilderSupplier(ResourceNotFoundException::builder).httpStatusCode(404).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("RangeNotSatisfiableException") .exceptionBuilderSupplier(RangeNotSatisfiableException::builder).httpStatusCode(416).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ForbiddenException") .exceptionBuilderSupplier(ForbiddenException::builder).httpStatusCode(403).build()) .registerModeledException( ExceptionMetadata.builder().errorCode("ResourceConflictException") .exceptionBuilderSupplier(ResourceConflictException::builder).httpStatusCode(409).build()); } @Override public void close() { clientHandler.close(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy