Apr 26, 2018

Springboot: Running Application on Https with Java keystore

Consider Source code available on my git repository https://github.com/mitanjos/sping4hibernate5.git. If I run this application with default profile, it will run on http port 8000

and can be accessed as url http://localhost:8000/api/v1/category

Now we want to ensure that this port is exposed as https service and will require client to have appropriate keystore to trust response sent by our service.

So first we generate keystore using java keygen tool as follows.

Run command

keytool -genkeypair -alias selfsignedcert -keypass password -keystore myapi.keystore -storepass password -validity 180

and provide required details as prompted.

For the sake of simplicity I have added generated file in resources.

Now we want to add this file in our server configuration. To achieve that you need to set following properties in spring boot startup configuration.

server.ssl.key-store = classpath:myapi.keystore
server.ssl.key-store-password = password
server.ssl.key-password = password

So we create a separate file (to dynamically chose between normal run and running application under https with keystore we have just created). Refer application-secure.properties here in the repository.

Now we run the same application with parameter -Dspring.profiles.active=secure so that system will pickup application-secure.properties and start listening to port 8443 on https protocol.

Now if you try to curl it normally it will give error as ssl handshake will fail.

In the next blog we will configure this keystore with Feign client to access this REST endpoint.

Apr 23, 2018

Maven configuration for Jenkins

Go to Jenkins home at http://localhost:8080/ and in right menu click on "Manage Jenkins" then click on "Global Tool Configuration"

Go to Maven section and click on "Maven Installation"

Select checkbox "Install Automatically"
Select option "Install from Apache"
Click on "Add Maven"

101 of Jenkins on Mac OS: First Job setup

Once we have completed Jenkins Installation on local machine as explained in previous blog. Go to http://localhost:8080/ and if no jobs are configured it will show you screen as follows.

Click on "Create New Job" --> Provide name for this Job and select type of project as "Free Project" and click on "Ok"

On next screen do as following

Under General tab provide description.
In "Source Code Management" select "Git" and provide "Repository URL" (here I have used my git project available at url https://github.com/mitanjos/sping4hibernate5.git (this is a SpringBoot project with H2 database and Maven as build tool) and branch as master.
Not selected any trigger for basic project.

Under build section select "Invoke top-level Maven targets"

Select Maven version and provide maven task to be executed.
If you do not have any option in dropdown and you want to create new configuration follow steps as explained here.

Once that is done click on "Save" button and it will create your first job.

Next click on "Build Now" to run a new build for this project and it will schedule a first build for this project. Click on the build number (in this case #1 and on the next page click on "Console output" and will show you build logs.

If you click on "Jenkins" icon (Home) it will show you "Dashboard" of all your projects (here only one project and only first build"

Thats all for this step.

Apr 17, 2018

BrainTree Integration with REST services

First Create your account on BrainTree sandbox.
Will send you an activation email --> Click on the activation link and activate your account.
Notedown following important information

  • merchantid
  • public key
  • private key
And configure in your project. In my case I have configured them as environment variable. In production ensure its encrypted.

Add following dependency in your project

Create a controller class

And a service class

List of nonce are available here

Perform few transactions like following

On Braintree Transaction Summary page you can see these transactions reflected.

Or you can check transactions

Apr 11, 2018

101 of Jenkins on Mac OS: Setup

Environment Setup

  • Downloaded Jenkins for MacOS
  • Command to Start Jenkins: sudo launchctl load /Library/LaunchDaemons/org.jenkins-ci.plist
  • Jenkins installation directory is /Users/Shared/Jenkins/
  • Note that to get the admin password you need to use sudo su
  • Initial Admin password is at /Users/Shared/Jenkins/Home/secrets/initialAdminPassword
  • Now hit the url http://localhost:8080/ and it will ask for initial admin password.  Provide initial password.  Will provide options to chose from
  • Once required plugins are installed it will show screen to create first admin user. Provide required details to create admin user

Next: Create your first Job