@Override public void postAppStart(App app) throws Throwable { for(Route route : app.routes()) { processRoute(route); } }
void accept(ApiImpl latest) { if(!app.routes().exists(this)) { app.routes().add(this); } latest.getProtocols().forEach((name, p) -> { if(!protocols.containsKey(name)) { ProtocolRoutes routes = new ProtocolRoutes(name, p.getPathTemplate()); protocols.put(name, routes); app.routes().add(routes); } }); this.latest = latest; }
@Override public boolean isOperationExists(RestdContext context, RouteBuilder r) { if(doCheckOperationExists(context, r, app.routes(), false)) { return true; } Routes routes = context.getApiConfig().getContainerRoutes(); if(routes != app.routes() && doCheckOperationExists(context, r, routes, true)) { return true; } return false; }
protected void resolveAppRoutes(App app, ApiConfigurator c) { String basePath = c.config().getBasePath(); for(Route route : app.routes()) { String pathTemplate = route.getPathTemplate().getTemplate(); if(pathTemplate.equals(basePath) || pathTemplate.startsWith(basePath)) { resolveResourceType(app, c, route); c.addRoute(route); } } }
@Override public void destroyDynaApi(DynaApi api) { ApiConfig config = api.getConfig(); if(log.isDebugEnabled()) { log.debug("Routes before destroying api '{}': \n\n{}\n", api.getName(), routesPrinter.print(app.routes())); } config.getApiRoutes().forEach(ar -> { if(ar.isDynamic()) { app.routes().remove(ar.getRoute()); } }); if(log.isDebugEnabled()) { log.debug("Routes after destroying api '{}': \n\n{}\n", api.getName(), routesPrinter.print(app.routes())); } apis.remove(api); }
public void configure() { if(!endpoints.isEmpty()) { endpoints.forEach(r -> app.routes().remove(r)); } Map<String, Object> map = ConfigUtils.extractMap(app.config(), CONF_PREFIX); if(null == map || map.isEmpty()) { return; } config = Converts.convert(map, OAuth2ServerConfig.class); if(!config.isEnabled()) { return; } //clients config.getClients().forEach((id, c) -> { c.setId(id); validator.validate(CONF_PREFIX + ".clients." + id, c); }); //url int port = app.config().getIntProperty("server.port", 8080); String contextPath = app.config().getProperty("server.context-path", ""); this.url = (config.isSsl() ? "https:" : "http") + "://localhost:" + port + contextPath; //gen key pair if(null == keyPair) { keyPair = RSA.generateKeyPair(); signer = new RsaSigner(keyPair.getPrivateKey()); verifier = new RsaVerifier(keyPair.getPublicKey()); } //create endpoint createEndpoints(app.routes()); }
protected Api doNewApi(ApiConfigurator configurator, boolean dynamic) { configurator.setContainerRoutes(app.routes()); if(null != configs) { ApiConfig c = configurator.config(); if(c.getOAuthConfig() == null){ configurator.setOAuthConfig(oauthConfig); }else{ configurator.setOAuthConfig(new OAuthConfigImpl().updateFrom(oauthConfig)); } configs.getCommonModels().forEach(model -> { if(null != c.getModelConfigByClassName(model.getClassName())) { return; } if(null != c.getModelConfig(model.getName())) { return; } configurator.addModelConfig(model); }); configs.getCommonParams().forEach(param -> { if(null != c.getParam(param.getClassName(),param.getName())) { return; } configurator.addParam(param); }); } return new DefaultApi(this::doCreate, configurator, dynamic); }