WebServices Part 1


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();
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值