Skip to content
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
32 changes: 32 additions & 0 deletions http-api/src/main/java/io/avaje/http/api/SupressLogging.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.avaje.http.api;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* For this client request suppress payload logging.
*
* <p>Used when the payload contains sensitive content and the request and response content should
* be suppressed.
*
* <pre>{@code
* @Client
* interface CustomerApi {
* ...
* @Get("/{id}")
* @SupressLogging
* Customer getById(long id);
*
* @Post
* @SupressLogging
* long save(Customer customer);
* }
*
* }</pre>
*/
@Retention(SOURCE)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface SupressLogging {}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.lang.model.type.TypeKind;
import javax.lang.model.util.ElementFilter;

import io.avaje.http.api.SupressLogging;
import io.avaje.http.generator.core.APContext;
import io.avaje.http.generator.core.Append;
import io.avaje.http.generator.core.BeanParamReader;
Expand All @@ -31,13 +32,14 @@
import io.avaje.http.generator.core.RequestTimeoutPrism;
import io.avaje.http.generator.core.Util;
import io.avaje.http.generator.core.WebMethod;
import io.avaje.prism.GeneratePrism;
import io.avaje.prism.GenerateUtils;
import io.avaje.http.generator.client.UType;

/**
* Write code to register Web route for a given controller method.
*/
@GenerateUtils
@GeneratePrism(SupressLogging.class)
final class ClientMethodWriter {
private static final KnownResponse KNOWN_RESPONSE = new KnownResponse();
private static final String BODY_HANDLER = "java.net.http.HttpResponse.BodyHandler";
Expand All @@ -59,6 +61,7 @@ final class ClientMethodWriter {
private final Map<String, String> segmentPropertyMap;
private final Set<String> propertyConstants;
private final List<Entry<String, String>> presetHeaders;
private boolean suppressLogging;

ClientMethodWriter(MethodReader method, Append writer, Set<String> propertyConstants) {
this.method = method;
Expand All @@ -67,7 +70,9 @@ final class ClientMethodWriter {
this.returnType = UType.parse(method.returnType());
this.timeout = method.timeout();
this.useConfig = ProcessingContext.typeElement("io.avaje.config.Config") != null;

this.suppressLogging =
SupressLoggingPrism.isPresent(method.element())
|| SupressLoggingPrism.isPresent(method.element().getEnclosingElement());
this.segmentPropertyMap =
method.pathSegments().segments().stream()
.filter(Segment::isProperty)
Expand Down Expand Up @@ -180,6 +185,9 @@ void write() {
PathSegments pathSegments = method.pathSegments();
Set<PathSegments.Segment> segments = pathSegments.segments();

if (suppressLogging) {
writer.append(" .suppressLogging()").eol();
}
writeHeaders();
writePaths(segments);
writeQueryParams(pathSegments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import io.avaje.http.api.Client;
import io.avaje.http.api.Get;
import io.avaje.http.api.Headers;
import io.avaje.http.api.SupressLogging;

@Client
@SupressLogging
@Headers("Content-Type: applicaton/json")
public interface TitanFall {

Expand Down
2 changes: 2 additions & 0 deletions tests/test-client/src/main/java/example/github/Simple.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

import io.avaje.http.api.Client;
import io.avaje.http.api.Get;
import io.avaje.http.api.SupressLogging;
import io.avaje.http.client.HttpException;

@Client
public interface Simple {

@SupressLogging
@Get("users/{user}/repos")
List<Repo> listRepos(String user, String other) throws HttpException;
}