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

Provide the possibility to log user data from exchange #26339

Merged
merged 1 commit into from
Jun 30, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.vertx.http.runtime.attribute;

import io.vertx.ext.web.RoutingContext;

/**
* Provide entries from the "user data" section of the RoutingContext
*/
public class ExchangeDataAttribute implements ExchangeAttribute {

private final String dataKey;

public ExchangeDataAttribute(String dataKey) {
this.dataKey = dataKey;
}

@Override
public String readAttribute(RoutingContext exchange) {
return exchange.get(dataKey);
}

@Override
public void writeAttribute(RoutingContext exchange, String newValue) throws ReadOnlyAttributeException {
throw new ReadOnlyAttributeException();
}

public static final class Builder implements ExchangeAttributeBuilder {

@Override
public String name() {
return "Exchange data";
}

@Override
public ExchangeAttribute build(final String token) {
if (token.startsWith("%{d,") && token.endsWith("}")) {
final String dataItemName = token.substring(4, token.length() - 1);
return new ExchangeDataAttribute(dataItemName);
}
return null;
}

@Override
public int priority() {
return 0;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
* <li><code>%{c,xxx}</code> for a specific cookie
* <li><code>%{r,xxx}</code> xxx is an attribute in the ServletRequest
* <li><code>%{s,xxx}</code> xxx is an attribute in the HttpSession
* <li><code>%{d,xxx}</code> xxx is a data item in the exchange</li>
* </ul>
*
* @author Stuart Douglas
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ io.quarkus.vertx.http.runtime.attribute.SecureExchangeAttribute$Builder
io.quarkus.vertx.http.runtime.attribute.RemoteHostAttribute$Builder
io.quarkus.vertx.http.runtime.attribute.RequestPathAttribute$Builder
io.quarkus.vertx.http.runtime.attribute.NullAttribute$Builder
io.quarkus.vertx.http.runtime.attribute.AllRequestHeadersAttribute$Builder
io.quarkus.vertx.http.runtime.attribute.AllRequestHeadersAttribute$Builder
io.quarkus.vertx.http.runtime.attribute.ExchangeDataAttribute$Builder