@Before public void before() { openPort = PortUtils.findOpenPort(); serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder().setPort(openPort).build(); serviceEndpointServer.initServices(new TestService()); serviceEndpointServer.startServerAndWait(); }
@Test public void testBadJSONCustomHandler() { serviceEndpointServer.stop(); openPort = PortUtils.findOpenPort(); serviceEndpointServer = EndpointServerBuilder.endpointServerBuilder() .setPort(openPort) .setErrorHandler( new Consumer<Throwable>() { @Override public void accept(Throwable throwable) { final Optional<HttpRequest> httpRequest = new HttpContext().getHttpRequest(); if (httpRequest.isPresent()) { httpRequest .get() .getReceiver() .respondOK("\"Bad JSON" + throwable.getMessage() + "\""); httpRequest.get().handled(); } } }) .build(); serviceEndpointServer.initServices(new TestService()); serviceEndpointServer.startServerAndWait(); HTTP.Response response = HTTP.jsonRestCallViaPOST( buildURL("addall"), "\"i\": 1, \"s\": \"string\"}, " + "{\"i\": 2, \"s\": \"string2\"}]"); assertEquals(200, response.status()); }