@Override public MeasurementPOJO _readItems(String input) throws Exception { return parser.parse(input, MeasurementPOJO.class); } }
if (o == null) return null; Object[] params = args == null ? null : p.parseArgs(args, method.getGenericParameterTypes()); return method.invoke(o, params);
@Override /* Context */ public ObjectMap asMap() { return super.asMap() .append("JsonParser", new ObjectMap()); } }
/** * Wraps the specified input object into a {@link ParserPipe} object so that it can be easily converted into * a stream or reader. * * @param input * The input. * <br>This can be any of the following types: * <ul> * <li><jk>null</jk> * <li>{@link Reader} * <li>{@link CharSequence} * <li>{@link InputStream} containing UTF-8 encoded text (or whatever the encoding specified by * {@link ReaderParser#RPARSER_inputStreamCharset}). * <li><code><jk>byte</jk>[]</code> containing UTF-8 encoded text (or whatever the encoding specified by * {@link ReaderParser#RPARSER_inputStreamCharset}). * <li>{@link File} containing system encoded text (or whatever the encoding specified by * {@link ReaderParser#RPARSER_fileCharset}). * </ul> * @return * A new {@link ParserPipe} wrapper around the specified input object. */ @SuppressWarnings("resource") @Override /* ParserSesson */ public final ParserPipe createPipe(Object input) { return setPipe(new ParserPipe(input, isDebug(), ctx.isStrict(), ctx.isAutoCloseStreams(), ctx.isUnbuffered(), getFileCharset(), getInputStreamCharset())); }
@Override /* MessageBodyReader */ public Object readFrom(Class<Object> type, Type gType, Annotation[] a, MediaType mediaType, MultivaluedMap<String,String> headers, InputStream in) throws IOException, WebApplicationException { try { String mt = parsers.findMatch(mediaType.toString()); if (mt == null) throw new WebApplicationException(SC_UNSUPPORTED_MEDIA_TYPE); Parser p = parsers.getParser(mt); BeanContext bc = p.getBeanContext(); ClassMeta<?> cm = bc.getClassMeta(gType); ObjectMap mp = getMethodProperties(a); mp.put("mediaType", mediaType.toString()); if (p.isReaderParser()) { ReaderParser p2 = (ReaderParser)p; InputStreamReader r = new InputStreamReader(in, IOUtils.UTF8); ParserSession session = p2.createSession(r, mp, null, null); return p2.parse(session, cm); } InputStreamParser p2 = (InputStreamParser)p; ParserSession session = p2.createSession(in, mp, null, null); return p2.parse(session, cm); } catch (ParseException e) { throw new IOException(e); } } }
/** * Create a new instance of a REST interface over the specified object. * * <p> * The parser is used as the bean context. * * @param o The object to be wrapped. * @param parser The parser to use for parsing arguments and converting objects to the correct data type. */ public PojoRest(Object o, ReaderParser parser) { if (parser == null) parser = JsonParser.DEFAULT; this.parser = parser; this.session = parser.createBeanSession(); this.root = new JsonNode(null, null, o, session.object()); }
/** * [POST /{javaInterface}/{javaMethod}] - Invoke the specified service method. * * @param req The HTTP request. * @param javaInterface The Java interface name. * @param javaMethod The Java method name or signature. * @return The results from invoking the specified Java method. * @throws Exception */ @RestMethod(name="POST", path="/{javaInterface}/{javaMethod}") public Object invoke(RestRequest req, @Path String javaInterface, @Path String javaMethod) throws Exception { // Find the parser. ReaderParser p = req.getReaderParser(); if (p == null) throw new RestException(SC_UNSUPPORTED_MEDIA_TYPE, "Could not find parser for media type ''{0}''", req.getMediaType()); //$NON-NLS-1$ Class<?> c = getInterfaceClass(javaInterface); // Find the service. Object service = getServiceMap().get(c); if (service == null) throw new RestException(SC_NOT_FOUND, "Service not found"); //$NON-NLS-1$ // Find the method. java.lang.reflect.Method m = getMethods(javaInterface).get(javaMethod); if (m == null) throw new RestException(SC_NOT_FOUND, "Method not found"); //$NON-NLS-1$ // Parse the args and invoke the method. ClassMeta<?>[] argTypes = p.getBeanContext().getClassMetas(m.getParameterTypes()); Object[] params = p.parseArgs(req.getReader(), argTypes); return m.invoke(service, params); }
/** * Configuration property: File charset. * * @see ReaderParser#RPARSER_fileCharset * @return * The character set to use for reading <code>Files</code> from the file system. */ protected final String getFileCharset() { return ctx.getFileCharset(); }
/** * Configuration property: Input stream charset. * * @see ReaderParser#RPARSER_inputStreamCharset * @return * The character set to use for converting <code>InputStreams</code> and byte arrays to readers. */ protected final String getInputStreamCharset() { return ctx.getInputStreamCharset(); }
/** * Constructor. * * @param ps The property store containing all the settings for this object. * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>, <js>"*​/json"</js>). */ protected ReaderParser(PropertyStore ps, String...consumes) { super(ps, consumes); inputStreamCharset = getStringProperty(RPARSER_inputStreamCharset, "UTF-8"); fileCharset = getStringProperty(RPARSER_fileCharset, "DEFAULT"); }
if (o == null) return null; Method m = p.getClassMeta(o.getClass()).getPublicMethods().get(method); if (m == null) throw new NoSuchMethodException(method);
/** * Wraps the specified input object into a {@link ParserPipe} object so that it can be easily converted into * a stream or reader. * * @param input * The input. * <br>This can be any of the following types: * <ul> * <li><jk>null</jk> * <li>{@link Reader} * <li>{@link CharSequence} * <li>{@link InputStream} containing UTF-8 encoded text (or whatever the encoding specified by * {@link ReaderParser#RPARSER_inputStreamCharset}). * <li><code><jk>byte</jk>[]</code> containing UTF-8 encoded text (or whatever the encoding specified by * {@link ReaderParser#RPARSER_inputStreamCharset}). * <li>{@link File} containing system encoded text (or whatever the encoding specified by * {@link ReaderParser#RPARSER_fileCharset}). * </ul> * @return * A new {@link ParserPipe} wrapper around the specified input object. */ @SuppressWarnings("resource") @Override /* ParserSesson */ public final ParserPipe createPipe(Object input) { return setPipe(new ParserPipe(input, isDebug(), ctx.isStrict(), ctx.isAutoCloseStreams(), ctx.isUnbuffered(), getFileCharset(), getInputStreamCharset())); }
ParserSession session = p2.createSession(getUnbufferedReader(), properties, getJavaMethod(), getServlet()); return p2.parse(session, type); } catch (ParseException e) { throw new RestException(SC_BAD_REQUEST,
/** * Create a new instance of a REST interface over the specified object. * * <p> * The parser is used as the bean context. * * @param o The object to be wrapped. * @param parser The parser to use for parsing arguments and converting objects to the correct data type. */ public PojoRest(Object o, ReaderParser parser) { if (parser == null) parser = JsonParser.DEFAULT; this.parser = parser; this.session = parser.createBeanSession(); this.root = new JsonNode(null, null, o, session.object()); }
/** * Configuration property: File charset. * * @see ReaderParser#RPARSER_fileCharset * @return * The character set to use for reading <code>Files</code> from the file system. */ protected final String getFileCharset() { return ctx.getFileCharset(); }
/** * Configuration property: Input stream charset. * * @see ReaderParser#RPARSER_inputStreamCharset * @return * The character set to use for converting <code>InputStreams</code> and byte arrays to readers. */ protected final String getInputStreamCharset() { return ctx.getInputStreamCharset(); }
/** * Constructor. * * @param ps The property store containing all the settings for this object. * @param consumes The list of media types that this parser consumes (e.g. <js>"application/json"</js>, <js>"*​/json"</js>). */ protected ReaderParser(PropertyStore ps, String...consumes) { super(ps, consumes); inputStreamCharset = getStringProperty(RPARSER_inputStreamCharset, "UTF-8"); fileCharset = getStringProperty(RPARSER_fileCharset, "DEFAULT"); }
if (o == null) return null; Method m = p.getClassMeta(o.getClass()).getPublicMethods().get(method); if (m == null) throw new NoSuchMethodException(method);
@Override public MeasurementPOJO _readItems(byte[] input) throws Exception { return parser.parse(input, MeasurementPOJO.class); }
@Override /* Context */ public ObjectMap asMap() { return super.asMap() .append("JsonParser", new ObjectMap()); } }