How to get stored images/videos from Object Storage in IBM Bluemix

screen-shot-2016-09-06-at-9-56-25-pm

What is Object Storage?

IBM® Object Storage for Bluemix® provides you with access to a fully provisioned Swift Object Storage account to manage your data. Swift provides a fully distributed, API-accessible storage platform. You can use it directly in your applications or for backups, making it ideal for cost effective, scale-out storage.

This blog will help you to get images/videos from Cloud Data Storage(Object Storage) into your application.

Prerequisites

Below shown is the UI of Object Storage. I have 4 images & 1 video uploaded to a container named store1.

screen-shot-2016-09-06-at-10-01-03-pm

Front end of the application:

screen-shot-2016-09-06-at-10-05-31-pm

Code to get the image/video from Object Storage

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

String imgoption = request.getParameter(“imgOpt”); //Takes the user input

String envApp = System.getenv(“VCAP_APPLICATION”);

String envServices = System.getenv(“VCAP_SERVICES”);

System.out.print(envServices);

JSONParser parser = new JSONParser();

try{

Object obj = parser.parse(envServices);

JSONObject jsonObject = (JSONObject) obj;

JSONArray vcapArray = (JSONArray) jsonObject.get(“Object-Storage”);

JSONObject vcap = (JSONObject) vcapArray.get(0);

JSONObject credentials = (JSONObject) vcap.get(“credentials”);

String userId = credentials.get(“userId”).toString();

String password = credentials.get(“password”).toString();

String auth_url = credentials.get(“auth_url”).toString() + “/v3”;

String domain = credentials.get(“domainName”).toString();

String project = credentials.get(“project”).toString();

Identifier domainIdent = Identifier.byName(domain);

Identifier projectIdent = Identifier.byName(project);

OSClientos = OSFactory.builderV3()

.endpoint(auth_url)

.credentials(userId, password)

.scopeToProject(projectIdent, domainIdent)

.authenticate();

System.out.print(os);

SwiftAccount account = os.objectStorage().account().get();

ObjectStorageService objectStorage = os.objectStorage();

List<? extends SwiftContainer> containers = os.objectStorage().containers().list();

System.out.println(containers); // Prints the list of containers

List<? extends SwiftObject> objs = os.objectStorage().objects().list(“store1”);

System.out.println(obj); //Prints the list of objects inside the container store1

SwiftObject fileObj = objectStorage.objects().get(“store1”,imgoption);

System.out.println(fileObj);

String mimeType = fileObj.getMimeType();

DLPayload payload = fileObj.download();

InputStream in = payload.getInputStream();

response.setContentType(mimeType);

OutputStream out = response.getOutputStream();

IOUtils.copy(in, out);

in.close();

out.close();

}catch(Exception e){

e.printStackTrace();

}

}

Ensure that you have added the dependency to POM.XML file

  <dependencies>

  <dependency>

  <groupId>org.pacesys</groupId>

  <artifactId>openstack4j</artifactId>

  <version>3.0.0</version>

</dependency>

<dependency>

    <groupId>org.apache.directory.studio</groupId>

    <artifactId>org.apache.commons.io</artifactId>

    <version>2.4</version>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<version>3.1.0</version>

<scope>provided</scope>

</dependency>

<dependency>

    <groupId>com.googlecode.json-simple</groupId>

    <artifactId>json-simple</artifactId>

    <version>1.1</version>

</dependency>

</dependencies>



<build>

    <plugins>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-compiler-plugin</artifactId>

            <version>3.1</version>

            <configuration>

                <source>1.8</source>

                <target>1.8</target>

            </configuration>

        </plugin>

    </plugins>

  </build>

 

Please note that OpenStack4j has some of the same libraries that are also provided in the Liberty profile if you are running this Java application on Bluemix. To avoid this you should use reverse class loading or exclude jaxrs from the enabled features. 

This is a Java app which was deployed on a Node.JS runtime.

Output of the app:

Video & Image

 

Advertisements

