Example usage for com.amazonaws.util.json Jackson fromJsonString

List of usage examples for com.amazonaws.util.json Jackson fromJsonString

Introduction

In this page you can find the example usage for com.amazonaws.util.json Jackson fromJsonString.

Prototype

public static <T> T fromJsonString(String json, Class<T> clazz) 

Source Link

Document

Returns the deserialized object from the given json string and target class; or null if the given json string is null.

Usage

From source file:com.easarrive.aws.client.cloudsearch.AmazonCloudSearchClient.java

License:Open Source License

/**
 * Execute a search and return result.//w  ww. ja va  2  s. c o m
 *
 * @param query search query to be executed.
 * @return result of the search.
 * @throws AmazonCloudSearchRequestException
 * @throws IllegalStateException
 * @throws AmazonCloudSearchInternalServerException
 */
public AmazonCloudSearchResult search(AmazonCloudSearchQuery query) throws IllegalStateException,
        AmazonCloudSearchRequestException, AmazonCloudSearchInternalServerException {
    if (this.getSearchEndpoint() == null || this.getSearchEndpoint().trim().length() < 1) {
        throw new AmazonCloudSearchRequestException("URI is null.");
    }
    AmazonCloudSearchResult result = null;
    String responseBody = null;
    try {
        Response response = Request
                .Get("https://" + this.getSearchEndpoint() + "/2013-01-01/search?" + query.build())
                .useExpectContinue().version(HttpVersion.HTTP_1_1)
                .addHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
                .addHeader("Accept", ContentType.APPLICATION_JSON.getMimeType()).execute();

        HttpResponse resp = response.returnResponse();
        int statusCode = resp.getStatusLine().getStatusCode();
        int statusType = statusCode / 100;
        if (statusType == 4) {
            throw new AmazonCloudSearchRequestException(statusCode + "", responseBody);
        } else if (statusType == 5) {
            throw new AmazonCloudSearchInternalServerException(
                    "Internal Server Error. Please try again as this might be a transient error condition.");
        }

        responseBody = inputStreamToString(resp.getEntity().getContent());
        result = Jackson.fromJsonString(responseBody, AmazonCloudSearchResult.class);
    } catch (ClientProtocolException e) {
        throw new AmazonCloudSearchInternalServerException(e);
    } catch (IOException e) {
        throw new AmazonCloudSearchInternalServerException(e);
    } catch (Exception e) {
        throw new AmazonCloudSearchInternalServerException(e);
    }

    return result;
}

From source file:com.example.RedshiftBasicExecutor.java

License:Open Source License

@Override
public KinesisConnectorRecordProcessorFactory<KinesisMessageModel, byte[]> getKinesisConnectorRecordProcessorFactory(
        String content) {/*  www.  ja  va 2  s.  c  o m*/
    KinesisMessageModel message = Jackson.fromJsonString(content, KinesisMessageModel.class);
    return new KinesisConnectorRecordProcessorFactory<>(new RedshiftBasicPipeline(message), config);
}

From source file:org.alanwilliamson.amazon.lambda.LambdaExecute.java

License:Open Source License

/**
 * Executes a lambda function and returns the result of the execution.
 *///  ww  w  .j  a v a  2s .co  m
@Override
public cfData execute(cfSession _session, cfArgStructData argStruct) throws cfmRunTimeException {

    AmazonKey amazonKey = getAmazonKey(_session, argStruct);

    // Arguments to extract
    String payload = getNamedStringParam(argStruct, "payload", null);
    String functionName = getNamedStringParam(argStruct, "function", null);
    String qualifier = getNamedStringParam(argStruct, "qualifier", null);

    try {

        // Construct the Lambda Client
        InvokeRequest invokeRequest = new InvokeRequest();
        invokeRequest.setInvocationType(InvocationType.RequestResponse);
        invokeRequest.setLogType(LogType.Tail);
        invokeRequest.setFunctionName(functionName);
        invokeRequest.setPayload(payload);
        if (qualifier != null) {
            invokeRequest.setQualifier(qualifier);
        }

        // Lambda client must be created with credentials
        BasicAWSCredentials awsCreds = new BasicAWSCredentials(amazonKey.getKey(), amazonKey.getSecret());
        AWSLambda awsLambda = AWSLambdaClientBuilder.standard()
                .withRegion(amazonKey.getAmazonRegion().toAWSRegion().getName())
                .withCredentials(new AWSStaticCredentialsProvider(awsCreds)).build();

        // Execute and process the results
        InvokeResult result = awsLambda.invoke(invokeRequest);

        // Convert the returned result
        ByteBuffer resultPayload = result.getPayload();
        String resultJson = new String(resultPayload.array(), "UTF-8");
        Map<String, Object> resultMap = Jackson.fromJsonString(resultJson, Map.class);

        return tagUtils.convertToCfData(resultMap);

    } catch (Exception e) {
        throwException(_session, "AmazonLambdaExecute: " + e.getMessage());
        return cfBooleanData.FALSE;
    }

}