In this recipe, we will use Google Maps to show how NetBeans enables developers to quickly create an application using web services provided by third parties.
It is required to have NetBeans with Java EE support installed to continue with this recipe.
If this particular NetBeans version is not available in your machine, please visit:
We will use the GlassFish Server in this recipe, since it is the only server that supports Java EE 6 at the moment.
For our recipe to work, we will need a valid key for the Google Maps API. The key can be found at:
http://code.google.com/apis/maps/signup.html
On the site, we will generate the key. Tick the box that says I have read and agree with the terms and conditions, after reading and agreeing of course.
Under My website URL, enter:
http://localhost:8080
Or the correct port in which GlassFish is registered.
Then click on Generate API key.
The generated key looks something like:
ABQIAFDAc4cEkV3R2yqZ_ooaRGXD1RT8M0brOpm-All5BF9Po1KBxRWWERQsusT9yyKEXQAGcYfTLTyArx88Uw
Creating Servlet
Right-click on the WebServiceClient project, and select New and then Servlet....
WSClientServlet
.When the WSClientServlet opens in the editor, remove the code starting with:
/* TODO output your page here
And ending with:
*/
And save the file.
Adding a Web Service
Navigate to the Services window and expand the Web Services node, followed by Google, and finally Map Service.
Accepting a security certificate is required to access this service and to continue with the recipe. Please refer the following screenshot:
Drag and drop getGoogleMap
into our Servlets processRequest
method.
A new window, Customize getGoogleMap SaaS Service, pops-up.
When the new block of code is written by NetBeans, uncomment the following line:
//out.println("The SaasService returned: "+result.getDataAsString());
Remember the key generated in the Getting Ready section?
In the Projects window, expand the Source Packages node and the package org.netbeans.saas.google
, and double-click on googlemapservice.properties
.
Paste the key after the = operator.
The line should look like:
api_key=ABQIAFDAc4cEkV3R2yqZ_ooaRGXD1RT8M0brOpm-All5BF9Po1KBxRWWERQsusT9yyKEXQAGcYfTLTyArx88Uw
Save file, open WSClientServlet
and press Shift+F6.
When the Set Servlet Execution URI window pops-up, click OK.
The browser will open with our application path already in place and it will display this:
After dragging and dropping the Google Web Service to our class, a folder structure is created by NetBeans:
Let's check what is in our folder structure:
Discovering other web services bundled with the IDE.
3.16.218.105