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

Update to Jetty 9.4.48 and store as property in parent pom #241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions modules/ads_lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<version>5.1.10</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ public void testDownloadReportWithServerErrorStatus() throws Exception {
RawReportDownloadResponse response = helper.downloadReport(reportRequest);

assertEquals("Response status code not failure", 500, response.getHttpStatus());
assertEquals("", Streams.readAll(response.getInputStream(), response.getCharset()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,27 @@
import com.google.common.collect.Lists;
import com.google.common.io.ByteSink;
import com.google.common.io.ByteSource;

import org.mortbay.http.HttpContext;
import org.mortbay.http.HttpException;
import org.mortbay.http.HttpFields;
import org.mortbay.http.HttpMessage;
import org.mortbay.http.HttpRequest;
import org.mortbay.http.HttpResponse;
import org.mortbay.jetty.Server;
import org.mortbay.util.InetAddrPort;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Deque;
import java.util.List;
import java.util.zip.GZIPInputStream;

/**
* HTTP server used to verify requests and send mocked responses.
*/
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;

/** HTTP server used to verify requests and send mocked responses. */
public class TestHttpServer {

private InternalHttpServer server;

/**
* Default constructor.
*/
/** Default constructor. */
public TestHttpServer() {}

/**
Expand All @@ -63,86 +56,69 @@ public void start() throws Exception {
* Stops the HTTP server.
*
* @throws InterruptedException Stopping a lifecycle is rarely atomic and may be interrupted by
* another thread. If this happens InterruptedException is throw and the component will be
* in an indeterminant state and should probably be discarded.
* another thread. If this happens InterruptedException is throw and the component will be in
* an indeterminant state and should probably be discarded.
*/
public void stop() throws InterruptedException {
server.stop();
public void stop() throws Exception {
TestPortFinder.getInstance().releaseUnusedPort(server.port);
server.stop();
}

/**
* Gets the body of the last request made to the server. This will be the inflated body if
* the last request was compressed.
* Gets the body of the last request made to the server. This will be the inflated body if the
* last request was compressed.
*/
public String getLastRequestBody() {
return server.getLastRequestBody();
}

/**
* Gets if the body of the last request made to the server was compressed.
*/
/** Gets if the body of the last request made to the server was compressed. */
public boolean wasLastRequestBodyCompressed() {
return server.wasLastRequestBodyCompressed();
}

/**
* Gets the body of the all requests made to the server, in order from oldest
* to newest.
*/

/** Gets the body of the all requests made to the server, in order from oldest to newest. */
public List<String> getAllRequestBodies() {
return Lists.newArrayList(server.requestBodies);
}

/**
* Gets the authorization header of the last request made to the server or
* {@code null} if none.
* Gets the authorization header of the last request made to the server or {@code null} if none.
*/
public String getLastAuthorizationHttpHeader() {
return server.getLastAuthorizationHttpHeader();
}

/**
* Gets the authorization headers of the all request made to the server, in
* order from oldest to newest. If a request did not contain an authorization
* header, its index contains {@code null}.
* Gets the authorization headers of the all request made to the server, in order from oldest to
* newest. If a request did not contain an authorization header, its index contains {@code null}.
*/
public List<String> getAllAuthorizationHttpHeaders() {
return Lists.newArrayList(server.authorizationHttpHeaders);
}

/**
* Sets the response body to return on the next request.
*/
/** Sets the response body to return on the next request. */
public void setMockResponseBody(String mockResponseBody) {
setMockResponseBodies(Lists.newArrayList(mockResponseBody));
}

/**
* Sets the response bodies to return on subsequent requests.
*/
/** Sets the response bodies to return on subsequent requests. */
public void setMockResponseBodies(List<String> mockResponseBodies) {
server.mockResponseBodies.clear();
server.mockResponseBodies.addAll(mockResponseBodies);
}

/**
* Sets the delay in milliseconds before the server responds.
*/

/** Sets the delay in milliseconds before the server responds. */
public void setDelay(long delay) {
server.delay = delay;
}

/**
* Gets the server URL with port.
*/
/** Gets the server URL with port. */
public String getServerUrl() {
return server.getServerUrl();
}

/**
* Jetty5 implementation of an HTTP server.
*/
/** Jetty implementation of an HTTP server. */
private class InternalHttpServer extends Server {

private final int port;
Expand All @@ -159,73 +135,87 @@ private class InternalHttpServer extends Server {
* @throws IOException if port could not be set
*/
public InternalHttpServer(int port) throws IOException {
super();
super(port);
this.port = port;
addListener(new InetAddrPort(port));

setHandler(
new AbstractHandler() {
@Override
public void handle(
String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

authorizationHttpHeaders.add(request.getHeader("Authorization"));

// Read the raw bytes from the request.
final byte[] rawRequestBytes =
new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return request.getInputStream();
}
}.read();

// Inflate the raw bytes if they are in gzip format.
boolean isGzipFormat =
"gzip".equals(request.getHeader(HttpHeader.CONTENT_ENCODING.asString()));

byte[] requestBytes;
if (isGzipFormat) {
requestBytes =
new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return new GZIPInputStream(ByteSource.wrap(rawRequestBytes).openStream());
}
}.read();
} else {
requestBytes = rawRequestBytes;
}

// Convert the (possibly inflated) request bytes to a string.
requestBodies.add(
ByteSource.wrap(requestBytes).asCharSource(Charset.forName(UTF_8)).read());
requestBodiesCompressionStates.add(isGzipFormat);

// Simulate a delay in processing.
simulateDelay();

if (numInteractions < mockResponseBodies.size()) {
String responseContent = mockResponseBodies.get(numInteractions++);
new ByteSink() {
@Override
public OutputStream openStream() {
try {
return response.getOutputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}.asCharSink(Charset.forName(UTF_8)).write(responseContent);
} else {
response.sendError(500, "error: no mockResponseBodies");
}

baseRequest.setHandled(true);
}
});
}

/**
* Gets the server URL with port.
*/
/** Gets the server URL with port. */
public String getServerUrl() {
return String.format("http://localhost:%s", port);
}

@Override
public HttpContext service(final HttpRequest request, final HttpResponse response)
throws IOException, HttpException {
request.setState(HttpMessage.__MSG_EDITABLE);
this.authorizationHttpHeaders.add(request.getHeader().get("Authorization"));

// Read the raw bytes from the request.
final byte[] rawRequestBytes = new ByteSource() {
@Override
public InputStream openStream() throws IOException {
return request.getInputStream();
}
}.read();

// Inflate the raw bytes if they are in gzip format.
boolean isGzipFormat = "gzip".equals(request.getHeader().get(HttpFields.__ContentEncoding));

byte[] requestBytes;
if (isGzipFormat) {
requestBytes = new ByteSource(){
@Override
public InputStream openStream() throws IOException {
return new GZIPInputStream(ByteSource.wrap(rawRequestBytes).openStream());
}
}.read();
} else {
requestBytes = rawRequestBytes;
}

// Convert the (possibly inflated) request bytes to a string.
this.requestBodies.add(
ByteSource.wrap(requestBytes).asCharSource(Charset.forName(UTF_8)).read());
this.requestBodiesCompressionStates.add(isGzipFormat);

// Simulate a delay in processing.
simulateDelay();

new ByteSink() {
@Override
public OutputStream openStream() {
return response.getOutputStream();
}
}.asCharSink(Charset.forName(UTF_8)).write(mockResponseBodies.get(numInteractions++));

return getContext(getServerUrl());
}

/**
* Simulates delays in processing requests.
*/
private void simulateDelay() throws HttpException {
/** Simulates delays in processing requests. */
private void simulateDelay() throws IOException {
try {
Thread.sleep(this.delay);
} catch (InterruptedException e) {
throw new HttpException(500, e.getMessage());
throw new IOException(e.getMessage());
}
}

Expand All @@ -235,14 +225,14 @@ private void simulateDelay() throws HttpException {
private String getLastRequestBody() {
return requestBodies.getLast();
}

/**
* Returns if the last request body was compressed.
*/
private boolean wasLastRequestBodyCompressed() {
return requestBodiesCompressionStates.getLast();
}

/**
* Gets the authorization header of the last request made to the server or
* {@code null} if none.
Expand Down
6 changes: 3 additions & 3 deletions modules/adwords_appengine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<version>5.1.10</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions modules/adwords_axis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<version>5.1.10</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions modules/dfp_appengine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<version>5.1.10</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
6 changes: 3 additions & 3 deletions modules/dfp_axis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>jetty</groupId>
<artifactId>jetty</artifactId>
<version>5.1.10</version>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<jetty.version>9.4.48.v20220622</jetty.version>
</properties>

<build>
Expand Down