public static void createQueuesNoncompliant()

in src/java/detectors/amazon_sqs_enable_long_polling/AmazonSqsEnableLongPollingNoncompliant.java [38:81]


    public static void createQueuesNoncompliant(AmazonSQS sqs,
                                                String queueNamePattern,
                                                int numOfQueues,
                                                String queue_url) {

        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put("FifoQueue", "true");
        attributes.put("ContentBasedDeduplication", "true");
        attributes.put("DelaySeconds", "0");
        attributes.put("MessageRetentionPeriod", "86400"); // this is 24 shours

        for (int i = 1; i < numOfQueues + 1; i++) {
            String queueName = queueNamePattern + "-" + i + ".fifo";
            // Noncompliant: avoids enabling long polling.
            CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName).withAttributes(attributes);
            try {
                CreateQueueResult res = sqs.createQueue(createQueueRequest);
                System.out.println("SQS Queue created, queue url: " + res.getQueueUrl());
            } catch (QueueNameExistsException e) {
                System.out.println("A queue with name " + queueName
                        + " already exist. Renaming it with _v1 suffix before next attempt");
                queueName = queueNamePattern + "-" + i + "-v1" + "-src.fifo";
                createQueueRequest = new CreateQueueRequest(queueName).withAttributes(attributes);
                sqs.createQueue(createQueueRequest);

            } catch (QueueDeletedRecentlyException e) {
                try {
                    System.out.println(e.getMessage());
                    System.out.println("Queue recently deleted. Sleeping for 65 seconds before recreating the queue");
                    Thread.sleep(65000);
                    createQueueRequest = new CreateQueueRequest(queueName).withAttributes(attributes);
                    sqs.createQueue(createQueueRequest);

                } catch (InterruptedException e1) {
                    e1.printStackTrace();
                }
            }
            ReceiveMessageRequest receive_request = new ReceiveMessageRequest()
                    .withQueueUrl(queue_url);
            sqs.receiveMessage(receive_request);

        }

    }