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

Upgdate to Jetty 9.4.55.v20240627 #89

Merged
merged 2 commits into from
Jul 31, 2024
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
Expand Up @@ -169,13 +169,12 @@ public Void handle(Request request, Response response)
try {
InputStream inputStream = response.getInputStream();
String responseBody = CharStreams.toString(new InputStreamReader(inputStream));
log.debug("Posting event to %s failed: status_code=%d status_line=%s body=%s", request.getUri(), statusCode, response.getStatusMessage(), responseBody);
log.debug("Posting event to %s failed: status_code=%d body=%s", request.getUri(), statusCode, responseBody);
}
catch (IOException bodyError) {
log.debug("Posting event to %s failed: status_code=%d status_line=%s error=%s",
log.debug("Posting event to %s failed: status_code=%d error=%s",
request.getUri(),
statusCode,
response.getStatusMessage(),
bodyError.getMessage());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public JsonResponse<T> handle(Request request, Response response)
byte[] bytes = readResponseBytes(response);
String contentType = response.getHeader(CONTENT_TYPE);
if ((contentType == null) || !MediaType.parse(contentType).is(MEDIA_TYPE_JSON)) {
return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), bytes);
return new JsonResponse<>(response.getStatusCode(), response.getHeaders(), bytes);
}
return new JsonResponse<>(response.getStatusCode(), response.getStatusMessage(), response.getHeaders(), jsonCodec, bytes);
return new JsonResponse<>(response.getStatusCode(), response.getHeaders(), jsonCodec, bytes);
}

