Quickly build and deploy a Java applet based on Bluemix-Weibo impact analyzer

Source: Internet
Author: User
Tags cloudant

First, preface

In recent years IT industry willow, a variety of new concepts such as big data, cloud platform, virtualization, etc., springing up endlessly. And the cloud platform, can be said in recent years to lead the era of the trend of the edge of one of the concept, major manufacturers compete to launch a variety of cloud products, seize the cloud market heights. Recently, IBM, the IT century-old factory, has also launched Bluemix, a cloud platform based on cloudfoundry open standards, that it spends heavily on. The purpose of this article is to quickly build and deploy a Java applet "Weibo impact Analyzer" from a common Java developer perspective, with the early adopters of the Bluemix cloud platform and the Cloudant services it provides.

Second, "Weibo Impact Analyzer" Small program introduction 1, what is the "Microblog Impact analyzer" applet?

"Weibo impact analyzer" is a small program evolved from an IBM Jstart-provided Bluemix demo program, Java Twitter Influencer Analyzer. It used Sina Weibo to replace Twitter in the original program, replaced Google Map with Baidu maps, and culture the program interface to make it more localized and approachable.

The main function of the program is very simple, through the micro-Bo open platform interface, read and calculate the current number of Weibo users of microblogging, number of forwarding and number of fans, etc., to the current microblog users of the "impact" evaluation score, of course, the score results for entertainment only. The evaluation results page also shows the current user's latest 10 tweets, and can display the microblog address information on the Baidu map below.


Figure 1, Weibo Impact Analyzer Home


Figure 2, Weibo Impact Analyzer results page


Figure 3, on the results page, a location-friendly Weibo display

The current user can choose to save the scoring results to a background database for review. If the current user's scoring results are already in the database, the user's score will be updated. The information saved in the background database can be deleted in whole or in bulk. Data that has been saved in the database can also be viewed in the form of a list.


Figure 4, the data query page saved in the database

2. The structure of the "Microblog Impact Analyzer" program.

This program consists of 3 pages and 6 Servlets, as shown in. 3 of these pages are primarily responsible for providing Weibo login buttons, displaying score results and data in the database, and 2 of the 6 servlets (Weibologinservlet and Dispcalc) are primarily responsible for Weibo open platform login and impact score calculations, The remaining 4 CRUD operations are primarily responsible for the database.


Figure 5, Program structure diagram

This program interacts with the Weibo open platform API and uses the official Java SDK of the Weibo open platform. The map uses the Baidu Map Javascriptapi VW edition. The backend database uses the Cloudant service provided by Bluemix. Cloudant provides the standard JSON on RESTful API interface (see: Cloudantcrud API Getting Started Guide), this program uses Apache httpcomponents fluent The API and the Jackson Streaming API enable HTTP and JSON operations in Java to interact with Cloudant's restful APIs.

Cloudant is an Apache COUCHDB-based No-sql database service platform provided by IBM. For developers, the use of platform services instead of using the product self-built database means that there is no need to care about database construction, configuration and maintenance, which can greatly improve the productivity of developers, eliminating some of the development unrelated to the complex work.


Figure 6, the data saved in Cloudant

Third, like a developer, using Eclipse to publish "Weibo impact Analyzer" 1, what needs to be prepared?

In order to remain concise, the details of the "Weibo Impact Analyzer" code are omitted here, and interested students can check the source code on my github.

In addition, you need to prepare Java EE edition eclipse as the IDE. You can download Eclipse IDE for Java EE version developers on the Eclipse official website. After that, use the egit from eclipse to clone the source code on GitHub, or download the source code and import it into eclipse.

Because the program uses the microblogging open platform interface and Baidu map interface, in addition to preparing Eclipse and import source code, before the release of the program you also need to advance the microblogging open Platform app key, app secret and Baidu map key (AK) to normal use of these two third-party services.

Weibo open Platform App key requires you to have a Weibo account and become a Weibo developer, then successfully create an app to get, more detailed instructions please read the Weibo official Weibo API Novice Guide. Please prepare your Weibo app key and app Secret in advance, which will be used later.


Figure 7, Weibo app key and app Secret

Baidu Map interface also requires a key to normal use. You need to have a Baidu account and become a developer before you can get it. For more detailed program key request instructions please read the Release notes in the official development guide and the Application API AK section. Please prepare the Baidu map key (AK) in advance, will be used later.