Hashtag sentiment Analyzer using Node-RED,Cloudant, dashDB,R script

2

Twitter Node Configuration:7

Switch Node Configuration:

3

Not so positive function node configuration:

4

Positive sentiment Function Node configuration:

5

Cloudant Node Configuration:

6

Once after wiring the nodes, click on DEPLOY ( top right corner of Node-RED).

Launch Cloudant and then you will find your database in the list

8

Create a dashDB warehouse to graphically analyze the sentiment

9

Goto dashDB and then run R script

10

Rscript.PNG

Data has been graphically analyzed using R Scripts.

1

1 represents Positive sentiment and 0 represents not-so-Positive sentiment

 

Web app using Java & Cloudant NoSQLDatabase in IBM Bluemix

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them.

IBM® Cloudant® NoSQL Database for Bluemix® is a NoSQL database as a service (DBaaS). It’s built from the ground up to scale globally, run non-stop, and handle a wide variety of data types like JSON, full-text, and geospatial. Cloudant NoSQL DB is an operational data store optimized to handle concurrent reads and writes, and provide high availability and data durability.

This tutorial will help you to build and deploy a java application that inserts registration details to Cloudant NoSQLDB

Prerequisites

Let’s start building the java application,before that lets go to our Bluemix Catalog and select required services to build it!

Step 1: Goto Catalog and then click on Java Runtime

blog_2

Step 2: Enter your application name. Eg: samplecloudant as shown in the image below. Click on CREATE

Step 3: Application has been created and it can be viewed on the Bluemix DASHBOARD. Click on the application

Step 4: Click on ADD SERVICE in the application(samplecloudant) DASHBOARD

Step 5: In CATALOG goto Data and Analytics and click on Cloudant NoSQL DB

Step 6: Change the Service name of Cloudant NoSQL DB to myCloudant and click on CREATE.

The service is now up and running in Bluemix! We can now proceed to Eclipse IDE to build the registration application that inserts details into Cloudant NoSQL Database.

We will be creating this web application using a Maven project in Eclipse(it is the easiest way to retrieve the dependencies we need — the ektorp client jars).

Step 7: Open Eclipse and create a new Maven project

Set the following values

  • Group ID: com.register
  • Artifact ID: registerblue
  • Version: 1
  • Packaging: war
  • Leave everything else as-is and Click Finish

 

 

Copy dependencies into pom.xml inside <project>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ektorp</groupId>
<artifactId>org.ektorp</artifactId>
<version>1.4.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

Create a servlet

  • Click on registerblue>src>main>java
  • Right click on register folder and then New > (Other) > Web > Servlet
  • Keep class name as RegisterServlet & package name as com and then click on Finish

In web.xml

<servlet>
<display-name>RegisterServlet</display-name>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>com.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/RegisterServlet</url-pattern>
</servlet-mapping>

In RegisterServlet.java ( Resource Injection)

@Resource(name = “couchdb/myCloudant”)
protected CouchDbInstance mydb ;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

response.setContentType(“text/html”);
response.sendRedirect(request.getContextPath() + “/success.jsp”);

String name=request.getParameter(“name”);
String emailid = request.getParameter(“emailid”);
String mobile = request.getParameter(“mobile”);
String company=request.getParameter(“company”);
String loc=request.getParameter(“loc”);

String dbname = “registerdb”;
try {
//creates a database with the specified name
CouchDbConnector dbconnector = mydb.createConnector(dbname, true);
//create a document to place into your new database
Map<String, Object> doc = new HashMap<String, Object>();
doc.put(“_id”, UUID.randomUUID().toString());
doc.put(“name”, name);
doc.put(“emailid”, emailid);
doc.put(“mobile”, mobile);
doc.put(“company”, company);
doc.put(“location”, loc);

dbconnector.create(doc);
} catch (Exception e) {
response.getWriter().println(e.getMessage());
}
}

Export the WAR file and push it into bluemix using Cloudfoundry command line interface.

Once the application has started,insert the details through registration page.

To view the inserted details,click on the Cloudant service that is bound to your application.