private static byte[] readResponseBytes(Response response)
Expand All @@ -82,18 +82,16 @@ private static byte[] readResponseBytes(Response response)
public static class JsonResponse<T>
{
private final int statusCode;
private final String statusMessage;
private final ListMultimap<HeaderName, String> headers;
private final boolean hasValue;
private final byte[] jsonBytes;
private final byte[] responseBytes;
private final T value;
private final IllegalArgumentException exception;

public JsonResponse(int statusCode, String statusMessage, ListMultimap<HeaderName, String> headers, byte[] responseBytes)
public JsonResponse(int statusCode, ListMultimap<HeaderName, String> headers, byte[] responseBytes)
{
this.statusCode = statusCode;
this.statusMessage = statusMessage;
this.headers = ImmutableListMultimap.copyOf(headers);

this.hasValue = false;
Expand All @@ -104,10 +102,9 @@ public JsonResponse(int statusCode, String statusMessage, ListMultimap<HeaderNam
}

@SuppressWarnings("ThrowableInstanceNeverThrown")
public JsonResponse(int statusCode, String statusMessage, ListMultimap<HeaderName, String> headers, JsonCodec<T> jsonCodec, byte[] jsonBytes)
public JsonResponse(int statusCode, ListMultimap<HeaderName, String> headers, JsonCodec<T> jsonCodec, byte[] jsonBytes)
{
this.statusCode = statusCode;
this.statusMessage = statusMessage;
this.headers = ImmutableListMultimap.copyOf(headers);

this.jsonBytes = requireNonNull(jsonBytes, "jsonBytes is null");
Expand All @@ -131,11 +128,6 @@ public int getStatusCode()
return statusCode;
}

public String getStatusMessage()
{
return statusMessage;
}

@Nullable
public String getHeader(String name)
{
Expand Down Expand Up @@ -201,7 +193,6 @@ public String toString()
{
return toStringHelper(this)
.add("statusCode", statusCode)
.add("statusMessage", statusMessage)
.add("headers", headers)
.add("hasValue", hasValue)
.add("value", value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public T handle(Request request, Response response)
{
if (!successfulResponseCodes.contains(response.getStatusCode())) {
throw new UnexpectedResponseException(
String.format("Expected response code to be %s, but was %d: %s", successfulResponseCodes, response.getStatusCode(), response.getStatusMessage()),
String.format("Expected response code to be %s, but was %d", successfulResponseCodes, response.getStatusCode()),
request,
response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public interface Response
{
int getStatusCode();

String getStatusMessage();

@Nullable
default String getHeader(String name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,17 @@ public StatusResponse handleException(Request request, Exception exception)
@Override
public StatusResponse handle(Request request, Response response)
{
return new StatusResponse(response.getStatusCode(), response.getStatusMessage(), response.getHeaders());
return new StatusResponse(response.getStatusCode(), response.getHeaders());
}

public static class StatusResponse
{
private final int statusCode;
private final String statusMessage;
private final ListMultimap<HeaderName, String> headers;

public StatusResponse(int statusCode, String statusMessage, ListMultimap<HeaderName, String> headers)
public StatusResponse(int statusCode, ListMultimap<HeaderName, String> headers)
{
this.statusCode = statusCode;
this.statusMessage = statusMessage;
this.headers = ImmutableListMultimap.copyOf(headers);
}

Expand All @@ -69,11 +67,6 @@ public int getStatusCode()
return statusCode;
}

public String getStatusMessage()
{
return statusMessage;
}

@Nullable
public String getHeader(String name)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,12 @@ public StringResponse handle(Request request, Response response)
MediaType mediaType = MediaType.parse(contentType);
return new StringResponse(
response.getStatusCode(),
response.getStatusMessage(),
response.getHeaders(),
new String(ByteStreams.toByteArray(response.getInputStream()), mediaType.charset().or(UTF_8)));
}

return new StringResponse(
response.getStatusCode(),
response.getStatusMessage(),
response.getHeaders(),
new String(ByteStreams.toByteArray(response.getInputStream()), UTF_8));
}
Expand All @@ -80,14 +78,12 @@ public StringResponse handle(Request request, Response response)
public static class StringResponse
{
private final int statusCode;
private final String statusMessage;
private final ListMultimap<HeaderName, String> headers;
private final String body;

public StringResponse(int statusCode, String statusMessage, ListMultimap<HeaderName, String> headers, String body)
public StringResponse(int statusCode, ListMultimap<HeaderName, String> headers, String body)
{
this.statusCode = statusCode;
this.statusMessage = statusMessage;
this.headers = ImmutableListMultimap.copyOf(headers);
this.body = body;
}
Expand All @@ -97,11 +93,6 @@ public int getStatusCode()
return statusCode;
}

public String getStatusMessage()
{
return statusMessage;
}

public String getBody()
{
return body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ public class UnexpectedResponseException
{
private final Request request;
private final int statusCode;
private final String statusMessage;
private final ListMultimap<HeaderName, String> headers;

public UnexpectedResponseException(Request request, Response response)
{
this(String.format("%d: %s", response.getStatusCode(), response.getStatusMessage()),
this(String.format("%d", response.getStatusCode()),
request,
response.getStatusCode(),
response.getStatusMessage(),
ImmutableListMultimap.copyOf(response.getHeaders()));
}

Expand All @@ -48,16 +46,14 @@ public UnexpectedResponseException(String message, Request request, Response res
this(message,
request,
response.getStatusCode(),
response.getStatusMessage(),
ImmutableListMultimap.copyOf(response.getHeaders()));
}

public UnexpectedResponseException(String message, Request request, int statusCode, String statusMessage, ListMultimap<HeaderName, String> headers)
public UnexpectedResponseException(String message, Request request, int statusCode, ListMultimap<HeaderName, String> headers)
{
super(message);
this.request = request;
this.statusCode = statusCode;
this.statusMessage = statusMessage;
this.headers = ImmutableListMultimap.copyOf(headers);
}

Expand All @@ -66,11 +62,6 @@ public int getStatusCode()
return statusCode;
}

public String getStatusMessage()
{
return statusMessage;
}

@Nullable
public String getHeader(String name)
{
Expand All @@ -94,7 +85,6 @@ public String toString()
return toStringHelper(this)
.add("request", request)
.add("statusCode", statusCode)
.add("statusMessage", statusMessage)
.add("headers", headers)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public JettyHttpClient(

creationLocation.fillInStackTrace();

SslContextFactory sslContextFactory = new SslContextFactory();
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setEndpointIdentificationAlgorithm("HTTPS");
if (config.getKeyStorePath() != null) {
Optional<KeyStore> pemKeyStore = tryLoadPemKeyStore(config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ public int getStatusCode()
return response.getStatus();
}

@Override
public String getStatusMessage()
{
return response.getReason();
}

@Override
public ListMultimap<HeaderName, String> getHeaders()
{
Expand All @@ -60,7 +54,6 @@ public String toString()
{
return toStringHelper(this)
.add("statusCode", getStatusCode())
.add("statusMessage", getStatusMessage())
.add("headers", getHeaders())
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ public int getStatusCode()
return status.code();
}

@Override
public String getStatusMessage()
{
return status.reason();
}

@Override
public ListMultimap<HeaderName, String> getHeaders()
{
Expand All @@ -73,7 +67,6 @@ public String toString()
{
return toStringHelper(this)
.add("statusCode", getStatusCode())
.add("statusMessage", getStatusMessage())
.add("headers", getHeaders())
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,22 @@

import java.util.List;

import static java.util.Objects.requireNonNull;

public class ThriftResponse<T>
{
private final int statusCode;
private final String statusMessage;
private final String errorMessage;
private final ListMultimap<HeaderName, String> headers;
private final T value;
private final IllegalArgumentException exception;

ThriftResponse(
int statusCode,
String statusMessage,
String errorMessage,
ListMultimap<HeaderName, String> headers,
T value,
IllegalArgumentException exception)
{
this.statusCode = statusCode;
this.statusMessage = requireNonNull(statusMessage, "statusMessage is null");
this.errorMessage = errorMessage;
this.headers = headers != null ? ImmutableListMultimap.copyOf(headers) : null;
this.value = value;
Expand All @@ -40,11 +35,6 @@ public int getStatusCode()
return statusCode;
}

public String getStatusMessage()
{
return statusMessage;
}

public String getErrorMessage()
{
return errorMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public ThriftResponse<T> handle(Request request, Response response)
catch (Exception e) {
exception = new IllegalArgumentException("Unable to create " + thriftCodec.getType() + " from THRIFT response", e);
}
return new ThriftResponse<>(response.getStatusCode(), response.getStatusMessage(), null, response.getHeaders(), value, exception);
return new ThriftResponse<>(response.getStatusCode(), null, response.getHeaders(), value, exception);
}

private ThriftResponse<T> createErrorResponse(Response response)
Expand All @@ -83,7 +83,7 @@ public InputStream openStream() throws IOException
};
try {
String errorMessage = byteSource.asCharSource(StandardCharsets.UTF_8).read();
return new ThriftResponse<>(response.getStatusCode(), response.getStatusMessage(), errorMessage, response.getHeaders(), null, null);
return new ThriftResponse<>(response.getStatusCode(), errorMessage, response.getHeaders(), null, null);
}
catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public void abstractSetup()
if (keystore != null) {
httpConfiguration.addCustomizer(new SecureRequestCustomizer());

SslContextFactory sslContextFactory = new SslContextFactory(keystore);
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client();
sslContextFactory.setKeyStorePath(keystore);
sslContextFactory.setKeyStorePassword("changeit");
SslConnectionFactory sslConnectionFactory = new SslConnectionFactory(sslContextFactory, "http/1.1");

Expand Down Expand Up @@ -621,27 +622,6 @@ public void testResponseStatusCode()
assertEquals(statusCode, 543);
}

@Test
public void testResponseStatusMessage()
throws Exception
{
servlet.setResponseStatusMessage("message");

Request request = prepareGet()
.setUri(baseURI)
.build();

String statusMessage = executeRequest(request, createStatusResponseHandler()).getStatusMessage();

if (createClientConfig().isHttp2Enabled()) {
// reason phrases are not supported in HTTP/2
assertNull(statusMessage);
}
else {
assertEquals(statusMessage, "message");
}
}

@Test
public void testRequestHeaders()
throws Exception
Expand Down Expand Up @@ -747,7 +727,7 @@ public void testCompressionIsDisabled()
assertEquals(body, "");
assertFalse(servlet.getRequestHeaders().containsKey(HeaderName.of(ACCEPT_ENCODING)));

String json = "{\"foo\":\"bar\",\"hello\":\"world\"}";
String json = "{\"fruit\":\"apple\",\"hello\":\"world\"}";
assertGreaterThanOrEqual(json.length(), GzipHandler.DEFAULT_MIN_GZIP_SIZE);

servlet.setResponseBody(json);
Expand Down
Loading