@Test public void retrieveQueuesListTest() { CamelContext context = new DefaultCamelContext(); AWSSQSMetaDataExtension extension = new AWSSQSMetaDataExtension(context); Map<String, Object> properties = new HashMap<>(); properties.put("accessKey", "accessKey"); properties.put("secretKey", "secretKey"); properties.put("region", "region"); Optional<MetaDataExtension.MetaData> meta = extension.meta(properties); assertThat(meta).isPresent(); assertThat(meta.get().getPayload()).isInstanceOf(HashSet.class); assertThat(meta.get().getAttributes()).hasEntrySatisfying(MetaDataExtension.MetaData.JAVA_TYPE, new Condition<Object>() { @Override public boolean matches(Object val) { return Objects.equals(String.class, val); } }); assertThat(meta.get().getAttributes()).hasEntrySatisfying(MetaDataExtension.MetaData.CONTENT_TYPE, new Condition<Object>() { @Override public boolean matches(Object val) { return Objects.equals("text/plain", val); } }); }
@Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey"); final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey"); final String region = ConnectorOptions.extractOption(parameters, "region"); AmazonSQSClientBuilder clientBuilder; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); clientBuilder = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider); clientBuilder = clientBuilder.withRegion(Regions.valueOf(region)); AmazonSQS sqsClient = clientBuilder.build(); List<String> attributeNames = new ArrayList<String>(); attributeNames.add("All"); try { ListQueuesResult result = sqsClient.listQueues(); Set<String> setQueue = new HashSet<String>(); if (result.getQueueUrls() != null) { for (String entry : result.getQueueUrls()) { GetQueueAttributesRequest req = new GetQueueAttributesRequest(); req.setQueueUrl(entry); req.setAttributeNames(attributeNames); GetQueueAttributesResult c = sqsClient.getQueueAttributes(req); setQueue.add(c.getAttributes().get(QueueAttributeName.QueueArn.name())); } } return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class) .withPayload(setQueue).build()); } catch (Exception e) { throw new IllegalStateException("Get information about existing queues with has failed.", e); } }
AWSSQSMetaDataExtension extends AbstractMetaDataExtension { @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey"); final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey"); final String region = ConnectorOptions.extractOption(parameters, "region"); AmazonSQSClientBuilder clientBuilder; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); clientBuilder = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider); clientBuilder = clientBuilder.withRegion(Regions.valueOf(region)); AmazonSQS sqsClient = clientBuilder.build(); List<String> attributeNames = new ArrayList<String>(); attributeNames.add("All"); try { ListQueuesResult result = sqsClient.listQueues(); Set<String> setQueue = new HashSet<String>(); if (result.getQueueUrls() != null) { for (String entry : result.getQueueUrls()) { GetQueueAttributesRequest req = new GetQueueAttributesRequest(); req.setQueueUrl(entry); req.setAttributeNames(attributeNames); GetQueueAttributesResult c = sqsClient.getQueueAttributes(req); setQueue.add(c.getAttributes().get(QueueAttributeName.QueueArn.name())); } } return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class) .withPayload(setQueue).build()); } catch (Exception e) { throw new IllegalStateException("Get information about existing queues with has failed.", e); } } }
AWSSQSMetaDataExtension extends AbstractMetaDataExtension { @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey"); final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey"); final String region = ConnectorOptions.extractOption(parameters, "region"); AmazonSQSClientBuilder clientBuilder; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); clientBuilder = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider); clientBuilder = clientBuilder.withRegion(Regions.valueOf(region)); AmazonSQS sqsClient = clientBuilder.build(); List<String> attributeNames = new ArrayList<String>(); attributeNames.add("All"); try { ListQueuesResult result = sqsClient.listQueues(); Set<String> setQueue = new HashSet<String>(); if (result.getQueueUrls() != null) { for (String entry : result.getQueueUrls()) { GetQueueAttributesRequest req = new GetQueueAttributesRequest(); req.setQueueUrl(entry); req.setAttributeNames(attributeNames); GetQueueAttributesResult c = sqsClient.getQueueAttributes(req); setQueue.add(c.getAttributes().get(QueueAttributeName.QueueArn.name())); } } return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class) .withPayload(setQueue).build()); } catch (Exception e) { throw new IllegalStateException("Get information about existing queues with has failed.", e); } } AWSSQSMetaDataExtension(CamelContext context); }
AWSSQSMetaDataExtension extends AbstractMetaDataExtension { @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey"); final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey"); final String region = ConnectorOptions.extractOption(parameters, "region"); AmazonSQSClientBuilder clientBuilder; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); clientBuilder = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider); clientBuilder = clientBuilder.withRegion(Regions.valueOf(region)); AmazonSQS sqsClient = clientBuilder.build(); List<String> attributeNames = new ArrayList<String>(); attributeNames.add("All"); try { ListQueuesResult result = sqsClient.listQueues(); Set<String> setQueue = new HashSet<String>(); if (result.getQueueUrls() != null) { for (String entry : result.getQueueUrls()) { GetQueueAttributesRequest req = new GetQueueAttributesRequest(); req.setQueueUrl(entry); req.setAttributeNames(attributeNames); GetQueueAttributesResult c = sqsClient.getQueueAttributes(req); setQueue.add(c.getAttributes().get(QueueAttributeName.QueueArn.name())); } } return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class) .withPayload(setQueue).build()); } catch (Exception e) { throw new IllegalStateException("Get information about existing queues with has failed.", e); } } AWSSQSMetaDataExtension(CamelContext context); @Override Optional<MetaData> meta(Map<String, Object> parameters); }
AWSSQSMetaDataExtension extends AbstractMetaDataExtension { @Override public Optional<MetaData> meta(Map<String, Object> parameters) { final String accessKey = ConnectorOptions.extractOption(parameters, "accessKey"); final String secretKey = ConnectorOptions.extractOption(parameters, "secretKey"); final String region = ConnectorOptions.extractOption(parameters, "region"); AmazonSQSClientBuilder clientBuilder; AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials); clientBuilder = AmazonSQSClientBuilder.standard().withCredentials(credentialsProvider); clientBuilder = clientBuilder.withRegion(Regions.valueOf(region)); AmazonSQS sqsClient = clientBuilder.build(); List<String> attributeNames = new ArrayList<String>(); attributeNames.add("All"); try { ListQueuesResult result = sqsClient.listQueues(); Set<String> setQueue = new HashSet<String>(); if (result.getQueueUrls() != null) { for (String entry : result.getQueueUrls()) { GetQueueAttributesRequest req = new GetQueueAttributesRequest(); req.setQueueUrl(entry); req.setAttributeNames(attributeNames); GetQueueAttributesResult c = sqsClient.getQueueAttributes(req); setQueue.add(c.getAttributes().get(QueueAttributeName.QueueArn.name())); } } return Optional.of(MetaDataBuilder.on(getCamelContext()).withAttribute(MetaData.CONTENT_TYPE, "text/plain").withAttribute(MetaData.JAVA_TYPE, String.class) .withPayload(setQueue).build()); } catch (Exception e) { throw new IllegalStateException("Get information about existing queues with has failed.", e); } } AWSSQSMetaDataExtension(CamelContext context); @Override Optional<MetaData> meta(Map<String, Object> parameters);  }