Bad Request while Submitting to JAX-RS Web Service
mprk Jun 9, 2014 9:54 AMI have an web service for creating database objects. I defined the EndPoint and run it in Errai 2.4.4.Final on JBoss 7.
The create method will return the new URI for the created object.
@Path("/incidents")
public interface IncidentEndpoint {
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_HTML)
public Response create(IncidentDTO dto);
@PUT
@Path("/{id:[0-9][0-9]*}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response update(@PathParam("id") Long id, IncidentDTO dto);
@DELETE
@Path("/{id:[0-9][0-9]*}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response delete(@PathParam("id") Long id);
@GET
@Path("/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response retrieveById(@PathParam("id") long id);
}
The DTO object is defined as follows:
@Portable
@Bindable
public class IncidentDTO implements Serializable, Photographable, MetaLabels {
private static final long serialVersionUID = 6907135906859327227L;
String id = "-1";
String iconUrl = "";
String title = "";
String unit = "";
String description = "";
String itemDate = "";
String location = "";
List<String> photos = new ArrayList<String>();
List<String> thumbnails = new ArrayList<String>();
String created = "";
String createdBy = "";
String lastUpdated = "";
String lastUpdatedBy = "";
double latitude = 0d;
double longitude = 0d;
String securityKey = "";
public IncidentDTO(@MapsTo("id") String id,
@MapsTo("title") String title,
@MapsTo("unit") String unit,
@MapsTo("description") String description,
@MapsTo("itemDate") String itemDate,
@MapsTo("location") String location,
@MapsTo("latitude") double latitude,
@MapsTo("longitude") double longitude,
@MapsTo("securityKey") String securityKey,
@MapsTo("created") String created, //All read-only properties here and below.
@MapsTo("createdBy") String createdBy,
@MapsTo("iconUrl") String iconUrl,
@MapsTo("lastUpdated") String lastUpdated,
@MapsTo("lastUpdatedBy") String lastUpdatedBy,
@MapsTo("photos") ArrayList<String> photos,
@MapsTo("thumbnails") ArrayList<String> thumbnails ){
this.id = id;
this.title = title;
this.unit = unit;
this.description = description;
this.itemDate = itemDate;
this.location = location;
this.latitude = latitude;
this.longitude = longitude;
this.securityKey = securityKey;
}
public IncidentDTO( String id,
String title,
String unit,
String description,
String itemDate,
String location,
double latitude,
double longitude,
String created,
String createdBy,
String lastUpdated,
String lastUpdatedBy,
List<String> photos,
List<String> thumbnails,
String securityKey ){
this.id = id;
this.title = title;
this.unit = unit;
this.description = description;
this.itemDate = itemDate;
this.location = location;
this.latitude = latitude;
this.longitude = longitude;
this.created = created;
this.createdBy = createdBy;
this.lastUpdated = lastUpdated;
this.lastUpdatedBy = lastUpdatedBy;
this.photos = photos;
this.thumbnails = thumbnails;
this.securityKey = securityKey;
}
public IncidentDTO(){
}
public String getId() {
return id;
}
public String getIconUrl() {
return iconUrl;
}
public String getTitle() {
return title;
}
public void setId(String id) {
this.id = id;
}
public void setIconUrl(String iconUrl) {
this.iconUrl = iconUrl;
}
public void setTitle(String title) {
this.title = title;
}
public void setUnit(String unit) {
this.unit = unit;
}
public void setDescription(String description) {
this.description = description;
}
public void setItemDate(String itemDate) {
this.itemDate = itemDate;
}
public void setLocation(String location) {
this.location = location;
}
public void setPhotos(List<String> photos) {
this.photos = photos;
}
public void setThumbnails(List<String> thumbnails) {
this.thumbnails = thumbnails;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public void setSecurityKey(String securityKey) {
this.securityKey = securityKey;
}
public String getUnit() {
return unit;
}
public String getDescription() {
return description;
}
public String getItemDate() {
return itemDate;
}
public String getLocation() {
return location;
}
public List<String> getPhotos() {
return photos;
}
public List<String> getThumbnails(){
return thumbnails;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
public String getSecurityKey(){
return securityKey;
}
@Override
public String getCreatedBy() {
return createdBy;
}
public void setCreated(String created) {
this.created = created;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public void setLastUpdated(String lastUpdated) {
this.lastUpdated = lastUpdated;
}
public void setLastUpdatedBy(String lastUpdatedBy) {
this.lastUpdatedBy = lastUpdatedBy;
}
@Override
public String getCreated() {
return created;
}
@Override
public String getLastUpdatedBy() {
return lastUpdatedBy;
}
@Override
public String getLastUpdated() {
return lastUpdated;
}
I make the remote call as follows:
@Dependent
public class IncidentFullInfoPopup extends DialogBox {
@Model DataBinder<IncidentDTO> databinder;
IncidentDTO model;
@Inject Caller<IncidentEndpoint> incidentService;
.<<<<.... Code Omitted......>>>>
@UiHandler("saveButton")
public void onSaveButtonClick(ClickEvent event) {
IncidentDTO dto = databinder.getModel();
dto.setSecurityKey("parkerm");
if ( incidentService == null ){
GWT.log("IncidentService is null");
}
GWT.log("Incident id: " + dto.getId() );
if ( dto.getId() != null && !dto.getId().equalsIgnoreCase("-1") ){
GWT.log("Calling incident update service...");
incidentService.call( new RemoteCallback<IncidentDTO>() {
@Override
public void callback(IncidentDTO dto) {
GWT.log("Incident updated " + dto.getId() );
hide();
}
}, new ErrorCallback<String>() {
@Override
public boolean error(String message, Throwable throwable) {
GWT.log("Error Upating Message: " + throwable.getMessage() );
throwable.printStackTrace();
return false;
}
}).update( new Long( dto.getId() ), dto );
} else {
GWT.log("Calling incident service..");
incidentService.call( new RemoteCallback<String>() {
@Override
public void callback(String url) {
GWT.log("Incident created. " + url );
hide();
}
}, new ErrorCallback<String>() {
@Override
public boolean error(String text, Throwable throwable) {
GWT.log("Error Creating Message: " + throwable.getMessage() );
throwable.printStackTrace();
return false;
}
}).create( dto );
}
}
I keep getting the following BadRequest error everytime I submit data:
[INFO] 09:29:34,514 INFO [com.gxm.servo.server.IncidentEndpointImpl] (http--127.0.0.1-8080-2) Incident created called...
[ERROR] org.jboss.errai.enterprise.client.jaxrs.api.ResponseException: Bad Request
[ERROR] at org.jboss.errai.enterprise.client.jaxrs.AbstractJaxrsProxy$1.onResponseReceived(AbstractJaxrsProxy.java:133)
[ERROR] at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
[ERROR] at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
[ERROR] at sun.reflect.GeneratedMethodAccessor242.invoke(Unknown Source)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:606)
[ERROR] at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
[ERROR] at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
[ERROR] at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
[ERROR] at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
[ERROR] at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
[ERROR] at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
[ERROR] at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
[ERROR] at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
[ERROR] at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
[ERROR] at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
[ERROR] at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
[ERROR] at sun.reflect.GeneratedMethodAccessor236.invoke(Unknown Source)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:606)
[ERROR] at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
[ERROR] at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
[ERROR] at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
[ERROR] at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
[ERROR] at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
[ERROR] at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
[ERROR] at java.lang.Thread.run(Thread.java:744)