public CompletableFuture<Render> renderToken(String token) { Current.getContext().addModifyResponse((http2Response) -> modifyResponse(http2Response)); CompletableFuture<Map<String, String>> future = storage.read(InstallSslCertPlugin.PLUGIN_PROPERTIES_KEY); return future.thenApply((props) -> { String result = props.get(token); log.info("token="+token+" value="+result); if(result == null) throw new NotFoundException(); int index = result.indexOf("---"); String authContent = result.substring(0, index); //check token exists in database return Actions.renderThis("authContent", authContent); }); }
public List<Object> createArgs(Method m, RequestContext ctx, BodyContentBinder binder) { RouterRequest req = ctx.getRequest(); try { return createArgsImpl(m, ctx, binder); } catch(DataMismatchException e) { if(req.method == HttpMethod.GET) { //For GET with query params or path urls, if we can't convert, it should be a 404... //This is because a human user typed in the wrong url so they should get back not found throw new NotFoundException(e); } else { //For POST with multipart, this should be a 500 because a human user does NOT type in post //urls and instead the developer typed in the wrong url and an issue needs to be fixed(or //some hacker is doing something so internal error there is fine as well) if(req.multiPartFields.size() > 0) throw new IllegalArgumentException(e); else //for apis that POST, this is a client error(or developer error when testing) throw new ClientDataError(e); } } }
public CompletableFuture<Void> invoke2(MatchResult result, RequestContext requestCtx, ResponseStreamer responseCb, ErrorRoutes errorRoutes) { //This makes us consistent with other NotFoundExceptions and without the cost of //throwing an exception and filling in stack trace... //We could convert the exc. to FastException and override method so stack is not filled in but that //can get very annoying RouteMeta meta = result.getMeta(); Route route = meta.getRoute(); RouteType routeType = route.getRouteType(); if(routeType == RouteType.NOT_FOUND) { CompletableFuture<Void> future = new CompletableFuture<Void>(); future.completeExceptionally(new NotFoundException("route not found")); return future; } return invokeImpl(result, meta.getService222(), requestCtx, responseCb); }
@SuppressWarnings("rawtypes") private Object convert(RouterRequest req, Method method, ParamNode valuesToUse, Meta fieldMeta, ObjectStringConverter converter, Validation validator) { Class<?> paramTypeToCreate = fieldMeta.getFieldClass(); if(fieldMeta instanceof ParamMeta) { //for params only not fields as with fields, we just don't set the field and skip it...before we call a method, //we MUST have a value to set checkForBadNullToPrimitiveConversion(req, valuesToUse, fieldMeta, method); } if(valuesToUse == null) return null; if(!(valuesToUse instanceof ValueNode)) throw new IllegalArgumentException("method takes param type="+paramTypeToCreate+" but complex structure found"); ValueNode node = (ValueNode) valuesToUse; String value = node.getValue(); try { return converter.stringToObject(value); } catch(Exception e) { if(node.getFrom() == FromEnum.FORM_MULTIPART) { validator.addError(node.getFullKeyName(), "Could not convert value"); return null; } else //This should be a 404 in production if the url is bad... throw new NotFoundException("The method='"+method+"' requires that the parameter or field '"+fieldMeta+"' be of type=" +paramTypeToCreate+" but the request contained a value that could not be converted="+value); } }