From 8eca3006606de766c5eb54eef0c96277534a14dc Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Mon, 6 Apr 2020 16:49:07 -0500 Subject: [PATCH 01/11] Code Exchange Upgrade --- .github/workflows/maven.yml | 30 ++++++++ .gitignore | 6 +- .mergify.yml | 13 ++++ CODE_OF_CONDUCT.md | 73 +++++++++++++++++++ CONTRIBUTING.md | 3 + LICENSE | 7 +- README.md | 5 ++ bin | 1 + pom.xml | 10 +-- .../servlets/VerifyServlet.java | 2 +- 10 files changed, 139 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/maven.yml create mode 100644 .mergify.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 160000 bin diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..75403ca --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,30 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Java + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11.0 + - name: Build with Maven + run: mvn compile + - name: Test + run: mvn clean test + env: + TWILIO_ACCOUNT_SID: ACXXXXXXXX + TWILIO_AUTH_TOKEN: xxxxxxxxxx + VERIFICATION_SID: VAxxxxxxxx diff --git a/.gitignore b/.gitignore index 1569efb..e669b56 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,8 @@ target/* .env -*.sqlite \ No newline at end of file +*.sqlite + +.classpath +.project +.settings diff --git a/.mergify.yml b/.mergify.yml new file mode 100644 index 0000000..0433495 --- /dev/null +++ b/.mergify.yml @@ -0,0 +1,13 @@ +pull_request_rules: + - name: automatic merge for Dependabot pull requests + conditions: + - author=dependabot-preview[bot] + - status-success=build (macos-latest, 10) + - status-success=build (macos-latest, 12) + - status-success=build (windows-latest, 10) + - status-success=build (windows-latest, 12) + - status-success=build (ubuntu-latest, 10) + - status-success=build (ubuntu-latest, 12) + actions: + merge: + method: squash diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..2f0727e --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,73 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +- Using welcoming and inclusive language +- Being respectful of differing viewpoints and experiences +- Gracefully accepting constructive criticism +- Focusing on what is best for the community +- Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +- The use of sexualized language or imagery and unwelcome sexual attention or + advances +- Trolling, insulting/derogatory comments, and personal or political attacks +- Public or private harassment +- Publishing others' private information, such as a physical or electronic + address, without explicit permission +- Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at open-source@twilio.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ad3257e --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,3 @@ +# Contributing to Twilio + +All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under. diff --git a/LICENSE b/LICENSE index 225d6ce..20edada 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ -The MIT License (MIT) +MIT License -Copyright (c) 2019 Twilio Inc. +Copyright (c) 2020 Twilio Labs Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,5 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 528df73..5337998 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ + + Twilio + + > We are currently in the process of updating this sample template. If you are encountering any issues with the sample, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues) and we'll try to help you. +![](https://github.com/TwilioDevEd/verify-v2-quickstart-java/workflows/Java/badge.svg) This application example demonstrates how to Simple phone verification with Java, Servlets, and Twilio Verify. diff --git a/bin b/bin new file mode 160000 index 0000000..3266d82 --- /dev/null +++ b/bin @@ -0,0 +1 @@ +Subproject commit 3266d82a564453c88d8c4763502622cbb1e4c610 diff --git a/pom.xml b/pom.xml index 71275c9..852de7d 100644 --- a/pom.xml +++ b/pom.xml @@ -18,17 +18,17 @@ org.xerial sqlite-jdbc - 3.27.2.1 + 3.30.1 org.eclipse.persistence org.eclipse.persistence.jpa - 2.7.4 + 2.7.6 junit junit - 4.12 + 4.13 test @@ -39,7 +39,7 @@ com.twilio.sdk twilio - 7.37.4 + 7.49.0 org.mindrot @@ -49,7 +49,7 @@ org.mockito mockito-all - 1.10.19 + 2.0.0-beta test diff --git a/src/main/java/com/twilio/verify_quickstart/servlets/VerifyServlet.java b/src/main/java/com/twilio/verify_quickstart/servlets/VerifyServlet.java index 1297d79..fd2aa70 100644 --- a/src/main/java/com/twilio/verify_quickstart/servlets/VerifyServlet.java +++ b/src/main/java/com/twilio/verify_quickstart/servlets/VerifyServlet.java @@ -42,7 +42,7 @@ protected void doPost(HttpServletRequest request, userService.update(user); response.sendRedirect("/"); } else { - request.setAttribute("message",result.getErrors()); + request.setAttribute("message",result.getErrors().toString()); request.getRequestDispatcher("/verify.jsp").forward(request, response); } } From 8aae6c40372e0d259a0945767d2e5c944044105d Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Mon, 20 Apr 2020 13:53:13 -0500 Subject: [PATCH 02/11] Update License --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 20edada..2c3cf9d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Twilio Labs +Copyright (c) 2020 Twilio Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 4ec14de868db2cbc7b63000b176cec62ce75182f Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Wed, 20 May 2020 14:43:44 -0500 Subject: [PATCH 03/11] Add makefile and update readme template --- .github/workflows/maven.yml | 4 +- .gitignore | 1 + Makefile | 7 ++ README.md | 129 ++++++++++++++++++++++++++---------- bin | 1 - 5 files changed, 104 insertions(+), 38 deletions(-) create mode 100644 Makefile delete mode 160000 bin diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 75403ca..d6df08b 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -5,9 +5,9 @@ name: Java on: push: - branches: [ master ] + branches: [ master, next ] pull_request: - branches: [ master ] + branches: [ master, next ] jobs: build: diff --git a/.gitignore b/.gitignore index e669b56..2da9de3 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ target/* .classpath .project .settings +bin diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..c5f44b8 --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +install: + mvn compile flyway:migrate + mvn compile + +serve: + . .env + mvn compile jetty:run diff --git a/README.md b/README.md index 5337998..7488eeb 100644 --- a/README.md +++ b/README.md @@ -1,65 +1,124 @@ - - Twilio + +Twilio -> We are currently in the process of updating this sample template. If you are encountering any issues with the sample, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues) and we'll try to help you. +# Twilio Verify Quickstart with Java servlets ![](https://github.com/TwilioDevEd/verify-v2-quickstart-java/workflows/Java/badge.svg) +> We are currently in the process of updating this sample template. If you are encountering any issues with the sample, please open an issue at [github.com/twilio-labs/code-exchange/issues](https://github.com/twilio-labs/code-exchange/issues) and we'll try to help you. + +## About + This application example demonstrates how to Simple phone verification with Java, Servlets, and Twilio Verify. -## Local Development +Implementations in other languages: + +| .NET | Python | Ruby | PHP | Node | +| :--- | :--- | :----- | :-- | :--- | +| [Done](https://github.com/TwilioDevEd/verify-v2-quickstart-csharp) | [Done](https://github.com/TwilioDevEd/verify-v2-quickstart-python) | [Done](https://github.com/TwilioDevEd/verify-v2-quickstart-rails) | [Done](https://github.com/TwilioDevEd/verify-v2-quickstart-php) | [Done](https://github.com/TwilioDevEd/verify-v2-quickstart-node) | + + + +## Set up + +### Requirements -1. First clone this repository and `cd`into it. +- [Java Development Kit](https://adoptopenjdk.net/) version 11 or later. +- A Twilio account - [sign up](https://www.twilio.com/try-twilio) - ```bash - $ git clone git@github.com:TwilioDevEd/verify-v2-quickstart-java.git - $ cd verify-v2-quickstart-java - ``` +### Twilio Account Settings -1. Copy the sample configuration file and edit it to match your configuration. +This application should give you a ready-made starting point for writing your +own appointment reminder application. Before we begin, we need to collect +all the config values we need to run the application: + +| Config Value | Description | +| :---------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Account Sid | Your primary Twilio account identifier - find this [in the Console](https://www.twilio.com/console). | +| Auth Token | Used to authenticate - [just like the above, you'll find this here](https://www.twilio.com/console). | +| Verification Sid | For Verification Service SID. You can generate one [here](https://www.twilio.com/console/verify/services) | + +### Local development + +After the above requirements have been met: + +1. Clone this repository and `cd` into it ```bash - $ cp .env.example .env + git clone git@github.com:TwilioDevEd/verify-v2-quickstart-java.git + cd verify-v2-quickstart-java ``` - You'll need to set your `TWILIO_ACCOUNT_SID` and `TWILIO_AUTH_TOKEN` from the - [Twilio Console](https://www.twilio.com/console). Also create a new verification - service [here](https://www.twilio.com/console/verify/services) and set the - service `VERIFICATION_SID` in your `.env`. - - Once you have populated all the values, load the variables with `source`. +2. Set your environment variables ```bash - $ source .env + cp .env.example .env ``` + See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables. - _If you are using a different operating system, make sure that all the variables - from the `.env` file are loaded into your environment._ + If you are using a UNIX operating system, when the application starts the environment variables will be loaded. _If you are using a different operating system, make sure that all the + variables from the `.env` file are loaded into your environment._ -1. Execute the migrations. +3. Build the project - ```bash - $ mvn compile flyway:migrate - ``` + ```bash + make install + ``` + **NOTE:** Running the build task will also run the tests -1. Run the application. - ```bash - $ mvn compile jetty:run - ``` +4. Run the application -1. Check it out at [http://localhost:8080/](http://localhost:8080/) + ```bash + make serve + ``` + **NOTE:** If you are using a dedicated Java IDE like Eclipse or IntelliJ, you can start the application within the IDE and it will start in development mode, which means any changes on a source file will be automatically reloaded. +5. Navigate to [http://localhost:8080](http://localhost:8080) -## Run the tests +That's it! -``` +### Tests + +You can run the tests locally by typing: + +```bash mvn clean test ``` -## Meta +### Cloud deployment + +Additionally to trying out this application locally, you can deploy it to a variety of host services. Here is a small selection of them. + +Please be aware that some of these might charge you for the usage or might make the source code for this application visible to the public. When in doubt research the respective hosting service first. + +| Service | | +| :-------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [Heroku](https://www.heroku.com/) | [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/TwilioDevEd/verify-v2-quickstart-java/tree/master) | + +**Some notes:** +- For Heroku, please [check this](https://devcenter.heroku.com/articles/deploying-gradle-apps-on-heroku) to properly configure the project for deployment. +- You can also follow [this guide](https://vaadin.com/blog/how-to-deploy-your-java-app-to-the-cloud) to deploy the application to several other cloud services including Google Cloud, Oracle Cloud, etc. + +## Resources + +- The CodeExchange repository can be found [here](https://github.com/twilio-labs/code-exchange/). + +## Contributing + +This template is open source and welcomes contributions. All contributions are subject to our [Code of Conduct](https://github.com/twilio-labs/.github/blob/master/CODE_OF_CONDUCT.md). + +## License + +[MIT](http://www.opensource.org/licenses/mit-license.html) + +## Disclaimer + +No warranty expressed or implied. Software is as is. -* No warranty expressed or implied. Software is as is. Diggity. -* [MIT License](http://www.opensource.org/licenses/mit-license.html) -* Lovingly crafted by Twilio Developer Education. +[twilio]: https://www.twilio.com diff --git a/bin b/bin deleted file mode 160000 index 3266d82..0000000 --- a/bin +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3266d82a564453c88d8c4763502622cbb1e4c610 From f48263261ad49582affce4bc64ee0d43362cc03b Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Fri, 29 May 2020 10:59:11 -0500 Subject: [PATCH 04/11] Update Makefile --- Makefile | 1 - README.md | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index c5f44b8..2ce93c7 100644 --- a/Makefile +++ b/Makefile @@ -3,5 +3,4 @@ install: mvn compile serve: - . .env mvn compile jetty:run diff --git a/README.md b/README.md index 7488eeb..8ae9188 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,13 @@ After the above requirements have been met: ``` See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables. - If you are using a UNIX operating system, when the application starts the environment variables will be loaded. _If you are using a different operating system, make sure that all the - variables from the `.env` file are loaded into your environment._ + If you are using a UNIX operating system, load the environment variables before the application starts. + + ```bash + source .env + ``` + + _If you are using a different operating system, make sure that all the variables from the `.env` file are loaded into your environment._ 3. Build the project From 5475454ac3503f99bcb7d9e0d66073b30edca9c6 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Wed, 10 Jun 2020 14:43:16 -0500 Subject: [PATCH 05/11] Add Docker --- .dockerignore | 5 +++++ Dockerfile | 15 +++++++++++++++ README.md | 8 ++++++++ docker-compose.yml | 12 ++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0705b0d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +bin/ +build/ +*.db +*.sqlite +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..923dd05 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM maven:3-openjdk-11 + +WORKDIR /usr/app/ + +RUN apt-get update && \ + apt-get upgrade -y && \ + apt-get install -y build-essential + +COPY . . + +RUN make install + +EXPOSE 8080 + +CMD ["make", "serve"] diff --git a/README.md b/README.md index 8ae9188..1e316ef 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,14 @@ After the above requirements have been met: That's it! +### Docker + +If you have [Docker](https://www.docker.com/) already installed on your machine, you can use our `docker-compose.yml` to setup your project. + +1. Make sure you have the project cloned. +2. Setup the environmental variables in the `docker-compose.yml` file, see the [Twilio Account Settings](#twilio-account-settings). +3. Run `docker-compose --env-file /dev/null up`. + ### Tests You can run the tests locally by typing: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..918f206 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.6" +services: + app: + stdin_open: true + tty: true + environment: + - TWILIO_ACCOUNT_SID=your_account_sid + - TWILIO_AUTH_TOKEN=your_account_token + - VERIFICATION_SID=VAXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + build: . + ports: + - "8080:8080" From cb57252e5c5b2ab7e836e513fd52b163f0d6baa4 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Wed, 17 Jun 2020 08:48:39 -0500 Subject: [PATCH 06/11] Update CI --- .github/workflows/maven.yml | 6 +++++- .mergify.yml | 9 +++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index d6df08b..7e24935 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -12,7 +12,11 @@ on: jobs: build: - runs-on: ubuntu-latest + runs-on: ${{ matrix.platform }} + strategy: + max-parallel: 3 + matrix: + platform: [windows-latest, macos-latest, ubuntu-latest] steps: - uses: actions/checkout@v2 diff --git a/.mergify.yml b/.mergify.yml index 0433495..91278e5 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -2,12 +2,9 @@ pull_request_rules: - name: automatic merge for Dependabot pull requests conditions: - author=dependabot-preview[bot] - - status-success=build (macos-latest, 10) - - status-success=build (macos-latest, 12) - - status-success=build (windows-latest, 10) - - status-success=build (windows-latest, 12) - - status-success=build (ubuntu-latest, 10) - - status-success=build (ubuntu-latest, 12) + - status-success=build (macos-latest) + - status-success=build (windows-latest) + - status-success=build (ubuntu-latest) actions: merge: method: squash From 95bd5a08d073f11e8aa9bdc16cc2cadb3310d316 Mon Sep 17 00:00:00 2001 From: Carlos Villavicencio Date: Mon, 22 Jun 2020 10:51:17 -0500 Subject: [PATCH 07/11] Update Makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 2ce93c7..e60c802 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +.PHONY: install serve + install: mvn compile flyway:migrate mvn compile From 42e1032d4203e0e8d92355962cb52f058a08daef Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 10:09:48 -0500 Subject: [PATCH 08/11] [DEVEDSB-98] Add custom error view and dotenv configuration --- .env.example | 6 +++--- pom.xml | 5 +++++ .../verify_quickstart/services/TwilioVerification.java | 10 ++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 005eff8..5251402 100644 --- a/.env.example +++ b/.env.example @@ -1,8 +1,8 @@ # Twilio API credentials # (find here https://www.twilio.com/console) -export TWILIO_ACCOUNT_SID= -export TWILIO_AUTH_TOKEN= +TWILIO_ACCOUNT_SID= +TWILIO_AUTH_TOKEN= # Verification Service SID # (create one here https://www.twilio.com/console/verify/services) -export VERIFICATION_SID= +VERIFICATION_SID= diff --git a/pom.xml b/pom.xml index 852de7d..6a4959a 100644 --- a/pom.xml +++ b/pom.xml @@ -52,6 +52,11 @@ 2.0.0-beta test + + io.github.cdimascio + dotenv-java + 2.2.0 + diff --git a/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java b/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java index fcab0be..98d1fbf 100644 --- a/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java +++ b/src/main/java/com/twilio/verify_quickstart/services/TwilioVerification.java @@ -4,12 +4,14 @@ import com.twilio.exception.ApiException; import com.twilio.rest.verify.v2.service.Verification; import com.twilio.rest.verify.v2.service.VerificationCheck; +import io.github.cdimascio.dotenv.Dotenv; -public class TwilioVerification implements VerificationService { - private static final String ACCOUNT_SID = System.getenv("TWILIO_ACCOUNT_SID"); - private static final String AUTH_TOKEN = System.getenv("TWILIO_AUTH_TOKEN"); - private static final String VERIFICATION_SID = System.getenv("VERIFICATION_SID"); +public class TwilioVerification implements VerificationService { + private static Dotenv env = Dotenv.configure().ignoreIfMissing().load(); + private static final String ACCOUNT_SID = env.get("TWILIO_ACCOUNT_SID"); + private static final String AUTH_TOKEN = env.get("TWILIO_AUTH_TOKEN"); + private static final String VERIFICATION_SID = env.get("VERIFICATION_SID"); public TwilioVerification() { Twilio.init(ACCOUNT_SID, AUTH_TOKEN); From f1ff8c77052b8b00b6670d7f4e61dcae4e1423b6 Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 13:06:40 -0500 Subject: [PATCH 09/11] [DEVEDSB-98] Add custom error view and dotenv configuration --- .../servlets/ErrorHandler.java | 21 +++++++++++++++++ src/main/webapp/WEB-INF/web.xml | 23 +++++++++++++++++++ src/main/webapp/error.html | 9 ++++++++ 3 files changed, 53 insertions(+) create mode 100644 src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/error.html diff --git a/src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java b/src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java new file mode 100644 index 0000000..3c45cf9 --- /dev/null +++ b/src/main/java/com/twilio/verify_quickstart/servlets/ErrorHandler.java @@ -0,0 +1,21 @@ +// Import required java libraries +import java.io.*; +import javax.servlet.*; +import javax.servlet.http.*; +import java.util.*; + +// Extend HttpServlet class +public class ErrorHandler extends HttpServlet { + + // Method to handle GET method request. + public void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + request.getRequestDispatcher("/error.html").forward(request, response); + } + + // Method to handle POST method request. + public void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + doGet(request, response); + } +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..93494a6 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,23 @@ + + + ErrorHandler + ErrorHandler + + + + + ErrorHandler + /ErrorHandler + + + + 404 + /ErrorHandler + + + + java.lang.Throwable + /ErrorHandler + + \ No newline at end of file diff --git a/src/main/webapp/error.html b/src/main/webapp/error.html new file mode 100644 index 0000000..8999c95 --- /dev/null +++ b/src/main/webapp/error.html @@ -0,0 +1,9 @@ + + + + +

Something went wrong!

+

Our Engineers are on it

+ Go Home + + From 3754f7d61173c9bf12c10ba07b9a66707863e08a Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 13:07:59 -0500 Subject: [PATCH 10/11] [DEVEDSB-98] Add custom error view and dotenv configuration --- README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/README.md b/README.md index 1e316ef..25f85c3 100644 --- a/README.md +++ b/README.md @@ -62,14 +62,6 @@ After the above requirements have been met: ``` See [Twilio Account Settings](#twilio-account-settings) to locate the necessary environment variables. - If you are using a UNIX operating system, load the environment variables before the application starts. - - ```bash - source .env - ``` - - _If you are using a different operating system, make sure that all the variables from the `.env` file are loaded into your environment._ - 3. Build the project ```bash From cde6f5c51c13d446ac3711a0ee2c27b09fd6847a Mon Sep 17 00:00:00 2001 From: Alejandro Vivanco Date: Mon, 8 Nov 2021 13:08:34 -0500 Subject: [PATCH 11/11] [DEVEDSB-98] Add custom error view and dotenv configuration --- src/main/webapp/WEB-INF/web.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 93494a6..f870121 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -20,4 +20,4 @@ java.lang.Throwable /ErrorHandler - \ No newline at end of file +