List of usage examples for com.amazonaws.auth STSSessionCredentialsProvider STSSessionCredentialsProvider
public STSSessionCredentialsProvider(AWSSecurityTokenService sts)
From source file:VideoServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); String url = request.getParameter("action"); System.out.println("url" + url); Connection conn = null;//from www . j a v a2 s. co m Statement setupStatement; Statement readStatement = null; ResultSet resultSet = null; String results = ""; int numresults = 0; String statement = null; List<Video> result = new ArrayList<>(); try { // Create connection to RDS instance conn = DriverManager.getConnection(jdbcUrl); setupStatement = conn.createStatement(); String retrieveVideoName = "select id from metadata where url like '" + url + "%';"; ResultSet rs = setupStatement.executeQuery(retrieveVideoName); rs.next(); String ids = rs.getString(1); String retrieveUrl = "select url from metadata where id =" + ids + ";"; ResultSet ru = setupStatement.executeQuery(retrieveUrl); ru.next(); String urls = ru.getString(1); System.out.println("este es el id:" + ids); System.out.println("esta es la url:" + urls); String[] urlIdeal = urls.split(".mp4"); String finalUrl = urlIdeal[0] + ".mp4"; System.out.println(finalUrl); AWSCredentials credentials = new PropertiesCredentials( new File("/Users/diana/Desktop/AwsCredentials.properties")); dynamoDBClient = new AmazonDynamoDBClient(new STSSessionCredentialsProvider(credentials)); dynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2)); String s = getItem(String.valueOf(ids)); System.out.println(s); String[] textArray = s.split("\\{"); String textFinal = textArray[3]; String[] newTextArray = textFinal.split(",}"); String textFinalFinal = newTextArray[0]; String[] last = textFinalFinal.split("S:"); System.out.println(last[1].trim()); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Mp4Servlet</title>"); out.println(" <script src=\"jquery-1.11.3.min.js\"></script>\n" + " <script type=\"text/javascript\" src=\"../libs/base64.js\"></script>\n" + " <script type=\"text/javascript\" src=\"../libs/sprintf.js\"></script>\n" + " <script type=\"text/javascript\" src=\"../jspdf.js\"></script>"); out.println(" <style type=\"text/css\">\n" + " body {\n" + " padding-top: 20px;\n" + " padding-bottom: 40px;\n" + " }\n" + "\n" + " table{\n" + " display: table;\n" + " border:black 5px solid;\n" + " border-collapse: separate;\n" + " border-spacing: 7px;\n" + " border-color: gray;\n" + " padding:2px;\n" + "\n" + " }\n" + " \n" + " #logo{\n" + " height: 130px;\n" + " width: 728px;\n" + " }\n" + " hr{\n" + " /*border-color:#357EC7;*/\n" + " border-color:#B6B6B4;\n" + " }\n" + "\n" + " /* Custom container */\n" + " .container-narrow {\n" + " margin: 0 auto;\n" + " max-width: 700px;\n" + " }\n" + " .container-narrow > hr {\n" + " margin: 30px 0;\n" + " }\n" + "\n" + " /* Main marketing messages */\n" + " .jumbotron {\n" + " margin: 60px 0;\n" + " text-align: center;\n" + " color: grey;\n" + " }\n" + " .jumbotron h1 {\n" + " font-size: 72px;\n" + " line-height: 1;\n" + "\n" + " }\n" + " .jumbotron .btn {\n" + " font-size: 21px;\n" + " padding: 14px 24px;\n" + " }\n" + "\n" + " /* Supporting marketing content */\n" + " .marketing {\n" + " margin: 60px 0;\n" + " }\n" + " .marketing p + h4 {\n" + " margin-top: 28px;\n" + " }\n" + " \n" + " \n" + " </style>\n" + " \n" + "\n" + "<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css\">\n" + ""); out.println("</head>"); out.println("<body>"); out.println("<div class=\"container-narrow\">\n" + " <img id = \"logo\" src=\"http://opennebula.org/wp-content/uploads/2015/05/IIT_Logo_stack_186_blk.png\">\n" + " </div>"); out.println("<div class='jumbotron'></div>"); out.println( "<div class='container-narrow'> <video id='idtry' controls preload='auto' width='500' height='200'></div>\n" + "\n" + " \n" + " </video>"); out.println( "<div class='container-narrow'><br><button id ='button' type='button' class='btn btn-primary btn-lg' onclick='getText()'>EDIT</button></div>\n" + " <div>\n" + " <div class='container-narrow'><form id='usrform'><textarea id='text' class = 'container-narrow' name='comment' style='width: 400px; height: 200px;' form='usrform'></textarea>\n" + " <br><button id ='button2' type='button' onclick='submitToDynamo()'>Submit changes</button>\n" + " </form></div>\n" + " </div>"); out.println("<script> \n" + " var textA = " + "\"" + last[1].trim() + "\"" + ";\n" + "\n" + " document.getElementById('usrform').style.visibility = 'hidden';\n" + " \n" + " function getText() {\n" + "\n" + " var t = document.createTextNode(textA);\n" + " document.getElementById('text').appendChild(t);\n" + " document.getElementById('button').style.visibility = 'hidden';\n" + " document.getElementById('usrform').style.visibility = 'visible';\n" + "\n" + " }"); out.println(" var x;\n" + " function submitToDynamo() {\n" + " \n" + " document.getElementById('usrform').style.visibility = 'hidden';\n" + " document.getElementById('button').style.visibility = 'visible';\n" + " x = document.getElementById('text').value;\n" + " download(f,x);\n" + " }\n" + " "); out.println(" function download(filename, text) {\n" + " var pom = document.createElement('a');\n" + " pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));\n" + " pom.setAttribute('download', filename);\n" + "\n" + " if (document.createEvent) {\n" + " var event = document.createEvent('MouseEvents');\n" + " event.initEvent('click', true, true);\n" + " pom.dispatchEvent(event);\n" + " }\n" + " else {\n" + " pom.click();\n" + " }\n" + "}\n" + " \n" + " \n" + "var f = '/Users/diana/Desktop/texto.txt';"); out.println("var code = '<source src=\"" + finalUrl + "\" type=\"video/mp4\" />';\n" + " document.getElementById(\"idtry\").innerHTML=code;"); out.println("</script>"); out.println("<div>"); out.println("</div><br>"); out.println("<a href='http://localhost:8080/studentUI/Uiservlet'>BACK TO LIST </a>"); out.println("</body>"); out.println("</html>"); } } catch (SQLException ex) { // handle any errors System.out.println("SQLException: " + ex.getMessage()); System.out.println("SQLState: " + ex.getSQLState()); System.out.println("VendorError: " + ex.getErrorCode()); } finally { System.out.println("Closing the connection."); if (conn != null) try { conn.close(); } catch (SQLException ignore) { } } }
From source file:com.mycompany.rproject.runnableClass.java
public static void putInDb(String s, String id) throws IOException { AWSCredentials credentials = new PropertiesCredentials( new File("/Users/paulamontojo/Desktop/AwsCredentials.properties")); dynamoDBClient = new AmazonDynamoDBClient(new STSSessionCredentialsProvider(credentials)); dynamoDBClient.setRegion(Region.getRegion(Regions.US_WEST_2)); createTable();/*from w w w . j ava 2 s . c o m*/ // Describe our new table describeTable(); // Add some items putItem(newItem(id, "url", s)); }