use of org.eclipse.hono.service.http.DefaultFailureHandler in project hono by eclipse.
the class DelegatingDeviceManagementHttpEndpointTest method setUp.
/**
* Sets up the fixture.
*/
@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() {
final Vertx vertx = mock(Vertx.class);
router = Router.router(vertx);
// make sure that ServiceInvocationExceptions are properly handled
// and result in the exception's error code being set on the response
router.route().failureHandler(new DefaultFailureHandler());
service = mock(DeviceManagementService.class);
when(service.searchDevices(anyString(), anyInt(), anyInt(), any(List.class), any(List.class), any(Span.class))).thenReturn(Future.succeededFuture(OperationResult.empty(HttpURLConnection.HTTP_OK)));
final var endpoint = new DelegatingDeviceManagementHttpEndpoint<>(vertx, service);
endpoint.setConfiguration(new ServiceConfigProperties());
endpoint.addRoutes(router);
requestBody = Buffer.buffer();
requestParams = MultiMap.caseInsensitiveMultiMap();
requestHeaders = MultiMap.caseInsensitiveMultiMap();
}
use of org.eclipse.hono.service.http.DefaultFailureHandler in project hono by eclipse.
the class AbstractVertxBasedHttpProtocolAdapter method createRouter.
/**
* Creates the router for handling requests.
* <p>
* This method creates a router instance along with a route matching all request. That route is initialized with the
* following handlers and failure handlers:
* <ol>
* <li>a handler to add a Micrometer {@code Timer.Sample} to the routing context,</li>
* <li>a handler and failure handler that creates tracing data for all server requests,</li>
* <li>a handler to log when the connection is closed prematurely,</li>
* <li>a default failure handler,</li>
* <li>a handler limiting the body size of requests to the maximum payload size set in the <em>config</em>
* properties.</li>
* </ol>
*
* @return The newly created router (never {@code null}).
*/
protected Router createRouter() {
final Router router = Router.router(vertx);
final Route matchAllRoute = router.route();
// the handlers and failure handlers are added here in a specific order!
// 1. handler to start the metrics timer
matchAllRoute.handler(ctx -> {
ctx.put(KEY_MICROMETER_SAMPLE, getMetrics().startTimer());
ctx.next();
});
// 2. tracing handler
final TracingHandler tracingHandler = createTracingHandler();
matchAllRoute.handler(tracingHandler).failureHandler(tracingHandler);
// 3. handler to log when the connection is closed prematurely
matchAllRoute.handler(ctx -> {
if (!ctx.response().closed() && !ctx.response().ended()) {
ctx.response().closeHandler(v -> logResponseGettingClosedPrematurely(ctx));
}
ctx.next();
});
// 4. default handler for failed routes
matchAllRoute.failureHandler(new DefaultFailureHandler());
// 5. BodyHandler with request size limit
log.info("limiting size of inbound request body to {} bytes", getConfig().getMaxPayloadSize());
final BodyHandler bodyHandler = BodyHandler.create(DEFAULT_UPLOADS_DIRECTORY).setBodyLimit(getConfig().getMaxPayloadSize());
matchAllRoute.handler(bodyHandler);
return router;
}
Aggregations