Click on LAUNCH, it will take you to database list,you can now find your database registerdb in the list.

Click on registerdb and then you can view your documents on the right side.

You can create a view in Design Documents section and then copy paste API URL(top right) to view the documents in the browserdetails

Courtesy:IBM Bluemix and Cloudant NoSQL DB!

Weather Notification App using IBM Insights for Weather, Node-RED and Twilio in IBM Bluemix

 

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them. Bluemix provides a dashboard for you to create, view, and manage your applications and services as well as monitor your application’s resource usage. Bluemix dashboard also provides the ability to manage organizations, spaces, and user access.

IBM Insights for Weather service lets you retrieve weather data for an area specified by a geolocation. The data allows you to forecast, detect, and visualize disruptive weather events that might affect decision making in your application.

Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click.JavaScript functions can be created within the editor using the a rich text editor.A built-in library allows you to save useful functions, templates or flows for re-use.

Twilio is a mobile service that is available on Bluemix which allows software developers to programmatically make and receive phone calls and send and receive text messages using its web service APIs.

This tutorial will help you build a weather notification app that will send you weather update every morning and necessary precautions you have to take to save you from daily weather.

Prerequisites

Step 1: Create a Node-RED service in Bluemix and then bind Insights for Weather and Twilio Service

2

Step 2: Click on Environment Variables(visible in the left side) and then make note of weather insights username and password in a Notepad

3

Step 3: Goto https://twcservice.mybluemix.net/rest-api/ and click on twc_observations_current

4

Step 4: Change the geocode according to your geography and then scroll down

5

Step 5: Click on Try it out! You would be prompted to enter the username and password.Enter it from the notepad

6

Step 5: Save the Request URL, you will require that subsequently

7

Step 6: Goto the Bluemix App URL and then click on Node-RED flow editor. Start dragging in the nodes. You will require

  • Inject Node
  • Http Request Node
  • JSON node
  • Function node
  • Twilio node and
  • Debug node

Let’s configure each node and then wire them accordingly!

Inject node: It will be triggered, every day 6:00AM thereby sending weather notification SMS

trigger.PNG

Http Request Node:

Enter the REQUEST URL, Click on Basic Authentication and then enter the Weather insights credentials

http_request

JSON Node: It will convert the output string from Http Request to JSON format which is fed into a function

json.PNG

Output of JSON node:

json_output.PNG

Function node: Write a function to extract the value

function

Twilio node: Insert the twilio credentials, To number to receive the Notification

twilio.PNG

You can add a debug node to understand whether it is functioning properly.

Click on Deploy button which is in the top right corner and then click on the left side of the Inject node to trigger.

Yipee! I just received a notification!! 🙂 You can schedule to receive it everyday morning!

13235034_1082577601799736_714966582_o

Courtesy:IBM Bluemix™(bluemix.net), Twilio, Weather Insights and Node-RED

Single Sign On(SSO) for Bluemix Web Apps

SSO_logo2

IBM® Bluemix™ is a Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud.

IBM Single Sign ON is a policy based authentication service that provides an easy to embed Single SIGN ON capability for NODE JS Or Java Applications.

Single SIGN ON supports several identity sources where users credentials are stored:

  • SAML Enterprise: A user registry with an exchange of SAML token that completes the authentication.
  • Cloud Directory: A user registry that is hosted in the IBM Cloud
  • Social Identity Sources: The user registries that are maintained by Google,Facebook and LinkedIn

This blog will help you to ADD SOCIAL IDENTITY SOURCE FROM FACEBOOK for Single SIGN ON (SSO) for Bluemix App

Prerequisites

So,let’s begin with CONFIGURING IDENTITY SOURCES :

Step 1: From Bluemix CATALOG, Select Single Sign On Security service

1

Step 2: Insert a Service Name and then click on CREATE

2

Step 3: Provide a name to the service. This name will be part of the service URL and Click on Continue

3

Step 4: Click FACEBOOK to add identity source.

4

