private <T> T getInner(ClassMeta<T> cm) throws BadRequest, UnsupportedMediaType, InternalServerError { try { return parse(cm); } catch (UnsupportedMediaType e) { throw e; } catch (SchemaValidationException e) { throw new BadRequest("Validation failed on request body. " + e.getLocalizedMessage()); } catch (ParseException e) { throw new BadRequest(e, "Could not convert request body content to class type ''{0}''.", cm); } catch (IOException e) { throw new InternalServerError(e, "I/O exception occurred while parsing request body."); } catch (Exception e) { throw new InternalServerError(e, "Exception occurred while parsing request body."); } }
/** * Constructor. * * @param msg The message. Can be <jk>null</jk>. */ public BadRequest(String msg) { super(msg); setStatus(CODE); }
private <T> T getInner(ClassMeta<T> cm) throws BadRequest, UnsupportedMediaType, InternalServerError { try { return parse(cm); } catch (UnsupportedMediaType e) { throw e; } catch (SchemaValidationException e) { throw new BadRequest("Validation failed on request body. " + e.getLocalizedMessage()); } catch (ParseException e) { throw new BadRequest(e, "Could not convert request body content to class type ''{0}''.", cm); } catch (IOException e) { throw new InternalServerError(e, "I/O exception occurred while parsing request body."); } catch (Exception e) { throw new InternalServerError(e, "Exception occurred while parsing request body."); } }
/** * Constructor. * * @param msg The message. Can be <jk>null</jk>. */ public BadRequest(String msg) { super(msg); setStatus(CODE); }
private <T> T getInner(ClassMeta<T> cm) throws BadRequest, UnsupportedMediaType, InternalServerError { try { return parse(cm); } catch (UnsupportedMediaType e) { throw e; } catch (SchemaValidationException e) { throw new BadRequest("Validation failed on request body. " + e.getLocalizedMessage()); } catch (ParseException e) { throw new BadRequest(e, "Could not convert request body content to class type ''{0}''.", cm); } catch (IOException e) { throw new InternalServerError(e, "I/O exception occurred while parsing request body."); } catch (Exception e) { throw new InternalServerError(e, "Exception occurred while parsing request body."); } }
/** * Constructor. * * @param msg The message. Can be <jk>null</jk>. */ public BadRequest(String msg) { super(msg); setStatus(CODE); }
throw new BadRequest("Invalid value for position. Must be between 1-10000"); if (in.limit < 1 || in.limit > 10000) throw new BadRequest("Invalid value for limit. Must be between 1-10000"); c.rollback(); } catch (SQLException e) { throw new BadRequest(e, "Invalid query: {0}", sql);
throw new BadRequest("Invalid value for position. Must be between 1-10000"); if (in.limit < 1 || in.limit > 10000) throw new BadRequest("Invalid value for limit. Must be between 1-10000"); c.rollback(); } catch (SQLException e) { throw new BadRequest(e, "Invalid query: {0}", sql);
@RestMethod public void badRequest() { throw new BadRequest(); } @RestMethod public void conflict() { throw new Conflict(); }
@RestMethod public void badRequest() { throw new BadRequest(t, "foo {0}", "bar"); } @RestMethod public void conflict() { throw new Conflict(t, "foo {0}", "bar"); }
@RestMethod public void badRequest() { throw new BadRequest(t); } @RestMethod public void conflict() { throw new Conflict(t); }
@RestMethod public void badRequest() { throw new BadRequest("foo {0}", "bar"); } @RestMethod public void conflict() { throw new Conflict("foo {0}", "bar"); }
@RestMethod public void badRequest() { throw new BadRequest(t, "foo {0}", "bar"); } }
private static void preOrPost(Object resource, Method m, RestMethodParam[] mp, RestRequest req, RestResponse res) throws RestException { if (m != null) { Object[] args = new Object[mp.length]; for (int i = 0; i < mp.length; i++) { try { args[i] = mp[i].resolve(req, res); } catch (RestException e) { throw e; } catch (Exception e) { throw new BadRequest(e, "Invalid data conversion. Could not convert {0} ''{1}'' to type ''{2}'' on method ''{3}.{4}''.", mp[i].getParamType().name(), mp[i].getName(), mp[i].getType(), m.getDeclaringClass().getName(), m.getName() ); } } try { m.invoke(resource, args); } catch (RestException e) { throw e; } catch (Exception e) { throw new InternalServerError(e); } } }
private static void preOrPost(Object resource, Method m, RestMethodParam[] mp, RestRequest req, RestResponse res) throws RestException { if (m != null) { Object[] args = new Object[mp.length]; for (int i = 0; i < mp.length; i++) { try { args[i] = mp[i].resolve(req, res); } catch (RestException e) { throw e; } catch (Exception e) { throw new BadRequest(e, "Invalid data conversion. Could not convert {0} ''{1}'' to type ''{2}'' on method ''{3}.{4}''.", mp[i].getParamType().name(), mp[i].getName(), mp[i].getType(), m.getDeclaringClass().getName(), m.getName() ); } } try { m.invoke(resource, args); } catch (RestException e) { throw e; } catch (Exception e) { throw new InternalServerError(e); } } }
private static void preOrPost(Object resource, Method m, RestMethodParam[] mp, RestRequest req, RestResponse res) throws RestException { if (m != null) { Object[] args = new Object[mp.length]; for (int i = 0; i < mp.length; i++) { try { args[i] = mp[i].resolve(req, res); } catch (RestException e) { throw e; } catch (Exception e) { throw new BadRequest(e, "Invalid data conversion. Could not convert {0} ''{1}'' to type ''{2}'' on method ''{3}.{4}''.", mp[i].getParamType().name(), mp[i].getName(), mp[i].getType(), m.getDeclaringClass().getName(), m.getName() ); } } try { m.invoke(resource, args); } catch (RestException e) { throw e; } catch (Exception e) { throw new InternalServerError(e); } } }
/** * Constructor. */ RestResponse(RestContext context, RestRequest req, HttpServletResponse res) throws BadRequest { super(res); this.request = req; for (Map.Entry<String,Object> e : context.getDefaultResponseHeaders().entrySet()) setHeader(e.getKey(), asString(e.getValue())); try { String passThroughHeaders = req.getHeader("x-response-headers"); if (passThroughHeaders != null) { HttpPartParser p = context.getPartParser(); ObjectMap m = p.createPartSession(req.getParserSessionArgs()).parse(HttpPartType.HEADER, null, passThroughHeaders, context.getBeanContext().getClassMeta(ObjectMap.class)); for (Map.Entry<String,Object> e : m.entrySet()) setHeader(e.getKey(), e.getValue().toString()); } } catch (Exception e1) { throw new BadRequest(e1, "Invalid format for header 'x-response-headers'. Must be in URL-encoded format."); } }
/** * Constructor. */ RestResponse(RestContext context, RestRequest req, HttpServletResponse res) throws BadRequest { super(res); this.request = req; for (Map.Entry<String,Object> e : context.getDefaultResponseHeaders().entrySet()) setHeader(e.getKey(), asString(e.getValue())); try { String passThroughHeaders = req.getHeader("x-response-headers"); if (passThroughHeaders != null) { HttpPartParser p = context.getPartParser(); ObjectMap m = p.createPartSession(req.getParserSessionArgs()).parse(HttpPartType.HEADER, null, passThroughHeaders, context.getBeanContext().getClassMeta(ObjectMap.class)); for (Map.Entry<String,Object> e : m.entrySet()) setHeader(e.getKey(), e.getValue().toString()); } } catch (Exception e1) { throw new BadRequest(e1, "Invalid format for header 'x-response-headers'. Must be in URL-encoded format."); } }
/** * Constructor. */ RestResponse(RestContext context, RestRequest req, HttpServletResponse res) throws BadRequest { super(res); this.request = req; for (Map.Entry<String,Object> e : context.getDefaultResponseHeaders().entrySet()) setHeader(e.getKey(), asString(e.getValue())); try { String passThroughHeaders = req.getHeader("x-response-headers"); if (passThroughHeaders != null) { HttpPartParser p = context.getPartParser(); ObjectMap m = p.createPartSession(req.getParserSessionArgs()).parse(HttpPartType.HEADER, null, passThroughHeaders, context.getBeanContext().getClassMeta(ObjectMap.class)); for (Map.Entry<String,Object> e : m.entrySet()) setHeader(e.getKey(), e.getValue().toString()); } } catch (Exception e1) { throw new BadRequest(e1, "Invalid format for header 'x-response-headers'. Must be in URL-encoded format."); } }
private <T> T getInner(HttpPartParser parser, HttpPartSchema schema, String name, T def, ClassMeta<T> cm) throws BadRequest, InternalServerError { try { if (cm.isMapOrBean() && isOneOf(name, "*", "")) { ObjectMap m = new ObjectMap(); for (Map.Entry<String,String[]> e : this.entrySet()) { String k = e.getKey(); HttpPartSchema pschema = schema == null ? null : schema.getProperty(k); ClassMeta<?> cm2 = cm.getValueType(); m.put(k, getInner(parser, pschema, k, null, cm2)); } return req.getBeanSession().convertToType(m, cm); } T t = parse(parser, schema, getString(name), cm); return (t == null ? def : t); } catch (SchemaValidationException e) { throw new BadRequest(e, "Validation failed on header ''{0}''. ", name); } catch (ParseException e) { throw new BadRequest(e, "Could not parse header ''{0}''.", name) ; } catch (Exception e) { throw new InternalServerError(e, "Could not parse header ''{0}''.", name); } }