List of usage examples for com.amazonaws.services.sqs AmazonSQSClient setEndpoint
@Deprecated public void setEndpoint(String endpoint) throws IllegalArgumentException
From source file:com.amazon.sqs.javamessaging.SQSConnectionFactory.java
License:Open Source License
private void configureClient(AmazonSQSClient client) throws JMSException { try {//from ww w .j a va 2 s. c om if (region != null) { client.setRegion(region); } if (endpoint != null) { client.setEndpoint(endpoint); } if (signerRegionOverride != null) { client.setSignerRegionOverride(signerRegionOverride); } } catch (IllegalArgumentException e) { throw (JMSException) new JMSException("Bad endpoint configuration: " + e.getMessage()).initCause(e); } }
From source file:com.athena.sqs.MessageContext.java
License:Apache License
@PostConstruct public void doConnect() throws Exception { try {//w w w. j a v a 2 s . co m //AmazonSQSClient sqs = new AmazonSQSAsyncClient(credentials); AmazonSQSClient sqs = new AmazonSQSClient(credentials); sqs.setEndpoint("http://sqs.eu-west-1.amazonaws.com"); logger.debug("Start Connection with Amazon SQS"); this.sqsClient = sqs; logger.debug("Binding Amazon SQS successfully."); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.brianmcmichael.sagu.AmazonDownloadRequest.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtDownload) { archiveId = jtfDownloadField.getText().trim(); if ((archiveId.equals(""))) { JOptionPane.showMessageDialog(null, "Enter the Archive ID of the file to be requested.", "Error", JOptionPane.ERROR_MESSAGE); } else {/* w ww .j av a2s . c o m*/ SwingWorker downloadWorker = new SwingWorker() { private String archiveId = jtfDownloadField.getText().trim(); @Override protected Object doInBackground() throws Exception { // Create dumb progressbar JFrame downloadFrame = new JFrame("Downloading"); { downloadFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL); dumJProgressBar.setIndeterminate(true); downloadFrame.add(dumJProgressBar, BorderLayout.NORTH); downloadFrame.setSize(300, 60); } centerDefineFrame(downloadFrame, 300, 50); String archiveId = jtfDownloadField.getText().trim(); try { String vaultName = dlVault; FileDialog fd = new FileDialog(new Frame(), "Save Archive As...", FileDialog.SAVE); fd.setFile("Save Archive As..."); fd.setDirectory(System.getProperty("user.dir")); fd.setLocation(50, 50); fd.setVisible(true); String filePath = "" + fd.getDirectory() + System.getProperty("file.separator") + fd.getFile(); File outFile = new File(filePath); if (outFile != null) { downloadFrame.setTitle("Downloading " + outFile.toString()); downloadFrame.setVisible(true); final Endpoint endpoint = Endpoint.getByIndex(locationChoice); AmazonSQSClient dlSQS = new AmazonSQSClient(dlCredentials); AmazonSNSClient dlSNS = new AmazonSNSClient(dlCredentials); dlSQS.setEndpoint(endpoint.getSQSEndpoint()); dlSNS.setEndpoint(endpoint.getSNSEndpoint()); // ArchiveTransferManager atm = new // ArchiveTransferManager(dlClient, // dlCredentials); ArchiveTransferManager atm = new ArchiveTransferManager(dlClient, dlSQS, dlSNS); atm.download("-", vaultName, archiveId, outFile); JOptionPane.showMessageDialog(null, "Sucessfully downloaded " + outFile.toString(), "Success", JOptionPane.INFORMATION_MESSAGE); downloadFrame.setVisible(false); } } catch (AmazonServiceException k) { JOptionPane.showMessageDialog(null, "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE); System.out.println("" + k); downloadFrame.setVisible(false); } catch (AmazonClientException i) { JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not downloaded.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } catch (Exception j) { JOptionPane.showMessageDialog(null, "Archive not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } return null; } }; downloadWorker.execute(); try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } this.setVisible(false); dispose(); } } else if (e.getSource() == jbtBack) { this.setVisible(false); dispose(); } else { JOptionPane.showMessageDialog(this, "Please choose a valid action."); } }
From source file:com.brianmcmichael.sagu.ui.AmazonDownloadRequest.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtDownload) { archiveId = jtfDownloadField.getText().trim(); if ((archiveId.equals(""))) { JOptionPane.showMessageDialog(null, "Enter the Archive ID of the file to be requested.", "Error", JOptionPane.ERROR_MESSAGE); } else {/*w ww . j a va 2s.co m*/ SwingWorker<Object, Void> downloadWorker = new SwingWorker<Object, Void>() { private String archiveId = jtfDownloadField.getText().trim(); @Override protected Void doInBackground() throws Exception { // Create dumb progressbar JFrame downloadFrame = new JFrame("Downloading"); { downloadFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL); dumJProgressBar.setIndeterminate(true); downloadFrame.add(dumJProgressBar, BorderLayout.NORTH); downloadFrame.setSize(300, 60); } centerDefineFrame(downloadFrame, 300, 50); try { String vaultName = dlVault; FileDialog fd = new FileDialog(new Frame(), "Save Archive As...", FileDialog.SAVE); fd.setFile("Save Archive As..."); fd.setDirectory(System.getProperty("user.dir")); fd.setLocation(50, 50); fd.setVisible(true); String filePath = "" + fd.getDirectory() + System.getProperty("file.separator") + fd.getFile(); File outFile = new File(filePath); if (outFile != null) { downloadFrame.setTitle("Downloading " + outFile.toString()); downloadFrame.setVisible(true); final Endpoint endpoint = Endpoint.getByIndex(locationChoice); AmazonSQSClient dlSQS = new AmazonSQSClient(dlCredentials); AmazonSNSClient dlSNS = new AmazonSNSClient(dlCredentials); dlSQS.setEndpoint(endpoint.getSQSEndpoint()); dlSNS.setEndpoint(endpoint.getSNSEndpoint()); // ArchiveTransferManager atm = new // ArchiveTransferManager(dlClient, // dlCredentials); ArchiveTransferManager atm = new ArchiveTransferManager(dlClient, dlSQS, dlSNS); atm.download("-", vaultName, archiveId, outFile); JOptionPane.showMessageDialog(null, "Sucessfully downloaded " + outFile.toString(), "Success", JOptionPane.INFORMATION_MESSAGE); downloadFrame.setVisible(false); } } catch (AmazonServiceException k) { JOptionPane.showMessageDialog(null, "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE); System.out.println("" + k); downloadFrame.setVisible(false); } catch (AmazonClientException i) { JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not downloaded.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } catch (Exception j) { JOptionPane.showMessageDialog(null, "Archive not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } return null; } }; downloadWorker.execute(); try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } this.setVisible(false); dispose(); } } else if (e.getSource() == jbtBack) { this.setVisible(false); dispose(); } else { JOptionPane.showMessageDialog(this, "Please choose a valid action."); } }
From source file:com.brianmcmichael.SimpleGlacierUploader.AmazonDownloadRequest.java
License:Open Source License
@Override public void actionPerformed(ActionEvent e) { if (e.getSource() == jbtDownload) { archiveId = jtfDownloadField.getText().trim(); if ((archiveId.equals(""))) { JOptionPane.showMessageDialog(null, "Enter the Archive ID of the file to be requested.", "Error", JOptionPane.ERROR_MESSAGE); } else {/*from ww w. j a va2 s. c o m*/ SwingWorker downloadWorker = new SwingWorker() { private String archiveId = jtfDownloadField.getText().trim(); @Override protected Object doInBackground() throws Exception { // Create dumb progressbar JFrame downloadFrame = new JFrame("Downloading"); { downloadFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final JProgressBar dumJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL); dumJProgressBar.setIndeterminate(true); downloadFrame.add(dumJProgressBar, BorderLayout.NORTH); downloadFrame.setSize(300, 60); } centerDefineFrame(downloadFrame, 300, 50); String archiveId = jtfDownloadField.getText().trim(); try { String vaultName = dlVault; FileDialog fd = new FileDialog(new Frame(), "Save Archive As...", FileDialog.SAVE); fd.setFile("Save Archive As..."); fd.setDirectory(System.getProperty("user.dir")); fd.setLocation(50, 50); fd.setVisible(true); String filePath = "" + fd.getDirectory() + System.getProperty("file.separator") + fd.getFile(); File outFile = new File(filePath); if (outFile != null) { downloadFrame.setTitle("Downloading " + outFile.toString()); downloadFrame.setVisible(true); Endpoints notificationEP = new Endpoints(locationChoice); AmazonSQSClient dlSQS = new AmazonSQSClient(dlCredentials); AmazonSNSClient dlSNS = new AmazonSNSClient(dlCredentials); dlSQS.setEndpoint(notificationEP.sqsEndpoint()); dlSNS.setEndpoint(notificationEP.snsEndpoint()); // ArchiveTransferManager atm = new // ArchiveTransferManager(dlClient, // dlCredentials); ArchiveTransferManager atm = new ArchiveTransferManager(dlClient, dlSQS, dlSNS); atm.download("-", vaultName, archiveId, outFile); JOptionPane.showMessageDialog(null, "Sucessfully downloaded " + outFile.toString(), "Success", JOptionPane.INFORMATION_MESSAGE); downloadFrame.setVisible(false); } } catch (AmazonServiceException k) { JOptionPane.showMessageDialog(null, "The server returned an error. Wait 24 hours after submitting an archive to attempt a download. Also check that correct location of archive has been set on the previous page.", "Error", JOptionPane.ERROR_MESSAGE); System.out.println("" + k); downloadFrame.setVisible(false); } catch (AmazonClientException i) { JOptionPane.showMessageDialog(null, "Client Error. Check that all fields are correct. Archive not downloaded.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } catch (Exception j) { JOptionPane.showMessageDialog(null, "Archive not found. Unspecified Error.", "Error", JOptionPane.ERROR_MESSAGE); downloadFrame.setVisible(false); } return null; } }; downloadWorker.execute(); try { Thread.sleep(500); } catch (InterruptedException e1) { e1.printStackTrace(); } this.setVisible(false); dispose(); } } else if (e.getSource() == jbtBack) { this.setVisible(false); dispose(); } else { JOptionPane.showMessageDialog(this, "Please choose a valid action."); } }
From source file:com.comcast.cmb.test.tools.CMBTutorial.java
License:Apache License
public static void main(String[] args) { try {//from www . j a v a2 s .c om Util.initLog4jTest(); //TODO: set user id and credentials for two distinct users // user "cqs_test_1" //BasicAWSCredentials user1Credentials = new BasicAWSCredentials("<access_key>", "<secret_key>"); BasicAWSCredentials user1Credentials = new BasicAWSCredentials("Z2DVBFRNZ2C2SSXDWS5F", "bH2UQiJkpctBaE3eaDob19fj5J9Q1FVafrZantBp"); // user "cqs_test_2" //String user2Id = "<user_id>"; String user2Id = "389653920093"; //BasicAWSCredentials user2Credentials = new BasicAWSCredentials("<access_key>", "<secret_key>"); BasicAWSCredentials user2Credentials = new BasicAWSCredentials("QL8Q1VOBCSJC5FZ2DMIU", "n6a82gyJZ04Z+Xqp7OgfqPtbbKqVc3UbuOTNrF+7"); // service urls //TODO: add service URLs //String cqsServerUrl = "http://<host>:<port>"; //String cnsServerUrl = "http://<host>:<port>"; String cqsServerUrl = "http://localhost:6059"; String cnsServerUrl = "http://localhost:6061"; // initialize service AmazonSQSClient sqs = new AmazonSQSClient(user1Credentials); sqs.setEndpoint(cqsServerUrl); AmazonSNSClient sns = new AmazonSNSClient(user2Credentials); sns.setEndpoint(cnsServerUrl); // create queue Random randomGenerator = new Random(); String queueName = QUEUE_PREFIX + randomGenerator.nextLong(); HashMap<String, String> attributeParams = new HashMap<String, String>(); CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName); createQueueRequest.setAttributes(attributeParams); String queueUrl = sqs.createQueue(createQueueRequest).getQueueUrl(); AddPermissionRequest addPermissionRequest = new AddPermissionRequest(); addPermissionRequest.setQueueUrl(queueUrl); addPermissionRequest.setActions(Arrays.asList("SendMessage")); addPermissionRequest.setLabel(UUID.randomUUID().toString()); addPermissionRequest.setAWSAccountIds(Arrays.asList(user2Id)); sqs.addPermission(addPermissionRequest); // create topic String topicName = "TSTT" + randomGenerator.nextLong(); CreateTopicRequest createTopicRequest = new CreateTopicRequest(topicName); CreateTopicResult createTopicResult = sns.createTopic(createTopicRequest); String topicArn = createTopicResult.getTopicArn(); // subscribe and confirm cqs endpoint SubscribeRequest subscribeRequest = new SubscribeRequest(); String queueArn = getArnForQueueUrl(queueUrl); subscribeRequest.setEndpoint(queueArn); subscribeRequest.setProtocol("cqs"); subscribeRequest.setTopicArn(topicArn); SubscribeResult subscribeResult = sns.subscribe(subscribeRequest); String subscriptionArn = subscribeResult.getSubscriptionArn(); if (subscriptionArn.equals("pending confirmation")) { Thread.sleep(500); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(); receiveMessageRequest.setQueueUrl(queueUrl); receiveMessageRequest.setMaxNumberOfMessages(1); ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); List<Message> messages = receiveMessageResult.getMessages(); if (messages != null && messages.size() == 1) { JSONObject o = new JSONObject(messages.get(0).getBody()); if (!o.has("SubscribeURL")) { throw new Exception("message is not a confirmation messsage"); } String subscriptionUrl = o.getString("SubscribeURL"); httpGet(subscriptionUrl); DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(); deleteMessageRequest.setReceiptHandle(messages.get(0).getReceiptHandle()); deleteMessageRequest.setQueueUrl(queueUrl); sqs.deleteMessage(deleteMessageRequest); } else { throw new Exception("no confirmation message found"); } } // publish and receive message PublishRequest publishRequest = new PublishRequest(); String messageText = "quamvis sint sub aqua, sub aqua maledicere temptant"; publishRequest.setMessage(messageText); publishRequest.setSubject("unit test message"); publishRequest.setTopicArn(topicArn); sns.publish(publishRequest); Thread.sleep(500); ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(); receiveMessageRequest.setQueueUrl(queueUrl); receiveMessageRequest.setMaxNumberOfMessages(1); ReceiveMessageResult receiveMessageResult = sqs.receiveMessage(receiveMessageRequest); List<Message> messages = receiveMessageResult.getMessages(); if (messages != null && messages.size() == 1) { String messageBody = messages.get(0).getBody(); if (!messageBody.contains(messageText)) { throw new Exception("message text not found"); } DeleteMessageRequest deleteMessageRequest = new DeleteMessageRequest(); deleteMessageRequest.setReceiptHandle(messages.get(0).getReceiptHandle()); deleteMessageRequest.setQueueUrl(queueUrl); sqs.deleteMessage(deleteMessageRequest); } else { throw new Exception("no messages found"); } // subscribe and confirm http endpoint String id = randomGenerator.nextLong() + ""; String endPointUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "recv/" + id; String lastMessageUrl = CMBTestingConstants.HTTP_ENDPOINT_BASE_URL + "info/" + id + "?showLast=true"; subscribeRequest = new SubscribeRequest(); subscribeRequest.setEndpoint(endPointUrl); subscribeRequest.setProtocol("http"); subscribeRequest.setTopicArn(topicArn); subscribeResult = sns.subscribe(subscribeRequest); subscriptionArn = subscribeResult.getSubscriptionArn(); if (subscriptionArn.equals("pending confirmation")) { Thread.sleep(500); String response = httpGet(lastMessageUrl); JSONObject o = new JSONObject(response); if (!o.has("SubscribeURL")) { throw new Exception("message is not a confirmation messsage"); } String subscriptionUrl = o.getString("SubscribeURL"); response = httpGet(subscriptionUrl); } // publish and receive message publishRequest = new PublishRequest(); publishRequest.setMessage(messageText); publishRequest.setSubject("unit test message"); publishRequest.setTopicArn(topicArn); sns.publish(publishRequest); Thread.sleep(500); String response = httpGet(lastMessageUrl); if (response != null && response.length() > 0) { if (!response.contains(messageText)) { throw new Exception("message text not found"); } } else { throw new Exception("no messages found"); } // delete queue and topic DeleteTopicRequest deleteTopicRequest = new DeleteTopicRequest(topicArn); sns.deleteTopic(deleteTopicRequest); sqs.deleteQueue(new DeleteQueueRequest(queueUrl)); System.out.println("OK"); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.connexience.server.model.archive.glacier.SetupUtils.java
License:Open Source License
public static SQSInfo setupSQS(String accessKey, String secretKey, String domainName, String vaultName) { SQSInfo sqsInfo = null;/*from w w w . j a v a 2 s . c om*/ try { AWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretKey); AmazonSQSClient amazonSQSClient = new AmazonSQSClient(awsCredentials); amazonSQSClient.setEndpoint("https://sqs." + domainName + ".amazonaws.com/"); String queueName = vaultName + "-inkspot_glacier-queue"; CreateQueueRequest createQueueRequest = new CreateQueueRequest(); createQueueRequest.withQueueName(queueName); CreateQueueResult createQueueResult = amazonSQSClient.createQueue(createQueueRequest); if (createQueueResult != null) { String queueURL = createQueueResult.getQueueUrl(); GetQueueAttributesRequest getQueueAttributesRequest = new GetQueueAttributesRequest(); getQueueAttributesRequest.withQueueUrl(queueURL); getQueueAttributesRequest.withAttributeNames("QueueArn"); GetQueueAttributesResult getQueueAttributesResult = amazonSQSClient .getQueueAttributes(getQueueAttributesRequest); if (getQueueAttributesResult != null) { String queueARN = getQueueAttributesResult.getAttributes().get("QueueArn"); Statement sqsStatement = new Statement(Effect.Allow); sqsStatement.withPrincipals(Principal.AllUsers); sqsStatement.withActions(SQSActions.SendMessage); sqsStatement.withResources(new Resource(queueARN)); Policy sqsPolicy = new Policy(); sqsPolicy.withStatements(sqsStatement); Map<String, String> sqsAttributes = new HashMap<>(); sqsAttributes.put("Policy", sqsPolicy.toJson()); SetQueueAttributesRequest setQueueAttributesRequest = new SetQueueAttributesRequest(); setQueueAttributesRequest.withQueueUrl(queueURL); setQueueAttributesRequest.withAttributes(sqsAttributes); amazonSQSClient.setQueueAttributes(setQueueAttributesRequest); sqsInfo = new SQSInfo(queueARN, queueURL); } else logger.warn("Unable to get queue attributes: \"" + queueName + "\""); } else logger.warn("Unable to create queue: \"" + queueName + "\""); amazonSQSClient.shutdown(); } catch (AmazonServiceException amazonServiceException) { logger.warn("AmazonServiceException: " + amazonServiceException); logger.debug(amazonServiceException); } catch (IllegalArgumentException illegalArgumentException) { logger.warn("IllegalArgumentException: " + illegalArgumentException); logger.debug(illegalArgumentException); } catch (AmazonClientException amazonClientException) { logger.warn("AmazonClientException: " + amazonClientException); logger.debug(amazonClientException); } catch (Throwable throwable) { logger.warn("Throwable: " + throwable); logger.debug(throwable); } return sqsInfo; }
From source file:com.leverno.ysbos.archive.example.ArchiveDownloadHighLevel.java
License:Open Source License
public static void main(String[] args) throws IOException { AWSCredentials credentials = getCredentials(); AmazonSQSClient sqs = new AmazonSQSClient(credentials); AmazonSNSClient sns = new AmazonSNSClient(credentials); glacier = new AmazonGlacierClient(credentials); glacier.setEndpoint(Constants.endpoint); sqs.setEndpoint(Constants.endpoint); sns.setEndpoint(Constants.endpoint); try {// w w w .j ava 2 s . c o m ArchiveTransferManager atm = new ArchiveTransferManager(glacier, sqs, sns); atm.download(vaultName, archiveId, new File(downloadFilePath)); } catch (Exception e) { System.err.println(e); } }