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

Add a new tracing resource and frontend page to execute requests and display the header data. #124

Merged
merged 1 commit into from
Apr 14, 2023
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
14 changes: 11 additions & 3 deletions tracing-example/README.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
== Usage
= RESTEasy Tracing Example

This is a demonstration of the resteasy tracing feature.

Expand All @@ -9,11 +9,14 @@ To run the example, you can simply run it with WildFly:
$ mvn wildfly:run
----

== Usage

After server started, we can access the server and get the tracing info:

=== Command Line
[source,bash]
----
$ curl -i http://localhost:8080/tracing-example/level
$ curl -i http://localhost:8080/tracing-example/trace/level
----

And here is the sample output:
Expand All @@ -34,4 +37,9 @@ X-RESTEasy-Tracing-189: org.jboss.resteasy.plugins.server.servlet.Servlet3AsyncH
X-RESTEasy-Tracing-190: org.jboss.resteasy.plugins.server.servlet.Servlet3AsyncHttpRequest@5c54713c MBW [ ---- / 90378.04 ms | ---- %] Find MBW for type=[java.lang.String] genericType=[java.lang.String] mediaType=[[jakarta.ws.rs.core.MediaType @45b9c1ef]] annotations=[@jakarta.ws.rs.GET(), @jakarta.ws.rs.Path(value="/level")]
----

Above is the basic usage of the sample. You should also see output on the console WildFly is running in as well.
Above is the basic usage of the sample. You should also see output on the console WildFly is running in as well.

=== Web

Navigate to http://localhost:8080/tracing-example. From there you should see a web page which can be used to execute
HTTP requests through a client returning the tracing headers.
67 changes: 47 additions & 20 deletions tracing-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,6 @@
<debugJvmArgs/>
</properties>

<profiles>
<profile>
<id>wildfly27</id>
<properties>
<version.org.wildfly>27.0.1.Final</version.org.wildfly>
<dep.tracing.scope>compile</dep.tracing.scope>
</properties>
</profile>
</profiles>

<dependencyManagement>
<dependencies>
<dependency>
Expand Down Expand Up @@ -196,16 +186,47 @@
<version>${version.wildfly-maven-plugin}</version>
<configuration>
<jboss-home>${jboss.home}</jboss-home>
<provisioning-dir>${jboss.home}</provisioning-dir>
<feature-packs>
<feature-pack>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ee-galleon-pack</artifactId>
<version>${version.org.wildfly}</version>
</feature-pack>
</feature-packs>
<galleon-options>
<jboss-fork-embedded>true</jboss-fork-embedded>
</galleon-options>
</configuration>
<executions>
<execution>
<id>provision-test-server</id>
<id>provision-server</id>
<phase>process-test-classes</phase>
<goals>
<goal>provision</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>wildfly27</id>
<properties>
<version.org.wildfly>27.0.1.Final</version.org.wildfly>
<dep.tracing.scope>compile</dep.tracing.scope>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly-maven-plugin}</version>
<configuration>
<provisioning-dir>${jboss.home}</provisioning-dir>
<jboss-home>${jboss.home}</jboss-home>
<!-- First configure the feature pack we are overriding -->
<feature-packs>
<feature-pack>
Expand All @@ -224,13 +245,19 @@
<version>${version.org.jboss.resteasy}</version>
</feature-pack>
</feature-packs>
<galleon-options>
<jboss-fork-embedded>true</jboss-fork-embedded>
</galleon-options>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<executions>
<execution>
<id>provision-server</id>
<phase>process-test-classes</phase>
<goals>
<goal>provision</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2023 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* 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 dev.resteasy.examples.tracing;

import jakarta.enterprise.context.RequestScoped;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

/**
* @author <a href="mailto:jperkins@redhat.com">James R. Perkins</a>
*/
@Path("/headers")
@RequestScoped
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
public class TraceMethodResource {

@GET
@Path("get")
public String get() {
return "GET trace";
}

@POST
@Path("post")
public String post(final String value) {
return String.format("POST trace: %s", value);
}

@PUT
@Path("put")
public String put(final String value) {
return String.format("PUT trace: %s", value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/")
@ApplicationPath("/trace")
public class TracingApp extends Application {
}
20 changes: 20 additions & 0 deletions tracing-example/src/main/webapp/WEB-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ JBoss, Home of Professional Open Source.
~
~ Copyright 2023 Red Hat, Inc., and individual contributors
~ as indicated by the @author tags.
~
~ 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.
-->

<beans xmlns="https://jakarta.ee/xml/ns/jakartaee" version="4.0"/>
113 changes: 113 additions & 0 deletions tracing-example/src/main/webapp/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<!--
~ JBoss, Home of Professional Open Source.
~
~ Copyright 2023 Red Hat, Inc., and individual contributors
~ as indicated by the @author tags.
~
~ 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.
-->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Contacts</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.10.2/font/bootstrap-icons.min.css"
integrity="sha512-YFENbnqHbCRmJt5d+9lHimyEMt8LKSNTMLSaHjvsclnZGICeY/0KYEeiHwD1Ux4Tcao0h60tdcMv+0GljvWyHg=="
crossorigin="anonymous" referrerpolicy="no-referrer"/>
</head>
<body>

<nav class="navbar navbar-dark bg-dark">
<div class="container-fluid">
<a href="#" class="navbar-brand">RESTEasy Tracing</a>
</div>
</nav>
<div aria-live="polite" aria-atomic="true" class="position-relative">
<div id="liveAlertPlaceholder" class="toast-container top-0 end-0 p-3"></div>
</div>

<main class="container">
<div class="mt-3 mb-3 col-5">
<fieldset class="border rounded-3 p-3">
<legend class="float-none w-auto px-3">Choose the HTTP method to invoke:</legend>
<div class="form-check">
<input class="form-check-input" type="radio" name="httpMethod" id="get" value="get" checked>
<label class="form-check-label" for="get">GET</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="httpMethod" id="post" value="post">
<label class="form-check-label" for="post">POST</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="httpMethod" id="put" value="put">
<label class="form-check-label" for="put">PUT</label>
</div>
<div class="mt-4 mb-2">
<hr>
<button class="btn btn-outline-primary me-2" type="button" name="submit" id="submit"
data-bs-toggle="tooltip" data-bs-placement="top"
data-bs-title="Submits an HTTP request">
Submit
</button>
<button class="btn btn-outline-danger" id="clear" name="clear" type="button"
data-bs-toggle="tooltip" data-bs-placement="top"
data-bs-title="Clears the data from a previous request">
Clear
</button>
</div>
</fieldset>
</div>
<div class="placeholder-glow">
<div class="mb-2">
<strong>HTTP Method: </strong><span id="sentHttpMethod"></span>
</div>
<div class="mb-2">
<strong>Invoked: </strong><span id="url"></span>
</div>
<div class="mb-2">
<strong>Response: </strong><span id="response"></span>
</div>
</div>
<table class="table table-striped mt-3">
<thead>
<tr>
<th class="col-md-2" scope="col">Header Name</th>
<th scope="col">Header Value</th>
</tr>
</thead>
<tbody id="output">

</tbody>
</table>
</main>
<template id="alert">
<div class="toast align-items-center border-0 opacity-75" role="alert" aria-live="assertive" aria-atomic="true">
<div class="d-flex">
<div class="toast-body"></div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"
aria-label="Close"></button>
</div>
</div>
</template>

<script src="resources/main.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous"></script>
</body>
Loading