WebServices Part 1 - Introduction (concept)
WebServices Part 3 - RESTful (concept)
Uniform Interface
access directly to the URL to the resource
self descriptive message
Web Services Part 5 - How to create RESTful Web Services (Hands
jersey.java.net to download the jersey
copy the content int he zipped jersey folder to the web-inf/lib
@Path("university") which could be accessed by the client
modify the web.xml file
<servlet-name>jersey REST Service
<servlet-class>com.sun.jersey.spi.container,servlet.ServletContainer
<param-name>servlet-class com.sun.jersey.config.property.packages
<param-value>com.infor.university
<servlet-name>jersey REST Service
<url-pattern>/rest/* --it is the url pattern used to build URI
Web Services Part 7 - How to test RESTful Web Services (Hands on
restclient-ui tool from code.google.com
Web Services Part 8 - @PathParam annotation in RESTful Web Services
parameters are seperated from each other using a forward slash "/"
Parameters appear in the end of the http url
@GET
@Path("{studentnum1}/{studentnum2}")
@produce(MediaType.TEXT_PLAIN)
public String getStudentInfo(@PathParam("studentnum1") String stunum1,
@PathParam("studentnum2") String stunum2)
{}
Web Services Part 9 - @QueryParam annotation in RESTful Web
?stunum=1&stunum2=45 which is query parameter;
@GET
@Path("{studentnum1}/{studentnum2}")
public String getStudentInfo(@QueryParam("studentnum1") String stunum1,
@QueryParam("studentnum2") String stunum2)
{}
Web Services Part 10 - @MatrixParam annotation in RESTful Web
matrix parameters in the http url
one parameter is seperated from other using the ';' symbol;
Parameters may apperar anywhere in the path
/rest/university/department;uniName=IndianUniversity;depatname=phtsics
@GET
@produce(MediaType.TEXT_PLAIN)
public String getStudentInfo(@MatrixParam("studentnum1") String stunum1,
@MatrixParam("studentnum2") String stunum2)
{}
Web Services Part 11 - @FormParam annotation in RESTful Web
@Path("/university")
public class UniversityRESTWS {
@POST
@Path("/add")
public String addStudentInfo(
@FormParam("name") String name,
@FormParam("age") int age
)
{
}
}
<form action="http://localhost:7001/RESTfulWM/rest/university/add" method="post">
Web Services Part 12 - How to Download a file from a RESTful Web
//In this way, the additional information could be sent to customer;
@GET
@Path("/get")
@produce(text/plain)/(application/pdf)
public Response getStudentFile(){
File file=new File("d:\\demo.txt");
ResponseBuilder response= Resonse.ok((Object) file);
response.header("content-Disposition", "attachement; filename=Displayname-DemoFile.txt")
return response.build();
}
//this will simply and directly send the file to the client;
@GET
@Path("/get")
@produce(text/plain)/(application/pdf)
public File getStudentFile(){
File file=new File("d:\\demo.txt");
return file;
}
Web Services Part 13 - How to Upload a file to a RESTful Web Service
public class UniversityRESTWS {
@POST
@Path("/upload")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String uploadFile(
@FormDataParam("file") InputStream name,
@FormDataParam("file") FormDataContentDisposition fileDetail
)
{
saveToDisk(uploadedInputStream, fileDetail);
return "File uploaded successfully!!"
}
}
private void saveToDisk(InputStream name, FormDataContentDisposition fileDetail)
{
String uploadedFileLocation = "d://upload/" + fileDetail.getFileName();
try
{
OUtputStream out = new FileOutputStream(new File(uploadedFileLocation))
int read = 0;
byte[] bytes = new byte[1024];
out = new FileOutputStream(new File(uploadedFileLocation))));
while ((read = uploadedInputStream.read(bytes)) != -1
{
out.write(bytes,0,read);
}
out.flush();
out.close();
}
} catch (IOException e){
e.printStackTrace();
}