Fulworx - RESTful接口实现


Apache
跨平台
Java

软件简介

Fulworx 通过一个简单的 Annotations 为 XWork 框架的
Action 增加了输出 RESTful 接口的功能,如下代码所示:

@URITemplate(uri=”/someURI/user/{lastname}/{firstname}”)
@Accessor(“user”)
public class UserAction implements CreateAction, ReadAction
{
private User user;
private String firstname;
private String lastname;
private UserService userService;

public UserAction(UserService service){
this.userService=service;
}

public String create()
{
user = this.userService.create(firstname,
lastname,
user.getEmail(),
user.getPhone());
if(user == null){
//if user isn’t found, insert firstname and lastname into
//resource bundle message, and return a 404 status code
throw new ApplicationException(
new BundledErrorDetail(“user.error.notfound”,
ResourceBundle.getBundle(“ErrorMessages”),
new Object[]{firstname, lastname}),
404);
}
return SUCCESS;
}

public String read()
{
user = this.userService.read(firstname, lastname);
return SUCCESS;
}

public User getUser()
{
return user;
}

public void setUser(User user)
{
this.user = user;
}
//also, getter / setter for firstname, lastname
}