Step 5: After changing the name (optional), Click on “Click here” which will redirect you to facebook for developers page.

5

Step 6: Click on My Apps and then click on Add a New App

6

Step 7: Click on Website

7

Step 8: Enter App Name and then Click on Create New Facebook App ID

8

Step 9: Choose a Category and then click on Create APP ID

9

Step 10: You can now see your App listed on My Apps section. Click on TweetAuth which will take you to Dashboard of the App

10

Step 11: In the Dashboard, Copy APP ID and APP Secret

11

Step 12: Go back to Bluemix Dashboard and then Paste the APP ID and APP Secret. Copy the OAuth Redirect URI and then Click on SAVE

12

Step 13: In the facebook for developers page, SETTINGS TAB>Basic enter your Contact Email and Website URL and click on SAVE CHANGES

13

Step 14: In Facebook for developer page, SETTINGS>ADVANCED, toggle from NO to YES for Client OAuth Login and then paste the OAuth Redirect URI in the textbox and then click on SAVE CHANGES

14

Step 15: Go back to Bluemix DASHBOARD, you will now find VERIFY button,click on that and Verify Access to Facebook by clicking on “Click here”

15

Step 16: Awesome! It’s working!!

15-b

Step 17: You can now see your identity source app in the list

16

The next step is to Configure APP by creating an APP:

Configuring a Liberty for Java APP with SSO:

  • For Liberty for Java Applications, the Single Sign On service leverages the OpenID Connect (OIDC) client feature from Liberty and the Bluemix Liberty buildpack. As a result, Java applications running on Bluemix do not need to include any code to support the OpenID Connect protocol or Single Sign On.
  • However, you must enable security constraints. To enable them, you can use declarative J2EE security to secure the application and all protocol support is completely “built-in.”

    After you bind the app to an instance of the single sign-on service, the Bluemix buildpack detects that the application is bound and automatically configures the OIDC client in the Liberty runtime server.xml to enable the application for the service. The configuration is done when you deploy the application in Bluemix using either the cf push command or using the restaging process in the Bluemix dashboard.

    To complete the configuration of the application, you must add security constraints. You can add the constraints in the same manner as you would for traditional J2EE applications using EAR/WAR binding files to declare roles and protected resources.

    The following example illustrates security constraint configuration for a Java application that uses the web.xml and the Liberty server.xml files.

  • Create a HelloWorld Servlet in com package with twitter as the Java application name
  • Open the web.xml file in a text editor.
  • Set security constraints: Consider the below as example.
