gwt 2.5 与 Jersey 1.17 和 RestyGWT 1.3
当我打电话时
我收到以下错误:
无法解析响应:org.fusesource.restygwt.client.ResponseFormatException:响应不是有效的 JSON 文档
我的资源类:
@Path("/person")
public class PersonResource {
private static int counter = 1;
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/hello")
public String sayHello(){
return "Hallo, Seryoga";
}
@GET
@Produces(MediaType.APPLICATION_JSON)
public Person getPersons() {
List<Person> persons = new ArrayList<Person>();
for (int i = 0; i < 5; i++) {
persons.add(new Person(counter, "name-" + counter, new Date()));
counter++;
}
return persons.get(0);
}
}
客户端界面
public interface PersonResourceAsync extends RestService {
@GET
void getPersons(MethodCallback<Person> callback);
/**
* Utility class to get the instance of the Rest Service
*/
public static final class Util {
private static PersonResourceAsync instance;
public static final PersonResourceAsync get() {
if (instance == null) {
instance = GWT.create(PersonResourceAsync.class);
((RestServiceProxy) instance).setResource(new Resource(
GWT.getHostPageBaseURL()+"rest/person"));
}
return instance;
}
private Util() {
}
}
}
person 类有一些用于 id 名称的 getter/setter 等是可序列化的并且 @XmlRootElement
我的 web.xml 包含:
<servlet>
<servlet-name>RestServlet</servlet-name>
<display-name>Rest Servlet</display-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>digitronic.ems.server.filebrowser</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
在 projekt.gwt.xml 中:
<!-- RestyGWT -->
<inherits name='org.fusesource.restygwt.RestyGWT' />
当我通过 http:/localhost:8080/Projekt/rest/person 调用它时,我得到了 json 语法中的值,但是通过 restygwt 我调用了 onError,我不知道为什么。
有人能帮我吗?