我在使用我的应用程序运行 Errai-jaxrs 时遇到了相当大的问题我从 GWT 开发模式收到此错误:
org.jboss.errai.enterprise.client.jaxrs.api.ResponseException: Bad Request
at org.jboss.errai.enterprise.client.jaxrs.AbstractJaxrsProxy$1.onResponseReceived(AbstractJaxrsProxy.java:132)
at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:287)
at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:395)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:474)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:337)
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:218)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:561)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:269)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:213)
at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:474)
at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:292)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:546)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Thread.java:722)
在服务器端:
[INFO] Caused by: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "^EncodedType" (Class com.mycompany.client.shared.Customer), not marked as ignorable
[INFO] at [Source: org.mortbay.jetty.HttpParser$Input@115194d; line: 1, column: 18] (through reference chain: com.mycompany.client.shared.Customer["^EncodedType"])
[INFO] at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
[INFO] at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
[INFO] at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
[INFO] at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
[INFO] at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
[INFO] at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
[INFO] at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
[INFO] at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
[INFO] at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
从堆栈跟踪来看,它看起来像是一个错误请求。这个后端是 RestEasy + Guice,它的配置非常正确,因为在我尝试使用 erai-jaxrs 之前,我只是使用普通的 GWT RequestBuilder,它工作得很好。我不确定问题出在哪里,但这是我的代码:
客户服务.java
@Path("/customerservice")
public interface CustomerService {
@GET
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Customer getCustomer(String id);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String createCustomer(Customer Customer);
}
CustomerServiceImpl.java
@Singleton
public class CustomerServiceImpl implements CustomerService {
@Override
public Customer getCustomer(String id) {
return new Customer();
}
@Override
public String createCustomer(Customer Customer) {
return "1";
}
}
在客户端:
@Inject
private Caller<CustomerService> customerService;
@EventHandler("submit")
public void createCustomer(ClickEvent event) {
event.preventDefault();
Customer customer = new Customer();
customerService.call(new RemoteCallback<String>() {
@Override
public void callback(String response) {
Window.alert("Customer created: " + response);
}
}).createCustomer(customer);
}
可能是什么问题呢?