<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>com.HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello/*</url-pattern>
    </servlet-mapping>
    
    <security-constraint>
    <display-name></display-name>
    <web-resource-collection>
      <web-resource-name>HelloServlet</web-resource-name>
      <url-pattern>/</url-pattern>
      <url-pattern>/*</url-pattern>
      <url-pattern>/</url-pattern>
      <http-method>GET</http-method>
      <http-method>PUT</http-method>
      <http-method>HEAD</http-method>
      <http-method>TRACE</http-method>
      <http-method>POST</http-method>
      <http-method>DELETE</http-method>
      <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>TESTROLE</role-name>
    </auth-constraint>
  </security-constraint>

  • Save the web.xml file.

 

  • Open the server.xml file in a text editor.
  • Enable the security constraints. Use the following example as a guide.
    <server description="new server">
    <featureManager>
    <feature>jsp-2.2</feature>
    <feature>localConnector-1.0</feature>
    </featureManager>
    <httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
    <applicationMonitor updateTrigger="mbean"/>
    <application type="war" id="twitter" name="twitter"
    location="twitter.war">
    <application-bnd>
    <security-role name="TESTROLE">
    <special-subject type="ALL_AUTHENTICATED_USERS"/>
    </security-role>
    </application-bnd>
    </application>
    </server>

  • Push the app(twitter.war) along with server.xml to Bluemix using CF Push command . Learn how to push application to bluemix using CF command through my earlier blog.
  • Bind the SSO service to the Java APP and then Restage it.
  • Open the app .Here eg: tweetout.mybluemix.net/twitter/hello ,It will redirect you to facebook page for logging in

Hurray your Bluemix App is now secured by Single Sign On facebook authentication!!

 

 

Courtesy: (bluemix.net) IBM Bluemix and Facebook for Developers (developers.facebook.com)

Java application to send mail using Sendgrid & IBM Bluemix

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them.

SendGrid provides a cloud-based email delivery service that assists businesses with transactional email management while abiding by anti-spam regulations. The service manages various types of email including shipping notifications, friend requests, sign-up confirmations, and email newsletters.

This tutorial will help you to build and deploy a java application that sends registration successful mail using SendGrid and IBM® Bluemix™

Prerequisites

Let’s start building the java application,before that lets go to our Bluemix Catalog and select required services to build it!

Step 1: Goto Catalog and then click on Java Runtime

blog1

Step 2: Enter your application name. Eg: mailreg as shown in the image below. Click on CREATE

4

Step 3: Application has been created and it can be viewed on the Bluemix DASHBOARD. Click on the application

5

Step 4: Click on ADD SERVICE

6

Step 5: In CATALOG goto Web and Application and click on SendGrid

7

Step 6: Change the Service name if required and click on CREATE

8

Step 7: Click on Add a service again and then in CATALOG goto Data and Analytics and click on SQLDB

blog_6

Step 8: Create the service by giving it a service name. Follow the steps to create a table in SQLDB as shown in my previous blog

The service is now up and running in Bluemix!! We can now proceed to Eclipse IDE to build the registration application that inserts details into database and also sends out registration successful mail.

Please ensure that you Copy and paste the SendGrid-java jar to the below shown location

10

Please refer to my previous blog to understand how to add data to SQL database and append the piece of code(shown below) to send mail upon successful completion of registration

import com.sendgrid.*;

public class SendGridExample {
  public static void main(String[] args) {
    SendGrid sendgrid = new SendGrid("sendgrid_username","sendgrid_password");;
//OR
    SendGrid sendgrid = new SendGrid("SENDGRID_APIKEY");

 SendGrid.Email email = new SendGrid.Email();   
 email.addTo("xxxxxxx@gmail.com"); //Can programatically add sender's email id!  
 email.setFrom("noreplybluemix@gmail.com");  
 email.setSubject("Thank You for registering for Email services");  
 email.setHtml("<h1>Thank You for registering for Email Services!</h1>");
 email.setText("Thank You for registering for Email Services!");

  SendGrid.Response response = sendgrid.send(email);  } } 

You can add attachment to the mail & there are more options apart from these!

Push the application to Bluemix(refer my previous blog) and on successful 
registration you will receive a mail in your inbox as shown below

OUTPUT:

Output

Integrating mail services had never been this easy! 
Thanks to IBM Bluemix and SendGrid!

Courtesy: (bluemix.net) IBM Bluemix and SendGrid (sendgrid.com)

Simple application using Node-RED Starter(SDK for Node js, Cloudant NoSQL database) in IBM Bluemix

bluemix1

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them. Bluemix provides a dashboard for you to create, view, and manage your applications and services as well as monitor your application’s resource usage. Bluemix dashboard also provides the ability to manage organizations, spaces, and user access.

Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click.JavaScript functions can be created within the editor using the a rich text editor.A built-in library allows you to save useful functions, templates or flows for re-use.

In IBM® Bluemix™, a boilerplate is a container for an application and its associated runtime environment and predefined services for a particular domain. You can use a boilerplate to quickly get up and running. The Node-RED Starter boilerplate has Node-RED,Cloudant databse and Monitoring and Analytics Services as a combo pack.You don’t have to spend time in adding or binding services.

The steps below will help you to build a simple twitter feed application and insert those tweets into Cloudant database with the Node-RED Starter boilerplate.

Prerequisites

Step 1: Choose the Boilerplate Node-RED Starter from the CATALOG tab1.2

Step 2: Input the host name and click on CREATE

1.1

Step 3: Hurray! The application is created with Cloudant NoSQL DB and SDK for Node js

blog2

Step 4: One instance of the application is running perfectly! Click on the URL

blog3Step 5: Click on the button Go to your Node-RED flow editor


3

Step 6: The Node-RED page opens up with the nodes for each functionality on the left side


4.1

Step 7: Drag and drop the twitter node to the sheet1 (ensure you drag and drop the correct node)

twitter

Step 8: Double click on the twitter node and enter the required fields(ensure that you authenticate it with your twitter id) and click Oktwitter3Step 9: Drag and drop debug node in sheet 1


debug

Step 10: Enter the required field as shown below

debug2

Step 11: Drag and drop cloudant node to sheet1(ensure that you have choosen the correct node)

cloudant

Step 12: Double click the node and enter the required details

cloudant2

Step 13: Wire the nodes from its node points and click on DEPLOY

out

Step 14:Yes,now you can see live tweets for the hastag #bluemix on your debug console!!

output

Step 15: Goto the cloudant database

cloudb

Step 16: Click on Launch

cloud1

Step 17: You can see the database (tweets) ! Click on it. 

cloud2

Step 18: You can see the documents with unique id and _rev

we

Step 19: Click on one of the document and you can see the tweet,date,time,created by whom and all other details in JSON format.

out2

You can use the documents inserted in the Cloudant NoSQL database for further use and Yes,the application was ready within few minutes! That’s the power of Node-RED in IBM Bluemix. You can drag and drop other several nodes which are available in Node-RED to make this a better application(for analysis,for sending notifications etc)

Thanks to Node-Red,Cloudant NoSQL database and IBM Bluemix! You just saved our time from writing 1000 lines of code!

Courtesy: IBM Bluemix, Node-RED, Cloudant NoSQL Database

Java application to send message using Twilio and IBM Bluemix™

twiliobluemix

IBM® Bluemix™ is a platform(PaaS) that helps users to build and deploy their applications easily without any worry of infrastructure setup.It abstracts and hides most of the complexities that are associated with hosting and managing cloud-based applications.Both IBM and third party services are available on IBM® Bluemix™. Twilio is a mobile service that is available on Bluemix which allows software developers to programmatically make and receive phone calls and send and receive text messages using its web service APIs.

This tutorial will help you to build and deploy a java application that sends registration successful message using Twilio and IBM® Bluemix™

Prerequisites

Let’s start building java application,before that lets go to our Bluemix Dashboard and select required services to build it!

Step 1: Goto Catalog and then click on Java Runtime

blog1Step 2: Enter your application name. Eg: registermsg. Click on CREATE

blog3Step 3: Application is created and it can be viewed on the Bluemix DASHBOARD. Click on the application

blog4Step 4: Click on ADD SERVICE

blog5Step 5: In CATALOG goto Mobile Services and click on Twilio

headerStep 6: Change the Service name if required, Enter the Twilio API credentials and click on CREATE

blog7

Step 7: Click on Add a service again and then in CATALOG goto Data and Analytics and click on SQLDB

blog_6Step 8: Create the service by giving it a service name. Follow the steps to create a table in SQLDB as shown in my previous blog

Cool! The service is now up and running in Bluemix!! We can now proceed to Eclipse IDE to build the registration application that inserts details into database and also sends out registration successful message.

Input–>Team Name, First participant name,emailid,mobile number,Second participant name,emailid,mobile number and Hackathon idea

Copy and paste the twilio-java jar to the below shown location

twiliojar

Database integration ( JNDI lookup of database, can be dynamically integrated using VCAP_SERVICES)

code0 code01

Twilio API (hard coded the Twilio accountSID, Twilio authentication token.Can be taken dynamically)

codeNext step is to push the WAR file to Bluemix using cf command line interface(CLI)

Step1: Login to Bluemix account from the cf command line interface cf login -a https://api.ng.bluemix.net ( Depending on the region selected your api endpoint changes). Enter the credentials

deployblog1Awesome! You have now logged into Bluemix from your cf command line interface

Step2: Now push the WAR file to Bluemix using the command

cf push appname -p <path_of_war_file>

deploy2Yipee!! The application have been successfully deployed in Bluemix!!

Common lets test it!!

INPUT

Click on REGISTER after providing the required details

input

OUTPUT

Awesome! The details have been inserted into database and I just received a message!! Yipeee!!

ResultThanks IBM® Bluemix™ and Twilio !! You made our life easier and simpler !!

Courtesy: (bluemix.net) IBM Bluemix and Twilio (twilio.com)

How to build and deploy java application using IBM Bluemix plugin for Eclipse IDE

IBM Bluemix™ is a cloud platform that helps developers rapidly build,manage and run web and mobile applications. With IBM Bluemix™, developers can focus on building excellent user experiences with flexible compute options, choice of DevOps tooling, and a powerful set of IBM and third-party APIs and services.

Built on Cloud Foundry open source technology,IBM Bluemix™ makes application development easier with Platform as a Service (PaaS). Bluemix also provides pre-built Mobile Backend as a Service (MBaaS) capabilities.By abstracting lower level infrastructure components,IBM Bluemix™ enables you to spend more of your time and talent writing the code.

You can use IBM Bluemix™ to quickly develop apps in the most popular programming languages. You can develop mobile apps in iOS, Android, and HTML with JavaScript. For web apps, you can use languages such as Ruby, PHP, Java™, Go, and Python et. al

You can deploy an application in IBM Bluemix by three ways either by using Cloud Foundry command line or Git/Jazzhub or by using IBM Bluemix plugin for Eclipse IDE.

The illustration below will help you to build and deploy java application in IBM Bluemix using IBM Bluemix plugin for Eclipse IDE

Prerequisites for building and deploying java application in IBM Bluemix

  1. Open your Bluemix page and click on the CATALOG, Goto Data and Analytics and click on SQL Database

blog_6 2) Add a service name(eg:javadb) and then click on CREATE

blog_73) Click on the LAUNCH button and then you can see the welcome screen. There will be 3 options,click on work with tables.

blog_8

4) Click on the + icon and then edit the DDL statement

blog_9

5) After editing the DDL statement,click on RUN DDL, If all is well, you will receive a message DDL Ran successfully

blog_10

6) After successful creation you can see your table details and also browse the data(if any)

blog_11Now we can move onto Eclipse IDE for pushing our code to Bluemix through the Bluemix plugin

Make sure that you have added Bluemix plugin in your Eclipse IDE or else follow the steps here

After installing the Bluemix plugin for Eclipse IDE, Click on File>New>Other and search for Server. Click on Next

blogblu_1

Then click IBM>IBM Bluemix and click on Next

blogblu_2Enter your Bluemix account details(email and password). Click on Finish

blogblu_3And its added !

blogblu_4

Create a jsp application to insert user’s details into database.

Front end: Input –> FirstName, LastName, Mobile Number and Email Address

For integration with the back end(SQL DB) in Bluemix you have to either hardcode the VCAP_SERVICE environment variable (You can view the credentials by clicking on show credentials) in your code or take it dynamically

blog_12or else do a JNDI look up of the database

blog_jndiOnce after the jsp application is ready,we can push it into bluemix directly from the Eclipse IDE with just one click( another advantage of Bluemix) using IBM Bluemix plugin for Eclipse IDE

Right click on your app in Eclipse IDE, Click on Run As>Run on Server>Cloud>IBM Bluemix and Enter your application name(eg:javadbapps) and Click next

deployblog

Customize the memory limit if required and click on Next

deployapp2

Select the database you wish to bind to your application,here we will bind it using javadb(the one that was created) and then click on FINISH

deployapp3

pushing the application into bluemix

deployapp5

Voila!Its now running in Bluemix

outputYou can now access your application using the unique URL <your_app_name>.mybluemix.net

An application ready within few minutes. Thanks to IBM Bluemix™ for making developer’s life so easy!

Courtesy:IBM Bluemix™(bluemix.net)