HttpHandler extends LoggingRequestHandler { @Override public HttpResponse handle(HttpRequest request) { log.log(Level.FINE, request.getMethod() + " " + request.getUri().toString()); try { switch (request.getMethod()) { case POST: return handlePOST(request); case GET: return handleGET(request); case PUT: return handlePUT(request); case DELETE: return handleDELETE(request); default: return createErrorResponse(request.getMethod()); } } catch (NotFoundException | com.yahoo.vespa.config.server.NotFoundException e) { return HttpErrorResponse.notFoundError(getMessage(e, request)); } catch (ActivationConflictException e) { return HttpErrorResponse.conflictWhenActivating(getMessage(e, request)); } catch (BadRequestException | IllegalArgumentException | IllegalStateException e) { return HttpErrorResponse.badRequest(getMessage(e, request)); } catch (OutOfCapacityException e) { return HttpErrorResponse.outOfCapacity(getMessage(e, request)); } catch (InvalidApplicationException e) { return HttpErrorResponse.invalidApplicationPackage(getMessage(e, request)); } catch (InternalServerException e) { return HttpErrorResponse.internalServerError(getMessage(e, request)); } catch (UnknownVespaVersionException e) { return HttpErrorResponse.unknownVespaVersion(getMessage(e, request)); } catch (RequestTimeoutException e) { return HttpErrorResponse.requestTimeout(getMessage(e, request)); } catch (ApplicationLockException e) { return HttpErrorResponse.applicationLockFailure(getMessage(e, request)); } catch (ParentHostUnavailableException e) { return HttpErrorResponse.parentHostNotReady(getMessage(e, request)); } catch (CertificateNotReadyException e) { return HttpErrorResponse.certificateNotReady(getMessage(e, request)); } catch (LoadBalancerServiceException e) { return HttpErrorResponse.loadBalancerNotReady(getMessage(e, request)); } catch (Exception e) { log.log(Level.WARNING, "Unexpected exception handling a config server request", e); return HttpErrorResponse.internalServerError(getMessage(e, request)); } } HttpHandler(HttpHandler.Context ctx); @Override HttpResponse handle(HttpRequest request);  }
@Test public void testResponse() throws IOException { final String message = "failed"; HttpHandler httpHandler = new HttpTestHandler(new InvalidApplicationException(message)); HttpResponse response = httpHandler.handle(HttpRequest.createTestRequest("foo", com.yahoo.jdisc.http.HttpRequest.Method.GET)); assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); response.render(baos); Slime data = SlimeUtils.jsonToSlime(baos.toByteArray()); assertThat(data.get().field("error-code").asString(), is(HttpErrorResponse.errorCodes.INVALID_APPLICATION_PACKAGE.name())); assertThat(data.get().field("message").asString(), is(message)); }