Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP Opentracing Implementation #826

Merged
merged 9 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,13 @@
<version>${project.version}</version>
</dependency>

<!-- REST Client -->
<dependency>
<groupId>io.helidon.microprofile.rest-client</groupId>
<artifactId>helidon-microprofile-rest-client</artifactId>
<version>${project.version}</version>
</dependency>

<!-- integrations -->
<dependency>
<groupId>io.helidon.serviceconfiguration</groupId>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/docs/microprofile/01_introduction.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Then declare the following dependency in your project:
----
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile-1.2</artifactId>
<artifactId>helidon-microprofile-2.2</artifactId>
</dependency>
----

Expand Down
116 changes: 116 additions & 0 deletions docs/src/main/docs/microprofile/09_rest-client.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
///////////////////////////////////////////////////////////////////////////////

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.

///////////////////////////////////////////////////////////////////////////////

= Rest Client
:description: Helidon MP Rest Client
= :keywords: helidon, rest, client, microprofile, micro-profile

== Configuring Rest Client with Helidon MP
MicroProfile Rest Client adds the capability to invoke remote microservices using a JAX-RS like interface to declare the
operations.

To use the rest client in your project, declare the following dependency:

[source,xml]
----
<dependency>
<groupId>io.helidon.microprofile.rest-client</groupId>
<artifactId>helidon-microprofile-rest-client</artifactId>
</dependency>
----

== Creating a new client using a builder

MicroProfile Rest Client can be created using a builder obtained from `RestClientBuilder.newBuilder()`.
The builder provides methods to configure details for the client and to define the desired rest client interface.

Example:
[source,java]
----
SomeResource someResource = RestClientBuilder.newBuilder()
.baseUri(URI.create("http://localhost:8080/baseUri"))
.build(SomeResource.class);

someResource.someMethod(apiModel);
----

== Creating new client - CDI
A rest client interface can be annotated with `@RegisterRestClient` to automatically register it with CDI.
The `RegisterRestClient` annotation has a property `baseUri` that can be used to define the base endpoint of this client.
This value can be overridden using configuration.

Example:
[source,java]
----
@RegisterRestClient(baseUri="http://localhost:8080/baseUri")
public interface SomeResource {

// ...

}
----

Once a rest client interface is annotated, it can be injected into any CDI bean.

Example:
[source,java]
----
@Inject
@RestClient
SomeResource client;

// ...

client.sampleMethod();

----

== Rest client configuration
Rest client implementation allows you to configure its parameters by builder,
annotations, and configuration.

You can configure new providers, base URI/URL and other options of the client.
See specification for full details:
https://download.eclipse.org/microprofile/microprofile-rest-client-1.2.1/microprofile-rest-client-1.2.1.html

== Quickstart example
To be able to run and test this example, please head to the Helidon examples/quickstarts
and start the helidon-quickstart-mp. Then create project with
the dependency on the Helidon rest client implementation and create the following rest client
interface:

Rest client interface
[source,java]
----
@Path("/greet")
interface GreetRestClient {

@GET
JsonObject getDefaultMessage();

@Path("/{name}")
@GET
JsonObject getMessage(@PathParam("name") String name);

}
----
Then create runnable method the same way as it is described in
`Creating new client - Interface`,but with baseUri `http://localhost:8080/greet`
and the above interface.

By calling `GreetRestClient.getDefaultMessage()` you reach the endpoint of Helidon quickstart.
59 changes: 59 additions & 0 deletions jersey/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>helidon-jersey-project</artifactId>
<groupId>io.helidon.jersey</groupId>
<version>1.1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>helidon-jersey-common</artifactId>
<name>Helidon Jersey Common</name>

<dependencies>
<dependency>
<groupId>io.helidon.jersey</groupId>
<artifactId>helidon-jersey-server</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.helidon.common</groupId>
<artifactId>helidon-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* 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.jersey.common;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.Optional;

import javax.ws.rs.container.ContainerRequestContext;

/**
* Information about the current request - invoked resource information.
*/
public interface InvokedResource {
/**
* Create a new invoked resource from Jersey container request context.
*
* @param context request context
* @return an instance of invoked resource to access information about resource class, method and annotations
*/
static InvokedResource create(ContainerRequestContext context) {
return InvokedResourceImpl.create(context);
}

/**
* Method that defines the invoked resource method.
* This may come from an interface.
*
* @return Method used to declared handling of the current request or empty if none found
*/
Optional<Method> definitionMethod();

/**
* Method that handles the invoked resource method.
* This must come from a class.
*
* @return Method used to handle current request or empty if none found
*/
Optional<Method> handlingMethod();

/**
* Resource definition class.
* The definition class is the class annotated with {@link javax.ws.rs.Path}
* annotation.
*
* @return class of the JAX-RS resource or empty if none found
*/
Optional<Class<?>> definitionClass();

/**
* Resource handling class.
* The handling class is the class that declares the handling method.
*
* @return class of the JAX-RS resource implementation or empty if none found
*/
Optional<Class<?>> handlingClass();

/**
* Find the annotation by class closest to the handling method.
* <p>
* Search order:
* <ol>
* <li>{@link #handlingMethod()}</li>
* <li>All methods from super classes up to {@link #definitionMethod()}</li>
* <li>{@link #handlingClass()}</li>
* <li>All super classes of the {@link #handlingClass()}</li>
* <li>All implemented interfaces</li>
* </ol>
* @param annotationClass class of the annotation to find
* @param <T> type of the annotation
* @return first annotation found, or empty if not declared
*/
<T extends Annotation> Optional<T> findAnnotation(Class<T> annotationClass);

/**
* Find method annotation by class closest to the handling method.
* <p>
* Search order:
* <ol>
* <li>{@link #handlingMethod()}</li>
* <li>All methods from super classes up to {@link #definitionMethod()}</li>
* </ol>
* @param annotationClass class of the annotation to find
* @param <T> type of the annotation
* @return first annotation found, or empty if not declared on a method
*/
<T extends Annotation> Optional<T> findMethodAnnotation(Class<T> annotationClass);

/**
* Find class annotation by class closest to the handling class.
* <p>
* Search order:
* <ol>
* <li>{@link #handlingClass()}</li>
* <li>All super classes of the {@link #handlingClass()}</li>
* <li>All implemented interfaces</li>
* </ol>
* @param annotationClass class of the annotation to find
* @param <T> type of the annotation
* @return first annotation found, or empty if not declared on a class
*/
<T extends Annotation> Optional<T> findClassAnnotation(Class<T> annotationClass);
}
Loading