Skip to content

Commit

Permalink
Move static method
Browse files Browse the repository at this point in the history
  • Loading branch information
skjolber committed Jan 18, 2025
1 parent fde70ae commit 7141685
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ protected void requestMessage(HttpRequest request, StringBuilder messageBuilder)

String contentType = request.getContentType();
boolean isJson = ContentType.isJsonMediaType(contentType);
boolean isXml = AbstractLogLevelLogstashLogbackSink.isXmlMediaType(contentType);
boolean isXml = isXmlMediaType(contentType);

if(isJson || isXml) {
final String body = request.getBodyAsString();
Expand All @@ -91,7 +91,7 @@ protected void responseMessage(Correlation correlation, HttpRequest request, Htt

String contentType = response.getContentType();
boolean isJson = ContentType.isJsonMediaType(contentType);
boolean isXml = AbstractLogLevelLogstashLogbackSink.isXmlMediaType(contentType);
boolean isXml = isXmlMediaType(contentType);

if(isJson || isXml) {
final String body = response.getBodyAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,6 @@

public abstract class AbstractLogLevelLogstashLogbackSink extends AbstractLogLevelSink {

public static boolean isXmlMediaType(@Nullable final String contentType) {
if (contentType == null) {
return false;
}

String contentTypeWithoutEncoding;
// text/xml;charset=UTF-8
int index = contentType.indexOf(';');
if(index == -1) {
contentTypeWithoutEncoding = contentType;
} else {
contentTypeWithoutEncoding = contentType.substring(0, index).trim();
}

final String lowerCasedContentType = contentTypeWithoutEncoding.toLowerCase();

boolean isApplicationOrText = lowerCasedContentType.startsWith("application/") || lowerCasedContentType.startsWith("text/");
if(!isApplicationOrText) {
return false;
}

return lowerCasedContentType.endsWith("+xml") || lowerCasedContentType.endsWith("/xml");
}

protected final MaxSizeJsonFilter maxSizeJsonFilter;
protected final JsonValidator jsonValidator;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,37 @@
import org.slf4j.Marker;
import org.zalando.logbook.*;

import javax.annotation.Nullable;
import java.io.IOException;
import java.util.function.BiConsumer;
import java.util.function.BooleanSupplier;

public abstract class AbstractLogLevelSink implements Sink {

public static boolean isXmlMediaType(@Nullable final String contentType) {
if (contentType == null) {
return false;
}

String contentTypeWithoutEncoding;
// text/xml;charset=UTF-8
int index = contentType.indexOf(';');
if(index == -1) {
contentTypeWithoutEncoding = contentType;
} else {
contentTypeWithoutEncoding = contentType.substring(0, index).trim();
}

final String lowerCasedContentType = contentTypeWithoutEncoding.toLowerCase();

boolean isApplicationOrText = lowerCasedContentType.startsWith("application/") || lowerCasedContentType.startsWith("text/");
if(!isApplicationOrText) {
return false;
}

return lowerCasedContentType.endsWith("+xml") || lowerCasedContentType.endsWith("/xml");
}

protected final BooleanSupplier logLevelEnabled;

protected final BiConsumer<Marker, String> logConsumer;
Expand Down

0 comments on commit 7141685

Please sign in to comment.