startBackendServer() throws IOException {
+ // configure logging in order to not have the standard JVM defaults
+ LogManager.getLogManager().readConfiguration(Main.class.getResourceAsStream("/logging.properties"));
+
+ Config config = Config.builder()
+ .sources(ConfigSources.environmentVariables())
+ .build();
+
+ WebServer webServer = WebServer.create(
+ ServerConfiguration.builder()
+ .port(9080)
+ .tracer(TracerBuilder.create(config.get("tracing"))
+ .serviceName("helidon-webserver-translator-backend")),
+ Routing.builder()
+ .register(new TranslatorBackendService()));
+
+ return webServer.start()
+ .thenApply(ws -> {
+ System.out.println(
+ "WEB server is up! http://localhost:" + ws.port());
+ ws.whenShutdown().thenRun(()
+ -> System.out.println("WEB server is DOWN. Good bye!"));
+ return ws;
+ }).exceptionally(t -> {
+ System.err.println("Startup failed: " + t.getMessage());
+ t.printStackTrace(System.err);
+ return null;
+ });
+ }
+
+ /**
+ * The main method of Translator backend.
+ *
+ * @param args command-line args, currently ignored.
+ * @throws Exception in case of an error
+ */
+ public static void main(String[] args) throws Exception {
+ startBackendServer();
+ }
+}
diff --git a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/TranslatorResource.java b/examples/translator-app/backend/src/main/java/io/helidon/examples/translator/backend/TranslatorBackendService.java
similarity index 74%
rename from examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/TranslatorResource.java
rename to examples/translator-app/backend/src/main/java/io/helidon/examples/translator/backend/TranslatorBackendService.java
index 341f2c85b..9e4063750 100644
--- a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/TranslatorResource.java
+++ b/examples/translator-app/backend/src/main/java/io/helidon/examples/translator/backend/TranslatorBackendService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -13,30 +13,21 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-package io.helidon.webserver.examples.translator.backend;
+package io.helidon.examples.translator.backend;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.Logger;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import io.helidon.webserver.BadRequestException;
+import io.helidon.webserver.Routing;
+import io.helidon.webserver.ServerRequest;
+import io.helidon.webserver.ServerResponse;
+import io.helidon.webserver.Service;
/**
- * Translator backend resource.
+ * Translator backend service.
*/
-@Path("translator")
-public class TranslatorResource {
-
- private static final Logger LOGGER = Logger.getLogger(TranslatorResource.class.getName());
-
- private static volatile boolean brokenFlag = false;
+public class TranslatorBackendService implements Service {
private static final String CZECH = "czech";
private static final String SPANISH = "spanish";
@@ -137,31 +128,17 @@ public class TranslatorResource {
TRANSLATED_WORDS_REPOSITORY.put("ten" + SEPARATOR + FRENCH, "dix");
}
- /**
- * Get method to translate a given query to a given language if possible.
- *
- * @param query the query to translate
- * @param language the target language to translate the query to
- * @return the translated text
- */
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public Response getText(@QueryParam("q") String query, @QueryParam("lang") String language) {
- if (Main.isSecurityDisabled()) {
- LOGGER.info("[dev-local] Security check is disabled by local development mode.");
- LOGGER.info("getText(\"" + query + "\", " + language + ")");
- } else {
- // TODO add security
-// if (SecurityModule.getUserPrincipal() == null) {
-// return Response.status(401).header("WWW-Authenticate", "Bearer realm=\"DefaultRealm\"").build();
-// }
-// LOGGER.info("getText(\"" + query + "\", " + language + ") - Principal: " + SecurityModule.getUserPrincipal());
- }
+ @Override
+ public void update(Routing.Rules rules) {
+ rules.get(this::getText);
+ }
- if (TranslatorResource.brokenFlag) {
- return Response.serverError().build();
- }
+ private void getText(ServerRequest request, ServerResponse response) {
+ String query = request.queryParams().first("q")
+ .orElseThrow(() -> new BadRequestException("missing query parameter 'q'"));
+ String language = request.queryParams().first("lang")
+ .orElseThrow(() -> new BadRequestException("missing query parameter 'lang'"));
String translation;
switch (language) {
case CZECH:
@@ -183,55 +160,19 @@ public class TranslatorResource {
translation = TRANSLATED_WORDS_REPOSITORY.get(query + SEPARATOR + FRENCH);
break;
default:
- return Response.status(Response.Status.NOT_FOUND)
- .entity(String.format(
+ response.status(404)
+ .send(String.format(
"Language '%s' not in supported. Supported languages: %s, %s, %s, %s.",
language,
- CZECH, SPANISH, CHINESE, HINDI))
- .build();
+ CZECH, SPANISH, CHINESE, HINDI));
+ return;
}
if (translation != null) {
- return Response.ok(translation).build();
+ response.send(translation);
} else {
- return Response.status(Response.Status.NOT_FOUND)
- .entity(String.format("Word '%s' not in the dictionary", query))
- .build();
+ response.status(404)
+ .send(String.format("Word '%s' not in the dictionary", query));
}
}
-
- /**
- * Start delay post method.
- */
- @POST
- @Path("/break")
- public void startDelay() {
- setBroken(true);
- }
-
- /**
- * Stop delay post method.
- */
- @POST
- @Path("/fix")
- public void stopDelay() {
- setBroken(false);
- }
-
- /**
- * Marathon health check.
- *
- * This should check the health of state/storage service (if present).
- *
- * @return HTTP 2xx response.
- */
- @GET
- @Path("health")
- public Response health() {
- return Response.noContent().build();
- }
-
- private static void setBroken(boolean broken) {
- brokenFlag = broken;
- }
}
diff --git a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/package-info.java b/examples/translator-app/backend/src/main/java/io/helidon/examples/translator/backend/package-info.java
similarity index 83%
rename from examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/package-info.java
rename to examples/translator-app/backend/src/main/java/io/helidon/examples/translator/backend/package-info.java
index d81345a8c..3c5c24fef 100644
--- a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/package-info.java
+++ b/examples/translator-app/backend/src/main/java/io/helidon/examples/translator/backend/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,4 +17,4 @@
/**
* Demo examples Translator Backend package.
*/
-package io.helidon.webserver.examples.translator.backend;
+package io.helidon.examples.translator.backend;
diff --git a/examples/webserver/demo-translator-backend/src/main/resources/logging.properties b/examples/translator-app/backend/src/main/resources/logging.properties
similarity index 100%
rename from examples/webserver/demo-translator-backend/src/main/resources/logging.properties
rename to examples/translator-app/backend/src/main/resources/logging.properties
diff --git a/examples/translator-app/frontend/Dockerfile b/examples/translator-app/frontend/Dockerfile
new file mode 100644
index 000000000..0ba4588cd
--- /dev/null
+++ b/examples/translator-app/frontend/Dockerfile
@@ -0,0 +1,48 @@
+#
+# Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# 1st stage, build the app
+FROM maven:3.5.4-jdk-9 as build
+
+WORKDIR /helidon
+
+# Create a first layer to cache the "Maven World" in the local repository.
+# Incremental docker builds will always resume after that, unless you update
+# the pom
+ADD pom.xml .
+RUN mvn package -Dmaven.test.skip
+
+# Do the Maven build!
+# Incremental docker builds will resume here when you change sources
+ADD src src
+RUN mvn package -Dmaven.test.skip
+
+RUN echo "done!"
+
+# 2nd stage, build the runtime image
+FROM openjdk:8-jre-slim
+WORKDIR /helidon
+
+# Copy the binary built in the 1st stage
+COPY --from=build /helidon/target/helidon-examples-translator-frontend.jar ./
+COPY --from=build /helidon/target/libs ./libs
+
+ENV tracing.host="zipkin"
+ENV backend.host="helidon-examples-translator-backend"
+
+CMD ["java", "-jar", "helidon-examples-translator-frontend.jar"]
+
+EXPOSE 8080
\ No newline at end of file
diff --git a/examples/translator-app/frontend/app.yaml b/examples/translator-app/frontend/app.yaml
new file mode 100644
index 000000000..b24f1639a
--- /dev/null
+++ b/examples/translator-app/frontend/app.yaml
@@ -0,0 +1,74 @@
+#
+# Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+apiVersion: extensions/v1beta1
+kind: Deployment
+metadata:
+ name: helidon-examples-translator-frontend
+ labels:
+ app: helidon-examples-translator-frontend
+spec:
+ replicas: 1
+ template:
+ metadata:
+ labels:
+ app: helidon-examples-translator-frontend
+ spec:
+ containers:
+ - image: helidon-examples-translator-frontend:latest
+ imagePullPolicy: IfNotPresent
+ name: translator-frontend
+ ports:
+ - containerPort: 8080
+ env:
+ - name: tracing.host
+ value: "zipkin"
+ - name: backend.host
+ value: "helidon-examples-translator-backend"
+ restartPolicy: Always
+---
+
+apiVersion: v1
+kind: Service
+metadata:
+ name: helidon-examples-translator-frontend
+ labels:
+ app: helidon-examples-translator-frontend
+spec:
+ type: ClusterIP
+ ports:
+ - name: http
+ port: 8080
+ selector:
+ app: helidon-examples-translator-frontend
+ sessionAffinity: None
+
+---
+
+apiVersion: extensions/v1beta1
+kind: Ingress
+metadata:
+ name: helidon-examples-translator-frontend
+spec:
+ rules:
+ - host: localhost
+ http:
+ paths:
+ - path: /translator
+ backend:
+ serviceName: helidon-examples-translator-frontend
+ servicePort: 8080
\ No newline at end of file
diff --git a/examples/translator-app/frontend/pom.xml b/examples/translator-app/frontend/pom.xml
new file mode 100644
index 000000000..ceb0ce804
--- /dev/null
+++ b/examples/translator-app/frontend/pom.xml
@@ -0,0 +1,108 @@
+
+
+
+
+ 4.0.0
+
+ io.helidon.applications
+ helidon-se
+ 1.2.2-SNAPSHOT
+ ../../../applications/se/pom.xml
+
+ io.helidon.examples.translator
+ helidon-examples-translator-frontend
+ 1.2.2-SNAPSHOT
+ Helidon Examples Translator Frontend
+
+
+ A translator frontend example app.
+
+
+
+ io.helidon.examples.translator.frontend.Main
+
+
+
+
+ io.helidon.webserver
+ helidon-webserver
+
+
+ io.helidon.config
+ helidon-config
+
+
+ io.helidon.tracing
+ helidon-tracing-jersey-client
+
+
+ io.helidon.tracing
+ helidon-tracing-zipkin
+
+
+ io.helidon.common
+ helidon-common
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ test
+
+
+ org.hamcrest
+ hamcrest-all
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-libs
+
+
+
+
+
+
+
+
+ add-backend-dependency
+
+
+ !maven.test.skip
+
+
+
+
+ io.helidon.examples.translator
+ helidon-examples-translator-backend
+ ${project.version}
+ test
+
+
+
+
+
diff --git a/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/Main.java b/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/Main.java
new file mode 100644
index 000000000..6723515b3
--- /dev/null
+++ b/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/Main.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.helidon.examples.translator.frontend;
+
+import java.io.IOException;
+import java.util.concurrent.CompletionStage;
+import java.util.logging.LogManager;
+
+import io.helidon.config.Config;
+import io.helidon.config.ConfigSources;
+import io.helidon.tracing.TracerBuilder;
+import io.helidon.webserver.Routing;
+import io.helidon.webserver.ServerConfiguration;
+import io.helidon.webserver.WebServer;
+
+/**
+ * Translator application frontend main class.
+ */
+public class Main {
+
+ private Main() {
+ }
+
+ /**
+ * Start the server.
+ * @return the created {@link WebServer} instance
+ * @throws IOException if there are problems reading logging properties
+ */
+ public static CompletionStage startFrontendServer() throws IOException {
+ // configure logging in order to not have the standard JVM defaults
+ LogManager.getLogManager().readConfiguration(Main.class.getResourceAsStream("/logging.properties"));
+
+ Config config = Config.builder()
+ .sources(ConfigSources.environmentVariables())
+ .build();
+
+ WebServer webServer = WebServer.create(
+ ServerConfiguration.builder()
+ .port(8080)
+ .tracer(TracerBuilder.create(config.get("tracing"))
+ .serviceName("helidon-webserver-translator-frontend")
+ .registerGlobal(false)),
+ Routing.builder()
+ .register(new TranslatorFrontendService(
+ config.get("backend.host").asString().orElse("localhost"),
+ 9080)));
+
+ return webServer.start()
+ .thenApply(ws -> {
+ System.out.println(
+ "WEB server is up! http://localhost:" + ws.port());
+ ws.whenShutdown().thenRun(()
+ -> System.out.println("WEB server is DOWN. Good bye!"));
+ return ws;
+ }).exceptionally(t -> {
+ System.err.println("Startup failed: " + t.getMessage());
+ t.printStackTrace(System.err);
+ return null;
+ });
+ }
+
+ /**
+ * The main method of Translator frontend.
+ *
+ * @param args command-line args, currently ignored.
+ * @throws Exception in case of an error
+ */
+ public static void main(String[] args) throws Exception {
+ startFrontendServer();
+ }
+}
diff --git a/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/TranslatorFrontendService.java b/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/TranslatorFrontendService.java
new file mode 100644
index 000000000..d943652e3
--- /dev/null
+++ b/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/TranslatorFrontendService.java
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.helidon.examples.translator.frontend;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.ws.rs.ProcessingException;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.Response;
+
+import io.helidon.tracing.jersey.client.ClientTracingFilter;
+import io.helidon.webserver.BadRequestException;
+import io.helidon.webserver.Routing;
+import io.helidon.webserver.ServerRequest;
+import io.helidon.webserver.ServerResponse;
+import io.helidon.webserver.Service;
+
+/**
+ * Translator frontend resource.
+ */
+public final class TranslatorFrontendService implements Service {
+
+ private static final Logger LOGGER = Logger.getLogger(TranslatorFrontendService.class.getName());
+ private final WebTarget backendTarget;
+
+ TranslatorFrontendService(String backendHostname, int backendPort) {
+ backendTarget = ClientBuilder.newClient()
+ .target("http://" + backendHostname + ":" + backendPort);
+ }
+
+ @Override
+ public void update(Routing.Rules rules) {
+ rules.get(this::getText);
+ }
+
+ private void getText(ServerRequest request, ServerResponse response) {
+ try {
+ String query = request.queryParams().first("q")
+ .orElseThrow(() -> new BadRequestException("missing query parameter 'q'"));
+ String language = request.queryParams().first("lang")
+ .orElseThrow(() -> new BadRequestException("missing query parameter 'lang'"));
+
+ Response backendResponse = backendTarget
+ .property(ClientTracingFilter.TRACER_PROPERTY_NAME, request.tracer())
+ .property(ClientTracingFilter.CURRENT_SPAN_CONTEXT_PROPERTY_NAME, request.spanContext())
+ .queryParam("q", query)
+ .queryParam("lang", language)
+ .request().get();
+
+ final String result;
+ if (backendResponse.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
+ result = backendResponse.readEntity(String.class);
+ } else {
+ result = "Error: " + backendResponse.readEntity(String.class);
+ }
+ response.send(result + "\n");
+ } catch (ProcessingException pe) {
+ LOGGER.log(Level.WARNING, "Problem to call translator frontend.", pe);
+ response.status(503).send("Translator backend service isn't available.");
+ }
+ }
+}
diff --git a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/package-info.java b/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/package-info.java
similarity index 83%
rename from examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/package-info.java
rename to examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/package-info.java
index e79b9ec12..93687d50c 100644
--- a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/package-info.java
+++ b/examples/translator-app/frontend/src/main/java/io/helidon/examples/translator/frontend/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,4 +17,4 @@
/**
* Demo examples Translator Frontend package.
*/
-package io.helidon.webserver.examples.translator.frontend;
+package io.helidon.examples.translator.frontend;
diff --git a/examples/webserver/demo-translator-frontend/src/main/resources/logging.properties b/examples/translator-app/frontend/src/main/resources/logging.properties
similarity index 100%
rename from examples/webserver/demo-translator-frontend/src/main/resources/logging.properties
rename to examples/translator-app/frontend/src/main/resources/logging.properties
diff --git a/examples/webserver/demo-translator-frontend/src/test/java/io/helidon/webserver/examples/translator/TranslatorTest.java b/examples/translator-app/frontend/src/test/java/io/helidon/examples/translator/TranslatorTest.java
similarity index 54%
rename from examples/webserver/demo-translator-frontend/src/test/java/io/helidon/webserver/examples/translator/TranslatorTest.java
rename to examples/translator-app/frontend/src/test/java/io/helidon/examples/translator/TranslatorTest.java
index 17c558e5e..5b07dce6f 100644
--- a/examples/webserver/demo-translator-frontend/src/test/java/io/helidon/webserver/examples/translator/TranslatorTest.java
+++ b/examples/translator-app/frontend/src/test/java/io/helidon/examples/translator/TranslatorTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-package io.helidon.webserver.examples.translator;
+package io.helidon.examples.translator;
-import java.util.concurrent.CompletionStage;
import java.util.concurrent.TimeUnit;
import javax.ws.rs.client.Client;
@@ -30,13 +29,11 @@ import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import static io.helidon.webserver.examples.translator.backend.Main.createBackendWebServer;
-import static io.helidon.webserver.examples.translator.frontend.Main.createFrontendWebServer;
+import static io.helidon.examples.translator.backend.Main.startBackendServer;
+import static io.helidon.examples.translator.frontend.Main.startFrontendServer;
+import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.AllOf.allOf;
-import static org.hamcrest.core.StringContains.containsString;
-
/**
* The TranslatorTest.
*/
@@ -49,14 +46,8 @@ public class TranslatorTest {
@BeforeAll
public static void setUp() throws Exception {
- CompletionStage backendStage =
- createBackendWebServer(null).start();
- webServerBackend = backendStage.toCompletableFuture().get(10, TimeUnit.SECONDS);
-
- CompletionStage frontendStage =
- createFrontendWebServer(null, "localhost", webServerBackend.port()).start();
- webServerFrontend = frontendStage.toCompletableFuture().get(10, TimeUnit.SECONDS);
-
+ webServerBackend = startBackendServer().toCompletableFuture().get(10, TimeUnit.SECONDS);
+ webServerFrontend = startFrontendServer().toCompletableFuture().get(10, TimeUnit.SECONDS);
client = ClientBuilder.newClient();
target = client.target("http://localhost:" + webServerFrontend.port());
}
@@ -65,23 +56,41 @@ public class TranslatorTest {
public static void tearDown() throws Exception {
webServerFrontend.shutdown().toCompletableFuture().get(10, TimeUnit.SECONDS);
webServerBackend.shutdown().toCompletableFuture().get(10, TimeUnit.SECONDS);
-
if (client != null) {
client.close();
}
}
@Test
- public void e2e() throws Exception {
-
- Response response = target.path("translator")
- .queryParam("q", "cloud")
+ public void testCzech() throws Exception {
+ Response response = target.queryParam("q", "cloud")
+ .queryParam("lang", "czech")
.request()
.get();
assertThat("Unexpected response! Status code: " + response.getStatus(),
- response.readEntity(String.class),
- allOf(containsString("oblak"),
- containsString("nube")));
+ response.readEntity(String.class), is("oblak\n"));
+ }
+
+ @Test
+ public void testItalian() throws Exception {
+ Response response = target.queryParam("q", "cloud")
+ .queryParam("lang", "italian")
+ .request()
+ .get();
+
+ assertThat("Unexpected response! Status code: " + response.getStatus(),
+ response.readEntity(String.class), is("nube\n"));
+ }
+
+ @Test
+ public void testFrench() throws Exception {
+ Response response = target.queryParam("q", "cloud")
+ .queryParam("lang", "french")
+ .request()
+ .get();
+
+ assertThat("Unexpected response! Status code: " + response.getStatus(),
+ response.readEntity(String.class), is("nuage\n"));
}
}
diff --git a/examples/translator-app/pom.xml b/examples/translator-app/pom.xml
new file mode 100644
index 000000000..eda5d4d95
--- /dev/null
+++ b/examples/translator-app/pom.xml
@@ -0,0 +1,42 @@
+
+
+
+
+ 4.0.0
+
+ io.helidon.examples
+ helidon-examples-project
+ 1.2.2-SNAPSHOT
+
+ io.helidon.examples.translator
+ helidon-examples-translator-project
+ pom
+ Helidon Examples Translator Demo
+
+
+ A translator example app.
+
+
+
+ backend
+ frontend
+
+
diff --git a/examples/webserver/README.md b/examples/webserver/README.md
index c1bb0d76d..41c29e619 100644
--- a/examples/webserver/README.md
+++ b/examples/webserver/README.md
@@ -1,4 +1,3 @@
-
# Helidon SE WebServer Examples
-
+This directory contains Helidon SE webserver examples.
\ No newline at end of file
diff --git a/examples/webserver/basics/README.md b/examples/webserver/basics/README.md
index 20708312c..894b86825 100644
--- a/examples/webserver/basics/README.md
+++ b/examples/webserver/basics/README.md
@@ -6,18 +6,17 @@ at runtime. Each method illustrates a different WebServer concept.
See the comments in `Main.java` for a description of the various
methods.
-## Build
+## Build and run
-```
+With JDK8+
+```bash
mvn package
```
-## Run
-
To see the list of methods that are available run:
-```
-mvn -DexampleName=help exec:java
+```bash
+java -DexampleName=help -jar target/helidon-examples-webserver-basics.jar
```
You should see output like:
@@ -41,8 +40,7 @@ Example method names:
You can then choose the method to execute by setting the `exampleName` system property:
```
-mvn -DexampleName=firstRouting exec:java
+java -DexampleName=firstRouting -jar target/helidon-examples-webserver-basics.jar
```
This will start the Helidon SE WebServer using the method indicated.
-
diff --git a/examples/webserver/basics/pom.xml b/examples/webserver/basics/pom.xml
index bf4bf0bfd..5f8a9b1c2 100644
--- a/examples/webserver/basics/pom.xml
+++ b/examples/webserver/basics/pom.xml
@@ -22,10 +22,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- io.helidon.examples.webserver
- helidon-examples-webserver-project
+ io.helidon.applications
+ helidon-se
1.2.2-SNAPSHOT
+ ../../../applications/se/pom.xml
+ io.helidon.examples.webserver
helidon-examples-webserver-basics
Helidon WebServer Examples Basics
@@ -41,17 +43,14 @@
io.helidon.webserver
helidon-webserver
- ${project.version}
io.helidon.webserver
helidon-webserver-jersey
- ${project.version}
io.helidon.media.jsonp
helidon-media-jsonp-server
- ${project.version}
com.google.guava
@@ -70,7 +69,6 @@
io.helidon.webserver
helidon-webserver-test-support
- ${project.version}
test
@@ -79,4 +77,18 @@
test
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-libs
+
+
+
+
+
diff --git a/examples/webserver/comment-aas/README.md b/examples/webserver/comment-aas/README.md
new file mode 100644
index 000000000..811f2322f
--- /dev/null
+++ b/examples/webserver/comment-aas/README.md
@@ -0,0 +1,21 @@
+# Comments As a Service
+
+This application allows users to add or read short comments related to a single topic.
+ Topic can be anything including blog post, newspaper article, and others.
+
+## Build and run
+
+With JDK8+
+```bash
+mvn package
+java -jar target/helidon-examples-webserver-comment-aas.jar
+```
+
+Try the application:
+
+```bash
+curl http://localhost:8080/comments/java -d "I use Helidon!"
+curl http://localhost:8080/comments/java -d "I use vertx"
+curl http://localhost:8080/comments/java -d "I use spring"
+curl http://localhost:8080/comments/java
+```
\ No newline at end of file
diff --git a/examples/webserver/comment-aas/pom.xml b/examples/webserver/comment-aas/pom.xml
index a0aab89a2..264138cb4 100644
--- a/examples/webserver/comment-aas/pom.xml
+++ b/examples/webserver/comment-aas/pom.xml
@@ -22,10 +22,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- io.helidon.examples.webserver
- helidon-examples-webserver-project
+ io.helidon.applications
+ helidon-se
1.2.2-SNAPSHOT
+ ../../../applications/se/pom.xml
+ io.helidon.examples.webserver
helidon-examples-webserver-comment-aas
Helidon WebServer Examples CommentsAAS
@@ -39,26 +41,18 @@
io.helidon.webserver
helidon-webserver
- ${project.version}
io.helidon.common
helidon-common
- ${project.version}
-
-
- io.projectreactor
- reactor-core
-
-
- io.helidon.bundles
- helidon-bundles-config
- ${project.version}
io.helidon.config
- helidon-config-etcd
- ${project.version}
+ helidon-config
+
+
+ io.helidon.config
+ helidon-config-yaml
org.junit.jupiter
@@ -73,13 +67,21 @@
io.helidon.webserver
helidon-webserver-test-support
- ${project.version}
- test
-
-
- org.slf4j
- slf4j-jdk14
test
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy-libs
+
+
+
+
+
diff --git a/examples/webserver/comment-aas/readme.md b/examples/webserver/comment-aas/readme.md
deleted file mode 100644
index 2f51eb10d..000000000
--- a/examples/webserver/comment-aas/readme.md
+++ /dev/null
@@ -1,7 +0,0 @@
-Comments As a Service
-=====================
-
-The **Web Server** example.
-
-Users can add or read short comments related to the single topic. Topic can be anything
-including blog post, newspaper article, and others.
\ No newline at end of file
diff --git a/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/CommentsService.java b/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/CommentsService.java
index b7dc138bc..379a58552 100644
--- a/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/CommentsService.java
+++ b/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/CommentsService.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,7 +58,6 @@ public class CommentsService implements Service {
req.content()
.as(String.class)
.thenAccept(msg -> addComment(msg, userName, topic))
- // Notice the beauty of fluent and reactive response composing...
.thenRun(resp::send)
.exceptionally(t -> {
req.next(t);
diff --git a/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/Main.java b/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/Main.java
index 6497b2a2a..b6d939a71 100644
--- a/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/Main.java
+++ b/examples/webserver/comment-aas/src/main/java/io/helidon/webserver/examples/comments/Main.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,16 +16,12 @@
package io.helidon.webserver.examples.comments;
-import java.net.URI;
import java.util.Optional;
import java.util.concurrent.CompletionException;
import io.helidon.common.OptionalHelper;
import io.helidon.common.http.Http;
-import io.helidon.common.http.MediaType;
import io.helidon.config.Config;
-import io.helidon.config.ConfigSources;
-import io.helidon.config.etcd.EtcdConfigSourceBuilder;
import io.helidon.webserver.HttpException;
import io.helidon.webserver.Routing;
import io.helidon.webserver.ServerConfiguration;
@@ -51,7 +47,7 @@ public final class Main {
*/
public static void main(String[] args) {
// Load configuration
- Config config = loadConfig();
+ Config config = Config.create();
boolean acceptAnonymousUsers = config.get("anonymous-enabled").asBoolean().orElse(false);
ServerConfiguration serverConfig = config.get("webserver").as(ServerConfiguration::create).get();
@@ -59,34 +55,19 @@ public final class Main {
WebServer server = WebServer.create(serverConfig, createRouting(acceptAnonymousUsers));
// Start the server and print some info.
- server.start().thenAccept(Main::printStartupMessage);
+ server.start().thenAccept((ws) -> {
+ System.out.println(
+ "WEB server is up! http://localhost:" + ws.port() + "/comments");
+ });
- // Server uses non-demon threads. It is not needed to block a main thread. Just react!
server.whenShutdown()
- .thenRun(() -> System.out.println("Comments-As-A-Service is DOWN. Good bye!"))
- .thenRun(() -> System.exit(0));
- }
-
- private static Config loadConfig() {
- String etcdUri = Optional.ofNullable(System.getenv("ETCD_URI"))
- .orElse("http://localhost:2379");
-
- return Config.builder()
- .sources(EtcdConfigSourceBuilder.create(URI.create(etcdUri),
- "comments-aas-config",
- EtcdConfigSourceBuilder.EtcdApi.v2)
- .mediaType("application/x-yaml")
- .optional()
- .build(),
- ConfigSources.classpath("application.conf"))
- .build();
+ .thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
}
static Routing createRouting(boolean acceptAnonymousUsers) {
return Routing.builder()
// Filter that translates user identity header into the contextual "user" information
.any((req, res) -> {
-
String user = OptionalHelper.from(req.headers().first("user-identity"))
.or(() -> acceptAnonymousUsers ? Optional.of("anonymous") : Optional.empty())
.asOptional()
@@ -95,21 +76,8 @@ public final class Main {
req.context().register("user", user);
req.next();
})
-
-
// Main service logic part is registered as a separated class to "/comments" context root
.register("/comments", new CommentsService())
-
-
- // Shut down logic is registered to "/mgmt/shutdown" path
- .post("/mgmt/shutdown", (req, res) -> {
- res.headers().contentType(MediaType.TEXT_PLAIN.withCharset("UTF-8"));
- res.send("Shutting down 'COMMENTS-As-A-Service' server. Good bye!\n");
- // Use reactive API nature to stop the server AFTER the response was sent.
- res.whenSent().thenRun(() -> req.webServer().shutdown());
- })
-
-
// Error handling for argot expressions.
.error(CompletionException.class, (req, res, ex) -> req.next(ex.getCause()))
.error(ProfanityException.class, (req, res, ex) -> {
@@ -126,14 +94,4 @@ public final class Main {
})
.build();
}
-
- private static void printStartupMessage(WebServer ws) {
- String urlBase = "http://localhost:" + ws.port();
- StringBuilder info = new StringBuilder();
- info.append("Comments-As-A-Service for your service! ").append(urlBase).append('\n');
- info.append(" - ").append("Add comment: POST ").append(urlBase).append("/comments/{topic}\n");
- info.append(" - ").append("List comments: GET ").append(urlBase).append("/comments/{topic}\n\n");
- info.append("Shutdown: POST ").append(urlBase).append("/mgmt/shutdown\n\n");
- System.out.println(info);
- }
}
diff --git a/examples/webserver/comment-aas/src/main/resources/application.conf b/examples/webserver/comment-aas/src/main/resources/application.yaml
similarity index 87%
rename from examples/webserver/comment-aas/src/main/resources/application.conf
rename to examples/webserver/comment-aas/src/main/resources/application.yaml
index b6b7a78fb..ec8334b64 100644
--- a/examples/webserver/comment-aas/src/main/resources/application.conf
+++ b/examples/webserver/comment-aas/src/main/resources/application.yaml
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,9 +14,8 @@
# limitations under the License.
#
-webserver {
- port: 8080
-}
+webserver:
+ port: 8080
# If true then anonymous access is enabled.
anonymous-enabled: true
diff --git a/examples/webserver/comment-aas/src/test/java/io/helidon/webserver/examples/comments/MainTest.java b/examples/webserver/comment-aas/src/test/java/io/helidon/webserver/examples/comments/MainTest.java
index 6547acb87..fd9ac7c5e 100644
--- a/examples/webserver/comment-aas/src/test/java/io/helidon/webserver/examples/comments/MainTest.java
+++ b/examples/webserver/comment-aas/src/test/java/io/helidon/webserver/examples/comments/MainTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,6 @@
package io.helidon.webserver.examples.comments;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
import io.helidon.common.http.Http;
import io.helidon.common.http.MediaType;
import io.helidon.webserver.testsupport.MediaPublisher;
@@ -28,28 +25,12 @@ import io.helidon.webserver.testsupport.TestResponse;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Tests {@link Main} class.
*/
public class MainTest {
- @Test
- public void testShutDown() throws Exception {
- TestResponse response = TestClient.create(Main.createRouting(true))
- .path("/mgmt/shutdown")
- .post();
-
- assertEquals(Http.Status.OK_200, response.status());
-
- CountDownLatch latch = new CountDownLatch(1);
- response.webServer()
- .whenShutdown()
- .thenRun(latch::countDown);
- assertTrue(latch.await(5, TimeUnit.SECONDS));
- }
-
@Test
public void argot() throws Exception {
TestResponse response = TestClient.create(Main.createRouting(true))
diff --git a/examples/webserver/demo-translator-backend/README.md b/examples/webserver/demo-translator-backend/README.md
deleted file mode 100644
index b379be75f..000000000
--- a/examples/webserver/demo-translator-backend/README.md
+++ /dev/null
@@ -1,100 +0,0 @@
-Translator Backend Example Application
-======================================
-
-Running locally
----------------
-Prerequisites:
-1. Requirements: JDK9, Maven, Docker (optional)
-2. Add following lines to `/etc/hosts`
- ```
- 127.0.0.1 zipkin
- 127.0.0.1 helidon-webserver-translator-backend
- 127.0.0.1 helidon-webserver-translator-frontend
- ```
-3. Run Zipkin:
- In Docker:
- ```
- docker run -d -p 9411:9411 openzipkin/zipkin
- ```
- or with Java 8+:
- ```
- curl -sSL https://zipkin.io/quickstart.sh | bash -s
- java -jar zipkin.jar
- ```
-
-Build and run:
-```
-mvn clean install -pl examples/demo-translator-backend
-mvn exec:java -pl examples/demo-translator-backend
-curl "http://helidon-webserver-translator-backend:9080/translator?q=cloud&lang=czech"
-```
-Check out the traces at: ```http://zipkin:9411```
-
-Aura
-----
-
-### Deployment
-In the parent `examples/` directory, execute:
-```
-export KUBECONFIG=/path/to/your/kubeconfig
-ls *translator*/**/*.yaml | while read FILE; do kubectl create -f <(istioctl kube-inject -f $FILE) & done
-```
-### Accessing
-```
-
-# Setup port-forwarding
-kubectl port-forward $(kubectl get pod -l component=aura-istio-zipkin -o jsonpath='{.items[0].metadata.name}') 9411:9411 &
-kubectl port-forward $(kubectl get pod -l component=aura-istio-grafana -o jsonpath='{.items[0].metadata.name}') 3000:3000 &
-kubectl port-forward $(kubectl get pod -l component=aura-istio-ingress -o jsonpath='{.items[0].metadata.name}') 30080:80 &
-
-# Call the FE
-watch -n 0.1 curl 'http://localhost:30080/translator?q=cloud'
-
-# Break a random BE pod
-watch -n 10 curl 'http://localhost:30080/translator/break' -X POST
-# or alternatively break a specific one by execing into a specific pod
-kubectl exec -c proxy "$(kubectl get pod -l app=helidon-webserver-translator-backend -o jsonpath='{.items[0].metadata.name}')" -i -t -- /bin/bash -c "watch -n 10 curl 'http://localhost:9080/translator/break' -X POST"
-
-# Fix a random BE pod
-watch -n 10 curl 'http://localhost:30080/translator/fix' -X POST
-
-# See Grafana
-open http://localhost:3000
-
-# See Zipkin
-open http://localhost:9411
-```
-### Uninstallation
-```
-export KUBECONFIG=/path/to/your/kubeconfig
-ls *translator*/**/*.yaml | while read FILE; do kubectl delete -f $FILE & done
-
-```
-
-Running in MiniKube
--------------------
-
-Prerequisites
-1. Requirements: JDK9, Docker client, Minikube, Maven
-2. Running Minikube and Zipkin: check out instructions at [WebServer Examples OpenTracing](../opentracing/README.md)
-
-Running Translator Backend app:
-```
-eval $(minikube docker-env)
-
-mvn clean deploy -Dmaven.deploy.skip=true -Drelease.enforce.no-snapshosts.phase=none -P release
-
-\# without Istio
-kubectl create -f examples/demo-translator-backend/k8s/backend.yaml
-\# with Istio
-kubectl create -f <(istioctl kube-inject -f examples/demo-translator-backend/k8s/backend.yaml)
-
-curl "$(minikube service helidon-webserver-translator-backend --url)/translator?q=cloud&lang=czech"
-
-```
-
-Check out Zipkin traces:
-```
-minikube service zipkin
-
-```
diff --git a/examples/webserver/demo-translator-backend/k8s/backend.yaml b/examples/webserver/demo-translator-backend/k8s/backend.yaml
deleted file mode 100644
index 98337458c..000000000
--- a/examples/webserver/demo-translator-backend/k8s/backend.yaml
+++ /dev/null
@@ -1,87 +0,0 @@
-#
-# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-
-apiVersion: extensions/v1beta1
-kind: Deployment
-metadata:
- name: helidon-webserver-translator-backend-v1
- labels:
- app: helidon-webserver-translator-backend
-spec:
- replicas: 2
- template:
- metadata:
- labels:
- app: helidon-webserver-translator-backend
- version: v1
- spec:
- containers:
- - image: registry.oracledx.com/skeppare/helidon/helidon-webserver-translator-backend:0.1.0-SNAPSHOT
- imagePullPolicy: Always
- name: helidon-webserver-translator-backend
- envFrom:
- - configMapRef:
- name: aura-env-config
- optional: true
- imagePullSecrets:
- - name: regsecret
- restartPolicy: Always
-
----
-
-apiVersion: extensions/v1beta1
-kind: Deployment
-metadata:
- name: helidon-webserver-translator-backend-v2
- labels:
- app: helidon-webserver-translator-backend
-spec:
- replicas: 3
- template:
- metadata:
- labels:
- app: helidon-webserver-translator-backend
- version: v2
- spec:
- containers:
- - image: registry.oracledx.com/skeppare/helidon/helidon-webserver-translator-backend:0.1.0-SNAPSHOT
- imagePullPolicy: Always
- name: helidon-webserver-translator-backend
- envFrom:
- - configMapRef:
- name: aura-env-config
- optional: true
- imagePullSecrets:
- - name: regsecret
- restartPolicy: Always
-
----
-
-apiVersion: v1
-kind: Service
-metadata:
- name: helidon-webserver-translator-backend
- labels:
- app: helidon-webserver-translator-backend
-spec:
- ports:
- - name: http
- port: 9080
- selector:
- app: helidon-webserver-translator-backend
- sessionAffinity: None
- type: NodePort
diff --git a/examples/webserver/demo-translator-backend/pom.xml b/examples/webserver/demo-translator-backend/pom.xml
deleted file mode 100644
index 30d10eb43..000000000
--- a/examples/webserver/demo-translator-backend/pom.xml
+++ /dev/null
@@ -1,150 +0,0 @@
-
-
-
-
- 4.0.0
-
- io.helidon.examples.webserver
- helidon-examples-webserver-project
- 1.2.2-SNAPSHOT
-
- helidon-examples-webserver-translator-backend
- Helidon WebServer Examples Translator Backend
-
-
- A translator backend example app.
-
-
-
- io.helidon.webserver.examples.translator.backend.Main
-
- ${docker.registry}/skeppare/helidon/helidon-webserver-translator-backend:${project.version}
-
- mic-docker-registry-automation
- registry.oracledx.com
- https://${docker.registry}/v1/
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-resources-plugin
-
-
- copy-docker-resources
- generate-resources
-
- copy-resources
-
-
- ${project.build.directory}/distribution/container
-
-
- src/main/docker
- true
-
-
-
-
-
-
-
- com.spotify
- docker-maven-plugin
-
- ${docker.server.id}
- ${docker.registry.url}
- ${docker.image.name}
- ${project.build.directory}/distribution/container
-
- ${docker.image.version}
- latest
-
-
-
- /
- ${project.build.directory}
- ${project.build.finalName}-fat.jar
-
-
-
-
-
-
-
-
- maven-surefire-plugin
-
-
- ${project.build.outputDirectory}/logging.properties
-
-
-
-
-
-
-
-
-
- io.helidon.webserver
- helidon-webserver
- ${project.version}
-
-
- io.helidon.webserver
- helidon-webserver-jersey
- ${project.version}
-
-
- io.helidon.tracing
- helidon-tracing-jersey
- ${project.version}
-
-
- io.helidon.tracing
- helidon-tracing-zipkin
- ${project.version}
-
-
- org.junit.jupiter
- junit-jupiter-api
- test
-
-
- org.hamcrest
- hamcrest-all
- test
-
-
- org.mockito
- mockito-core
- test
-
-
- io.helidon.webserver
- helidon-webserver-test-support
- ${project.version}
- test
-
-
-
diff --git a/examples/webserver/demo-translator-backend/src/main/docker/Dockerfile b/examples/webserver/demo-translator-backend/src/main/docker/Dockerfile
deleted file mode 100644
index d0934997f..000000000
--- a/examples/webserver/demo-translator-backend/src/main/docker/Dockerfile
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-FROM java:9
-
-EXPOSE 9080
-COPY ./* /
-RUN rm Dockerfile
-WORKDIR /
-CMD if [ ! -z "$MIC_CONTAINER_MEM_QUOTA" ]; then java -Xmx${MIC_CONTAINER_MEM_QUOTA}m ${JAVA_OPTS} -jar ${artifactId}-${version}-fat.jar ; else java ${JAVA_OPTS} -jar ${artifactId}-${version}-fat.jar ; fi
diff --git a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/Application.java b/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/Application.java
deleted file mode 100644
index a5d0cdab2..000000000
--- a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/Application.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.helidon.webserver.examples.translator.backend;
-
-import io.helidon.tracing.jersey.TracingFilter;
-
-import org.glassfish.jersey.server.ResourceConfig;
-
-/**
- * Translator backend JAX-RS Application.
- */
-public class Application extends ResourceConfig {
-
- /**
- * Translator Backend application.
- */
- public Application() {
- packages(TranslatorResource.class.getPackage().getName());
- register(TracingFilter.class);
- }
-}
diff --git a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/Main.java b/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/Main.java
deleted file mode 100644
index 148377e63..000000000
--- a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/Main.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.helidon.webserver.examples.translator.backend;
-
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-import io.helidon.tracing.TracerBuilder;
-import io.helidon.webserver.Routing;
-import io.helidon.webserver.ServerConfiguration;
-import io.helidon.webserver.WebServer;
-import io.helidon.webserver.jersey.JerseySupport;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.NANOSECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
-/**
- * Demo Backend Example Application main class.
- */
-public class Main {
-
- private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
-
- /**
- * (design) HideUtilityClassConstructor: Utility classes should not have a public or default constructor.
- */
- private Main() {
- }
-
- /**
- * Creates new instance of {@link WebServer} configured for this service.
- *
- * @param configuration the server configuration
- * @return new {@link WebServer} instance.
- */
- public static WebServer createBackendWebServer(ServerConfiguration configuration) {
-
- Routing.Builder router = Routing.builder()
- .register(JerseySupport.create(new Application()));
-
- if (!isSecurityDisabled()) {
- // TODO Add security
- // builder.addModule(SecurityModule.builder()
- // .enforceAuthentication("/translator/*")
- // .skipAuthentication("/translator/break")
- // .skipAuthentication("/translator/fix")
- // .skipAuthentication("/translator/health")
- // .build());
- } else {
- LOGGER.info("[dev-local] Running without Security module.");
- }
- return WebServer.create(configuration, router.build());
- }
-
- /**
- * Is the application running in local development mode?
- *
- * @return {@code true} if the application is running locally.
- */
- public static boolean isSecurityDisabled() {
- // TODO enable security return System.getenv("MIC_DEV_LOCAL") != null;
- return true;
- }
-
- /**
- * The main method of Translator backend.
- *
- * @param args command-line args, currently ignored.
- * @throws Exception in case of an error
- */
- public static void main(String[] args) throws Exception {
- // configure logging in order to not have the standard JVM defaults
- LogManager.getLogManager().readConfiguration(Main.class.getResourceAsStream("/logging.properties"));
-
- dumpEnv();
-
- long initNanoTime = System.nanoTime();
-
- WebServer webServer = createBackendWebServer(
- ServerConfiguration.builder()
- .port(9080)
- .tracer(TracerBuilder.create("helidon-webserver-translator-backend")
- .collectorHost(System.getenv().getOrDefault("ODX_AURA_ZIPKIN_ADDRESS", "localhost"))
- .buildAndRegister())
- .build())
- .start()
- .toCompletableFuture()
- .get(10, SECONDS);
-
- System.out.println("Translator backend started in " + MILLISECONDS
- .convert(System.nanoTime() - initNanoTime, NANOSECONDS) + " ms.");
- System.out.println("Webserver running at http://localhost:" + webServer.port());
- }
-
- private static void dumpEnv() {
- Map sortedEnvVars = new TreeMap<>(System.getenv());
-
- System.out.println("Environment variables:");
- sortedEnvVars.forEach((key, value) -> System.out.println(key + "=" + value));
- System.out.println("---");
- }
-
-}
diff --git a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/StaticFrontPageResource.java b/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/StaticFrontPageResource.java
deleted file mode 100644
index 6edae7ad7..000000000
--- a/examples/webserver/demo-translator-backend/src/main/java/io/helidon/webserver/examples/translator/backend/StaticFrontPageResource.java
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.helidon.webserver.examples.translator.backend;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-/**
- * Static resources JAX-RS Resource.
- */
-@Path("/")
-public class StaticFrontPageResource {
-
- /**
- * Static page get method.
- *
- * @return The page.
- */
- @GET
- @Produces(MediaType.TEXT_HTML)
- @SuppressWarnings("checkstyle:methodlength")
- public String get() {
-
- return "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + " \n"
- + " Translator Backend Service\n"
- + " \n"
- + "\n"
- + " Translator Backend Service\n"
- + "
\n"
- + "\n"
- + "Summary
\n"
- + "\n"
- + " \n"
- + " | Resource | \n"
- + " Method | \n"
- + " Description | \n"
- + "
\n"
- + " \n"
- + " | ./translator | \n"
- + " GET
| \n"
- + "
| \n"
- + "
\n"
- + "
\n"
- + "\n"
- + "\n"
- + "Resources
\n"
- + "\n"
- + "\n"
- + "\n"
- + "Methods
\n"
- + "\n"
- + "\n"
- + "
\n"
- + "
\n"
- + "
request
\n"
- + "\n"
- + "
\n"
- + "
query params
\n"
- + "
\n"
- + " \n"
- + " | q | \n"
- + " string | \n"
- + "
\n"
- + " \n"
- + " | lang | \n"
- + " string | \n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
responses
\n"
- + "\n"
- + "
\n"
- + "
status:
\n"
- + " 200 - OK\n"
- + "
\n"
- + "
representations
\n"
- + "
\n"
- + " \n"
- + " | text/plain | \n"
- + " | \n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "\n"
- + "\n";
- }
-}
diff --git a/examples/webserver/demo-translator-frontend/README.md b/examples/webserver/demo-translator-frontend/README.md
deleted file mode 100644
index efd0043d1..000000000
--- a/examples/webserver/demo-translator-frontend/README.md
+++ /dev/null
@@ -1,105 +0,0 @@
-Translator Frontend Example Application
-======================================
-
-Running locally
----------------
-Prerequisites:
-1. Requirements: JDK9, Maven, Docker (optional)
-2. Add following lines to `/etc/hosts`
- ```
- 127.0.0.1 zipkin
- 127.0.0.1 helidon-webserver-translator-backend
- 127.0.0.1 helidon-webserver-translator-frontend
- ```
-3. Run Zipkin:
- In Docker:
- ```
- docker run -d -p 9411:9411 openzipkin/zipkin
- ```
- or with Java 8+:
- ```
- curl -sSL https://zipkin.io/quickstart.sh | bash -s
- java -jar zipkin.jar
- ```
-
-Build and run:
-```
-mvn clean install -pl examples/demo-translator-frontend
-mvn exec:java -pl examples/demo-translator-frontend
-curl "http://helidon-webserver-translator-frontend:8080/translator?q=cloud"
-```
-Check out the traces at: ```http://zipkin:9411```
-
-
-Aura
-----
-
-### Deployment
-In the parent `examples/` directory, execute:
-```
-export KUBECONFIG=/path/to/your/kubeconfig
-ls *translator*/**/*.yaml | while read FILE; do kubectl create -f <(istioctl kube-inject -f $FILE) & done
-```
-### Accessing
-```
-
-# Setup port-forwarding
-kubectl port-forward $(kubectl get pod -l component=aura-istio-zipkin -o jsonpath='{.items[0].metadata.name}') 9411:9411 &
-kubectl port-forward $(kubectl get pod -l component=aura-istio-grafana -o jsonpath='{.items[0].metadata.name}') 3000:3000 &
-kubectl port-forward $(kubectl get pod -l component=aura-istio-ingress -o jsonpath='{.items[0].metadata.name}') 30080:80 &
-
-# Call the FE
-watch -n 0.1 curl 'http://localhost:30080/translator?q=cloud'
-
-# Break a random BE pod
-watch -n 10 curl 'http://localhost:30080/translator/break' -X POST
-# or alternatively break a specific one by execing into a specific pod
-kubectl exec -c proxy "$(kubectl get pod -l app=helidon-webserver-translator-backend -o jsonpath='{.items[0].metadata.name}')" -i -t -- /bin/bash -c "watch -n 10 curl 'http://localhost:9080/translator/break' -X POST"
-
-# Fix a random BE pod
-watch -n 10 curl 'http://localhost:30080/translator/fix' -X POST
-
-# See Grafana
-open http://localhost:3000
-
-# See Zipkin
-open http://localhost:9411
-```
-### Uninstallation
-```
-export KUBECONFIG=/path/to/your/kubeconfig
-ls *translator*/**/*.yaml | while read FILE; do kubectl delete -f $FILE & done
-
-```
-
-Running in MiniKube
--------------------
-
-Prerequisites
-1. Running Minikube and Zipkin: check out instructions at [WebServer Examples OpenTracing](../opentracing/README.md)
-
-Running Translator Frontend app
-```
-eval $(minikube docker-env)
-
-mvn clean deploy -Dmaven.deploy.skip=true -Drelease.enforce.no-snapshosts.phase=none -P release
-
-\# Without Istio
-kubectl create -f examples/demo-translator-frontend/k8s/frontend.yaml
-\# With Istio
-kubectl create -f <(istioctl kube-inject -f examples/demo-translator-frontend/k8s/frontend.yaml)
-kubectl create -f examples/demo-translator-frontend/k8s/gateway.yaml
-
-\# Without Istio
-curl "$(minikube service helidon-webserver-translator-frontend --url)/translator?q=cloud"
-
-\# With Istio
-curl "$(minikube service -l istio=ingress --url)/translator?q=cloud"
-```
-
-Check out Zipkin traces:
-```
-minikube service zipkin
-
-```
-
diff --git a/examples/webserver/demo-translator-frontend/k8s/gateway.yaml b/examples/webserver/demo-translator-frontend/k8s/gateway.yaml
deleted file mode 100644
index 226e61406..000000000
--- a/examples/webserver/demo-translator-frontend/k8s/gateway.yaml
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-
-apiVersion: extensions/v1beta1
-kind: Ingress
-metadata:
- name: helidon-webserver-gateway
- annotations:
- kubernetes.io/ingress.class: "istio"
-spec:
- rules:
- - http:
- paths:
- - path: /translator
- backend:
- serviceName: helidon-webserver-translator-frontend
- servicePort: 8080
- - path: /translator/break
- backend:
- serviceName: helidon-webserver-translator-backend
- servicePort: 9080
- - path: /translator/fix
- backend:
- serviceName: helidon-webserver-translator-backend
- servicePort: 9080
diff --git a/examples/webserver/demo-translator-frontend/pom.xml b/examples/webserver/demo-translator-frontend/pom.xml
deleted file mode 100644
index 03e150171..000000000
--- a/examples/webserver/demo-translator-frontend/pom.xml
+++ /dev/null
@@ -1,162 +0,0 @@
-
-
-
-
- 4.0.0
-
- io.helidon.examples.webserver
- helidon-examples-webserver-project
- 1.2.2-SNAPSHOT
-
- helidon-examples-webserver-translator-frontend
- Helidon WebServer Examples Translator Frontend
-
-
- A translator frontend example app.
-
-
-
- io.helidon.webserver.examples.translator.frontend.Main
-
- ${docker.registry}/skeppare/helidon/helidon-webserver-translator-frontend:${project.version}
-
- mic-docker-registry-automation
- registry.oracledx.com
- https://${docker.registry}/v1/
- 1.0.0
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-resources-plugin
-
-
- copy-docker-resources
- generate-resources
-
- copy-resources
-
-
- ${project.build.directory}/distribution/container
-
-
- src/main/docker
- true
-
-
-
-
-
-
-
- com.spotify
- docker-maven-plugin
-
- ${docker.server.id}
- ${docker.registry.url}
- ${docker.image.name}
- ${project.build.directory}/distribution/container
-
- ${docker.image.version}
- latest
-
-
-
- /
- ${project.build.directory}
- ${project.build.finalName}-fat.jar
-
-
-
-
-
-
-
-
- maven-surefire-plugin
-
-
- ${project.build.outputDirectory}/logging.properties
-
-
-
-
-
-
-
-
-
- io.helidon.webserver
- helidon-webserver
- ${project.version}
-
-
- io.helidon.webserver
- helidon-webserver-jersey
- ${project.version}
-
-
- io.helidon.tracing
- helidon-tracing-jersey
- ${project.version}
-
-
- io.helidon.tracing
- helidon-tracing-zipkin
- ${project.version}
-
-
- io.helidon.common
- helidon-common
- ${project.version}
-
-
- io.helidon.examples.webserver
- helidon-examples-webserver-translator-backend
- test
- ${project.version}
-
-
- org.junit.jupiter
- junit-jupiter-api
- test
-
-
- org.hamcrest
- hamcrest-all
- test
-
-
- org.mockito
- mockito-core
- test
-
-
- io.helidon.webserver
- helidon-webserver-test-support
- ${project.version}
- test
-
-
-
diff --git a/examples/webserver/demo-translator-frontend/src/main/docker/Dockerfile b/examples/webserver/demo-translator-frontend/src/main/docker/Dockerfile
deleted file mode 100644
index 6cd9a2799..000000000
--- a/examples/webserver/demo-translator-frontend/src/main/docker/Dockerfile
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-FROM java:9
-
-EXPOSE 8080
-COPY ./* /
-RUN rm Dockerfile
-WORKDIR /
-CMD if [ ! -z "$MIC_CONTAINER_MEM_QUOTA" ]; then java -Xmx${MIC_CONTAINER_MEM_QUOTA}m ${JAVA_OPTS} -jar ${artifactId}-${version}-fat.jar ; else java ${JAVA_OPTS} -jar ${artifactId}-${version}-fat.jar ; fi
diff --git a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/Application.java b/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/Application.java
deleted file mode 100644
index 106a52bbb..000000000
--- a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/Application.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.helidon.webserver.examples.translator.frontend;
-
-import io.helidon.tracing.jersey.TracingFilter;
-
-import org.glassfish.hk2.utilities.binding.AbstractBinder;
-import org.glassfish.jersey.server.ResourceConfig;
-
-/**
- * Translator frontend JAX-RS Application.
- */
-public class Application extends ResourceConfig {
-
-
- /**
- * Translator Frontend application.
- *
- * @param backendHostname the translator backend hostname
- * @param backendPort the translator backend port
- */
- public Application(String backendHostname, int backendPort) {
- register(new AbstractBinder() {
- @Override
- protected void configure() {
- bind(backendPort).to(Integer.class).named(TranslatorResource.BACKEND_PORT);
- bind(backendHostname).to(String.class).named(TranslatorResource.BACKEND_HOSTNAME);
-
- }
- });
- register(TracingFilter.class);
- packages(TranslatorResource.class.getPackage().getName());
- }
-}
diff --git a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/Main.java b/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/Main.java
deleted file mode 100644
index d0eed3884..000000000
--- a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/Main.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.helidon.webserver.examples.translator.frontend;
-
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.logging.LogManager;
-import java.util.logging.Logger;
-
-import io.helidon.tracing.TracerBuilder;
-import io.helidon.webserver.Routing;
-import io.helidon.webserver.ServerConfiguration;
-import io.helidon.webserver.WebServer;
-import io.helidon.webserver.jersey.JerseySupport;
-
-import static java.util.concurrent.TimeUnit.MILLISECONDS;
-import static java.util.concurrent.TimeUnit.NANOSECONDS;
-import static java.util.concurrent.TimeUnit.SECONDS;
-
-/**
- * Demo Frontend Example Application main class.
- */
-public class Main {
-
- private static final Logger LOGGER = Logger.getLogger(Main.class.getName());
-
- /**
- * (design) HideUtilityClassConstructor: Utility classes should not have a public or default constructor.
- */
- private Main() {
- }
-
- /**
- * Creates new instance of {@link WebServer} configured for this service.
- *
- * @param configuration the server configuration
- * @param backendHostname the translator backend hostname
- * @param backendPort the translator backend port
- * @return new {@link WebServer} instance.
- */
- public static WebServer createFrontendWebServer(ServerConfiguration configuration, String backendHostname, int backendPort) {
-
- Routing.Builder router = Routing.builder()
- .register(JerseySupport.create(new Application(backendHostname, backendPort)));
-
- if (!isSecurityDisabled()) {
- // TODO Add security
- // builder.addModule(SecurityModule.builder().build());
- } else {
- LOGGER.info("[dev-local] Running without Security module.");
- }
- return WebServer.create(configuration, router.build());
- }
-
- /**
- * Is the application running in local development mode?
- *
- * @return {@code true} if the application is running locally.
- */
- public static boolean isSecurityDisabled() {
- // TODO add security return System.getenv("MIC_DEV_LOCAL") != null;
- return true;
- }
-
- /**
- * The main method of Translator frontend.
- *
- * @param args command-line args, currently ignored.
- * @throws Exception in case of an error
- */
- public static void main(String[] args) throws Exception {
- // configure logging in order to not have the standard JVM defaults
- LogManager.getLogManager().readConfiguration(Main.class.getResourceAsStream("/logging.properties"));
-
- dumpEnv();
-
- long initNanoTime = System.nanoTime();
-
- WebServer webServer = createFrontendWebServer(
- ServerConfiguration.builder()
- .port(8080)
- .tracer(TracerBuilder.create("helidon-webserver-translator-frontend")
- .collectorHost(System.getenv().getOrDefault("ODX_AURA_ZIPKIN_ADDRESS", "localhost"))
- .buildAndRegister())
- .build(),
- "helidon-webserver-translator-backend",
- 9080)
- .start()
- .toCompletableFuture()
- .get(10, SECONDS);
-
- System.out.println("Translator frontend started in " + MILLISECONDS
- .convert(System.nanoTime() - initNanoTime, NANOSECONDS) + " ms.");
- System.out.println("Webserver running at http://localhost:" + webServer.port());
- }
-
- private static void dumpEnv() {
- Map sortedEnvVars = new TreeMap<>(System.getenv());
-
- System.out.println("Environment variables:");
- sortedEnvVars.forEach((key, value) -> System.out.println(key + "=" + value));
- System.out.println("---");
- }
-
-}
diff --git a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/StaticFrontPageResource.java b/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/StaticFrontPageResource.java
deleted file mode 100644
index fc690cdb0..000000000
--- a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/StaticFrontPageResource.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.helidon.webserver.examples.translator.frontend;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-/**
- * Static resources JAX-RS Resource.
- */
-@Path("/")
-public class StaticFrontPageResource {
-
- /**
- * Static page get method.
- *
- * @return The page.
- */
- @GET
- @Produces(MediaType.TEXT_HTML)
- @SuppressWarnings("checkstyle:methodlength")
- public String get() {
-
- return "\n"
- + "\n"
- + "\n"
- + " \n"
- + " \n"
- + " \n"
- + " Translator Frontend Service\n"
- + " \n"
- + "\n"
- + " Translator Frontend Service\n"
- + "
\n"
- + "\n"
- + "Summary
\n"
- + "\n"
- + " \n"
- + " | Resource | \n"
- + " Method | \n"
- + " Description | \n"
- + "
\n"
- + " \n"
- + " | ./translator | \n"
- + " GET POST
| \n"
- + "
| \n"
- + "
\n"
- + "
\n"
- + "\n"
- + "\n"
- + "Resources
\n"
- + "\n"
- + "\n"
- + "\n"
- + "Methods
\n"
- + "\n"
- + "\n"
- + "
\n"
- + "
\n"
- + "
request
\n"
- + "\n"
- + "
\n"
- + "
query params
\n"
- + "
\n"
- + " \n"
- + " | q | \n"
- + " string | \n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
responses
\n"
- + "\n"
- + "
\n"
- + "
status:
\n"
- + " 200 - OK\n"
- + "
\n"
- + "
representations
\n"
- + "
\n"
- + " \n"
- + " | text/plain | \n"
- + " | \n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
request
\n"
- + "\n"
- + "
\n"
- + " unspecified\n"
- + "
\n"
- + "
responses
\n"
- + "\n"
- + "
\n"
- + "
status:
\n"
- + " 200 - OK\n"
- + "
\n"
- + "
representations
\n"
- + "
\n"
- + " \n"
- + " | text/plain | \n"
- + " | \n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "
\n"
- + "\n"
- + "\n";
- }
-}
diff --git a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/TranslatorResource.java b/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/TranslatorResource.java
deleted file mode 100644
index dc97ebff8..000000000
--- a/examples/webserver/demo-translator-frontend/src/main/java/io/helidon/webserver/examples/translator/frontend/TranslatorResource.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*
- * Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package io.helidon.webserver.examples.translator.frontend;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.ProcessingException;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import io.helidon.common.CollectionsHelper;
-import io.helidon.tracing.jersey.client.ClientTracingFilter;
-import io.helidon.webserver.ServerRequest;
-
-import io.opentracing.Tracer;
-import org.glassfish.jersey.server.Uri;
-
-/**
- * Translator frontend resource.
- */
-@Path("translator")
-public class TranslatorResource {
-
- private static final Logger LOGGER = Logger.getLogger(TranslatorResource.class.getName());
-
- private static final String TRANSLATOR_VERSION = "TRANSLATOR_VERSION";
- private static final String TRANSLATOR_BACKEND = "http://{backend-hostname}:{backend-port}";
-
- /** The backend port named injection qualifier. */
- public static final String BACKEND_PORT = "backend-port";
- /** The backend hostname named injection qualifier. */
- public static final String BACKEND_HOSTNAME = "backend-hostname";
-
- private List languages = CollectionsHelper.listOf("czech", "spanish", "chinese", "hindi");
-
- private List languagesV2 = CollectionsHelper.listOf("italian", "french");
-
- @Inject
- private ServerRequest request;
-
- @Inject @Named(BACKEND_PORT)
- private Integer backendPort;
-
- @Inject @Named(BACKEND_HOSTNAME)
- private String backendHostname;
-
- /**
- * Get the translated text as a html page.
- *
- * @param query the text to translate
- * @param translator the backend translator to use
- * @return a page with the translated text
- */
- @GET
- @Produces(MediaType.TEXT_HTML)
- public String getHtml(@QueryParam("q") String query,
- @Uri(TRANSLATOR_BACKEND) WebTarget translator) {
- return "\n"
- + "\n"
- + "\n"
- + " \n"
- + " Translator Frontend\n"
- + "\n"
- + "\n"
- + "\n"
- + "Translator Frontend
\n"
- + getText(query, translator).replace("\n", "
")
- + "\n"
- + "\n";
- }
-
- /**
- * Get method to translate a given query.
- *
- * @param query the query to translate
- * @param translator the backend translator to use
- * @return the translated text
- */
- @GET
- @Produces(MediaType.TEXT_PLAIN)
- public String getText(@QueryParam("q") String query,
- @Uri(TRANSLATOR_BACKEND) WebTarget translator) {
- try {
- translator = translator.resolveTemplate("backend-port", backendPort)
- .resolveTemplate("backend-hostname", backendHostname)
- .property(ClientTracingFilter.TRACER_PROPERTY_NAME, tracer(request))
- .property(ClientTracingFilter.CURRENT_SPAN_CONTEXT_PROPERTY_NAME, request.spanContext())
- .path("translator").queryParam("q", query);
- final StringBuilder sb = new StringBuilder();
-
- // Add languages for version 2
- final String version = System.getenv(TRANSLATOR_VERSION);
- if ("2".equals(version)) {
- languages.addAll(languagesV2);
- }
-
- for (String language : languages) {
- final WebTarget lang = translator.queryParam("lang", language);
- LOGGER.info("GET " + lang.getUri());
-
- translate(lang, sb);
- }
-
- return sb.toString();
- } catch (ProcessingException pe) {
- LOGGER.log(Level.WARNING, "Problem to call translator frontend.", pe);
- return "Translator backend service isn't available.";
- } catch (Exception e) {
- final StringWriter stringWriter = new StringWriter();
- e.printStackTrace(new PrintWriter(stringWriter));
-
- return stringWriter.toString();
- }
- }
-
- private Tracer tracer(ServerRequest request) {
- return request.tracer();
- }
-
- private void translate(final WebTarget backend, final StringBuilder sb) {
- if (Main.isSecurityDisabled()) {
- LOGGER.info("[dev-local] Backend is called without security.");
- translateImpl(backend, sb);
- } else {
- // TODO add security
- //SecurityModule.runAsSystem(() -> translateImpl(backend, sb));
- }
- }
-
- private void translateImpl(final WebTarget backend, final StringBuilder sb) {
- Response response = backend.request().get();
- final String result;
- if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
- result = response.readEntity(String.class);
- } else {
- result = "Error: " + response.readEntity(String.class);
- }
- sb.append(result).append('\n');
- }
-
- /**
- * An example of a post method that simply sleeps.
- *
- * @return {@code post!} string
- */
- @POST
- @Produces(MediaType.TEXT_PLAIN)
- public String post() {
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
-
- return "post!";
- }
-
- /**
- * Marathon health check.
- *
- * This should check the health of state/storage service (if present).
- *
- * @return HTTP 2xx response.
- */
- @GET
- @Path("health")
- public Response health() {
- return Response.noContent().build();
- }
-}
diff --git a/examples/webserver/jersey/README.md b/examples/webserver/jersey/README.md
index 48ff385f0..ebe45b3d3 100644
--- a/examples/webserver/jersey/README.md
+++ b/examples/webserver/jersey/README.md
@@ -1,21 +1,19 @@
-WebServer Jersey Application Example
-=====================
+# WebServer Jersey Application Example
An example of **Jersey** integration into the **Web Server**.
This is just a simple Hello World example. A user can start the application using the `WebServerJerseyMain` class
and `GET` the `Hello World!` response by accessing `http://localhost:8080/jersey/hello`.
-Running the example
--------------------
+## Build and run
-Running this example requires
- * To have checked out the Java sources of this Maven module locally
- * JDK 9
- * Maven 3
- * CURL
+With JDK8+
+```bash
+mvn package
+java -jar target/helidon-examples-webserver-jersey.jar
+```
-Execute from this directory (where this `README.md` file is located):
-
- mvn exec:java -pl examples/jersey
- curl http://localhost:8080/jersey/hello
+Make an HTTP request to application:
+```bash
+curl http://localhost:8080/jersey/hello
+```
\ No newline at end of file
diff --git a/examples/webserver/jersey/pom.xml b/examples/webserver/jersey/pom.xml
index 4b44ba455..fdac69984 100644
--- a/examples/webserver/jersey/pom.xml
+++ b/examples/webserver/jersey/pom.xml
@@ -22,10 +22,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- io.helidon.examples.webserver
- helidon-examples-webserver-project
+ io.helidon.applications
+ helidon-se
1.2.2-SNAPSHOT
+ ../../../applications/se/pom.xml
+ io.helidon.examples.webserver
helidon-examples-webserver-jersey
Helidon WebServer Examples Jersey
@@ -34,19 +36,17 @@