public static KnotContext create(List<Pair<List<String>, String>> fragments) { return new KnotContext() .setFragments( fragments != null ? fragments.stream().map(data -> Fragment.snippet(data.getKey(), data.getValue())).collect(Collectors.toList()) : null) .setClientRequest(new ClientRequest()) .setClientResponse( new ClientResponse() .setHeaders(MultiMap.caseInsensitiveMultiMap())); }
public static KnotContext empty(String template) { return new KnotContext() .setClientResponse( new ClientResponse() .setBody(StringUtils.isEmpty(template) ? Buffer.buffer() : Buffer.buffer(template)) .setStatusCode(HttpResponseStatus.OK.code()) .setHeaders(MultiMap.caseInsensitiveMultiMap())) .setClientRequest(new ClientRequest()); }
private KnotContext createSuccessResponse(KnotContext inputContext, String renderedContent) { ClientResponse clientResponse = inputContext.getClientResponse(); if (StringUtils.isBlank(renderedContent)) { clientResponse.setStatusCode(HttpResponseStatus.NO_CONTENT.code()); } else { MultiMap headers = clientResponse.getHeaders(); headers.add(HttpHeaders.CONTENT_LENGTH.toString().toLowerCase(), Integer.toString(renderedContent.length())); clientResponse.setBody(Buffer.buffer(renderedContent)).setHeaders(headers); clientResponse.setStatusCode(HttpResponseStatus.OK.code()); } return new KnotContext() .setClientRequest(inputContext.getClientRequest()) .setClientResponse(clientResponse); } }
private KnotContext createSuccessResponse(KnotContext inputContext) { return new KnotContext() .setClientRequest(inputContext.getClientRequest()) .setClientResponse(inputContext.getClientResponse()) .setFragments( Optional.ofNullable(inputContext.getFragments()).orElse(Collections.emptyList())) .setTransition(DEFAULT_TRANSITION); }
private KnotContext createSuccessResponse(KnotContext inputContext) { return new KnotContext() .setClientRequest(inputContext.getClientRequest()) .setClientResponse(inputContext.getClientResponse()) .setFragments( Optional.ofNullable(inputContext.getFragments()).orElse(Collections.emptyList())) .setTransition(DEFAULT_TRANSITION); }
@Override protected KnotContext processError(KnotContext knotContext, Throwable error) { ClientResponse errorResponse = new ClientResponse() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()); return new KnotContext() .setClientRequest(knotContext.getClientRequest()) .setClientResponse(errorResponse); }
@Override protected KnotContext processError(KnotContext knotContext, Throwable error) { ClientResponse errorResponse = new ClientResponse() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()); return new KnotContext() .setClientRequest(knotContext.getClientRequest()) .setClientResponse(errorResponse); }
@Override protected KnotContext processError(KnotContext knotContext, Throwable error) { ClientResponse errorResponse = new ClientResponse() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()); return new KnotContext() .setClientRequest(knotContext.getClientRequest()) .setClientResponse(errorResponse); }
private KnotContext createSuccessResponse(KnotContext inputContext) { ClientResponse clientResponse = new ClientResponse(); String responseBody = getResponseBodyAsString(inputContext); clientResponse.setBody(Buffer.buffer(responseBody)) .setHeaders(getHeaders(clientResponse, responseBody.length())); clientResponse.setStatusCode(HttpResponseStatus.OK.code()); return new KnotContext() .setClientRequest(inputContext.getClientRequest()) .setClientResponse(clientResponse); }
private KnotContext createSuccessResponse(KnotContext inputContext) { ClientResponse clientResponse = new ClientResponse(); String responseBody = getResponseBodyAsString(inputContext); clientResponse.setBody(Buffer.buffer(responseBody)) .setHeaders(getHeaders(clientResponse, responseBody.length())); clientResponse.setStatusCode(HttpResponseStatus.OK.code()); return new KnotContext() .setClientRequest(inputContext.getClientRequest()) .setClientResponse(clientResponse); }
@Override protected KnotContext processError(KnotContext knotContext, Throwable error) { LOGGER.error("Error happened during Template processing", error); ClientResponse errorResponse = new ClientResponse() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()); return new KnotContext() .setClientRequest(knotContext.getClientRequest()) .setClientResponse(errorResponse); }
@Override protected KnotContext processError(KnotContext knotContext, Throwable error) { LOGGER.error("Error happened during Template processing", error); ClientResponse errorResponse = new ClientResponse() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()); return new KnotContext() .setClientRequest(knotContext.getClientRequest()) .setClientResponse(errorResponse); }
@Override protected KnotContext processError(KnotContext knotContext, Throwable error) { LOGGER.error("Error happened during Template processing", error); ClientResponse errorResponse = new ClientResponse() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()); return new KnotContext() .setClientRequest(knotContext.getClientRequest()) .setClientResponse(errorResponse); }
@Test public void handleRepositoryResponse_whenResponseIsSuccessAndShouldBeProcessed_expectContextContinuation() { when(clientResponse.getStatusCode()).thenReturn(200); when(repositoryEntry.isDoProcessing()).thenReturn(true); tested.handleRepositoryResponse(clientResponse, routingContext, repositoryEntry, knotContext); verify(knotContext, times(1)).setClientResponse(clientResponse); verify(routingContext, times(1)).put(KnotContext.KEY, knotContext); verify(routingContext, times(1)).next(); }
@Override protected KnotContext processError(KnotContext context, Throwable error) { LOGGER.error("Could not process template [{}]", context.getClientRequest().getPath(), error); KnotContext errorResponse = new KnotContext().setClientResponse(context.getClientResponse()); errorResponse.getClientResponse() .setStatusCode(HttpResponseStatus.INTERNAL_SERVER_ERROR.code()); return errorResponse; }
void handleRepositoryResponse(ClientResponse repoResponse, RoutingContext context, RepositoryEntry repositoryEntry, KnotContext knotContext) { if (isSuccessResponse(repoResponse)) { if (repositoryEntry.isDoProcessing()) { knotContext.setClientResponse(repoResponse); context.put(KnotContext.KEY, knotContext); context.next(); } else { endResponse(repoResponse, context); } } else { endResponse(repoResponse, context); } }
void handleRepositoryResponse(ClientResponse repoResponse, RoutingContext context, RepositoryEntry repositoryEntry, KnotContext knotContext) { if (isSuccessResponse(repoResponse)) { if (repositoryEntry.isDoProcessing()) { knotContext.setClientResponse(repoResponse); context.put(KnotContext.KEY, knotContext); context.next(); } else { endResponse(repoResponse, context); } } else { endResponse(repoResponse, context); } }
void handleRepositoryResponse(ClientResponse repoResponse, RoutingContext context, RepositoryEntry repositoryEntry, KnotContext knotContext) { if (isSuccessResponse(repoResponse)) { if (repositoryEntry.doProcessing()) { knotContext.setClientResponse(repoResponse); context.put(KnotContext.KEY, knotContext); context.next(); } else { endResponse(repoResponse, context); } } else { endResponse(repoResponse, context); } }
public static KnotContext empty(String template) { return new KnotContext() .setClientResponse( new ClientResponse() .setBody(StringUtils.isEmpty(template) ? Buffer.buffer() : Buffer.buffer(template)) .setStatusCode(HttpResponseStatus.OK.code()) .setHeaders(MultiMap.caseInsensitiveMultiMap())) .setClientRequest(new ClientRequest()); }
private void createSimpleGatewayKnot(Vertx vertx, final String address, final String transition) { MockKnotProxy.register(vertx.getDelegate(), address, knotContext -> { ClientResponse clientResponse = new ClientResponse(); clientResponse.setStatusCode(200); knotContext.setClientResponse(clientResponse); knotContext.setTransition(transition); }); }