RESTful Webservices Environment Setup:
Prequistes:
1. JDK 8 installation on ubuntu:
i) sudo add-apt-repository ppa:webupdteam/java -y
ii) sudo apt-get update
iii) sudo apt-get install oracle-java8-installer
iv) Check java version : java -version
2. Nebeans installation on ubuntu:
i) Download and install Netbeans from this URL.
ii) Give Executable Permission:
$ chmod +x ~/Downloads/Netbeans-8.2-linux-*.sh
$ cd ~/Downloads && ./Netbeans-8.2-linux-*.sh
iii) After starting installer, set path JDK installation location.
i) To browse glassfish server ----> http://localhost:8080 (default server ip and port no)
ii) To browse glass fish admin --->http://localhost:4848 (default server ip and port no)
iii) To Start glassfish server;
$ cd /<installation_dir of glassfish>/bin && ./startserv
iv) To Stop glassfish server:
$cd /<installation_dir of glassfish>/bin && ./stopserv
v) To change port number and remote ip configuration :
$ gedit <installation dir of glassfish path>/server/domain.xml
ii) Give Executable Permission:
$ chmod +x ~/Downloads/Netbeans-8.2-linux-*.sh
$ cd ~/Downloads && ./Netbeans-8.2-linux-*.sh
iii) After starting installer, set path JDK installation location.
3. Download Jersey Framework (Optional):
Download from URL and add all jars in libraries.4. Glassfish server Configuration:
GlassFish Server Open Source Edition provides a server for the development and deployment of Java Platform, Enterprise Edition (Java EE platform) applications and web technologies based on Java technology.ii) To browse glass fish admin --->http://localhost:4848 (default server ip and port no)
iii) To Start glassfish server;
$ cd /<installation_dir of glassfish>/bin && ./startserv
iv) To Stop glassfish server:
$cd /<installation_dir of glassfish>/bin && ./stopserv
v) To change port number and remote ip configuration :
$ gedit <installation dir of glassfish path>/server/domain.xml
<network-listener
protocol="http-listener-" address="<Your_System_ip>"
port=”<Your_port>" name="http-listener-1"
thread-pool="http-thread-pool"
transport="tcp"></network-listener>
Create Simple Restful Application:
1. Start Netbeans ---->Choose Java Web Application
2. Give Java Web Application Name:
3. choose Glassfish Server:
4. Finally Finish.
5. Create New Java Package:
Under your Project=>sourcePackages=>right click=>New=>Java Package
6. Create New Java Class:
Under Newly created Package=>right click=>new=>java
class=> Put your sample code.
7. Develop Code:
By default a class name called "MypathResource" will be created with some methods and instance variable define in it.Delete the code and replace with the following code.
package com.test;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.PathParam;
import javax.ws.rs.Consumes;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
@Path("Mypath")
public class MypathResource {
@GET
@Produces("text/plain")
public String getText() {
return "My First RESTful Servivce....";
}
}
This is the very basic and simplest RESTful Service , it will accept the Path "MyPath" in the URL and invoke the method getText which in turn return a Response as Text with the wording "My First RESTful Servivce..."
7. Create Restful Web-services:
Under Newly created
Package=>right click=>Restful webservice patterns
8. Clean and Build
Right click your project=>clean
and Build and Deploy
9. To test
Webservice Resources:
10. It will open web browser in below url:
The Port Number and server ip depends on your server setting.
Comments
Post a Comment