Witam,
Stworzyłem sobie RESTowy webservice w Jersey. Generalnie WebService dziala (testowanie SoapUI). Chcialbym jednak utworzyc customowy komunikat bledu gdy np. nie mozna dokonac edycji. Domyslam sie, ze w tym celu nalezy zmodyfikowac Response.
Jak zrobic, aby do klienta zwrocic customowy komunikat np. "PODANE ID JEST JUZ UZYWANE!". To powinno byc dosc proste.
Pozdrawiam,
@Path("/item")
@Stateless
@LocalBean
@Produces("application/json")
@Consumes("application/json")
public class ItemFacadeWebImpl {
@EJB
private ItemFacadeLocal itemDao;
// rozne metody: podalem tylko jedna
@POST
@Path("edit")
public Response edit(JAXBElement<Item> t) {
Item item = t.getValue();
if (item.getItemId() != null && itemDao.itemExists(item.getItemId())) {
return Response.serverError().build();
}
if (itemDao.itemExists(item.getItemId())) {
itemDao.edit(item);
return Response.ok().build();
} else {
return Response.serverError().build();
}
}