private PojoRest getPojoRest() { if (pojoRest == null) pojoRest = new PojoRest(this); return pojoRest; }
private PojoRest getPojoRest() { if (pojoRest == null) pojoRest = new PojoRest(this); return pojoRest; }
private PojoRest getPojoRest() { if (pojoRest == null) pojoRest = new PojoRest(this); return pojoRest; }
private PojoRest getPojoRest() { if (pojoRest == null) pojoRest = new PojoRest(this); return pojoRest; }
private PojoRest getPojoRest() { if (pojoRest == null) pojoRest = new PojoRest(this); return pojoRest; }
private PojoRest getPojoRest() { if (pojoRest == null) pojoRest = new PojoRest(this); return pojoRest; }
/** * Parses the output from the connection into the specified type and then wraps that in a {@link PojoRest}. * * <p> * Useful if you want to quickly retrieve a single value from inside of a larger JSON document. * * @param innerType The class type of the POJO being wrapped. * @return The parsed output wrapped in a {@link PojoRest}. * @throws IOException If a connection error occurred. * @throws ParseException * If the input contains a syntax error or is malformed for the <code>Content-Type</code> header. */ public PojoRest getResponsePojoRest(Class<?> innerType) throws IOException, ParseException { return new PojoRest(getResponse(innerType)); }
/** * Parses the output from the connection into the specified type and then wraps that in a {@link PojoRest}. * * <p> * Useful if you want to quickly retrieve a single value from inside of a larger JSON document. * * @param innerType The class type of the POJO being wrapped. * @return The parsed output wrapped in a {@link PojoRest}. * @throws IOException If a connection error occurred. * @throws ParseException * If the input contains a syntax error or is malformed for the <code>Content-Type</code> header. */ public PojoRest getResponsePojoRest(Class<?> innerType) throws IOException, ParseException { return new PojoRest(getResponse(innerType)); }
/** * Parses the output from the connection into the specified type and then wraps that in a {@link PojoRest}. * * <p> * Useful if you want to quickly retrieve a single value from inside of a larger JSON document. * * @param innerType The class type of the POJO being wrapped. * @return The parsed output wrapped in a {@link PojoRest}. * @throws IOException If a connection error occurred. * @throws ParseException * If the input contains a syntax error or is malformed for the <code>Content-Type</code> header. */ public PojoRest getResponsePojoRest(Class<?> innerType) throws IOException, ParseException { return new PojoRest(getResponse(innerType)); }
/** * Resolves a <js>"$ref"</js> tags to nodes in this swagger document. * * @param ref The ref tag value. * @param c The class to convert the reference to. * @return The referenced node, or <jk>null</jk> if the ref was <jk>null</jk> or empty or not found. */ public <T> T findRef(String ref, Class<T> c) { if (isEmpty(ref)) return null; if (! ref.startsWith("#/")) throw new RuntimeException("Unsupported reference: '" + ref + '"'); try { return new PojoRest(this).get(ref.substring(1), c); } catch (Exception e) { throw new BeanRuntimeException(e, c, "Reference ''{0}'' could not be converted to type ''{1}''.", ref, c.getName()); } } }
private String getDeepString(ObjectMap m, String url) { PojoRest r = new PojoRest(m); return (String)r.get(url); }
private Boolean getDeepBoolean(ObjectMap m, String url) { PojoRest r = new PojoRest(m); return (Boolean)r.get(url); }
/** * [PUT /people/{id}/*] * Change property on Person bean. */ @RestMethod(name="PUT", path="/people/{id}/*", guards=AdminGuard.class ) public String updatePerson(RestRequest req, @Path int id) throws Exception { try { Person p = findPerson(id); String pathRemainder = req.getPathRemainder(); PojoRest r = new PojoRest(p); ClassMeta<?> cm = r.getClassMeta(pathRemainder); Object in = req.getBody(cm); r.put(pathRemainder, in); return "PUT successful"; } catch (Exception e) { throw new RestException(SC_BAD_REQUEST, "PUT unsuccessful").initCause(e); } }
@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 testGetPublicMethods() throws Exception { PojoRest model = new PojoRest(new AddressBook().init()); assertTrue(SimpleJsonSerializer.DEFAULT.toString(model.getPublicMethods("0")).contains("'toString'")); assertTrue(SimpleJsonSerializer.DEFAULT.toString(model.getPublicMethods("0/addresses/0/state")).contains("'toString'")); assertNull(model.getPublicMethods("1")); }
@Test public void testGetClassMeta() throws Exception { PojoRest model = new PojoRest(new AddressBook().init()); assertEquals("Person", model.getClassMeta("0").getInnerClass().getSimpleName()); assertEquals("String", model.getClassMeta("0/addresses/0/state").getInnerClass().getSimpleName()); assertNull(model.getClassMeta("1")); assertNull(model.getClassMeta("0/addresses/1/state")); } }
@Test public void testAddressBook() { PojoRest model; model = new PojoRest(new AddressBook()); // Try adding a person to the address book. Person billClinton = new Person("Bill Clinton", 65, new Address("55W. 125th Street", "New York", "NY", 10027, true) ); model.post("/", billClinton); // Make sure we get the original person back. billClinton = (Person)model.get("/0"); }
@Test public void testInvokeMethod() throws Exception { PojoRest model = new PojoRest(new AddressBook().init()); assertEquals("Person(name=Bill Clinton,age=65)", model.invokeMethod("0", "toString", "")); model = new PojoRest(new AddressBook().init(), JsonParser.DEFAULT); assertEquals("Person(name=Bill Clinton,age=65)", model.invokeMethod("0", "toString", "")); assertEquals("NY", model.invokeMethod("0/addresses/0/state", "toString", "")); assertNull(model.invokeMethod("1", "toString", "")); }
@Test public void testConstructors() throws Exception { PojoRest model = new PojoRest(new AddressBook(), JsonParser.DEFAULT); // Try adding a person to the address book. Person billClinton = new Person("Bill Clinton", 65, new Address("55W. 125th Street", "New York", "NY", 10027, true) ); model.post("/", billClinton); // Make sure we get the original person back. billClinton = (Person)model.get("/0"); }
@Test public void testGetRootObject() throws Exception { PojoRest model = new PojoRest(new AddressBook()); assertTrue(model.getRootObject() instanceof AddressBook); model.put("", "foobar"); assertTrue(model.getRootObject() instanceof String); model.put("", null); assertNull(model.getRootObject()); }