Thursday, July 16, 2015

Building of Java API

Creating a Simple Hello World Backend API


In this part of the tutorial, we'll use the App Engine Maven artifact endpoints-skeleton-archetype to create a new Endpoints project. We'll then show you how to add code.

Creating and building the project

To create the Hello World backend API:
  1. In a terminal window, change to the directory where you want to build the project.
  2. Invoke the following Maven command:
    mvn archetype:generate -Dappengine-version=1.9.23 -Dfilter=com.google.appengine.archetypes:
    
  3. Enter the number 2 to select the archetype remote -> com.google.appengine.archetypes:endpoints-skeleton-archetype from the list of App Engine archetypes.
  4. Accept the default to use the most recent version.
  5. When prompted to Define value for property 'groupId', enter the namespace com.example.helloworld to keep this tutorial in sync with the source files at GitHub. (The typical convention is to use a namespace starting with the reversed form of your domain name.)
  6. When prompted to Define value for property 'artifactId', supply the project name helloworld.
  7. When prompted to Define value for property 'version', accept the default value.
  8. When prompted to Define value for property 'package', accept the default value.
  9. When prompted to confirm your choices, accept the default value (Y).
  10. Wait for the project to finish generating, then take a look at the resulting project layout:
    Maven Project Layout
    The pom.xml file contains all the configuration and dependencies needed for your backend API.
  11. Change directories to the project's Java source directory: /src/main/java/com/example/helloworld.
  12. Create a JavaBean class file named MyBean.java copy-paste the following code into it                               
    package com.example.helloworld;
    /** The object model for the data we are sending through endpoints */
    public class MyBean {
    
        private String myData;
    
        public String getData() {
            return myData;
        }
    
        public void setData(String data) {
            myData = data;
        }
    }
  13. requires a browser that supports JavaScript and iframes.]</p> We'll use this JavaBean object to send data through the backend API.
  14. Edit the file YourFirstAPI.java, replacing all of the contents with the following code:                                                                                                                     
    package com.example.helloworld;
    import com.google.api.server.spi.config.Api;
    import com.google.api.server.spi.config.ApiMethod;
    import com.google.api.server.spi.config.ApiNamespace;
    import javax.inject.Named;
    /** An endpoint class we are exposing */
    @Api(name = "myApi",
         version = "v1",
         namespace = @ApiNamespace(ownerDomain = "helloworld.example.com",
                                    ownerName = "helloworld.example.com",
                                    packagePath=""))
    public class YourFirstAPI {
    
        /** A simple endpoint method that takes a name and says Hi back */
        @ApiMethod(name = "sayHi")
        public MyBean sayHi(@Named("name") String name) {
            MyBean response = new MyBean();
            response.setData("Hi, " + name);
    
            return response;
        }
    }
                                                   

    @Api; this is where we set the configuration of the backend API.
  15. Notice the @ApiMethod annotation; it allows you to configure your methods.
    Finally, notice the use of the javax.inject.Named annotation (@Named) in the sayHi method definition. You must supply this annotation for all parameters passed to server-side methods, unless the parameter is an entity type.
  16. Build the project by invoking
    mvn clean install
    Wait for the project to build. When the project successfully finishes, you will see a message similar to this one:
    [INFO] BUILD SUCCESS[INFO] ------------------------------------------------------------------------
    [INFO] Total time: 14.846s
    [INFO] Finished at: Tue Jun 03 09:43:09 PDT 2014
    [INFO] Final Memory: 24M/331M
    

Running and testing the API locally

To test the backend API locally:
  1. From the main directory helloworld/, start the API in the development server as follows:
    mvn appengine:devserver
    Wait for the dev server to start up. When the server is ready, you will see a message similar to this one:
    [INFO] INFO: Module instance default is running at http://localhost:8080/
    [INFO] Jun 03, 2014 9:44:47 AM com.google.appengine.tools.development.AbstractModule startup[INFO] INFO: The admin console is running at http://localhost:8080/_ah/admin
    [INFO] Jun 03, 2014 9:44:47 AM com.google.appengine.tools.development.DevAppServerImpl doStart[INFO] INFO: Dev App Server is now running
  2. Visit the APIs Explorer at this URL:
    http://localhost:8080/_ah/api/explorer
    
    (The Google APIs Explorer is a built-in tool that lets you send requests to a backend service without using a client app.)
  3. Click myApi API to display the methods available from this API.
  4. Click myApi.sayHi to display the Explorer for this method:
    SayHi form
  5. In the name field, supply your name, and click Execute and check the Response for the greeting.

