├── box-webhook-aws-sample ├── box-webhook-aws-sns │ ├── settings.gradle │ ├── src │ │ ├── main │ │ │ ├── resources │ │ │ │ └── box-samples-aws-sns.properties │ │ │ └── java │ │ │ │ ├── com │ │ │ │ └── box │ │ │ │ │ └── samples │ │ │ │ │ └── aws │ │ │ │ │ └── sns │ │ │ │ │ ├── utils │ │ │ │ │ ├── StringUtils.java │ │ │ │ │ ├── ExceptionUtils.java │ │ │ │ │ ├── FileUtils.java │ │ │ │ │ ├── ValidationUtils.java │ │ │ │ │ └── LambdaUtils.java │ │ │ │ │ ├── validation │ │ │ │ │ ├── ValidationException.java │ │ │ │ │ └── Validation.java │ │ │ │ │ ├── logging │ │ │ │ │ ├── LambdaLoggerSlf4jLoggerFactory.java │ │ │ │ │ └── LambdaLoggerSlf4j.java │ │ │ │ │ ├── ResponseBuilder.java │ │ │ │ │ ├── Configuration.java │ │ │ │ │ └── Services.java │ │ │ │ └── org │ │ │ │ └── slf4j │ │ │ │ └── impl │ │ │ │ └── StaticLoggerBinder.java │ │ └── assembly │ │ │ └── bin.xml │ ├── build.gradle │ ├── gradlew.bat │ └── gradlew ├── .gitignore ├── settings.gradle ├── box-webhook-aws-webapp │ ├── src │ │ └── main │ │ │ ├── webapp │ │ │ ├── webhook_sample.css │ │ │ ├── bottom.jsp │ │ │ ├── login.jsp │ │ │ ├── signin.jsp │ │ │ ├── top.jsp │ │ │ ├── createuser.jsp │ │ │ ├── corsupload.js │ │ │ ├── dashboard.jsp │ │ │ ├── appusers_sample.css │ │ │ ├── assets │ │ │ │ └── test.txt │ │ │ ├── WEB-INF │ │ │ │ └── web.xml │ │ │ └── docDetails.jsp │ │ │ ├── resources │ │ │ └── config.properties │ │ │ └── java │ │ │ └── com │ │ │ └── box │ │ │ └── sdk │ │ │ └── webhookawssample │ │ │ ├── DownloadServlet.java │ │ │ ├── PreviewServlet.java │ │ │ ├── helpers │ │ │ ├── AWSHelper.java │ │ │ ├── ConfigHelper.java │ │ │ └── BoxHelper.java │ │ │ ├── SignInServlet.java │ │ │ ├── CreateUserServlet.java │ │ │ ├── ThumbnailServlet.java │ │ │ ├── DashboardServlet.java │ │ │ ├── LoginServlet.java │ │ │ ├── DocDetailsServlet.java │ │ │ └── NotifyOnPreviewServlet.java │ ├── .gitignore │ └── build.gradle ├── gradle.properties.template ├── config │ └── checkstyle │ │ ├── suppressions.xml │ │ └── checkstyle.xml ├── build.gradle ├── README.md └── LICENSE ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── box-appusers-java-server-sample ├── private_key.pem.example ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── config.properties.example ├── src │ └── main │ │ ├── webapp │ │ ├── bottom.jsp │ │ ├── login.jsp │ │ ├── signin.jsp │ │ ├── top.jsp │ │ ├── corsupload.js │ │ ├── createuser.jsp │ │ ├── dashboard.jsp │ │ ├── appusers_sample.css │ │ ├── assets │ │ │ └── test.txt │ │ ├── docDetails.jsp │ │ └── WEB-INF │ │ │ └── web.xml │ │ └── java │ │ └── com │ │ ├── box │ │ └── sdk │ │ │ └── appusersexample │ │ │ ├── DownloadServlet.java │ │ │ ├── PreviewServlet.java │ │ │ ├── SignInServlet.java │ │ │ ├── CreateUserServlet.java │ │ │ ├── DashboardServlet.java │ │ │ ├── ThumbnailServlet.java │ │ │ ├── LoginServlet.java │ │ │ └── DocDetailsServlet.java │ │ └── helpers │ │ ├── ConfigHelper.java │ │ └── BoxHelper.java ├── config │ └── checkstyle │ │ ├── suppressions.xml │ │ └── checkstyle.xml ├── build.gradle ├── LICENSE ├── pom.xml ├── gradlew.bat ├── README.md └── gradlew ├── .gitignore ├── README.md ├── gradlew.bat └── gradlew /box-webhook-aws-sample/box-webhook-aws-sns/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'box-webhook-aws-sns' 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/box/box-java-sdk-samples/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /box-appusers-java-server-sample/private_key.pem.example: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | 3 | -----END RSA PRIVATE KEY----- 4 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/.gitignore: -------------------------------------------------------------------------------- 1 | !box-webhook-aws-sns/src/main/resources/box-samples-aws-sns.properties 2 | !gradle/**/* 3 | build 4 | .gradle 5 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = "box-webhook-aws-sample" 2 | 3 | include 'box-webhook-aws-sns', 'box-webhook-aws-webapp' 4 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/box/box-java-sdk-samples/master/box-appusers-java-server-sample/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/webapp/webhook_sample.css: -------------------------------------------------------------------------------- 1 | .notifyLabel { 2 | margin-top: 5px; 3 | } 4 | 5 | .notifyEmailInput { 6 | width: 100%; margin-top: 3px 7 | } 8 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/resources/config.properties: -------------------------------------------------------------------------------- 1 | boxClientId=@box.clientId@ 2 | boxClientSecret=@box.clientSecret@ 3 | boxEnterpriseId=@box.enterpriseId@ 4 | boxPrivateKeyPassword=@box.privateKeyPassword@ 5 | boxPublicKeyId=@box.publicKeyId@ -------------------------------------------------------------------------------- /box-webhook-aws-sample/gradle.properties.template: -------------------------------------------------------------------------------- 1 | box.enterpriseId={boxEnterpriseId} 2 | box.clientId={boxClientId} 3 | box.clientSecret={boxClientSecret} 4 | box.publicKeyId={boxPublicKeyId} 5 | box.privateKeyPassword={boxPrivateKeyPassword} 6 | box.privateKeyFile={boxPrivateKeyFile} 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Thu Jul 21 18:58:11 PDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip 7 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/resources/box-samples-aws-sns.properties: -------------------------------------------------------------------------------- 1 | dynamodb.table.topic_by_webhook = box_webhook_sns 2 | box.clientId = @box.clientId@ 3 | box.clientSecret = @box.clientSecret@ 4 | box.publicKeyId = @box.publicKeyId@ 5 | box.privateKeyPassword = @box.privateKeyPassword@ -------------------------------------------------------------------------------- /box-appusers-java-server-sample/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Jul 11 11:45:03 PDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip 7 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/config.properties.example: -------------------------------------------------------------------------------- 1 | boxClientId= 2 | boxClientSecret= 3 | boxEnterpriseId= 4 | boxPrivateKeyFile= 5 | boxPrivateKeyPassword= 6 | boxPublicKeyId= -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/webapp/bottom.jsp: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/webapp/bottom.jsp: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # *.pem 7 | # *.properties 8 | 9 | #intellij 10 | .idea/ 11 | target/ 12 | .gradle/ 13 | build/ 14 | *.iml 15 | 16 | # Package Files # 17 | *.jar 18 | *.war 19 | *.ear 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | 24 | !*.properties 25 | gradle.properties -------------------------------------------------------------------------------- /box-webhook-aws-sample/config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 10 | 12 | 13 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/config/checkstyle/suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 10 | 12 | 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # do not publish credentials 7 | *.pem 8 | *.properties 9 | 10 | !gradle-wrapper.properties 11 | 12 | #intellij 13 | .idea/ 14 | target/ 15 | .gradle/ 16 | build/ 17 | *.iml 18 | 19 | # Eclipse 20 | .project 21 | 22 | # Package Files # 23 | *.jar 24 | 25 | !gradle-wrapper.jar 26 | 27 | *.war 28 | *.ear 29 | 30 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 31 | hs_err_pid* 32 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'java' 2 | apply plugin: 'maven' 3 | apply plugin: 'war' 4 | apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin' 5 | 6 | group = 'com.box' 7 | archivesBaseName = 'java-sdk.example' 8 | version = '0.1-SNAPSHOT' 9 | repositories { 10 | mavenCentral() 11 | } 12 | 13 | dependencies { 14 | compile 'javax.servlet:javax.servlet-api:3.0.1' 15 | compile 'com.box:box-java-sdk:2.1.0' 16 | compile 'com.mashape.unirest:unirest-java:1.4.5' 17 | } 18 | gretty { 19 | contextPath = '/' 20 | host="localhost" 21 | } 22 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/java/com/box/samples/aws/sns/utils/StringUtils.java: -------------------------------------------------------------------------------- 1 | package com.box.samples.aws.sns.utils; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | /** 6 | * {@link String} related utilities. 7 | */ 8 | public class StringUtils { 9 | 10 | /** 11 | * UTF_8 {@link Charset}. 12 | */ 13 | public static final Charset UTF_8 = Charset.forName("UTF-8"); 14 | 15 | /** 16 | * Only static members. 17 | */ 18 | protected StringUtils() { 19 | } 20 | 21 | /** 22 | * @param value 23 | * for check 24 | * @return true if a provided value is blank 25 | */ 26 | public static boolean isBlank(String value) { 27 | return value == null || value.trim().isEmpty(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/java/com/box/samples/aws/sns/utils/ExceptionUtils.java: -------------------------------------------------------------------------------- 1 | package com.box.samples.aws.sns.utils; 2 | 3 | import java.io.PrintWriter; 4 | import java.io.StringWriter; 5 | 6 | /** 7 | * {@link Exception} related utilities. 8 | */ 9 | public class ExceptionUtils { 10 | 11 | /** 12 | * Only static members. 13 | */ 14 | protected ExceptionUtils() { 15 | } 16 | 17 | /** 18 | * @param e 19 | * for transformation 20 | * @return builds stack trace for a provided {@link Exception}. 21 | */ 22 | public static String stackTrace(Exception e) { 23 | StringWriter result = new StringWriter(); 24 | PrintWriter writer = new PrintWriter(result); 25 | e.printStackTrace(writer); 26 | writer.close(); 27 | return result.toString(); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/java/com/box/samples/aws/sns/utils/FileUtils.java: -------------------------------------------------------------------------------- 1 | package com.box.samples.aws.sns.utils; 2 | 3 | /** 4 | * {@link java.io.File} related utilities. 5 | */ 6 | public class FileUtils { 7 | 8 | /** 9 | * Only static members. 10 | */ 11 | protected FileUtils() { 12 | } 13 | 14 | /** 15 | * Builds human readable size. 16 | * 17 | * @param size 18 | * in bytes 19 | * @return human readable size 20 | */ 21 | public static String humanReadableSize(long size) { 22 | int unit = 1024; 23 | if (size < unit) { 24 | return size + " B"; 25 | } 26 | int exp = (int) (Math.log(size) / Math.log(unit)); 27 | String pre = "KMGTPE".charAt(exp - 1) + "i"; 28 | return String.format("%.1f %sB", size / Math.pow(unit, exp), pre); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if ( request.getAttribute("error") != null ) { %> 4 | <%-- TODO Escape and encode ${param.error} properly. It can be done using jstl c:out. --%> 5 | ${error} 6 | <% } %> 7 |

