Search in sources :

Example 1 with Routes

use of org.apache.meecrowave.proxy.servlet.configuration.Routes in project meecrowave by apache.

the class ConfigurationLoader method doLoad.

protected Optional<Routes> doLoad(final String content) {
    try (final Jsonb jsonb = JsonbBuilder.newBuilder().withProvider(loadJsonpProvider()).withConfig(new JsonbConfig().setProperty("org.apache.johnzon.supports-comments", true)).build()) {
        routes = jsonb.fromJson(content, Routes.class);
        final boolean hasRoutes = routes.routes != null && !routes.routes.isEmpty();
        if (routes.defaultRoute == null && !hasRoutes) {
            return Optional.empty();
        }
        if (hasRoutes) {
            // before merging, ensure all routes have an id to not duplicate default id
            routes.routes.stream().filter(it -> it.id == null).forEach(it -> it.id = newId());
        }
        if (routes.defaultRoute != null) {
            if (routes.defaultRoute.id == null) {
                routes.defaultRoute.id = "default";
            }
            if (routes.routes == null) {
                // no route were defined, consider it is the default route, /!\ empty means no route, don't default
                routes.routes = singletonList(routes.defaultRoute);
            }
            if (hasRoutes) {
                final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(emptyMap());
                final JsonObject template = jsonb.fromJson(jsonb.toJson(routes.defaultRoute), JsonObject.class);
                routes.routes = routes.routes.stream().map(r -> merge(jsonb, jsonFactory, template, r)).collect(toList());
            }
        }
    } catch (final Exception e) {
        throw new IllegalArgumentException(e);
    }
    routes.routes.forEach(this::init);
    return Optional.of(routes);
}
Also used : X509Certificate(java.security.cert.X509Certificate) SSLContext(javax.net.ssl.SSLContext) Routes(org.apache.meecrowave.proxy.servlet.configuration.Routes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) JsonBuilderFactory(javax.json.JsonBuilderFactory) Client(javax.ws.rs.client.Client) TrustManager(javax.net.ssl.TrustManager) KeyStoreException(java.security.KeyStoreException) JsonbConfig(javax.json.bind.JsonbConfig) Collections.singletonList(java.util.Collections.singletonList) JsonProvider(javax.json.spi.JsonProvider) JsonValue(javax.json.JsonValue) NotificationOptions(javax.enterprise.event.NotificationOptions) ClientBuilder(javax.ws.rs.client.ClientBuilder) Collectors.toMap(java.util.stream.Collectors.toMap) Json(javax.json.Json) Collector(java.util.stream.Collector) ThreadFactory(java.util.concurrent.ThreadFactory) Path(java.nio.file.Path) Collections.emptyMap(java.util.Collections.emptyMap) JsonObject(javax.json.JsonObject) JsonbBuilder(javax.json.bind.JsonbBuilder) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) Files(java.nio.file.Files) Optional.ofNullable(java.util.Optional.ofNullable) IOException(java.io.IOException) KeyStore(java.security.KeyStore) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) FileInputStream(java.io.FileInputStream) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) UUID(java.util.UUID) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) InvocationTargetException(java.lang.reflect.InvocationTargetException) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) X509TrustManager(javax.net.ssl.X509TrustManager) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Jsonb(javax.json.bind.Jsonb) JsonObjectBuilder(javax.json.JsonObjectBuilder) InputStream(java.io.InputStream) Jsonb(javax.json.bind.Jsonb) JsonbConfig(javax.json.bind.JsonbConfig) JsonBuilderFactory(javax.json.JsonBuilderFactory) JsonObject(javax.json.JsonObject) Routes(org.apache.meecrowave.proxy.servlet.configuration.Routes) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 KeyManagementException (java.security.KeyManagementException)1 KeyStore (java.security.KeyStore)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Collections.singletonList (java.util.Collections.singletonList)1 Optional (java.util.Optional)1 Optional.ofNullable (java.util.Optional.ofNullable)1