Sunday, March 22, 2015

Rest WebService Theory

To understand Rest - Lets see first -

What is Webservice?
If you Refer Wiki Page -"A Web service is a method of communication between two electronic devices over a network"

Let's understand it with this analogy -

  • Suppose you have created an awesome functionally to retrieve employee details -(using getEmpDetails() ). You can use this function to run in your application easily.  
  • Now if your friend wants to use this functionality you would give him this function but will he be able to run it ??? - No
  • He has the function but he doesn't have the DB and various other Config connection because that resides local to your system. So what you can do, now??
  • Put everything on a network and everybody can use it's functionality. This is the simplest thought to write a WebService.

In Short, This is a way so that an API can be used by everyone over Network.

There are two ways to write a WebService
  1. SOAP - Simple Object Access Protocol
  2. Rest - REpresentational State Transfer
  • Rest is a preferred way over more heavyweight SOAP 
  • Rest is an Architectural style to communicate over HTTP Protocol(not necessarily though), over standartd HTTP methods -- get, post ,put,delete

RESTful API HTTP methods
ResourceGETPUTPOSTDELETE
Collection URI, such ashttp://example.com/resources/List the URIs and perhaps other details of the collection's members.Replace the entire collection with another collection.Create a new entry in the collection. The new entry's URI is assigned automatically and is usually returned by the operation.[9]Delete the entire collection.
Element URI, such ashttp://example.com/resources/item17Retrieve a representation of the addressed member of the collection, expressed in an appropriate Internet media type.Replace the addressed member of the collection, or if it doesn't exist,create it.Not generally used. Treat the addressed member as a collection in its own right and create a new entry in it.[9]Delete the addressed member of the collection.


Tuesday, March 17, 2015

A simple Rest Web Service using basic JAX-RS notations in Maven

I am just trying to jot down some very basic steps to stand up a simple Rest WebService.
WebService in Today's world play a very vital role in Web Aplication'zs world.

To understand theory behind Rest , please refer my other blog.


1.)  Create a new Maven Project

               Archetype : maven-archetype-webapp

2.) pom.xml content : Add dependencies for Spring core,web & web-mvc and Apache CXF



3.)  web.xml --

  • It needs to have a Servlet for Apache CXF , we can also use Jersey libraries instead
  • context param us defined to laod beans.xml which contains endpoint for our webservice


3.)  Let's jump to beans.xml where in we define our endpoint reference bean for the "Jaxrs" , you may also jump to step 4 and then implement this step.


4.) Lets Create the UserEndPoint which would have the actual business logic -



And we are ready just build it and deploy it in your web-server(Tomcat)

Execute the url in browser

http://localhost:8080/services/user/id





for any questions write me at jsapan4@gmail.com


     

Sunday, March 15, 2015

RSA SSH Keys using PuttyGen

As a Developer you  need to generate SSH Keys to talk to your Repositories on a Server.

In short, a public key is stored on the Repository server and a private key is stored on your local workstation. 
I have tried to gather few steps below to generate SSH keys below, in further posts i'd include how to clone Repositories from Git Server with the help of SSH keys

Steps:

1.)Download PuttyGen from the below link :

2.) Open PuttyGen

3,) Click on Generate


4.) Keep moving your mouse in the blank space until the progress bar completes, in that  way PuttyGen knows you are human, lame :)

x

5.) And your keys are Geneated  , boy that was easy :D

6.)You can copy the keys from the above area and paste it your Stash or Github server for further use .This will be your public key generated

7.) Save and store Private key  to a Folder for future usage .



8.) Go to File and Exit PuttyGen

Now you can use this SSH keys to talk to your Server, Remember while cloning you need to paste correct keys to server in case there are multiple keys on local

Conclusion :

Private Keys is at your local machine and public key copied to Server and that how they connect making public -private key pair