${connectMessage}

8 | 9 | 19 | 20 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/webapp/login.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if ( request.getAttribute("error") != null ) { %> 4 | <%-- TODO Escape and encode ${param.error} properly. It can be done using jstl c:out. --%> 5 | ${error} 6 | <% } %> 7 |

${connectMessage}

8 | 9 | 19 | 20 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 3 | aws 4 | 5 | zip 6 | 7 | 8 | 9 | 10 | 11 | lib 12 | 0755 13 | 14 | **/* 15 | 16 | 17 | 18 | 19 | 20 | true 21 | lib 22 | 0644 23 | 0755 24 | runtime 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/java/com/box/samples/aws/sns/validation/ValidationException.java: -------------------------------------------------------------------------------- 1 | package com.box.samples.aws.sns.validation; 2 | 3 | /** 4 | * Exception wrapper for {@link Validation}. 5 | * 6 | * @see Validation#validate() 7 | */ 8 | public class ValidationException extends RuntimeException { 9 | 10 | /** 11 | * Serialization value. 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | 15 | /** 16 | * @see #getValidation() 17 | */ 18 | private final Validation validation; 19 | 20 | /** 21 | * Constructor. 22 | * 23 | * @param validation 24 | * {@link #getValidation()} 25 | */ 26 | public ValidationException(Validation validation) { 27 | this.validation = validation; 28 | } 29 | 30 | /** 31 | * @return wrapped {@link Validation} 32 | */ 33 | public Validation getValidation() { 34 | return this.validation; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/java/com/box/samples/aws/sns/logging/LambdaLoggerSlf4jLoggerFactory.java: -------------------------------------------------------------------------------- 1 | package com.box.samples.aws.sns.logging; 2 | 3 | import org.slf4j.ILoggerFactory; 4 | import org.slf4j.Logger; 5 | import org.slf4j.event.Level; 6 | 7 | /** 8 | * {@link ILoggerFactory} for {@link LambdaLoggerSlf4j}. 9 | */ 10 | public class LambdaLoggerSlf4jLoggerFactory implements ILoggerFactory { 11 | 12 | /** 13 | * Singleton. 14 | */ 15 | public static final LambdaLoggerSlf4jLoggerFactory INSTANCE = new LambdaLoggerSlf4jLoggerFactory(); 16 | 17 | /** 18 | * @see #INSTANCE 19 | */ 20 | protected LambdaLoggerSlf4jLoggerFactory() { 21 | } 22 | 23 | /** 24 | * {@inheritDoc} 25 | */ 26 | @Override 27 | public Logger getLogger(String name) { 28 | Level level; 29 | if (name.startsWith("com.box.samples")) { 30 | level = Level.INFO; 31 | } else { 32 | level = Level.WARN; 33 | } 34 | return new LambdaLoggerSlf4j(level, name); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/webapp/signin.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if ( request.getParameter("error") != null ) { %> 4 | <%-- TODO Escape and encode ${param.error} properly. It can be done using jstl c:out. --%> 5 | ${param.error} 6 | <% } %> 7 | 8 |

Sign In

9 |
10 |
11 | Sign is as App User 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
User ID
Password
25 |
26 |
27 | 28 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/webapp/signin.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if ( request.getParameter("error") != null ) { %> 4 | <%-- TODO Escape and encode ${param.error} properly. It can be done using jstl c:out. --%> 5 | ${param.error} 6 | <% } %> 7 | 8 |

Sign In

9 |
10 |
11 | Sign is as App User 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |
User ID
Password
25 |
26 |
27 | 28 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 box-platform-demo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/webapp/top.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Java Servlet Template 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 24 |
25 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/webapp/top.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Java Servlet Template 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 25 |
26 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/java/com/box/sdk/appusersexample/DownloadServlet.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.appusersexample; 2 | 3 | import java.io.IOException; 4 | import java.net.URL; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import com.box.sdk.BoxFile; 12 | import com.helpers.BoxHelper; 13 | 14 | public class DownloadServlet extends HttpServlet { 15 | @Override 16 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, 17 | IOException { 18 | response.setContentType("text/html"); 19 | String boxFileId = request.getParameter("id"); 20 | String boxAppUserId = BoxHelper.getBoxAppUserId(request); 21 | if (boxAppUserId == null) { // session timeout. force login again. 22 | request.getRequestDispatcher("login.jsp").forward(request, response); 23 | return; 24 | } 25 | URL downloadUrl; 26 | BoxFile boxFile = new BoxFile(BoxHelper.userClient(boxAppUserId), boxFileId); 27 | downloadUrl = boxFile.getDownloadURL(); 28 | response.sendRedirect(downloadUrl.toString()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/webapp/corsupload.js: -------------------------------------------------------------------------------- 1 | /** 2 | * corsupload form page 3 | */ 4 | var form = document.getElementById('file-form'); 5 | var fileSelect = document.getElementById('file-select'); 6 | var uploadButton = document.getElementById('upload-button'); 7 | form.onsubmit = function (event) 8 | { 9 | event.preventDefault(); 10 | uploadButton.innerHTML = 'Uploading...'; 11 | // The Box Auth Header. Supplied when the dashboard.jps page is rendered by the server 12 | var headers = {'Authorization': 'Bearer ' + accessToken}; 13 | var uploadUrl = 'https://upload.box.com/api/2.0/files/content'; 14 | var files = fileSelect.files; 15 | var formData = new FormData(); 16 | formData.append('files', files[0], files[0].name); 17 | // Add the destination folder for the upload to the form 18 | formData.append('parent_id', '0'); 19 | $.ajax({ 20 | url: uploadUrl, 21 | headers: headers, 22 | type: 'POST', 23 | // This prevents JQuery from trying to append the form as a querystring 24 | processData: false, 25 | contentType: false, 26 | data: formData 27 | }).complete(function (data) 28 | { 29 | uploadButton.innerHTML = 'Upload'; 30 | console.log(data.responseText); 31 | location.reload(true); 32 | }); 33 | // TODO add error handling for production versions 34 | } 35 | 36 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/webapp/createuser.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if ( request.getParameter("error") != null ) { %> 4 | <%-- TODO Escape and encode ${param.error} properly. It can be done using jstl c:out. --%> 5 | ${param.error} 6 | <% } %> 7 | 8 |

Create New App User

9 |
10 |
11 | Create App User 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Create App User
Password
Retype Password
29 |
30 |
31 | 32 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/java/org/slf4j/impl/StaticLoggerBinder.java: -------------------------------------------------------------------------------- 1 | package org.slf4j.impl; 2 | 3 | import org.slf4j.ILoggerFactory; 4 | import org.slf4j.spi.LoggerFactoryBinder; 5 | 6 | import com.box.samples.aws.sns.logging.LambdaLoggerSlf4jLoggerFactory; 7 | 8 | /** 9 | * {@link LoggerFactoryBinder} for {@link LambdaLoggerSlf4jLoggerFactory}. 10 | */ 11 | public final class StaticLoggerBinder implements LoggerFactoryBinder { 12 | 13 | /** 14 | * Singleton. 15 | */ 16 | private static final StaticLoggerBinder INSTANCE = new StaticLoggerBinder(); 17 | 18 | /** 19 | * @see #INSTANCE 20 | */ 21 | private StaticLoggerBinder() { 22 | } 23 | 24 | /** 25 | * @return {@link LoggerFactoryBinder} implementation 26 | */ 27 | public static StaticLoggerBinder getSingleton() { 28 | return StaticLoggerBinder.INSTANCE; 29 | } 30 | 31 | /** 32 | * {@inheritDoc} 33 | */ 34 | @Override 35 | public ILoggerFactory getLoggerFactory() { 36 | return LambdaLoggerSlf4jLoggerFactory.INSTANCE; 37 | } 38 | 39 | /** 40 | * {@inheritDoc} 41 | */ 42 | @Override 43 | public String getLoggerFactoryClassStr() { 44 | return "com.box.samples.aws.sns.logging.LambdaLoggerSlf4jLoggerFactory"; 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/webapp/createuser.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if ( request.getParameter("error") != null ) { %> 4 | <%-- TODO Escape and encode ${param.error} properly. It can be done using jstl c:out. --%> 5 | ${param.error} 6 | <% } %> 7 | 8 |

Create New App User

9 |
10 |
11 | Create App User 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 |
Create App User
Password
Retype Password
29 |
30 |
31 | 32 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/java/com/box/sdk/webhookawssample/DownloadServlet.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.webhookawssample; 2 | 3 | import java.io.IOException; 4 | import java.net.URL; 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import com.box.sdk.BoxFile; 11 | import com.box.sdk.webhookawssample.helpers.BoxHelper; 12 | 13 | /** 14 | * 15 | */ 16 | public class DownloadServlet extends HttpServlet { 17 | @Override 18 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, 19 | IOException { 20 | response.setContentType("text/html"); 21 | String boxFileId = request.getParameter("id"); 22 | String boxAppUserId = BoxHelper.getBoxAppUserId(request); 23 | if (boxAppUserId == null) { // session timeout. force login again. 24 | request.getRequestDispatcher("login.jsp").forward(request, response); 25 | return; 26 | } 27 | URL downloadUrl; 28 | BoxFile boxFile = new BoxFile(BoxHelper.userClient(boxAppUserId), boxFileId); 29 | downloadUrl = boxFile.getDownloadURL(); 30 | response.sendRedirect(downloadUrl.toString()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/java/com/box/sdk/appusersexample/PreviewServlet.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.appusersexample; 2 | 3 | import java.io.IOException; 4 | import java.net.URL; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServlet; 8 | import javax.servlet.http.HttpServletRequest; 9 | import javax.servlet.http.HttpServletResponse; 10 | 11 | import com.box.sdk.BoxFile; 12 | import com.helpers.BoxHelper; 13 | import com.box.sdk.BoxAPIConnection; 14 | 15 | 16 | public class PreviewServlet extends HttpServlet { 17 | @Override 18 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, 19 | IOException { 20 | String boxFileId = request.getParameter("id"); 21 | String boxId = BoxHelper.getBoxAppUserId(request); 22 | URL previewUrl; 23 | response.setContentType("text/html"); 24 | BoxAPIConnection userClient = BoxHelper.userClient(boxId); 25 | if (userClient == null) { // session timeout. force login again. 26 | request.getRequestDispatcher("login.jsp").forward(request, response); 27 | return; 28 | } 29 | BoxFile boxFile = new BoxFile(userClient, boxFileId); 30 | previewUrl = boxFile.getPreviewLink(); 31 | response.sendRedirect(previewUrl.toString()); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/java/com/box/sdk/appusersexample/SignInServlet.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.appusersexample; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import javax.servlet.http.HttpSession; 10 | 11 | import com.helpers.BoxHelper; 12 | 13 | public class SignInServlet extends HttpServlet { 14 | 15 | public void doPost(HttpServletRequest request, HttpServletResponse response) 16 | throws ServletException, IOException { 17 | response.setContentType("text/html"); 18 | BoxHelper.setBoxAppUserName(request, request.getParameter("username")); 19 | BoxHelper.setBoxAppUserId(request, null); 20 | String boxId = BoxHelper.boxIdFromRequest(request); 21 | if (boxId != null) { 22 | BoxHelper.setBoxAppUserId(request, boxId); 23 | response.sendRedirect("dashboard"); 24 | } else { 25 | request.setAttribute("error", "Could not find an App user with that name. "); 26 | request.getRequestDispatcher("login.jsp").forward(request, response); 27 | // response.sendRedirect("login"); 28 | } 29 | 30 | // request.getRequestDispatcher("dashboard.jsp").forward(request, response); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/java/com/box/sdk/webhookawssample/PreviewServlet.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.webhookawssample; 2 | 3 | import java.io.IOException; 4 | import java.net.URL; 5 | import javax.servlet.ServletException; 6 | import javax.servlet.http.HttpServlet; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | 10 | import com.box.sdk.BoxAPIConnection; 11 | import com.box.sdk.BoxFile; 12 | import com.box.sdk.webhookawssample.helpers.BoxHelper; 13 | 14 | /** 15 | * 16 | */ 17 | public class PreviewServlet extends HttpServlet { 18 | @Override 19 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, 20 | IOException { 21 | String boxFileId = request.getParameter("id"); 22 | String boxId = BoxHelper.getBoxAppUserId(request); 23 | URL previewUrl; 24 | response.setContentType("text/html"); 25 | BoxAPIConnection userClient = BoxHelper.userClient(boxId); 26 | if (userClient == null) { // session timeout. force login again. 27 | request.getRequestDispatcher("login.jsp").forward(request, response); 28 | return; 29 | } 30 | BoxFile boxFile = new BoxFile(userClient, boxFileId); 31 | previewUrl = boxFile.getPreviewLink(); 32 | response.sendRedirect(previewUrl.toString()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-sns/src/main/java/com/box/samples/aws/sns/utils/ValidationUtils.java: -------------------------------------------------------------------------------- 1 | package com.box.samples.aws.sns.utils; 2 | 3 | import com.box.samples.aws.sns.validation.Validation; 4 | 5 | /** 6 | * {@link Validation} related utilities. 7 | */ 8 | public class ValidationUtils { 9 | 10 | /** 11 | * Only static members. 12 | */ 13 | protected ValidationUtils() { 14 | } 15 | 16 | /** 17 | * Check that a provided value is not null. 18 | * 19 | * @param validation 20 | * context 21 | * @param path 22 | * to the value 23 | * @param value 24 | * for check 25 | */ 26 | public static void notNull(Validation validation, String path, Object value) { 27 | if (value == null) { 28 | validation.addError(path, "must_not_be_null"); 29 | } 30 | } 31 | 32 | /** 33 | * Checks that a provided {@link String} value is not blank (empty or white space only). 34 | * 35 | * @param validation 36 | * context 37 | * @param path 38 | * to the value 39 | * @param value 40 | * for check 41 | */ 42 | public static void notBlank(Validation validation, String path, String value) { 43 | if (StringUtils.isBlank(value)) { 44 | validation.addError(path, "must_not_be_blank"); 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/java/com/helpers/ConfigHelper.java: -------------------------------------------------------------------------------- 1 | package com.helpers; 2 | 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.Properties; 8 | 9 | /** 10 | * 11 | */ 12 | public final class ConfigHelper { 13 | 14 | private static Object syncObject = new Object(); 15 | private static Properties properties = null; 16 | 17 | /** 18 | * Utility Classe ConfigHelper. Do not allow 19 | * default constructor to be called. 20 | */ 21 | 22 | private ConfigHelper() { 23 | 24 | } 25 | 26 | /** 27 | * @return properties a key value map 28 | */ 29 | protected static Properties properties() { 30 | synchronized (syncObject) { 31 | if (properties == null) { 32 | Properties prop = new Properties(); 33 | try { 34 | InputStream input = new FileInputStream("config.properties"); 35 | prop.load(input); 36 | input.close(); 37 | } catch (FileNotFoundException e) { 38 | e.printStackTrace(); 39 | } catch (IOException e) { 40 | e.printStackTrace(); 41 | } 42 | 43 | properties = prop; 44 | } 45 | 46 | return properties; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/webapp/corsupload.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by dmaynard on 6/21/16. 3 | */ 4 | var form = document.getElementById('file-form'); 5 | var fileSelect = document.getElementById('file-select'); 6 | var uploadButton = document.getElementById('upload-button'); 7 | form.onsubmit = function (event) 8 | { 9 | event.preventDefault(); 10 | uploadButton.innerHTML = 'Uploading...'; 11 | // The Box Auth Header. Supplied when the dashboard.jps page is rendered by the server 12 | var headers = {'Authorization': 'Bearer ' + accessToken}; 13 | var uploadUrl = 'https://upload.box.com/api/2.0/files/content'; 14 | var files = fileSelect.files; 15 | var formData = new FormData(); 16 | formData.append('files', files[0], files[0].name); 17 | // Add the destination folder for the upload to the form 18 | formData.append('parent_id', '0'); 19 | $.ajax({ 20 | url: uploadUrl, 21 | headers: headers, 22 | type: 'POST', 23 | // This prevents JQuery from trying to append the form as a querystring 24 | processData: false, 25 | contentType: false, 26 | contentType: false, 27 | data: formData 28 | }).complete(function (data) 29 | { 30 | uploadButton.innerHTML = 'Upload'; 31 | console.log(data.responseText); 32 | location.reload(true); 33 | }); 34 | // TODO add error handling for production versions 35 | } 36 | 37 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/java/com/box/sdk/webhookawssample/helpers/AWSHelper.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.webhookawssample.helpers; 2 | 3 | import java.text.MessageFormat; 4 | 5 | /** 6 | * AWS related helper methods. 7 | */ 8 | public final class AWSHelper { 9 | private static final String API_GATEWAY_URL = System.getProperty("awsAPIGatewayURL"); 10 | private static final String API_GATEWAY_REGISTER_WEBHOOK_EMAIL_TRIGGER_URL = API_GATEWAY_URL + "/sns/email"; 11 | private static final String API_GATEWAY_INVOKE_WEBHOOK_EMAIL_TRIGGER_URL = API_GATEWAY_URL + "/sns/box/preview/{0}"; 12 | 13 | /** 14 | * Private constructor for utility class. 15 | */ 16 | private AWSHelper() { 17 | } 18 | 19 | /** 20 | * API Gateway URL of resource to register new Webhook Email Trigger. 21 | * 22 | * @return url of the resource 23 | */ 24 | public static String getAPIGatewayRegisterWebhookEmailTriggerURL() { 25 | return API_GATEWAY_REGISTER_WEBHOOK_EMAIL_TRIGGER_URL; 26 | } 27 | 28 | /** 29 | * API Gateway URL of resource to invoke Webhook Email Trigger. 30 | * 31 | * @param webhookTriggerID id of the trigger created in AWS 32 | * @return url of the resource 33 | */ 34 | public static String getAPIGatewayInvokeWebhookEmailTriggerURL(String webhookTriggerID) { 35 | return MessageFormat.format(API_GATEWAY_INVOKE_WEBHOOK_EMAIL_TRIGGER_URL, webhookTriggerID); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/java/com/box/sdk/webhookawssample/helpers/ConfigHelper.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.webhookawssample.helpers; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.Properties; 7 | 8 | /** 9 | * 10 | */ 11 | public final class ConfigHelper { 12 | 13 | private static Object syncObject = new Object(); 14 | private static Properties properties = null; 15 | 16 | /** 17 | * Utility Classe ConfigHelper. Do not allow 18 | * default constructor to be called. 19 | */ 20 | 21 | private ConfigHelper() { 22 | 23 | } 24 | 25 | /** 26 | * @return properties a key value map 27 | */ 28 | protected static Properties properties() { 29 | synchronized (syncObject) { 30 | if (properties == null) { 31 | Properties prop = new Properties(); 32 | try { 33 | InputStream input = ConfigHelper.class.getResourceAsStream("/config.properties"); 34 | prop.load(input); 35 | input.close(); 36 | } catch (FileNotFoundException e) { 37 | e.printStackTrace(); 38 | } catch (IOException e) { 39 | e.printStackTrace(); 40 | } 41 | 42 | properties = prop; 43 | } 44 | 45 | return properties; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Box Java SDK Samples 2 | ==================== 3 | 4 | box-appusers-java-sample 5 | ------------------------ 6 | 7 | A sample Java Servlet application that can create and utilize Box App User accounts. 8 | Functionality includes App User creation, file upload and download, file preview and basic file navigation. 9 | 10 | box-webhook-aws-sample 11 | ---------------------- 12 | 13 | A sample Java Servlet application that can create and utilize Box App User accounts. 14 | Functionality includes App User creation, file upload and download, file preview, basic file navigation, 15 | and the ability to create a webhook which allows the user to specify and email address to be 16 | notified whenever the given file is previewed. 17 | 18 | Ths sample uses Amazon AWS services and Box Webhooks V2 to enable these notifications. 19 | 20 | 21 | Copyright and License 22 | --------------------- 23 | 24 | Copyright 2015 Box, Inc. All rights reserved. 25 | 26 | Licensed under the Apache License, Version 2.0 (the "License"); 27 | you may not use this file except in compliance with the License. 28 | You may obtain a copy of the License at 29 | 30 | http://www.apache.org/licenses/LICENSE-2.0 31 | 32 | Unless required by applicable law or agreed to in writing, software 33 | distributed under the License is distributed on an "AS IS" BASIS, 34 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 35 | See the License for the specific language governing permissions and 36 | limitations under the License. 37 | -------------------------------------------------------------------------------- /box-webhook-aws-sample/box-webhook-aws-webapp/src/main/java/com/box/sdk/webhookawssample/SignInServlet.java: -------------------------------------------------------------------------------- 1 | package com.box.sdk.webhookawssample; 2 | 3 | import java.io.IOException; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.http.HttpServlet; 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | 9 | import com.box.sdk.webhookawssample.helpers.BoxHelper; 10 | 11 | /** 12 | * 13 | */ 14 | public class SignInServlet extends HttpServlet { 15 | 16 | @Override 17 | public void doPost(HttpServletRequest request, HttpServletResponse response) 18 | throws ServletException, IOException { 19 | response.setContentType("text/html"); 20 | BoxHelper.setBoxAppUserName(request, request.getParameter("username")); 21 | BoxHelper.setBoxAppUserId(request, null); 22 | String boxId = BoxHelper.boxIdFromRequest(request); 23 | if (boxId != null) { 24 | BoxHelper.setBoxAppUserId(request, boxId); 25 | response.sendRedirect("dashboard"); 26 | } else { 27 | request.setAttribute("error", "Could not find an App user with this name: " 28 | + request.getParameter("username")); 29 | request.getRequestDispatcher("login.jsp").forward(request, response); 30 | // response.sendRedirect("login"); 31 | } 32 | 33 | // request.getRequestDispatcher("dashboard.jsp").forward(request, response); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /box-appusers-java-server-sample/src/main/webapp/dashboard.jsp: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if (request.getParameter("error") != null) { %> 4 | <%-- TODO Escape and encode ${param.error} properly. It can be done using jstl c:out. --%> 5 | ${param.error} 6 | <% } %> 7 | 8 |

Your Dashboard

9 |

${dashboardMessage}

10 |
11 | 12 | <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 13 | 14 |

Folders

15 | 16 |

${folder.getName()}

17 |
18 | 19 |

Files

20 | 21 |
22 | 23 |
24 |
25 | 26 |
27 |

Upload File using CORS

28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 | 38 |
39 |
40 |
41 |
42 | 43 | 44 | 43 | 44 |