private static int parseInt(String key) { try { return Integer.parseInt(key); } catch (NumberFormatException e) { throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot address an item in an array with a non-integer key ''{0}''", key ); } } }
/** * Constructor. * * @param cause The cause of this exception. * @param status HTTP status code. * @param message The {@link MessageFormat}-style message. * @param args Optional {@link MessageFormat}-style arguments. */ public PojoRestException(Throwable cause, int status, String message, Object... args) { super(cause, getMessage(cause, message, null), args); this.status = status; }
@Override /* RestConverter */ @SuppressWarnings({"rawtypes", "unchecked"}) public Object convert(RestRequest req, Object o, ClassMeta cm) throws RestException { if (o == null) return null; if (req.getPathRemainder() != null) { try { if (cm.getPojoSwap() != null) o = cm.getPojoSwap().swap(o, req.getBeanContext()); PojoRest p = new PojoRest(o, req.getReaderParser()); o = p.get(req.getPathRemainder()); } catch (SerializeException e) { throw new RestException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e); } catch (PojoRestException e) { throw new RestException(e.getStatus(), e); } } return o; } }
@Test public void testRootLocked() throws Exception { PojoRest model = new PojoRest(new AddressBook()).setRootLocked(); try { model.put("", new AddressBook()); fail(); } catch (PojoRestException e) { assertEquals("Cannot overwrite root object", e.getLocalizedMessage()); } try { model.put(null, new AddressBook()); fail(); } catch (PojoRestException e) { assertEquals("Cannot overwrite root object", e.getLocalizedMessage()); } try { model.put("/", new AddressBook()); fail(); } catch (PojoRestException e) { assertEquals("Cannot overwrite root object", e.getLocalizedMessage()); } }
@Override /* RestConverter */ @SuppressWarnings({"rawtypes", "unchecked"}) public Object convert(RestRequest req, Object o) throws RestException, InternalServerError { if (o == null) return null; String pathRemainder = req.getPathMatch().getRemainder(); if (pathRemainder != null) { try { BeanSession bs = req.getBeanSession(); PojoSwap swap = bs.getClassMetaForObject(o).getPojoSwap(bs); if (swap != null) o = swap.swap(bs, o); PojoRest p = new PojoRest(o, req.getBody().getReaderParser()); o = p.get(pathRemainder); } catch (PojoRestException e) { throw new RestException(e, e.getStatus()); } catch (Exception e) { throw new InternalServerError(e); } } return o; } }
private static int parseInt(String key) { try { return Integer.parseInt(key); } catch (NumberFormatException e) { throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot address an item in an array with a non-integer key ''{0}''", key ); } } }
@Override /* RestConverter */ @SuppressWarnings({"rawtypes", "unchecked"}) public Object convert(RestRequest req, Object o) throws RestException, InternalServerError { if (o == null) return null; String pathRemainder = req.getPathMatch().getRemainder(); if (pathRemainder != null) { try { BeanSession bs = req.getBeanSession(); PojoSwap swap = bs.getClassMetaForObject(o).getPojoSwap(bs); if (swap != null) o = swap.swap(bs, o); PojoRest p = new PojoRest(o, req.getBody().getReaderParser()); o = p.get(pathRemainder); } catch (PojoRestException e) { throw new RestException(e, e.getStatus()); } catch (Exception e) { throw new InternalServerError(e); } } return o; } }
/** * Constructor. * * @param cause The cause of this exception. * @param status HTTP status code. * @param message The {@link MessageFormat}-style message. * @param args Optional {@link MessageFormat}-style arguments. */ public PojoRestException(Throwable cause, int status, String message, Object... args) { super(cause, getMessage(cause, message, null), args); this.status = status; }
private static int parseInt(String key) { try { return Integer.parseInt(key); } catch (NumberFormatException e) { throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot address an item in an array with a non-integer key ''{0}''", key ); } } }
@Override /* RestConverter */ @SuppressWarnings({"rawtypes", "unchecked"}) public Object convert(RestRequest req, Object o) throws RestException, InternalServerError { if (o == null) return null; String pathRemainder = req.getPathMatch().getRemainder(); if (pathRemainder != null) { try { BeanSession bs = req.getBeanSession(); PojoSwap swap = bs.getClassMetaForObject(o).getPojoSwap(bs); if (swap != null) o = swap.swap(bs, o); PojoRest p = new PojoRest(o, req.getBody().getReaderParser()); o = p.get(pathRemainder); } catch (PojoRestException e) { throw new RestException(e, e.getStatus()); } catch (Exception e) { throw new InternalServerError(e); } } return o; } }
/** * Constructor. * * @param cause The cause of this exception. * @param status HTTP status code. * @param message The {@link MessageFormat}-style message. * @param args Optional {@link MessageFormat}-style arguments. */ public PojoRestException(Throwable cause, int status, String message, Object... args) { super(cause, getMessage(cause, message, null), args); this.status = status; }
BeanPropertyMeta pMeta = m.getPropertyMeta(parentKey); if (pMeta == null) throw new PojoRestException(HTTP_BAD_REQUEST, "Unknown property ''{0}'' encountered while trying to parse into class ''{1}''", parentKey, m.getClassMeta()
if (url.length() == 0) { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; root = new JsonNode(null, null, val, session.object()); throw new PojoRestException(HTTP_NOT_FOUND, "Node at URL ''{0}'' not found.", parentUrl); ClassMeta cm = n.cm; Object o = n.o; throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' with parent node type ''{1}''", url, pct); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' whose parent is of type ''{1}''", url, cm); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' of type ''{1}''", url, cm); throw new PojoRestException(HTTP_NOT_FOUND, "Node at URL ''{0}'' not found.", url); ClassMeta cm = n.cm; Object o = n.o; throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' with parent node type ''{1}''", url, pct); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' of type ''{1}''", url, cm); if (url.length() == 0) { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; root = new JsonNode(null, null, null, session.object());
if (url.length() == 0) { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; root = new JsonNode(null, null, val, session.object()); throw new PojoRestException(HTTP_NOT_FOUND, "Node at URL ''{0}'' not found.", parentUrl); ClassMeta cm = n.cm; Object o = n.o; throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' with parent node type ''{1}''", url, pct); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' whose parent is of type ''{1}''", url, cm); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' of type ''{1}''", url, cm); throw new PojoRestException(HTTP_NOT_FOUND, "Node at URL ''{0}'' not found.", url); ClassMeta cm = n.cm; Object o = n.o; throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' with parent node type ''{1}''", url, pct); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' of type ''{1}''", url, cm); if (url.length() == 0) { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; root = new JsonNode(null, null, null, session.object());
if (url.length() == 0) { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; root = new JsonNode(null, null, val, session.object()); throw new PojoRestException(HTTP_NOT_FOUND, "Node at URL ''{0}'' not found.", parentUrl); ClassMeta cm = n.cm; Object o = n.o; throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' with parent node type ''{1}''", url, pct); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform PUT on ''{0}'' whose parent is of type ''{1}''", url, cm); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' of type ''{1}''", url, cm); throw new PojoRestException(HTTP_NOT_FOUND, "Node at URL ''{0}'' not found.", url); ClassMeta cm = n.cm; Object o = n.o; throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' with parent node type ''{1}''", url, pct); throw new PojoRestException(HTTP_BAD_REQUEST, "Cannot perform POST on ''{0}'' of type ''{1}''", url, cm); if (url.length() == 0) { if (rootLocked) throw new PojoRestException(HTTP_FORBIDDEN, "Cannot overwrite root object"); Object o = root.o; root = new JsonNode(null, null, null, session.object());
BeanPropertyMeta pMeta = m.getPropertyMeta(parentKey); if (pMeta == null) throw new PojoRestException(HTTP_BAD_REQUEST, "Unknown property ''{0}'' encountered while trying to parse into class ''{1}''", parentKey, m.getClassMeta()
BeanPropertyMeta pMeta = m.getPropertyMeta(parentKey); if (pMeta == null) throw new PojoRestException(HTTP_BAD_REQUEST, "Unknown property ''{0}'' encountered while trying to parse into class ''{1}''", parentKey, m.getClassMeta()