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
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.swisspush</groupId>
<artifactId>rest-storage</artifactId>
<version>3.1.20-SNAPSHOT</version>
<version>3.1.21-SNAPSHOT</version>
<name>rest-storage</name>
<description>
Persistence for REST resources in the filesystem or a redis database
Expand Down Expand Up @@ -410,7 +410,7 @@
</profile>
</profiles>
<properties>
<vertx.version>4.5.2</vertx.version>
<vertx.version>4.5.23</vertx.version>
<awssdk.version>2.39.2</awssdk.version>
<aws-crt.version>0.40.0</aws-crt.version>
<rxjava.version>3.1.12</rxjava.version>
Expand Down
52 changes: 35 additions & 17 deletions src/main/java/org/swisspush/reststorage/EventBusAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import javax.net.ssl.SSLSession;
import javax.security.cert.X509Certificate;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
Expand All @@ -44,19 +44,19 @@ public EventBusAdapter(
) {
this.exceptionFactory = exceptionFactory;
}

public void init(final Vertx vertx, String address, final Handler<HttpServerRequest> requestHandler) {
vertx.eventBus().consumer(address, (Handler<Message<Buffer>>) message -> {
try {
requestHandler.handle(new MappedHttpServerRequest(vertx, message, exceptionFactory));
} catch (RuntimeException ex) {
String msg = "TODO_63941634: Fix that broken requestHandler above (See also https://medium.com/swlh/yagni-and-kiss-cfd44b0654b6)";
log.error("{}", msg, log.isDebugEnabled() ? ex : null);
message.fail(500, msg);
}
});
}

public void init(final Vertx vertx, String address, final Handler<HttpServerRequest> requestHandler) {
vertx.eventBus().consumer(address, (Handler<Message<Buffer>>) message -> {
try {
requestHandler.handle(new MappedHttpServerRequest(vertx, message, exceptionFactory));
} catch (RuntimeException ex) {
String msg = "TODO_63941634: Fix that broken requestHandler above (See also https://medium.com/swlh/yagni-and-kiss-cfd44b0654b6)";
log.error("{}", msg, log.isDebugEnabled() ? ex : null);
message.fail(500, msg);
}
});
}
private static class MappedHttpServerRequest extends HttpServerRequestInternal {
private final Vertx vertx;
private final Buffer requestPayload;
Expand Down Expand Up @@ -151,6 +151,11 @@ public HostAndPort authority() {
return null;
}

@Override
public HostAndPort authority(boolean real) {
return null;
}

@Override
public String host() {
throw new UnsupportedOperationException();
Expand Down Expand Up @@ -271,6 +276,11 @@ public HttpServerResponse endHandler(Handler<Void> handler) {
throw new UnsupportedOperationException();
}

@Override
public Future<Void> writeHead() {
throw new UnsupportedOperationException();
}

@Override
public Future<Void> write(String chunk, String enc) {
responsePayload.appendBuffer(Buffer.buffer(chunk, enc));
Expand Down Expand Up @@ -560,8 +570,16 @@ public String getParamsCharset() {

@Override
public MultiMap params() {
return params(false);
}

@Override
public MultiMap params(boolean semicolonIsNormalChar) {
if (params == null) {
QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri(), paramsCharset);
QueryStringDecoder queryStringDecoder = QueryStringDecoder.builder()
.charset(paramsCharset)
.semicolonIsNormalChar(semicolonIsNormalChar)
.build(uri());
Map<String, List<String>> prms = queryStringDecoder.parameters();
params = new HeadersMultiMap();
if (!prms.isEmpty()) {
Expand All @@ -575,7 +593,7 @@ public MultiMap params() {

@Override
public String getParam(String paramName) {
return params.get(paramName);
return params().get(paramName);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.core.http.HttpVersion;
import io.vertx.core.http.impl.HttpServerRequestInternal;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import io.vertx.core.net.HostAndPort;
import io.vertx.ext.unit.Async;
import io.vertx.ext.unit.TestContext;
import io.vertx.ext.unit.junit.VertxUnitRunner;
Expand Down Expand Up @@ -58,6 +60,7 @@ public void setUp(TestContext context) {
request = Mockito.mock(HttpServerRequestInternal.class);
response = Mockito.mock(HttpServerResponse.class);

when(request.version()).thenReturn(HttpVersion.HTTP_1_0);
when(request.method()).thenReturn(HttpMethod.PUT);
when(request.uri()).thenReturn("/some/resource");
when(request.path()).thenReturn("/some/resource");
Expand Down Expand Up @@ -503,6 +506,11 @@ public Future<Void> end() {
request = new FailFastVertxHttpServerRequest() {
private final HeadersMultiMap headers = new HeadersMultiMap();

@Override
public HttpVersion version() {
return HttpVersion.HTTP_1_0;
}

@Override
public HttpMethod method() {
return HttpMethod.PUT;
Expand Down Expand Up @@ -547,6 +555,11 @@ public HttpServerResponse response() {
public String query() {
return "";
}

@Override
public HostAndPort authority() {
return null;
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public HostAndPort authority() {
throw new UnsupportedOperationException(msg);
}

@Override
public HostAndPort authority(boolean real) {
throw new UnsupportedOperationException(msg);
}

@Override
public String host() {
throw new UnsupportedOperationException(msg);
Expand Down Expand Up @@ -147,6 +152,11 @@ public MultiMap params() {
throw new UnsupportedOperationException(msg);
}

@Override
public MultiMap params(boolean semicolonIsNormalChar) {
throw new UnsupportedOperationException(msg);
}

@Override
public String getParam(String paramName) {
throw new UnsupportedOperationException(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ public HttpServerResponse endHandler(Handler<Void> handler) {
throw new UnsupportedOperationException(msg);
}

@Override
public Future<Void> writeHead() {
throw new UnsupportedOperationException(msg);
}

@Override
public Future<Void> write(String chunk, String enc) {
throw new UnsupportedOperationException(msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ public User user() {
throw new UnsupportedOperationException(msg);
}

@Override
public UserContext userContext() {
throw new UnsupportedOperationException(msg);
}

@Override
public Throwable failure() {
throw new UnsupportedOperationException(msg);
Expand Down
Loading