Figure 8, Baidu map key (AK)

2. Add the wings of Bluemix to eclipse.

After you import the project in Eclipse, you also need to install the Bluemix plugin for Eclipse to publish. It's easy to add a plugin to Eclipse's Bluemix, just click Help in the Eclipse menu bar to find and open Eclipse Marketplace.


Figure 9, Eclipse Marketplace in the Help menu

Then search for Bluemix in Eclipse Marketplace, find the IBM Eclipse Tools for Bluemix and click Install.


Figure 10, IBM Eclipsetools for Bluemix in Eclipse Marketplace

At this point, the development environment you need is all ready. There is no other server, the database needs to be installed and configured, because all this has been ready for you on the Bluemix cloud, is it particularly simple? Next, like a programmer who has programmed Java EE, the finished program will be published to the server to run.

3. Publish "Weibo impact analyzer" to bluemix like a developer.

As an experienced Java EE developer, I believe you must have configured and used Apache-like Tomcat or Java EE servers in Eclipse and are familiar with how to publish a project. With Bluemix, you'll find that publishing a project and publishing it to other Java EE servers is almost consistent, and it's easy for an experienced developer to get started.

First, right-click the new server in Eclipse's servers window. In the New Server dialog box, locate the IBM folder, select the IBM Bluemix, and then click Next.


Figure 11, new server


Figure 12, new IBM Bluemix Server

At this point we need to specify an account for the Bluemix server. Enter your Bluemix account and password in the email and password input boxes, and make sure IBM Bluemix is selected in the URL drop-down menu. Click Next when you are done.


Figure 13, specify the Bluemix account password

Upon successful login, the dialog will show you the organization and space in your Bluemix account. As a general developer, there is no specific requirement for organization and space, so choose the default dev. Then click Next. For questions about organization and space in Bluemix, see the official documentation, which is no longer in this article.


Figure 14, setting up organization and space

Then there is the add and remove interface. If you've published a project using Eclipse, you'll be familiar with this interface. Just move to the right of the project that will be published (we need to publish the project at this point Weibo-influence-analyzer). When finished, click Finish, the assigned project will be published to the server, at this time from the servers window can see the published project is displayed under the server, and the status of the server is republish, indicating that the project is not yet ready to be published to the server.


Figure 15, adding and removing projects


Figure 16, server in republish state

Eclipse will then start publishing the project automatically in the background. It will pop up later as shown in the dialog box that asks you to configure some of the required parameters. The first one that needs to be configured is the program name. The program name can consist of uppercase and lowercase letters, numbers, bars, or underscores, and there can be no other special characters. In general, you can use the default. Also, it is recommended that you do not use the underlined program name, as this will prevent you from debugging your app remotely. Instructions on how to remotely debug an app on Bluemix will be detailed later. Click Next when the settings are complete.


Figure 17, setting program name

The next step is to set the program's domain name and memory usage. Bluemix prepares you for mybluemix.net as the primary domain name for the program, and uses the program name as the subdomain. The memory usage is set to 512MB by default. In general, you don't need to change these settings, just click Next.


Figure 18, setting the domain name and memory usage

The next step is to configure the services used for the program. All the services you created on Bluemix are listed in the following list of dialog Windows. You can simply tick the created service to bind to the program you are going to publish. Here we need to create a new Cloudantnosql database service to serve as a backend database for the microblog Impact Analyzer. Click the button with the plus sign in the top right corner of the list to open the Add service interface to create the Cloudant nosqldb service.


Figure 19, new service

All available services on Bluemix are listed in the Add Service dialog box. We only need to enter "Cloudant" in the Fliter to filter out the CLOUDANTNOSQLDB service. Select it and click Finish to go back to the Program Settings dialog box.


Figure 20, new CLOUDANTNOSQLDB server

After returning to the Program Settings dialog box, you can see that the newly created CLOUDANTNOSQLDB database service is new and has been checked. Click Next to set the environment variables.


Figure 21, binding a new service

In the environment variables, we need to set three values respectively, which are the Weibo app Client, app secret and Baidu map key (AK) mentioned above. Click the New button on the right to enter the corresponding variable and value respectively. Then click Finish to start the release should. The name of the variable and the corresponding values are shown in the following table.


