@Override public CompletionStage<Response<ByteString>> send(Request request, Optional<Request> incoming) { final Request withService = !request.service().isPresent() ? request.withService(serviceName) : request; return delegate.send(withService, incoming); } }
private String getPath(final Request message) { try { final URI uri = new URI(message.uri()); return uri.getRawPath(); } catch (URISyntaxException e) { LOG.warn("Invalid URI sent {} {} by service {}", message.method(), message.uri(), message.service().orElse("<unknown>"), e); return null; } }
@Override public Optional<RuleMatch<T>> match(Request message) throws InvalidUriException { final String method = message.method(); final String path = getPath(message); if (method == null) { LOG.warn("Invalid request for {} sent without method by service {}", message.uri(), message.service().orElse("<unknown>")); throw new InvalidUriException(); } if (path == null) { // Problem already logged in detail upstream throw new InvalidUriException(); } final Router.Result<Rule<T>> result = router.result(); router.route(method, path, result); if (!result.isSuccess()) { return Optional.empty(); } final Rule<T> rule = result.target(); final ImmutableMap.Builder<String, String> pathArgs = ImmutableMap.builder(); for (int i = 0; i < result.params(); i++) { pathArgs.put(result.paramName(i), readParameterValue(result, i)); } return Optional.of(new RuleMatch<T>(rule, pathArgs.build())); }
@Override public void gatherIncomingCall(OngoingRequest ongoingRequest, Endpoint endpoint) { Request message = ongoingRequest.request(); String fromService = message.service().orElse(null); String method = message.method(); EndpointInfo info = endpoint.info(); String endpointMethodName = info.getJavaMethodName(); CallsGatherer callsGatherer = gatherer.getIncomingCallsGatherer(fromService); EndpointGatherer endpointGatherer = callsGatherer.namedEndpointGatherer(endpointMethodName); endpointGatherer.setUri(info.getUri()); endpointGatherer.addMethod(method); for (String name : message.parameters().keySet()) { endpointGatherer.addQueryParameterName(name); } } }
@Override public CompletionStage<Response<ByteString>> send(Request request, Optional<Request> incoming) { final Request withService = !request.service().isPresent() ? request.withService(serviceName) : request; return delegate.send(withService, incoming); } }