Skip to content

Commit 11e7d8b

Browse files
authored
fix: Support header-, query- and path params (#8)
1 parent 5686657 commit 11e7d8b

45 files changed

Lines changed: 1702 additions & 470 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

acceptance/k6/script.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const listBody = JSON.stringify(exampleListRequest);
4444
export default function () {
4545
group('get request', () => {
4646
const url = 'http://localhost:8080/api/v1/data';
47-
const res = http.get(url);
47+
const res = http.get(url, { headers: { 'X-Name': "Alotta" }});
4848

4949
check(res, {
5050
'is status 200': (r) => r.status === 200,
@@ -80,4 +80,43 @@ export default function () {
8080
'is status 200': (r) => r.status === 200,
8181
});
8282
});
83+
84+
group('get query params', () => {
85+
const url = 'http://localhost:8080/api/v1/params/query?q1=data&q2=data';
86+
const res = http.get(url, listBody, {
87+
headers: {
88+
'Content-Type':'application/json',
89+
}
90+
});
91+
92+
check(res, {
93+
'is status 200': (r) => r.status === 200,
94+
});
95+
});
96+
97+
group('get path params', () => {
98+
const url = 'http://localhost:8080/api/v1/params/path/1234567890';
99+
const res = http.get(url, listBody, {
100+
headers: {
101+
'Content-Type':'application/json',
102+
}
103+
});
104+
105+
check(res, {
106+
'is status 200': (r) => r.status === 200,
107+
});
108+
});
109+
110+
group('get with many path params', () => {
111+
const url = 'http://localhost:8080/api/v1/params/path/1234567890/Justin/Case';
112+
const res = http.get(url, listBody, {
113+
headers: {
114+
'Content-Type':'application/json',
115+
}
116+
});
117+
118+
check(res, {
119+
'is status 200': (r) => r.status === 200,
120+
});
121+
});
83122
}

pom.xml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,49 @@
138138
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
139139
</configuration>
140140
</plugin>
141+
<plugin>
142+
<groupId>org.apache.maven.plugins</groupId>
143+
<artifactId>maven-failsafe-plugin</artifactId>
144+
<version>3.5.2</version>
145+
<configuration>
146+
<!-- Remove Mockito agent warning -->
147+
<argLine>@{argLine} -javaagent:${org.mockito:mockito-core:jar}</argLine>
148+
</configuration>
149+
<executions>
150+
<execution>
151+
<goals>
152+
<goal>integration-test</goal>
153+
<goal>verify</goal>
154+
</goals>
155+
</execution>
156+
</executions>
157+
</plugin>
141158
<plugin>
142159
<groupId>org.jacoco</groupId>
143160
<artifactId>jacoco-maven-plugin</artifactId>
144161
<version>0.8.12</version>
145162
<executions>
146163
<execution>
164+
<id>jacoco-surefire</id>
147165
<goals>
148166
<goal>prepare-agent</goal>
149167
</goals>
168+
<phase>initialize</phase>
169+
<configuration>
170+
<destFile>${project.build.directory}/jacoco.exec</destFile>
171+
<append>true</append>
172+
</configuration>
150173
</execution>
151174
<execution>
152-
<id>generate-code-coverage-report</id>
175+
<id>jacoco-report</id>
153176
<goals>
154177
<goal>report</goal>
155178
</goals>
156-
<phase>test</phase>
179+
<phase>verify</phase>
180+
<configuration>
181+
<dataFile>${project.build.directory}/jacoco.exec</dataFile>
182+
<outputDirectory>${project.reporting.outputDirectory}/jacoco</outputDirectory>
183+
</configuration>
157184
</execution>
158185
</executions>
159186
</plugin>

src/main/java/com/retailsvc/http/Handlers.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ public static ExceptionHandler internalServerErrorHandler() {
3333
}
3434

3535
public static ExceptionHandler defaultExceptionHandler() {
36-
LOG.warn("No exception handler set, using default.");
3736
return (exchange, e) -> internalServerErrorHandler().handleException(exchange, e);
3837
}
3938

src/main/java/com/retailsvc/http/OpenApiServer.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import static com.retailsvc.http.Handlers.notFoundHandler;
44
import static java.lang.Thread.ofVirtual;
5+
import static java.util.Objects.isNull;
56
import static java.util.Objects.requireNonNull;
6-
import static java.util.Objects.requireNonNullElseGet;
77
import static java.util.concurrent.Executors.newThreadPerTaskExecutor;
88

99
import com.retailsvc.http.openapi.OpenApiValidationFilter;
@@ -70,11 +70,19 @@ public OpenApiServer(
7070
requireNonNull(specification, "OpenAPI specification must not be null");
7171
requireNonNull(jsonMapper, "Request body mapper must not be null");
7272
requireNonNull(requestHandlers, "Request handlers must not be null");
73-
ExceptionHandler errorHandler =
74-
requireNonNullElseGet(exceptionHandler, Handlers::defaultExceptionHandler);
73+
74+
if (isNull(exceptionHandler)) {
75+
LOG.warn("No exception handler set, using default.");
76+
exceptionHandler = Handlers.defaultExceptionHandler();
77+
}
7578

7679
httpServer =
77-
initializeServer(httpPort, specification, jsonMapper, requestHandlers, errorHandler, t0);
80+
initializeServer(
81+
httpPort, specification, jsonMapper, requestHandlers, exceptionHandler, t0);
82+
}
83+
84+
public int listenPort() {
85+
return httpServer.getAddress().getPort();
7886
}
7987

8088
private HttpServer initializeServer(
@@ -94,7 +102,7 @@ private HttpServer initializeServer(
94102
filters.add(new BodyHandler());
95103
filters.add(new OpenApiValidationFilter(specification, jsonMapper));
96104

97-
context.setHandler(new RequestDispatchingHandler(specification, requestHandlers));
105+
context.setHandler(new RequestDispatchingHandler(requestHandlers));
98106

99107
server.createContext("/", notFoundHandler());
100108
server.start();

0 commit comments

Comments
 (0)