Skip to content

Five minutes quick start

itstamen edited this page Mar 2, 2012 · 39 revisions

#case descripton We need to create new account through Rop framework. #Create a rest api:

Step 1:create the rop request of create new user:

    package com.stamen.sample.rop.request;

import com.stamen.rop.RopRequest;
import org.springframework.format.annotation.NumberFormat;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Pattern;

public class CreateUserRequest extends RopRequest {

@Pattern(regexp = "\\w{4,30}")//① constraint of the field
private String userName;

@Pattern(regexp = "\\w{6,30}")//②
private String password;
 
@DecimalMin("1000.00")
@DecimalMax("100000.00")
@NumberFormat(pattern = "#,###.##")//③
private long salary;

//getter and setter...
}

The ①、② and ③ is the JSR 303 annotation,ROP use the JSR 303 to validate the request data.If the request datais invalid ,ROP will generate the standard error respone(see the ROP error system for detail).

Step 2:create rop response of create new user

package com.stamen.sample.rop;

import com.stamen.rop.RopResponse;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
@XmlAccessorType(XmlAccessType.FIELD) //①
@XmlRootElement(name = "sampleRopResponse1")
public class CreateUserResponse implements RopResponse{
	@XmlAttribute
	private String userId;
	@XmlAttribute
	private String createTime;
   //getter and setter...
}

The ① is the JAXB annotation,ROP use the JAXB to marshaller respone to corresponding format respone message.currently ROP supoort xml and json format message.

Step 3:create the rop rest service:

Clone this wiki locally