mirror of
https://github.com/jlengrand/helidon.git
synced 2026-03-10 08:21:17 +00:00
Update examples (#1715)
* Update examples to get rid of deprecated methods. Don't use Application classes when not needed Remove references to JDK8 in readmes And other minor changes
This commit is contained in:
@@ -10,8 +10,7 @@ containing config in HOCON (Human-Optimized Config Object Notation) format
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-config-basics.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -30,8 +30,7 @@ the most up-to-date value. Sometimes that is all you need.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-config-changes.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -21,7 +21,6 @@ checks to make sure the value is the expected `hello`.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
export ENVIRONMENT_NAME=test
|
||||
|
||||
@@ -17,8 +17,7 @@ system how to construct a POJO instance.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-config-mapping.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -21,8 +21,7 @@ take precedence over the settings in the original config sources.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-config-overrides.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -17,7 +17,6 @@ filter.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-config-sources.jar
|
||||
|
||||
@@ -13,7 +13,6 @@ The service uses Helidon DB Client that provides reactive and non-blocking acces
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/employee-app.jar
|
||||
|
||||
@@ -4,7 +4,6 @@ A basic example gRPC server.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-grpc-basics.jar
|
||||
@@ -14,4 +13,8 @@ Exercise the example:
|
||||
```bash
|
||||
java -cp target/helidon-examples-grpc-basics.jar \
|
||||
io.helidon.grpc.examples.basics.HealthClient
|
||||
```
|
||||
```
|
||||
|
||||
The HealthClient will report a SERVING status for the
|
||||
first check, and a NOT_FOUND status for a non-existent
|
||||
service.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2019, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -75,8 +75,8 @@ public class Server {
|
||||
|
||||
// add support for standard and gRPC health checks
|
||||
HealthSupport health = HealthSupport.builder()
|
||||
.add(HealthChecks.healthChecks())
|
||||
.add(grpcServer.healthChecks())
|
||||
.addLiveness(HealthChecks.healthChecks())
|
||||
.addLiveness(grpcServer.healthChecks())
|
||||
.build();
|
||||
|
||||
// start web server with health endpoint
|
||||
|
||||
@@ -4,7 +4,6 @@ A basic example using metrics with gRPC server.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-grpc-metrics.jar
|
||||
@@ -13,4 +12,4 @@ java -jar target/helidon-examples-grpc-metrics.jar
|
||||
Try the metrics:
|
||||
```bash
|
||||
curl http://localhost:8080/metrics
|
||||
```
|
||||
```
|
||||
|
||||
@@ -4,7 +4,6 @@ An example gRPC server for attribute based access control.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn -f ../pom.xml -pl common/security-abac package
|
||||
java -jar target/helidon-examples-grpc-security-abac.jar
|
||||
@@ -13,4 +12,4 @@ java -jar target/helidon-examples-grpc-security-abac.jar
|
||||
Take a look at the metrics:
|
||||
```bash
|
||||
curl http://localhost:8080/metrics
|
||||
```
|
||||
```
|
||||
|
||||
@@ -4,7 +4,6 @@ An example gRPC outbound security
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn -f ../pom.xml -pl common/security-outbound package
|
||||
java -jar target/helidon-examples-grpc-security-outbound.jar
|
||||
@@ -14,4 +13,4 @@ Exercise the example:
|
||||
```bash
|
||||
java -cp target/helidon-examples-grpc-security-outbound.jar \
|
||||
io.helidon.grpc.examples.security.outbound.SecureGreetClient
|
||||
```
|
||||
```
|
||||
|
||||
@@ -4,7 +4,6 @@ An example gRPC server using basic auth security.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn -f ../pom.xml -pl common/security package
|
||||
java -jar target/helidon-examples-grpc-security.jar
|
||||
@@ -16,4 +15,4 @@ java -cp target/helidon-examples-grpc-security.jar \
|
||||
io.helidon.grpc.examples.security.SecureGreetClient
|
||||
java -cp target/helidon-examples-grpc-security.jar \
|
||||
io.helidon.grpc.examples.security.SecureStringClient
|
||||
```
|
||||
```
|
||||
|
||||
@@ -6,8 +6,18 @@ custom health check.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
Start the application:
|
||||
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-health-basics.jar
|
||||
```
|
||||
|
||||
Note the port number reported by the application.
|
||||
|
||||
Probe the health endpoints:
|
||||
|
||||
```bash
|
||||
curl -X GET http://localhost:PORT/health/
|
||||
curl -X GET http://localhost:PORT/health/ready
|
||||
|
||||
|
||||
@@ -61,4 +61,19 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-libs</id>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,8 +39,8 @@ public final class Main {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
HealthSupport health = HealthSupport.builder()
|
||||
.add(HealthChecks.healthChecks())
|
||||
.add((HealthCheck) () -> HealthCheckResponse.named("exampleHealthCheck")
|
||||
.addLiveness(HealthChecks.healthChecks())
|
||||
.addReadiness((HealthCheck) () -> HealthCheckResponse.named("exampleHealthCheck")
|
||||
.up()
|
||||
.withData("time", System.currentTimeMillis())
|
||||
.build())
|
||||
|
||||
@@ -8,7 +8,6 @@ database.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-integrations-examples-datasource-hikaricp-h2.jar
|
||||
|
||||
@@ -40,7 +40,6 @@ javax.sql.DataSource.example.dataSource.password = tiger
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-integrations-examples-datasource-hikaricp-mysql.jar
|
||||
|
||||
@@ -67,7 +67,6 @@ docker run --rm -d \
|
||||
-p 8080:8080 helidon-examples-integrations-datasource-hikaricp:latest
|
||||
```
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-integrations-datasource-hikaricp.jar
|
||||
@@ -81,4 +80,4 @@ curl http://localhost:8080/tables
|
||||
Stop the docker containers:
|
||||
```bash
|
||||
docker stop oracle helidon-examples-integrations-datasource-hikaricp
|
||||
```
|
||||
```
|
||||
|
||||
@@ -17,7 +17,7 @@ docker run --rm -d \
|
||||
-p 8080:8080 helidon-examples-integrations-cdi-jedis:latest
|
||||
```
|
||||
|
||||
With Java 8+:
|
||||
With Java:
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-integrations-cdi-jedis.jar
|
||||
@@ -50,4 +50,4 @@ docker stop redis helidon-examples-integrations-cdi-jedis
|
||||
Delete the Kubernetes resources:
|
||||
```bash
|
||||
kubectl delete -f ../../k8s/ingress.yaml -f app.yaml
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 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.
|
||||
*/
|
||||
package io.helidon.integrations.examples.jedis.jaxrs;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
|
||||
/**
|
||||
* A JAX-RS {@link javax.ws.rs.core.Application application} in
|
||||
* {@linkplain ApplicationScoped application scope}.
|
||||
*
|
||||
* @see #getClasses()
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class Application extends javax.ws.rs.core.Application {
|
||||
|
||||
private final Set<Class<?>> classes;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Application}.
|
||||
*/
|
||||
public Application() {
|
||||
super();
|
||||
final Set<Class<?>> classes = new HashSet<>();
|
||||
classes.add(RedisClientResource.class);
|
||||
this.classes = Collections.unmodifiableSet(classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a non-{@code null} {@linkplain
|
||||
* java.util.Collections#unmodifiableSet(Set) immutable
|
||||
* <code>Set</code>} of {@link Class}es that comprise this JAX-RS
|
||||
* application.
|
||||
*
|
||||
* @return a non-{@code null} {@linkplain
|
||||
* java.util.Collections#unmodifiableSet(Set) immutable
|
||||
* <code>Set</code>}
|
||||
*/
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# JPA Integration Example
|
||||
|
||||
With Java 8+:
|
||||
With Java:
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-integrations-examples-jpa.jar
|
||||
|
||||
@@ -29,7 +29,7 @@ docker run --rm -d -p 8080:8080 \
|
||||
helidon-examples-integrations-cdi-oci-objectstorage:latest
|
||||
```
|
||||
|
||||
With Java 8+:
|
||||
With Java:
|
||||
```bash
|
||||
mvn package
|
||||
java -Doci.auth.fingerprint="${OCI_AUTH_FINGERPRINT}" \
|
||||
@@ -70,4 +70,4 @@ docker stop helidon-examples-integrations-cdi-oci-objectstorage
|
||||
Delete the Kubernetes resources:
|
||||
```bash
|
||||
kubectl delete -f ../../../k8s/ingress.yaml -f app.yaml
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
package io.helidon.integrations.examples.oci.objectstorage.jaxrs;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
|
||||
/**
|
||||
* A JAX-RS {@linkplain javax.ws.rs.core.Application application} in {@linkplain ApplicationScoped application scope}.
|
||||
*
|
||||
* @see #getClasses()
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class Application extends javax.ws.rs.core.Application {
|
||||
|
||||
private final Set<Class<?>> classes;
|
||||
|
||||
/**
|
||||
* Creates a new {@link Application}.
|
||||
*/
|
||||
public Application() {
|
||||
super();
|
||||
final Set<Class<?>> classes = new HashSet<>();
|
||||
classes.add(HelidonLogoResource.class);
|
||||
this.classes = Collections.unmodifiableSet(classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a non-{@code null} {@linkplain
|
||||
* java.util.Collections#unmodifiableSet(Set) immutable
|
||||
* <code>Set</code>} of {@link Class}es that comprise this JAX-RS application.
|
||||
*
|
||||
* @return a non-{@code null} {@linkplain
|
||||
* java.util.Collections#unmodifiableSet(Set) immutable
|
||||
* <code>Set</code>}
|
||||
*/
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return this.classes;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.helidon.microprofile.example.helloworld.explicit;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class HelloWorldApplication extends Application {
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Set.of(
|
||||
HelloWorldResource.class
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,7 @@ public class Main {
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Server server = Server.builder()
|
||||
.addApplication(HelloWorldApplication.class)
|
||||
// using a customized helidon config instance (in this case the default...)
|
||||
// Provide a MicroProfile config instance (in this case the default...)
|
||||
.config(ConfigProviderResolver.instance()
|
||||
.getBuilder()
|
||||
.build())
|
||||
|
||||
@@ -6,7 +6,6 @@ It is implicit because in this example you don't write the
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-microprofile-hello-world-implicit.jar
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.helidon.microprofile.example.helloworld.implicit;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
* Application for example with two resource classes.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class HelloWorldApplication extends Application {
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Set.of(
|
||||
HelloWorldResource.class,
|
||||
AnotherResource.class
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import javax.ws.rs.client.ClientBuilder;
|
||||
|
||||
import io.helidon.microprofile.server.Main;
|
||||
|
||||
import io.helidon.microprofile.server.Server;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -35,9 +36,12 @@ import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
* Unit test for {@link HelloWorldResource}.
|
||||
*/
|
||||
class ImplicitHelloWorldTest {
|
||||
private static Server server;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
static void initClass() {
|
||||
Main.main(new String[0]);
|
||||
server = Server.create().start();
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
@@ -49,7 +53,7 @@ class ImplicitHelloWorldTest {
|
||||
@Test
|
||||
void testJsonResource() {
|
||||
JsonObject jsonObject = ClientBuilder.newClient()
|
||||
.target("http://localhost:" + Main.serverPort() + "/helloworld/unit")
|
||||
.target("http://localhost:" + server.port() + "/helloworld/unit")
|
||||
.request()
|
||||
.get(JsonObject.class);
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ Example JAX-RS application with resources protected by IDCS
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-microprofile-security-idcs.jar
|
||||
|
||||
@@ -46,6 +46,10 @@ public class MessagingExampleResource {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process send.
|
||||
* @param msg message to process
|
||||
*/
|
||||
@Path("/send/{msg}")
|
||||
@GET
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@@ -53,6 +57,12 @@ public class MessagingExampleResource {
|
||||
msgBean.process(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume event.
|
||||
*
|
||||
* @param eventSink sink
|
||||
* @param sse event
|
||||
*/
|
||||
@GET
|
||||
@Path("sse")
|
||||
@Produces(MediaType.SERVER_SENT_EVENTS)
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* 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.microprofile.example.messaging.sse;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
* Example showing
|
||||
* <a href="https://github.com/eclipse/microprofile-reactive-messaging">Microprofile Reactive Messaging</a>
|
||||
* with <a href="https://github.com/eclipse/microprofile-reactive-streams-operators">Microprofile Reactive Stream Operators</a>
|
||||
* connected to <a href="https://eclipse-ee4j.github.io/jersey.github.io/documentation/latest/sse.html">Server-Sent Events</a>.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class MessagingSseExampleApplication extends Application {
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Set.of(
|
||||
MessagingExampleResource.class
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -33,11 +33,19 @@ import org.glassfish.jersey.media.sse.OutboundEvent;
|
||||
import org.reactivestreams.FlowAdapters;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
/**
|
||||
* Bean for message processing.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class MsgProcessingBean {
|
||||
private final SubmissionPublisher<String> emitter = new SubmissionPublisher<>();
|
||||
private SseBroadcaster sseBroadcaster;
|
||||
|
||||
/**
|
||||
* Create a publisher for the emitter.
|
||||
*
|
||||
* @return A Publisher from the emitter
|
||||
*/
|
||||
@Outgoing("multiplyVariants")
|
||||
public Publisher<String> preparePublisher() {
|
||||
// Create new publisher for emitting to by this::process
|
||||
@@ -46,6 +54,11 @@ public class MsgProcessingBean {
|
||||
.buildRs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a builder for a processor that maps a string into three variants.
|
||||
*
|
||||
* @return ProcessorBuilder
|
||||
*/
|
||||
@Incoming("multiplyVariants")
|
||||
@Outgoing("wrapSseEvent")
|
||||
public ProcessorBuilder<String, String> multiply() {
|
||||
@@ -62,6 +75,12 @@ public class MsgProcessingBean {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Maps a message to an sse event.
|
||||
*
|
||||
* @param msg to wrap
|
||||
* @return an outbound SSE event
|
||||
*/
|
||||
@Incoming("wrapSseEvent")
|
||||
@Outgoing("broadcast")
|
||||
public OutboundSseEvent wrapSseEvent(String msg) {
|
||||
@@ -69,12 +88,23 @@ public class MsgProcessingBean {
|
||||
return new OutboundEvent.Builder().data(msg).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts an event.
|
||||
*
|
||||
* @param sseEvent Event to broadcast
|
||||
*/
|
||||
@Incoming("broadcast")
|
||||
public void broadcast(OutboundSseEvent sseEvent) {
|
||||
// Broadcast to all sse sinks
|
||||
this.sseBroadcaster.broadcast(sseEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Consumes events.
|
||||
*
|
||||
* @param eventSink event sink
|
||||
* @param sse event
|
||||
*/
|
||||
public void addSink(final SseEventSink eventSink, final Sse sse) {
|
||||
if (this.sseBroadcaster == null) {
|
||||
this.sseBroadcaster = sse.newBroadcaster();
|
||||
@@ -82,6 +112,11 @@ public class MsgProcessingBean {
|
||||
this.sseBroadcaster.register(eventSink);
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit a message.
|
||||
*
|
||||
* @param msg message to emit
|
||||
*/
|
||||
public void process(final String msg) {
|
||||
emitter.submit(msg);
|
||||
}
|
||||
|
||||
@@ -14,23 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Helidon MicroProfile Messaging Example.
|
||||
*/
|
||||
package io.helidon.microprofile.example.messaging.sse;
|
||||
|
||||
import io.helidon.microprofile.server.Server;
|
||||
|
||||
/**
|
||||
* Explicit example.
|
||||
*/
|
||||
public class Main {
|
||||
private Main() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts server and initializes CDI container manually.
|
||||
*
|
||||
* @param args command line arguments (ignored)
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Server.create().start();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ levels of security.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-microprofile-mp1_1-security.jar
|
||||
|
||||
@@ -7,7 +7,6 @@ The configuration for the static content is in the
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-microprofile-mp1_1-static-content.jar
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,7 +39,7 @@ public class Main {
|
||||
long now = System.nanoTime();
|
||||
|
||||
// everything is configured through application.yaml
|
||||
Server server = Server.create(StaticContentApp.class);
|
||||
Server server = Server.create();
|
||||
|
||||
now = System.nanoTime() - now;
|
||||
System.out.println("Create server: " + TimeUnit.MILLISECONDS.convert(now, TimeUnit.NANOSECONDS));
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package io.helidon.microprofile.example.staticc;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
* Example JAX-RS application with static content.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class StaticContentApp extends Application {
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Set.of(
|
||||
HelloWorldResource.class
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,7 @@ in `application.yaml`.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-oidc-login.jar
|
||||
```
|
||||
java -jar target/helidon-examples-microprofile-security-oidc-login.jar
|
||||
```
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 2020 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.microprofile.security.oidc;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
* A simple JAX-rs application that just returns the single {@link OidcResource resource}.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class OidcTestApplication extends Application {
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Set.of(OidcResource.class);
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ Helidon MP QuickStart, enhanced with OpenAPI support.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-microprofile-openapi-basic.jar
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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.microprofile.examples.openapi.basic;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.ws.rs.ApplicationPath;
|
||||
import javax.ws.rs.core.Application;
|
||||
|
||||
/**
|
||||
* Simple Application that produces a greeting message.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
@ApplicationPath("/")
|
||||
public class GreetApplication extends Application {
|
||||
|
||||
@Override
|
||||
public Set<Class<?>> getClasses() {
|
||||
return Set.of(GreetResource.class);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
|
||||
Copyright (c) 2018, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@@ -40,5 +40,6 @@
|
||||
<module>oidc</module>
|
||||
<module>openapi-basic</module>
|
||||
<module>websocket</module>
|
||||
<module>messaging-sse</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
||||
@@ -5,7 +5,6 @@ that combines REST resources and WebSocket endpoints.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-microprofile-websocket.jar
|
||||
|
||||
@@ -100,7 +100,7 @@ public final class Main {
|
||||
MetricsSupport metrics = MetricsSupport.create();
|
||||
GreetService greetService = new GreetService(config);
|
||||
HealthSupport health = HealthSupport.builder()
|
||||
.add(HealthChecks.healthChecks()) // Adds a convenient set of checks
|
||||
.addLiveness(HealthChecks.healthChecks()) // Adds a convenient set of checks
|
||||
.build();
|
||||
|
||||
return Routing.builder()
|
||||
|
||||
@@ -4,8 +4,7 @@ JAX-RS (Jersey) example for attribute based access control.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-abac.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -19,8 +19,7 @@ Update the following files with your client id (it should support http://localho
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-google-login.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -39,7 +39,6 @@ Edit application.yaml for IdcsMain.java or OidcConfig variable definition for Id
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-oidc.jar
|
||||
|
||||
@@ -12,7 +12,6 @@ There are three examples with exactly the same behavior
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-jersey.jar
|
||||
@@ -25,4 +24,4 @@ curl -v http://localhost:8080/rest/protected
|
||||
curl -u "jack:password" http://localhost:8080/rest/protected
|
||||
curl -u "jack:password" http://localhost:8080/rest/protected
|
||||
curl -v -u "john:password" http://localhost:8080/rest/protected
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package io.helidon.security.examples.jersey;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -29,7 +30,7 @@ import io.helidon.security.Security;
|
||||
import io.helidon.security.integration.jersey.SecurityFeature;
|
||||
import io.helidon.security.providers.abac.AbacProvider;
|
||||
import io.helidon.security.providers.httpauth.HttpBasicAuthProvider;
|
||||
import io.helidon.security.providers.httpauth.UserStore;
|
||||
import io.helidon.security.providers.httpauth.SecureUserStore;
|
||||
import io.helidon.webserver.Routing;
|
||||
import io.helidon.webserver.WebServer;
|
||||
import io.helidon.webserver.jersey.JerseySupport;
|
||||
@@ -38,7 +39,7 @@ import io.helidon.webserver.jersey.JerseySupport;
|
||||
* Example of integration between Jersey and Security module using builders.
|
||||
*/
|
||||
public final class JerseyBuilderMain {
|
||||
private static final Map<String, UserStore.User> USERS = new HashMap<>();
|
||||
private static final Map<String, SecureUserStore.User> USERS = new HashMap<>();
|
||||
private static volatile WebServer server;
|
||||
|
||||
static {
|
||||
@@ -51,17 +52,21 @@ public final class JerseyBuilderMain {
|
||||
}
|
||||
|
||||
private static void addUser(String user, String password, List<String> roles) {
|
||||
USERS.put(user, new UserStore.User() {
|
||||
USERS.put(user, new SecureUserStore.User() {
|
||||
@Override
|
||||
public String login() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] password() {
|
||||
private char[] password() {
|
||||
return password.toCharArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPasswordValid(char[] password) {
|
||||
return Arrays.equals(password(), password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> roles() {
|
||||
return roles;
|
||||
@@ -84,7 +89,7 @@ public final class JerseyBuilderMain {
|
||||
.build());
|
||||
}
|
||||
|
||||
private static UserStore users() {
|
||||
private static SecureUserStore users() {
|
||||
return login -> Optional.ofNullable(USERS.get(login));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,7 @@ Example of manually using the security APIs.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-nohttp-programmatic.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -6,7 +6,6 @@ sets the username and password.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-outbound-override.jar
|
||||
@@ -18,4 +17,4 @@ curl -u "jack:password" http://localhost:8080/propagate
|
||||
curl -u "jack:password" http://localhost:8080/override
|
||||
curl -u "jill:anotherPassword" http://localhost:8080/propagate
|
||||
curl -u "jill:anotherPassword" http://localhost:8080/override
|
||||
```
|
||||
```
|
||||
|
||||
@@ -12,7 +12,6 @@ There are two examples with exactly the same behavior:
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-webserver-digest-auth.jar
|
||||
@@ -27,4 +26,4 @@ curl --digest -u "john:password" http://localhost:56551/user
|
||||
curl --digest -u "jack:password" http://localhost:56551/admin
|
||||
curl -v --digest -u "john:password" http://localhost:56551/deny
|
||||
curl --digest -u "jack:password" http://localhost:56551/noAuthn
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,10 @@
|
||||
package io.helidon.security.examples.webserver.digest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -27,8 +31,9 @@ import io.helidon.common.http.MediaType;
|
||||
import io.helidon.security.Security;
|
||||
import io.helidon.security.SecurityContext;
|
||||
import io.helidon.security.integration.webserver.WebSecurity;
|
||||
import io.helidon.security.providers.httpauth.HttpDigest;
|
||||
import io.helidon.security.providers.httpauth.HttpDigestAuthProvider;
|
||||
import io.helidon.security.providers.httpauth.UserStore;
|
||||
import io.helidon.security.providers.httpauth.SecureUserStore;
|
||||
import io.helidon.webserver.Routing;
|
||||
import io.helidon.webserver.WebServer;
|
||||
|
||||
@@ -41,6 +46,8 @@ public final class DigestExampleBuilderMain {
|
||||
// simple approach to user storage - for real world, use data store...
|
||||
private static Map<String, MyUser> users = new HashMap<>();
|
||||
|
||||
private static final char[] HEX_ARRAY = "0123456789abcdef".toCharArray();
|
||||
|
||||
static {
|
||||
users.put("jack", new MyUser("jack", "password".toCharArray(), Set.of("user", "admin")));
|
||||
users.put("jill", new MyUser("jill", "password".toCharArray(), Set.of("user")));
|
||||
@@ -97,7 +104,7 @@ public final class DigestExampleBuilderMain {
|
||||
return WebSecurity.create(security);
|
||||
}
|
||||
|
||||
private static UserStore buildUserStore() {
|
||||
private static SecureUserStore buildUserStore() {
|
||||
return login -> Optional.ofNullable(users.get(login));
|
||||
}
|
||||
|
||||
@@ -105,7 +112,7 @@ public final class DigestExampleBuilderMain {
|
||||
return server;
|
||||
}
|
||||
|
||||
private static class MyUser implements UserStore.User {
|
||||
private static class MyUser implements SecureUserStore.User {
|
||||
private String login;
|
||||
private char[] password;
|
||||
private Set<String> roles;
|
||||
@@ -116,11 +123,41 @@ public final class DigestExampleBuilderMain {
|
||||
this.roles = roles;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] password() {
|
||||
private char[] password() {
|
||||
return password;
|
||||
}
|
||||
|
||||
private static String bytesToHex(byte[] bytes) {
|
||||
char[] hexChars = new char[bytes.length * 2];
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
int v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2] = HEX_ARRAY[v >>> 4];
|
||||
hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPasswordValid(char[] password) {
|
||||
return Arrays.equals(password(), password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> digestHa1(String realm, HttpDigest.Algorithm algorithm) {
|
||||
if (algorithm != HttpDigest.Algorithm.MD5) {
|
||||
throw new IllegalArgumentException("Unsupported algorithm " + algorithm);
|
||||
}
|
||||
String a1 = login + ":" + realm + ":" + new String(password());
|
||||
byte[] bytes = a1.getBytes(StandardCharsets.UTF_8);
|
||||
MessageDigest digest;
|
||||
try {
|
||||
digest = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new IllegalStateException("MD5 algorithm should be supported", e);
|
||||
}
|
||||
return Optional.of(bytesToHex(digest.digest(bytes)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> roles() {
|
||||
return roles;
|
||||
|
||||
@@ -16,7 +16,6 @@ There are two examples with exactly the same behavior
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-security-webserver-signatures.jar
|
||||
@@ -27,4 +26,4 @@ Try the endpoints:
|
||||
curl -u "jack:password" http://localhost:8080/service1
|
||||
curl -u "jill:password" http://localhost:8080/service1-rsa
|
||||
curl -v -u "john:password" http://localhost:8080/service1
|
||||
```
|
||||
```
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2018, 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2018, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,9 +15,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
package io.helidon.security.examples.signatures;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -35,7 +38,7 @@ import io.helidon.security.integration.webserver.WebSecurity;
|
||||
import io.helidon.security.providers.common.OutboundConfig;
|
||||
import io.helidon.security.providers.common.OutboundTarget;
|
||||
import io.helidon.security.providers.httpauth.HttpBasicAuthProvider;
|
||||
import io.helidon.security.providers.httpauth.UserStore;
|
||||
import io.helidon.security.providers.httpauth.SecureUserStore;
|
||||
import io.helidon.security.providers.httpsign.HttpSignProvider;
|
||||
import io.helidon.security.providers.httpsign.InboundClientDefinition;
|
||||
import io.helidon.security.providers.httpsign.OutboundTargetDefinition;
|
||||
@@ -46,7 +49,7 @@ import io.helidon.webserver.WebServer;
|
||||
* Example of authentication of service with http signatures, using configuration file as much as possible.
|
||||
*/
|
||||
public class SignatureExampleBuilderMain {
|
||||
private static final Map<String, UserStore.User> USERS = new HashMap<>();
|
||||
private static final Map<String, SecureUserStore.User> USERS = new HashMap<>();
|
||||
// used from unit tests
|
||||
private static WebServer service1Server;
|
||||
private static WebServer service2Server;
|
||||
@@ -69,17 +72,21 @@ public class SignatureExampleBuilderMain {
|
||||
}
|
||||
|
||||
private static void addUser(String user, String password, List<String> roles) {
|
||||
USERS.put(user, new UserStore.User() {
|
||||
USERS.put(user, new SecureUserStore.User() {
|
||||
@Override
|
||||
public String login() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] password() {
|
||||
char[] password() {
|
||||
return password.toCharArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPasswordValid(char[] password) {
|
||||
return Arrays.equals(password(), password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> roles() {
|
||||
return roles;
|
||||
@@ -228,7 +235,7 @@ public class SignatureExampleBuilderMain {
|
||||
.build();
|
||||
}
|
||||
|
||||
private static UserStore users() {
|
||||
private static SecureUserStore users() {
|
||||
return login -> Optional.ofNullable(USERS.get(login));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"dependencies": {
|
||||
"jquery": "3.3.1",
|
||||
"knockout": "^3.2.0",
|
||||
"npm": "^6.14.4",
|
||||
"todomvc-app-css": "^2.1.0",
|
||||
"todomvc-common": "^1.0.1"
|
||||
},
|
||||
|
||||
@@ -8,7 +8,6 @@ methods.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
```
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,7 +19,6 @@ package io.helidon.webserver.examples.basics;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
|
||||
import javax.json.Json;
|
||||
@@ -30,8 +29,8 @@ import io.helidon.common.http.Http;
|
||||
import io.helidon.common.http.MediaType;
|
||||
import io.helidon.common.http.Parameters;
|
||||
import io.helidon.common.http.Reader;
|
||||
import io.helidon.media.common.ContentReaders;
|
||||
import io.helidon.media.jsonp.server.JsonSupport;
|
||||
import io.helidon.media.common.MediaSupport;
|
||||
import io.helidon.media.jsonp.common.JsonProcessing;
|
||||
import io.helidon.webserver.Handler;
|
||||
import io.helidon.webserver.HttpException;
|
||||
import io.helidon.webserver.RequestPredicate;
|
||||
@@ -78,13 +77,16 @@ public class Main {
|
||||
|
||||
/**
|
||||
* {@link Routing} instance together with optional {@link io.helidon.webserver.ServerConfiguration configuration} parameter
|
||||
* can be used to create {@link WebServer} instance. It provides a simple, non-blocking lifecycle API returning
|
||||
* can be used to create {@link WebServer} instance.It provides a simple, non-blocking life-cycle API returning
|
||||
* {@link java.util.concurrent.CompletionStage CompletionStages} to provide reactive access.
|
||||
*
|
||||
* @param routing the routing to drive by WebServer instance
|
||||
* @param mediaSupport media support
|
||||
*/
|
||||
protected void startServer(Routing routing) {
|
||||
WebServer.create(routing)
|
||||
protected void startServer(Routing routing, MediaSupport mediaSupport) {
|
||||
WebServer.builder(routing)
|
||||
.mediaSupport(mediaSupport)
|
||||
.build()
|
||||
.start()
|
||||
// All lifecycle operations are non-blocking and provides CompletionStage
|
||||
.whenComplete((ws, thr) -> {
|
||||
@@ -97,6 +99,17 @@ public class Main {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Routing} instance together with optional {@link io.helidon.webserver.ServerConfiguration configuration} parameter
|
||||
* can be used to create {@link WebServer} instance.It provides a simple, non-blocking life-cycle API returning
|
||||
* {@link java.util.concurrent.CompletionStage CompletionStages} to provide reactive access.
|
||||
*
|
||||
* @param routing the routing to drive by WebServer instance
|
||||
*/
|
||||
protected void startServer(Routing routing) {
|
||||
startServer(routing, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* All routing rules (routes) are evaluated in a definition order. The {@link Handler} assigned with the first valid route
|
||||
* for given request is called. It is a responsibility of each handler to process in one of the following ways:
|
||||
@@ -150,13 +163,13 @@ public class Main {
|
||||
// Request headers
|
||||
req.headers()
|
||||
.first("foo")
|
||||
.ifPresent(v -> sb.append("foo: " + v + "\n"));
|
||||
.ifPresent(v -> sb.append("foo: ").append(v).append("\n"));
|
||||
// Request parameters
|
||||
req.queryParams()
|
||||
.first("bar")
|
||||
.ifPresent(v -> sb.append("bar: " + v + "\n"));
|
||||
.ifPresent(v -> sb.append("bar: ").append(v).append("\n"));
|
||||
// Path parameters
|
||||
sb.append("id: " + req.path().param("id"));
|
||||
sb.append("id: ").append(req.path().param("id"));
|
||||
// Response headers
|
||||
res.headers().contentType(MediaType.TEXT_PLAIN);
|
||||
// Response entity (payload)
|
||||
@@ -238,30 +251,20 @@ public class Main {
|
||||
*/
|
||||
public void filterAndProcessEntity() {
|
||||
Routing routing = Routing.builder()
|
||||
// Handler (filter) to register custom reader
|
||||
.any((req, res) -> {
|
||||
// Register 'name' reader only for "application/name" Content-Type
|
||||
if (req.headers()
|
||||
.contentType()
|
||||
.map(ct -> MediaType.parse("application/name").equals(ct))
|
||||
.orElse(false)) {
|
||||
req.content()
|
||||
.registerReader(Name.class, (publisher, clazz) -> ContentReaders
|
||||
.stringReader(StandardCharsets.UTF_8)
|
||||
.apply(publisher, String.class)
|
||||
.thenApply(Name::new));
|
||||
}
|
||||
// Reader registration is typically done in a 'filter' - req.next() must be called
|
||||
req.next();
|
||||
})
|
||||
// Registered reader can be used by following handlers
|
||||
.post("/create-record", Handler.create(Name.class, (req, res, name) -> {
|
||||
System.out.println("Name: " + name);
|
||||
res.status(Http.Status.CREATED_201)
|
||||
.send(name.toString());
|
||||
}))
|
||||
.build();
|
||||
startServer(routing);
|
||||
|
||||
// Create a media support that contains the defaults and our custom Name reader
|
||||
MediaSupport mediaSupport = MediaSupport.builder()
|
||||
.registerDefaults()
|
||||
.registerReader(NameReader.create())
|
||||
.build();
|
||||
|
||||
startServer(routing, mediaSupport);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -272,7 +275,6 @@ public class Main {
|
||||
public void supports() {
|
||||
Routing routing = Routing.builder()
|
||||
.register(StaticContentSupport.create("/static"))
|
||||
.register("/hello", JsonSupport.create())
|
||||
.get("/hello/{what}", (req, res) -> res.send(JSON.createObjectBuilder()
|
||||
.add("message",
|
||||
"Hello " + req.path()
|
||||
@@ -282,7 +284,13 @@ public class Main {
|
||||
.register(HelloWorldResource.class)
|
||||
.build())
|
||||
.build();
|
||||
startServer(routing);
|
||||
|
||||
MediaSupport mediaSupport = MediaSupport.builder()
|
||||
.registerDefaults()
|
||||
.registerWriter(JsonProcessing.create().newWriter())
|
||||
.build();
|
||||
|
||||
startServer(routing, mediaSupport);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* 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.basics;
|
||||
|
||||
import java.util.concurrent.Flow;
|
||||
|
||||
import io.helidon.common.GenericType;
|
||||
import io.helidon.common.http.DataChunk;
|
||||
import io.helidon.common.http.MediaType;
|
||||
import io.helidon.common.reactive.Single;
|
||||
import io.helidon.media.common.ContentReaders;
|
||||
import io.helidon.media.common.MessageBodyReader;
|
||||
import io.helidon.media.common.MessageBodyReaderContext;
|
||||
|
||||
public class NameReader implements MessageBodyReader<Name> {
|
||||
|
||||
private NameReader() {
|
||||
}
|
||||
|
||||
static NameReader create() {
|
||||
return new NameReader();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <U extends Name> Single<U> read(Flow.Publisher<DataChunk> publisher, GenericType<U> type,
|
||||
MessageBodyReaderContext context) {
|
||||
return (Single<U>) ContentReaders.readString(publisher, context.charset()).map(Name::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean accept(GenericType<?> type, MessageBodyReaderContext context) {
|
||||
return context.contentType()
|
||||
.map(ct -> MediaType.parse("application/name").equals(ct))
|
||||
.map(acceptable -> acceptable && Name.class.isAssignableFrom(type.rawType()))
|
||||
.orElse(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,7 @@ import java.util.function.Consumer;
|
||||
|
||||
import io.helidon.common.http.Http;
|
||||
import io.helidon.common.http.MediaType;
|
||||
import io.helidon.media.common.MediaSupport;
|
||||
import io.helidon.webserver.Routing;
|
||||
import io.helidon.webserver.testsupport.MediaPublisher;
|
||||
import io.helidon.webserver.testsupport.TestClient;
|
||||
@@ -148,17 +149,18 @@ public class MainTest {
|
||||
TMain tm = new TMain();
|
||||
callTestedMethod.accept(tm);
|
||||
assertNotNull(tm.routing);
|
||||
return TestClient.create(tm.routing);
|
||||
return TestClient.create(tm.routing, tm.mediaSupport);
|
||||
}
|
||||
|
||||
static class TMain extends Main {
|
||||
|
||||
private Routing routing;
|
||||
private MediaSupport mediaSupport;
|
||||
|
||||
@Override
|
||||
protected void startServer(Routing routing) {
|
||||
protected void startServer(Routing routing, MediaSupport mediaSupport) {
|
||||
this.routing = routing;
|
||||
this.mediaSupport = mediaSupport;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ This application allows users to add or read short comments related to a single
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-webserver-comment-aas.jar
|
||||
@@ -18,4 +17,4 @@ 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
|
||||
```
|
||||
```
|
||||
|
||||
@@ -7,7 +7,6 @@ and `GET` the `Hello World!` response by accessing `http://localhost:8080/jersey
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-webserver-jersey.jar
|
||||
@@ -16,4 +15,4 @@ java -jar target/helidon-examples-webserver-jersey.jar
|
||||
Make an HTTP request to application:
|
||||
```bash
|
||||
curl http://localhost:8080/jersey/hello
|
||||
```
|
||||
```
|
||||
|
||||
@@ -5,7 +5,6 @@ This application demonstrates use of the StaticContentSupport to serve static fi
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-webserver-static-content.jar
|
||||
|
||||
@@ -7,7 +7,6 @@ to the size of the file being uploaded or downloaded.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-webserver-streaming.jar
|
||||
@@ -17,4 +16,4 @@ Upload a file and download it back with `curl`:
|
||||
```bash
|
||||
curl --data-binary "@target/classes/large-file.bin" http://localhost:8080/upload
|
||||
curl http://localhost:8080/download
|
||||
```
|
||||
```
|
||||
|
||||
@@ -4,8 +4,7 @@ This application demonstrates various WebServer use cases together and in its co
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-webserver-tutorial.jar
|
||||
```
|
||||
```
|
||||
|
||||
@@ -4,11 +4,10 @@ This application demonstrates use of websockets and REST.
|
||||
|
||||
## Build and run
|
||||
|
||||
With JDK8+
|
||||
```bash
|
||||
mvn package
|
||||
java -jar target/helidon-examples-webserver-websocket.jar
|
||||
```
|
||||
|
||||
Open http://localhost:8080 in your browser.
|
||||
``
|
||||
``
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2019 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,6 +36,7 @@ import io.helidon.common.http.DataChunk;
|
||||
import io.helidon.common.http.Http;
|
||||
import io.helidon.common.http.ReadOnlyParameters;
|
||||
import io.helidon.common.reactive.Single;
|
||||
import io.helidon.media.common.MediaSupport;
|
||||
import io.helidon.webserver.BareRequest;
|
||||
import io.helidon.webserver.BareResponse;
|
||||
import io.helidon.webserver.Handler;
|
||||
@@ -50,6 +51,7 @@ public class TestClient {
|
||||
private static final Duration TIMEOUT = Duration.ofMinutes(10);
|
||||
|
||||
private final Routing routing;
|
||||
private final MediaSupport mediaSupport;
|
||||
private final Handler mockingHandler;
|
||||
|
||||
/**
|
||||
@@ -59,13 +61,13 @@ public class TestClient {
|
||||
* @param mockingHandler a handler representing mocking
|
||||
* @throws NullPointerException if routing parameter is null
|
||||
*/
|
||||
private TestClient(Routing routing, Handler mockingHandler) {
|
||||
private TestClient(Routing routing, MediaSupport mediaSupport, Handler mockingHandler) {
|
||||
Objects.requireNonNull(routing, "Parameter 'routing' is null!");
|
||||
this.routing = routing;
|
||||
this.mediaSupport = mediaSupport;
|
||||
this.mockingHandler = mockingHandler;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates new {@link TestClient} instance with specified routing.
|
||||
*
|
||||
@@ -79,6 +81,18 @@ public class TestClient {
|
||||
return create(routingBuilder.get());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link TestClient} instance with specified routing.
|
||||
*
|
||||
* @param routing a routing to test
|
||||
* @param mediaSupport media support
|
||||
* @return new instance
|
||||
* @throws NullPointerException if routing parameter is null
|
||||
*/
|
||||
public static TestClient create(Routing routing, MediaSupport mediaSupport) {
|
||||
return new TestClient(routing, mediaSupport, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link TestClient} instance with specified routing.
|
||||
*
|
||||
@@ -87,7 +101,7 @@ public class TestClient {
|
||||
* @throws NullPointerException if routing parameter is null
|
||||
*/
|
||||
public static TestClient create(Routing routing) {
|
||||
return new TestClient(routing, null);
|
||||
return new TestClient(routing, null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,7 +132,7 @@ public class TestClient {
|
||||
URI path,
|
||||
Map<String, List<String>> headers,
|
||||
Flow.Publisher<DataChunk> publisher) throws InterruptedException, TimeoutException {
|
||||
TestBareRequest req = new TestBareRequest(method, version, path, headers, publisher);
|
||||
TestBareRequest req = new TestBareRequest(method, version, path, headers, publisher, mediaSupport);
|
||||
TestBareResponse res = new TestBareResponse(req.webServer);
|
||||
routing.route(req, res);
|
||||
try {
|
||||
@@ -139,17 +153,18 @@ public class TestClient {
|
||||
private final URI path;
|
||||
private final Map<String, List<String>> headers;
|
||||
private final Flow.Publisher<DataChunk> publisher;
|
||||
private final TestWebServer webServer = new TestWebServer();
|
||||
private final TestWebServer webServer;
|
||||
|
||||
TestBareRequest(Http.RequestMethod method,
|
||||
Http.Version version,
|
||||
URI path,
|
||||
Map<String, List<String>> headers,
|
||||
Flow.Publisher<DataChunk> publisher) {
|
||||
Flow.Publisher<DataChunk> publisher,
|
||||
MediaSupport mediaSupport) {
|
||||
Objects.requireNonNull(method, "Parameter 'method' is null!");
|
||||
Objects.requireNonNull(version, "Parameter 'version' is null!");
|
||||
Objects.requireNonNull(path, "Parameter 'path' is null!");
|
||||
webServer.start();
|
||||
webServer = new TestWebServer(mediaSupport);
|
||||
this.method = method;
|
||||
this.version = version;
|
||||
this.path = path;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,7 +37,7 @@ public class TestRequest {
|
||||
private final TestClient testClient;
|
||||
private final String path;
|
||||
private final StringBuilder query = new StringBuilder();
|
||||
private final Map<String, List<String>> headers = new HashMap();
|
||||
private final Map<String, List<String>> headers = new HashMap<>();
|
||||
private volatile Http.Version version = Http.Version.V1_1;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2017, 2020 Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,11 +29,25 @@ import io.helidon.webserver.WebServer;
|
||||
*/
|
||||
class TestWebServer implements WebServer {
|
||||
|
||||
private static final MediaSupport DEFAULT_MEDIA_SUPPORT = MediaSupport.createWithDefaults();
|
||||
|
||||
private final CompletableFuture<WebServer> startFuture = new CompletableFuture<>();
|
||||
private final CompletableFuture<WebServer> shutdownFuture = new CompletableFuture<>();
|
||||
private final ServerConfiguration configuration = ServerConfiguration.builder().build();
|
||||
private final ContextualRegistry context = ContextualRegistry.create();
|
||||
private final MediaSupport mediaSupport = MediaSupport.createWithDefaults();
|
||||
private final MediaSupport mediaSupport;
|
||||
|
||||
TestWebServer() {
|
||||
this.mediaSupport = DEFAULT_MEDIA_SUPPORT;
|
||||
}
|
||||
|
||||
TestWebServer(MediaSupport mediaSupport) {
|
||||
if (mediaSupport == null) {
|
||||
this.mediaSupport = DEFAULT_MEDIA_SUPPORT;
|
||||
} else {
|
||||
this.mediaSupport = mediaSupport;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServerConfiguration configuration() {
|
||||
|
||||
Reference in New Issue
Block a user