Jersey builds a rest service style

Source: Internet
Author: User

Jersey builds a rest service style

Here we will first introduce how to update the list Array Using the rest post method. For details about the concept of rest, refer
Http://blog.csdn.net/lfsfxy9/article/details/9205337

Since the service is provided, there must be a service end and a cient end. Here, some classes encapsulated by the jersey framework are used to demonstrate a rest service-style server and client.

Service end

'@ POST @ Path (/updatePwd) @ Produces ({MediaType. APPLICATION_XML, MediaType. APPLICATION_JSON}) @ Consumes (application/x-www-form-urlencoded) @ SuppressWarnings ({unchecked, rawtypes}) public Response updatePwd (MultivaluedMap
  
   
> UserMap) throws ServiceException {// verify if (0. equals (userMap. size () {ServiceRevisionUtils. registerError (STATUS_ICT_ERR_PARAM, pass required parameter is null error, please confirm the parameter is required, not required, parameter length and other information .); } If (StringUtils. isEmpty (userMap. get (token ). toString () {ServiceRevisionUtils. registerError (STATUS_ICT_ERR_PARAM, pass required parameter is null error, please confirm the parameter is required, not required, parameter length and other information .); } HashMap accountPwdMap = new HashMap
   
    
(); List userList = new ArrayList
    
     
(); UserList = userMap. get (userList); for (int I = 0; I
     
    
   
  

Client

`public static void main(String[] args) {    ClientConfig cc = new DefaultClientConfig();    Client c = Client.create(cc);    MultivaluedMap form = new MultivaluedMapImpl();    form.add(token, b310e7cb766146d28caa458fc34ed62a);    List userList=new ArrayList
   
    ();          userList.add(super,1);    userList.add(XPKY01SG03,2);    form.put(userList,userList);    String baseUrl = http://localhost:8080/baseconnect/rest/fieldServiceRevision/updatePwd;    WebResource wr = c.resource(baseUrl);    String response = wr.post(String.class, form);    System.out.println(result: + response);}`
   

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.