public TomcatSettings(PippoSettings pippoSettings) { super(pippoSettings); this.baseFolder = pippoSettings.getString(TomcatSettings.BASE_FOLDER, "tomcat_home"); this.maxConnections = pippoSettings.getInteger(TomcatSettings.MAX_CONNECTIONS, 100); this.keyAlias = pippoSettings.getString(TomcatSettings.KEY_ALIAS, "tomcat"); this.keyType = pippoSettings.getString(TomcatSettings.KEY_TYPE, "JKS"); this.clientAuth = pippoSettings.getBoolean(TomcatSettings.CLIENT_AUTH, false); }
@Override public void init(Application application) { prettyPrint = application.getPippoSettings().isDev(); }
public UndertowSettings(PippoSettings pippoSettings) { super(pippoSettings); bufferSize = pippoSettings.getInteger(UndertowSettings.BUFFER_SIZE, 0); buffersPerRegion = pippoSettings.getInteger(UndertowSettings.BUFFERS_PER_REGION, 0); directBuffers = pippoSettings.getBoolean(UndertowSettings.DIRECT_BUFFERS, false); ioThreads = pippoSettings.getInteger(UndertowSettings.IO_THREADS, 0); workerThreads = pippoSettings.getInteger(UndertowSettings.WORKER_THREADS, 0); this.pippoSettings = pippoSettings; }
/** * Returns a string value that has been interpolated from System Properties * and Environment Variables using the ${name} or @{name} syntax. * * @param name * @param defaultValue * @return an interpolated string */ public String getInterpolatedString(String name, String defaultValue) { String value = getString(name, defaultValue); return interpolateString(value); }
@Override public void start(PippoSettings settings, MetricRegistry metricRegistry) { if (settings.getBoolean("metrics.librato.enabled", false)) { String hostname = settings.getLocalHostname(); String username = settings.getRequiredString("metrics.librato.username"); String apiKey = settings.getRequiredString("metrics.librato.apikey"); long period = settings.getDurationInSeconds("metrics.librato.period", 60); LibratoReporter.Builder builder = LibratoReporter.builder(metricRegistry, username, apiKey, hostname); LibratoReporter.enable(builder, period, TimeUnit.SECONDS); log.info("Started Librato Metrics reporter for '{}', updating every {} seconds", hostname, period); } else { log.debug("Librato Metrics reporter is disabled"); } }
int value = pippoSettings.getInteger(propertyName, Integer.MIN_VALUE); if (value > Integer.MIN_VALUE) { Option<Integer> option = getOption(undertowPropName); long value = pippoSettings.getLong(propertyName, Long.MIN_VALUE); if (value > Long.MIN_VALUE) { Option<Long> option = getOption(undertowPropName); addUndertowOption(builder, option, pippoSettings.getString(propertyName, ""), prefix); } else if (typeName.equals(Boolean.class.toString())) { Option<Boolean> option = getOption(undertowPropName); addUndertowOption(builder, option, pippoSettings.getBoolean(propertyName, false), prefix);
public WebServerSettings(PippoSettings pippoSettings) { this.port = pippoSettings.getInteger(PippoConstants.SETTING_SERVER_PORT, DEFAULT_PORT); this.host = pippoSettings.getString(PippoConstants.SETTING_SERVER_HOST, host); this.contextPath = pippoSettings.getString(PippoConstants.SETTING_SERVER_CONTEXT_PATH, contextPath); this.keystoreFile = pippoSettings.getString(PippoConstants.SETTING_SERVER_KEYSTORE_FILE, keystoreFile); this.keystorePassword = pippoSettings.getString(PippoConstants.SETTING_SERVER_KEYSTORE_PASSWORD, keystorePassword); this.truststoreFile = pippoSettings.getString(PippoConstants.SETTING_SERVER_TRUSTSTORE_FILE, truststoreFile); this.truststorePassword = pippoSettings.getString(PippoConstants.SETTING_SERVER_TRUSTSTORE_PASSWORD, truststorePassword); }
String pathPrefix = pippoSettings.getString(PippoConstants.SETTING_TEMPLATE_PATH_PREFIX, null); if (StringUtils.isNullOrEmpty(pathPrefix)) { pathPrefix = TemplateEngine.DEFAULT_PATH_PREFIX; properties.setProperty("myloader.resource.loader.class", PrefixedClasspathResourceLoader.class.getName()); properties.setProperty("myloader.resource.loader.prefix", StringUtils.addEnd(pathPrefix, "/")); properties.setProperty("myloader.resource.loader.cache", String.valueOf(!pippoSettings.isDev()));
String applicationName = pippoSettings.getString(PippoConstants.SETTING_APPLICATION_NAME, "Pippo"); if (pippoSettings.getBoolean("metrics.jvm.enabled", false)) { registerAll("jvm.gc", new GarbageCollectorMetricSet()); registerAll("jvm.memory", new MemoryUsageGaugeSet()); if (pippoSettings.getBoolean("metrics.mbeans.enabled", false)) { JmxReporter reporter = JmxReporter.forRegistry(metricRegistry).inDomain(applicationName).build(); reporter.start();
/** * Create a memcached client with pippo settings. * * @param settings pippo settings * @return memcached client */ public static final MemcachedClient create(final PippoSettings settings) { String host = settings.getString(HOST, "localhost:11211"); String prot = settings.getString(PROT, "BINARY"); Protocol protocol = Protocol.valueOf(prot); String user = settings.getString(USER, ""); String pass = settings.getString(PASS, ""); List<String> autM = settings.getStrings(AUTM); String[] mechanisms = autM.toArray(new String[autM.size()]); return create(host, protocol, user, pass, mechanisms); }
public void addEtag(RouteContext routeContext, long lastModified) { if (pippoSettings.isProd()) { String maxAge = pippoSettings.getString(PippoConstants.SETTING_HTTP_CACHE_CONTROL, "3600"); if (maxAge.equals("0")) { routeContext.setHeader(HttpConstants.Header.CACHE_CONTROL, "no-cache"); } else { routeContext.setHeader(HttpConstants.Header.CACHE_CONTROL, "max-age=" + maxAge); } } else { routeContext.setHeader(HttpConstants.Header.CACHE_CONTROL, "no-cache"); } // Use etag on demand: String etag = null; boolean useEtag = pippoSettings.getBoolean(PippoConstants.SETTING_HTTP_USE_ETAG, true); if (useEtag) { // ETag right now is only lastModified long. // maybe we change that in the future. etag = "\"" + lastModified + "\""; routeContext.setHeader(HttpConstants.Header.ETAG, etag); } if (isModified(etag, lastModified, routeContext)) { routeContext.setHeader(HttpConstants.Header.LAST_MODIFIED, DateUtils.formatForHttpHeader(lastModified)); } else if (routeContext.isRequestMethod(HttpConstants.Method.GET)) { routeContext.status(HttpConstants.StatusCode.NOT_MODIFIED); } }
private static Map<String, String> getPac4jSettings(PippoSettings settings, String prefix) { Map<String, String> pac4jSettings = new HashMap<>(); int beginIndex = prefix.length(); List<String> names = settings.getSettingNames(prefix); for (String name : names) { pac4jSettings.put(name.substring(beginIndex), settings.getString(name, "")); } return pac4jSettings; }
public JettySettings(PippoSettings pippoSettings) { super(pippoSettings); maxThreads = pippoSettings.getInteger(JettySettings.MAX_THREADS, 0); minThreads = pippoSettings.getInteger(JettySettings.MIN_THREADS, 0); idleTimeout = pippoSettings.getInteger(JettySettings.IDLE_TIMEOUT, 0); }
protected Map<String, String> settingsToMap(PippoSettings settings) { List<String> settingNames = settings.getSettingNames(); Map<String, String> settingsMap = new TreeMap<>(); for (String settingName : settingNames) { settingsMap.put(settingName, settings.getRequiredString(settingName)); } return settingsMap; }
/** * Get the template bindings for the error response. * * @param routeContext * @return bindings map */ protected Map<String, Object> prepareTemplateBindings(int statusCode, RouteContext routeContext) { Map<String, Object> locals = new LinkedHashMap<>(); locals.put("applicationName", application.getApplicationName()); locals.put("applicationVersion", application.getApplicationVersion()); locals.put("runtimeMode", application.getPippoSettings().getRuntimeMode().toString()); if (application.getPippoSettings().isDev()) { locals.put("routes", application.getRouter().getRoutes()); } return locals; }
/** * Gets the duration setting and converts it to seconds. * <p/> * The setting must be use one of the following conventions: * <ul> * <li>n MILLISECONDS * <li>n SECONDS * <li>n MINUTES * <li>n HOURS * <li>n DAYS * </ul> * * @param name * @return seconds */ public long getDurationInSeconds(String name) { return getDurationInSeconds(name, 0); }
/** * Returns the list of all setting names. * * @return list of setting names */ public List<String> getSettingNames() { return getSettingNames(null); }
@Override public void start(PippoSettings settings, MetricRegistry metricRegistry) { if (settings.getBoolean("metrics.prometheus.enabled", false)) { String hostname = settings.getLocalHostname(); String address = settings.getRequiredString("metrics.prometheus.address"); int port = settings.getInteger("metrics.prometheus.port", 2003); long period = settings.getDurationInSeconds("metrics.prometheus.period", 60); Pushgateway pushgateway = new Pushgateway(address, port); reporter = PrometheusReporter.forRegistry(metricRegistry) .prefixedWith(hostname) .filter(MetricFilter.ALL) .build(pushgateway); reporter.start(period, TimeUnit.SECONDS); log.info("Started Prometheus Metrics reporter for '{}', updating every {} seconds", hostname, period); } else { log.debug("Prometheus Metrics reporter is disabled"); } }
/** * Create a Jedis poll with pippo settings. URL format: * 'redis://[:password@]host[:port][/db-number][?option=value]' * * @param settings pippo settings * @return Jedis pool */ public static JedisPool create(final PippoSettings settings) { String host = settings.getString(HOST, Protocol.DEFAULT_HOST).trim(); int minIdle = settings.getInteger(MIN_IDLE, GenericObjectPoolConfig.DEFAULT_MIN_IDLE); int maxIdle = settings.getInteger(MAX_IDLE, GenericObjectPoolConfig.DEFAULT_MAX_IDLE); int maxTotal = settings.getInteger(MAX_TOTAL, GenericObjectPoolConfig.DEFAULT_MAX_TOTAL); JedisPoolConfig config = new JedisPoolConfig(); config.setMinIdle(minIdle); config.setMaxIdle(maxIdle); config.setMaxTotal(maxTotal); try { return new JedisPool(config, new URI(host)); } catch (URISyntaxException e) { throw new PippoRuntimeException("Malformed redis URI", e); } }