CXF Related Knowledge collation

Source: Internet
Author: User

① Request mode is get

  @GET       = "/useraddressmanage")    "text/html; Charset=utf-8 " })    public  buyeraddressresponsemodel useraddressmanage (              @QueryParam ("Buyertel") string Buyertel,              @QueryParam("detailaddress") string Detailaddress);

The way to get parameter data corresponding to the POST request method is: @QueryParam

② Request Mode is post

By using get to submit data, the length of the parameter is limited, and when the length of the data exceeds the limit, the request fails.

In this case, the POST request has to be used.

        @POST= "/addorder")    "text/html; charset=utf-8" })      Public Orderresponsemodel AddOrder (            @FormParam("OrderInfo") String OrderInfo,             @FormParam("orderdetailslist") String orderdetailslist,            @FormParam(" AddressInfo ") String AddressInfo);

The way to get parameter data corresponding to the POST request method is: @ Formparam

③CXF Related annotation Finishing

1) @WebService and @WebMethod are WSDL mapping annatotion. The WSDL document element that describes the Web Service is associated with the Java source code.

2) @WebParam used to get request parameters

3) @WebResult used to define the return value

4) @SOAPBinding is a binding annotation used to illustrate network protocols and formats.

Use annotation to define the webservice

Importjava.util.List;ImportJavax.jws.WebMethod;ImportJavax.jws.WebParam;ImportJavax.jws.WebResult;ImportJavax.jws.WebService;ImportCom.cxf.pojo.User; @WebService (targetnamespace= "Http://jdk.study.hermit.org/client") Public InterfaceUserService {@WebMethod (OperationName= "Insert")     Public voidInsert
@WebParam (name = "UserId") String userid, @WebParam (name= "UserName") String username, @WebParam (name= "UserEmail") String UserEmail, @WebParam (name= "Userage")intuserage); @WebMethod (OperationName= "Getuserbyid") @WebResult (name= "Result") PublicUser Getuserbyid (@WebParam (name = "UserID")) String userid); @WebMethod (OperationName= "GetAllUsers") @WebResult (name= "Result") PublicList getAllUsers ();}

The implementation classes are as follows:

Importjava.util.List;ImportJavax.jws.WebService;ImportCom.cxf.dao.UserDao;ImportCom.cxf.pojo.User;ImportCom.cxf.service.UserService; @WebService (Endpointinterface= "Com.cxf.service.UserService" )  PublicclassUserserviceimplImplementsUserService {PrivateUserdao Userdao;  PublicList getAllUsers () {returnUserdao. Findalluser ();}  PublicUser Getuserbyid (String userid) {returnUserdao. Finduserbyid (userid);  PublicvoidInsert (string userid, String username, String useremail,intuserage) {User User=NewUser ();     User.setuserage (Userage);     User.setuseremail (UserEmail);     User.setuserid (userid);     User.setusername (username);     Userdao. Insert (user); System. Out. println ("Insert successfully!" ); } Public   voidSetuserdao (Userdao Userdao) { This. Userdao =Userdao; } }
Note: The @webservice in the implementation class, where the Endpointinterface member specifies the interface that the class implements

Below is a description of restful under SPRINGMVC

  
@Path  defines the resource base URI. consists of upper and lower root and host names, resource identifiers similar to http://Localhost:8080/restful/rest/hello used on classes and methods
@GET This means that the following methods can respond to the HTTP GET method
@Produces to define the response content MIME type in plain text

@FormParam receive the parameters submitted by the Post method
@QueryParam receive parameters submitted by the Get method
@Consumes declares that the method uses HTML FORM
@Produces ({mediatype.application_json, "text/html; Charset=utf-8 "})

Defining the Rest Interface service

 Packagedemo.ws.rest_cxf;Importjava.util.List;ImportJava.util.Map;ImportJavax.ws.rs.Consumes;ImportJavax.ws.rs.DELETE;ImportJavax.ws.rs.FormParam;ImportJavax.ws.rs.GET;ImportJavax.ws.rs.POST;ImportJavax.ws.rs.PUT;ImportJavax.ws.rs.Path;ImportJavax.ws.rs.PathParam;Importjavax.ws.rs.Produces;ImportJavax.ws.rs.core.MediaType; Public InterfaceProductservice {@GET @Path ("/products") @Produces (Mediatype.application_json) List<Product>retrieveallproducts (); @GET @Path ( "/product/{id}" ) @Produces (Mediatype.application_json) Product Retrieveproductbyid (@PathParam ( "id") long ID); @POST @Path ("/products") @Consumes (mediatype.application_form_urlencoded) @Produces (Mediatype.application_json) List<Product> Retrieveproductsbyname (@FormParam ("name" ) String name); @POST @Path ("/product") @Consumes (Mediatype.application_json) @Produces (Mediatype.application_json) Product createproduct (    product product); @PUT @Path ("/product/{id}") @Consumes (Mediatype.application_json) @Produces (Mediatype.application_json) Product Updateproductbyid (@Path Param ("id")LongID, map<string, object>FieldMap); @DELETE @Path ("/product/{id}") @Produces (Mediatype.application_json) Product Deleteproductbyid (@PathParam ("id")LongID);}

The above ProductService interface provides a series of methods that use the annotations provided by Jax-rs in each method, including the following three main categories:

    1. Annotation of request mode, including: @GET, @POST, @PUT, @DELETE
    2. Request path annotations, including: @Path, including a path parameter
    3. Data format annotations, including: @Consumes (Input), @Produces (output), using mediatype constants
    4. Related parameter annotations, including: @PathParam (Path parameter), @FormParam (form parameters), plus @QueryParam (Request parameters)

For updateProductById the method, simply explain:

The method is PUT:/product/{id} called, the parameter in the request path is id mapped to the long id parameter, the data in the request body is automatically converted to JSON format and mapped to the Map<String, Object> fieldMap parameter, and the returned Product type of data is automatically converted to JSON format and returned to the client.

Reference URL:

http://my.oschina.net/huangyong/blog/294324

Http://www.cnblogs.com/hoojo/archive/2012/07/23/2605219.html

CXF Related Knowledge collation

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.