Congratulations!

You've just built and tested your first backend API!
Next, let's build a more complete backend API wiith GET and POST methods that write to and fetch from the datastore.

Saturday, November 13, 2010

Pain to Feel

Life may not be same for all human beings which we all can understand. But when we come across a situation in which our self hatred for the so called urban society gets shook then it really hurts. It was last week during the diwali when one such incident just enlarged in front of my eye the skeleton of our modern civilization. It was day time when I was returning from a local shop and on my way I had come across a very feeble lady of age may be 50 to 55 years approx with her lean figure just keeping itself from falling to the ground. This very picture just shook me, i was simply dumbstruck at her condition. She had one plastic full of cooked rice and a small piece of fish just with its head coming out from the plastic end and had a rugged many a time scratched jute bag with few embroidery on its handle. She was wearing a dirty printed sari with her blouse hardly getting distinguished from her dirty skin color. As far as her countenance concerned,she was beautiful though had signs of weakness and burden of starvation.
What will i say!this very figure on that afternoon empty road made my eyes really watery,after coming to my home i could have my lunch with her picture wandering in my inner world.
May be i am becoming little bit emotional but truly speaking that day i came to realize one thing when you came alone in this world you have to leave it alone with what ever gift good or bad life has given it to you. After that day i did not see her,may be she was an eyeopener to me, may be my gift from lord, but still my eyes search for her one glance.
I hope today wherever she went her soul must not suffer much the hardship of the society for i do not think she deserves any more....

Friday, September 10, 2010

Understanding The GoogleHeads

With the birth of every little kid in this phase of time a very familiar but interesting pseudo-eclecticism of internet giants,mind it 'internet giants' is making some sort of mark on them in their unknowing world of imaginative power.Please forgive me if I am going into too much futuristic scenario.Can't help it.What future holds for us is what we can can see in the palm of these little brains.Little as they seem today!But undoubtedly our own rather very own relative,common to all,the Google will obviously taking the responsibility of creating what we proudly say as futuristic culmination of ourselves.

Why go into so much literary conundrums!Yes its they who single handedly ushered a new beginning what layman can call as 'Technological Appetite' for their children.But wait a sec!Are Google is The HE!!!think again.Can't think!uuf it is there nah...who?areee the search engine with the same name.Ok don't have waste any time,why I am there for,yes our very own google is the brain child of two of the smartest kids that mother Earth ever produced.Don't have to be proud of them just praise them.Serjey Brin and Larry Page was just like other normal American kids,but check out fellow Indians they are Americans.You can take both positive and negative thoughts into your head.Thats the obvious thing to do for us Indians.But they are Americans of highest degree of innovative skills,prowess and unending zeal for success. Never mind we too possess the same but problem is please don't dare to laugh in agony also,yes the problem is we are in one simple word Indians.Please separate those who have been to the States to works for them like Krishna Bharat the 42nd Google employee and founder of Google News.and other 'brilliant minds' who just had to do this unpatriotic thing to follow their own dreams and why shouldn't they.Perhaps a knowledgeable man sitting on his couch will point finger to us and say to do this things ypu should have courage and passion.But sir we also want to have the brains of American politicians.Please forgive me for going into the same filthy well again.Yes these two youngsters who not only uplifted the whole humanity onto their shoulders but pointed us the real world of technology.We who spend handsome amount of time in a day among technology feel proud of these two brothers of us.But watch again we are missing a fellow Indian in the process,yes IIT Kanpur graduate Stanford university professor Mr. Rajeev Motwani the chief advisor to Google and pretty much a friend philosopher and guide to Brin and Page.
To much dose in one day!!Ok digest this first....further discussion will continue later..tataz folks