Skip to content

Commit

Permalink
Review comments fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
  • Loading branch information
tomas-langer committed Jun 2, 2020
1 parent 324240b commit 9ce610a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.tests.functional.context.hello;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.ext.Provider;

import io.helidon.common.context.Contexts;

/**
* A filter that adds request scoped context record.
*/
@Provider
public class ContextFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
Contexts.context().ifPresent(ctx -> ctx.register(new MyMessage()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import io.helidon.common.context.Context;
import io.helidon.common.context.Contexts;
import io.helidon.metrics.RegistryFactory;

import org.eclipse.microprofile.faulttolerance.Asynchronous;
import org.eclipse.microprofile.faulttolerance.Timeout;
Expand All @@ -41,9 +42,12 @@ public class HelloBean {
* @return Hello string.
*/
public String getHello() {
Context context = Contexts.context().get();
Context context = Contexts.context().orElse(null);
Objects.requireNonNull(context);

// application scoped context
Objects.requireNonNull(context.get(RegistryFactory.class).orElse(null));
// request scoped context
Objects.requireNonNull(context.get(MyMessage.class).orElse(null));
return "Hello World";
}

Expand All @@ -54,10 +58,12 @@ public String getHello() {
*/
@Timeout(1000)
public String getHelloTimeout() {
Context context = Contexts.context().get();
Context context = Contexts.context().orElse(null);
Objects.requireNonNull(context);
// span context may be null if tracer is not configured
//Objects.requireNonNull(context.get(SpanContext.class).get());
// application scoped context
Objects.requireNonNull(context.get(RegistryFactory.class).orElse(null));
// request scoped context
Objects.requireNonNull(context.get(MyMessage.class).orElse(null));
return "Hello World";
}

Expand All @@ -68,9 +74,12 @@ public String getHelloTimeout() {
*/
@Asynchronous
public CompletionStage<String> getHelloAsync() {
Context context = Contexts.context().get();
Context context = Contexts.context().orElse(null);
Objects.requireNonNull(context);
//Objects.requireNonNull(context.get(SpanContext.class).get());
// application scoped context
Objects.requireNonNull(context.get(RegistryFactory.class).orElse(null));
// request scoped context
Objects.requireNonNull(context.get(MyMessage.class).orElse(null));
return CompletableFuture.completedFuture("Hello World");
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
* 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.
Expand All @@ -16,18 +16,10 @@

package io.helidon.tests.functional.context.hello;

import java.util.Set;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.core.Application;

/**
* HelloApplication class.
* Class to test context.
*/
@ApplicationScoped
public class HelloApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return Set.of(HelloResource.class);
class MyMessage {
MyMessage() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ static final class RequestSpanHandler implements Handler {

@Override
public void accept(ServerRequest req, ServerResponse res) {
if (checkedIfShouldTrace.compareAndSet(false, true)) {
if (shouldTrace && checkedIfShouldTrace.compareAndSet(false, true)) {
if (req.tracer().scopeManager() instanceof NoopScopeManager) {
shouldTrace = false;
}
Expand Down

0 comments on commit 9ce610a

Please sign in to comment.