Figure 22, setting environment variables

table 1, variable name, corresponding value

Variable name

corresponding Value

weibo_client_id

Weibo App Client

Weibo_client_sercret

Weibo App Secret

Baidu_map_ak

Baidu Map AK

After setting up the above and clicking Finish, you can see in the Servers window that the status of the server becomes "publishing ...", indicating that Eclipse has started to release the project. And in the console window you can see the log that the system typed when the program was published.


Figure 23, the Bluemix server in the release


Figure 24, log displayed when the program is published

After the program has been successfully published to the server, you can see in the Servers window that the status of the server is displayed as "Started, Synchronized". and the program you publish appears in the same state below the server. You can now open your browser and enter the application address you configured earlier to run your program.


Figure 25, Release complete


Figure 26, using a browser to access the application

When you sign in to your Bluemix dashboard, you can see that the program you just published is already displayed in the list of applications, and the newly created CLOUDANTNOSQLDB is already displayed in the list of services. And the status of the program is displayed as a green light "running", indicating that the program is running healthily.


Figure 27, show published programs on the Bluemix dashboard


Figure 28, a new service is displayed on the Bluemix dashboard

4. Remotely debug applications on Bluemix.

Here's how you can use the Eclipse plug-in to publish your program to Bluemix, and then you'll explain in detail how to debug your application remotely in eclipse.

As an experienced Java EE developer, you must be aware that the development of a development environment, writing programs, compiling code, publishing to a development server, and testing these steps in the development environment. Thanks to the auto-compile and release capabilities of Eclipse, we don't need to specifically compile the code, which is usually done automatically. And once the program has been successfully published to the test server, if the code changes, we do not need to be specifically recompiled and then released, which is automatically done by Eclipse.

The release of the program to Bluemix is almost identical to that of publishing to other Java EE servers, and will soon be available to a developer with Java EE development experience. And if the code changes, Eclipse's auto-compile and release capabilities are still valid on Bluemix, and Eclipse will automatically compile and publish it to Bluemix. Taking into account the nature of Bluemix's cloud platform is surprisingly quick and easy.

And Bluemix can debug remotely like other Java EE servers. The way to start remote debugging is simple, just right click on the application you need to debug, select Enable Application Debug to go to remote debugging mode. Eclipse will begin to establish a link to the remote debugging session, which can be debugged like a generic Java EE server once the link is established successfully. Note that remote debugging is not possible if the application name is underlined. In addition, the application that goes into debug mode automatically goes into development mode and later tells you what the development mode is.


Figure 29, enabling application debugging


Figure 30, remote debugging of the Bluemix application

5. Enable the development mode applied on Bluemix.

If your application is not yet in development mode, and you have modified the program several times to let Eclipse automatically publish to Bluemix, you will find that by default no matter how many changes you make, the program will be re-published and restarted every time, with a long time, Cause unnecessary waste of time. For this, you can start the development mode (development mode) for the program. In the development mode, the program is published incrementally (Incremental Publish), which means that only modified files are pushed, so that each time the auto-release time is much less than the full release, it can be obvious that the speed of automatic publishing is faster.


Figure 31, enabling development mode

For more information about the Bluemix plugin for Eclipse, please read the official Bluemix documentation.

Iv. Conclusion

Earlier we tried to use the Bluemix cloud platform to publish and debug our applets as a common Java developer. From a developer's point of view, the advent of the Bluemix cloud Platform accelerates the development of traditional applications. It reduces developer build environment, configuration server and so on with the development of a few related work, the developer from the cumbersome redundant work release, greatly frees the developer's initiative, thus increasing the development efficiency, accelerating the application development iteration cycle.

In addition to the Eclipse plugin described above, Bluemix can be used in conjunction with IBM DevOps Services to truly write, compile, and publish online, without having to configure any other environment outside of the browser, eliminating the need to install a configuration server or a background database. Because all of this has Bluemix and IBM DevOps ready for you in the cloud. For more information about the use of Bluemix and IBM DevOps Services, see this article: Getting Started with IBM Bluemixand DEVOPS services using Java.

Bluemix has more powerful features waiting for you to explore.

Quickly build and deploy a Java applet based on Bluemix-Weibo impact analyzer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.