return new PojoIntrospector(get(url), parser).invokeMethod(method, args);
return new PojoIntrospector(get(url), parser).invokeMethod(method, args);
return new PojoIntrospector(get(url), parser).invokeMethod(method, args);
@Override /* RestConverter */ @SuppressWarnings({"unchecked", "rawtypes"}) public Object convert(RestRequest req, Object o, ClassMeta cm) throws RestException { String method = req.getQueryParameter("invokeMethod"); String args = req.getQueryParameter("invokeArgs"); if (method == null) return o; try { if (cm.getPojoSwap() != null) o = cm.getPojoSwap().swap(o, req.getBeanContext()); return new PojoIntrospector(o, JsonParser.DEFAULT).invokeMethod(method, args); } catch (Exception e) { e.printStackTrace(); return new RestException(SC_INTERNAL_SERVER_ERROR, "Error occurred trying to invoke method: {0}", e.getLocalizedMessage() ).initCause(e); } } }
@Test public void testBasic() throws Exception { String in = null; Object r; r = new PojoIntrospector(in, null).invokeMethod("substring(int,int)", "[3,6]"); assertNull(r); in = "foobar"; r = new PojoIntrospector(in).invokeMethod("substring(int,int)", "[3,6]"); assertEquals("bar", r); r = new PojoIntrospector(in).invokeMethod("toString", null); assertEquals("foobar", r); r = new PojoIntrospector(in).invokeMethod("toString", ""); assertEquals("foobar", r); r = new PojoIntrospector(in).invokeMethod("toString", "[]"); assertEquals("foobar", r); try { new PojoIntrospector(in).invokeMethod("noSuchMethod", "[3,6]"); fail(); } catch (NoSuchMethodException e) {} r = new PojoIntrospector(null).invokeMethod(String.class.getMethod("toString"), null); assertNull(r); r = new PojoIntrospector("foobar").invokeMethod(String.class.getMethod("toString"), null); assertEquals("foobar", r); } }
@Override /* RestConverter */ @SuppressWarnings({"unchecked", "rawtypes"}) public Object convert(RestRequest req, Object o) throws InternalServerError { String method = req.getQuery().getString("invokeMethod"); String args = req.getQuery().getString("invokeArgs"); if (method == null) return o; try { BeanSession bs = req.getBeanSession(); PojoSwap swap = bs.getClassMetaForObject(o).getPojoSwap(bs); if (swap != null) o = swap.swap(bs, o); return new PojoIntrospector(o, JsonParser.DEFAULT).invokeMethod(method, args); } catch (Exception e) { return new InternalServerError(e, "Error occurred trying to invoke method: {0}", e.getLocalizedMessage() ); } } }
@Override /* RestConverter */ @SuppressWarnings({"unchecked", "rawtypes"}) public Object convert(RestRequest req, Object o) throws InternalServerError { String method = req.getQuery().getString("invokeMethod"); String args = req.getQuery().getString("invokeArgs"); if (method == null) return o; try { BeanSession bs = req.getBeanSession(); PojoSwap swap = bs.getClassMetaForObject(o).getPojoSwap(bs); if (swap != null) o = swap.swap(bs, o); return new PojoIntrospector(o, JsonParser.DEFAULT).invokeMethod(method, args); } catch (Exception e) { return new InternalServerError(e, "Error occurred trying to invoke method: {0}", e.getLocalizedMessage() ); } } }
@Override /* RestConverter */ @SuppressWarnings({"unchecked", "rawtypes"}) public Object convert(RestRequest req, Object o) throws InternalServerError { String method = req.getQuery().getString("invokeMethod"); String args = req.getQuery().getString("invokeArgs"); if (method == null) return o; try { BeanSession bs = req.getBeanSession(); PojoSwap swap = bs.getClassMetaForObject(o).getPojoSwap(bs); if (swap != null) o = swap.swap(bs, o); return new PojoIntrospector(o, JsonParser.DEFAULT).invokeMethod(method, args); } catch (Exception e) { return new InternalServerError(e, "Error occurred trying to invoke method: {0}", e.getLocalizedMessage() ); } } }
@Test public void testInvokeMethod() throws Exception { F t5 = new F(); ReaderParser p = JsonParser.DEFAULT; BeanMap m = session.toBeanMap(t5); new PojoIntrospector(t5, p).invokeMethod("doSetAProperty(java.lang.String)", "['baz']"); assertEquals("baz", m.get("prop")); }