@Nullable static String determineMethod(ServiceRequestContext ctx) { // Remove the leading slash of the path and get the fully qualified method name final String path = ctx.mappedPath(); if (path.charAt(0) != '/') { return null; } return path.substring(1); }
@Override public String mappedPath() { return delegate().mappedPath(); }
private static MetaData.Request toRequestMetadata(ServiceRequestContext ctx, AggregatedHttpMessage aReq) { // Construct the HttpURI final StringBuilder uriBuf = new StringBuilder(); final HttpHeaders aHeaders = aReq.headers(); uriBuf.append(ctx.sessionProtocol().isTls() ? "https" : "http"); uriBuf.append("://"); uriBuf.append(aHeaders.authority()); uriBuf.append(aHeaders.path()); final HttpURI uri = new HttpURI(uriBuf.toString()); uri.setPath(ctx.mappedPath()); // Convert HttpHeaders to HttpFields final HttpFields jHeaders = new HttpFields(aHeaders.size()); aHeaders.forEach(e -> { final AsciiString key = e.getKey(); if (!key.isEmpty() && key.byteAt(0) != ':') { jHeaders.add(key.toString(), e.getValue()); } }); return new MetaData.Request( aHeaders.method().name(), uri, HttpVersion.HTTP_1_1, jHeaders, aReq.content().length()); }
@Override public O serve(ServiceRequestContext ctx, I req) throws Exception { final PathMappingContext mappingCtx = ctx.pathMappingContext(); final PathMapped<Service<I, O>> mapped = findService(mappingCtx.overridePath(ctx.mappedPath())); if (!mapped.isPresent()) { throw HttpStatusException.of(HttpStatus.NOT_FOUND); } final Optional<String> childPrefix = mapped.mapping().prefix(); if (childPrefix.isPresent()) { final PathMapping newMapping = PathMapping.ofPrefix(ctx.pathMapping().prefix().get() + childPrefix.get().substring(1)); final ServiceRequestContext newCtx = new CompositeServiceRequestContext( ctx, newMapping, mapped.mappingResult().path()); try (SafeCloseable ignored = newCtx.push(false)) { return mapped.value().serve(newCtx, req); } } else { return mapped.value().serve(ctx, req); } }
@Nullable private Request convertRequest(ServiceRequestContext ctx, AggregatedHttpMessage req) throws Throwable { final String mappedPath = ctx.mappedPath(); final Request coyoteReq = new Request();
@Nullable static String determineMethod(ServiceRequestContext ctx) { // Remove the leading slash of the path and get the fully qualified method name final String path = ctx.mappedPath(); if (path.charAt(0) != '/') { return null; } return path.substring(1); }