我正在尝试从GWTP演示者处获取REST服务的响应。我的securityDelegate触发onSuccess方法,但UserDTO似乎是空的。网络工具向我显示HTTP代码200的请求和当前用户的响应。出于某种原因,UserDTO似乎是空的。
LOGGER告诉我
CLASS:xx.xxxx.xxx.web.shared.dto.UserDTO@1f
名称:未定义
//LoginPresenter.java
securityDelegate.withCallback(new AsyncCallback<UserDTO>() {
@Override
public void onFailure(Throwable throwable) {
Window.alert("fail");
}
@Override
public void onSuccess(UserDTO user) {
LOGGER.info("CLASS:"+user.toString());
LOGGER.info("Name:"+user.getName());
}
}).authenticate(username,password);
//SecurityResource.java
@Path("/security")
@Produces (MediaType.APPLICATION_JSON)
@Consumes (MediaType.APPLICATION_JSON)
public interface SecurityResource {
@POST
@Path ("/authenticate")
RestAction<UserDTO> authenticate(@HeaderParam ("username") String username,@HeaderParam("password") String password);
}
//SecurityResourceImpl.java
@Path ("/security")
@Produces(MediaType.APPLICATION_JSON)
@Consumes (MediaType.APPLICATION_JSON)
public class SecurityResourceImpl {
@EJB
private SecurityBean securityBean;
@POST
@Path("/authenticate")
@Override
public Response authenticate(@HeaderParam ("username")
String username, @HeaderParam("password") String password){
User currentUser = securityBean.find(username,password);
return Response.ok().entity(new UserDTO(currentUser)).build();
}
}
//UserDTO.java
public class UserDTO implements Serializable {
private String name;
public UserDTO(){
}
public UserDTO(User user){...}
//getters/setters
}
答案 0 :(得分:0)
我的不好,我忘了定义二传手!我将UserDTO定义为构建器模式。