diff options
Diffstat (limited to 'application')
4 files changed, 25 insertions, 0 deletions
diff --git a/application/abi-spec.json b/application/abi-spec.json index 95a9d2a524a..27b01d02b5f 100644 --- a/application/abi-spec.json +++ b/application/abi-spec.json @@ -324,6 +324,7 @@ "public com.yahoo.application.container.Processing processing()", "public com.yahoo.application.container.DocumentProcessing documentProcessing()", "public com.yahoo.component.provider.ComponentRegistry components()", + "public com.yahoo.component.provider.ComponentRegistry handlers()", "public com.yahoo.application.container.handler.Response handleRequest(com.yahoo.application.container.handler.Request)", "public void close()" ], @@ -450,11 +451,13 @@ "public void <init>(java.lang.String, java.lang.String)", "public void <init>(java.lang.String, byte[], com.yahoo.application.container.handler.Request$Method)", "public void <init>(java.lang.String, byte[], com.yahoo.application.container.handler.Request$Method, java.security.Principal)", + "public void <init>(java.lang.String, byte[], com.yahoo.application.container.handler.Request$Method, java.security.Principal, java.net.SocketAddress)", "public void <init>(java.lang.String, java.lang.String, com.yahoo.application.container.handler.Request$Method)", "public com.yahoo.application.container.handler.Headers getHeaders()", "public byte[] getBody()", "public java.lang.String getUri()", "public java.util.Map getAttributes()", + "public java.util.Optional remoteAddress()", "public java.lang.String toString()", "public com.yahoo.application.container.handler.Request$Method getMethod()", "public java.util.Optional getUserPrincipal()" diff --git a/application/src/main/java/com/yahoo/application/container/JDisc.java b/application/src/main/java/com/yahoo/application/container/JDisc.java index 162a5f343a1..3223c8d31c9 100644 --- a/application/src/main/java/com/yahoo/application/container/JDisc.java +++ b/application/src/main/java/com/yahoo/application/container/JDisc.java @@ -169,6 +169,9 @@ public final class JDisc implements AutoCloseable { return container.getComponentRegistry(); } + /** @return registry of all request handlers configured */ + public ComponentRegistry<RequestHandler> handlers() { return container.getRequestHandlerRegistry(); } + /** * Handles the given {@link com.yahoo.application.container.handler.Request} by passing it to the {@link RequestHandler} * that is bound to the request's URI. diff --git a/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java b/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java index c54b3f60cf9..1b4862c75c0 100644 --- a/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java +++ b/application/src/main/java/com/yahoo/application/container/SynchronousRequestResponseHandler.java @@ -90,6 +90,7 @@ final class SynchronousRequestResponseHandler { URI.create(request.getUri()), com.yahoo.jdisc.http.HttpRequest.Method.valueOf(request.getMethod().name())); request.getUserPrincipal().ifPresent(httpRequest::setUserPrincipal); + request.remoteAddress().ifPresent(httpRequest::setRemoteAddress); discRequest = httpRequest; } else { discRequest = new com.yahoo.jdisc.Request(currentContainer, URI.create(request.getUri())); diff --git a/application/src/main/java/com/yahoo/application/container/handler/Request.java b/application/src/main/java/com/yahoo/application/container/handler/Request.java index b6dff44269b..d877258cb15 100644 --- a/application/src/main/java/com/yahoo/application/container/handler/Request.java +++ b/application/src/main/java/com/yahoo/application/container/handler/Request.java @@ -3,6 +3,7 @@ package com.yahoo.application.container.handler; import com.yahoo.api.annotations.Beta; +import java.net.SocketAddress; import java.nio.charset.StandardCharsets; import java.security.Principal; import java.util.Map; @@ -24,6 +25,7 @@ public class Request { private final Method method; private final Map<String, Object> attributes = new ConcurrentHashMap<>(); private final Principal userPrincipal; + private final SocketAddress remoteAddress; /** * Creates a Request with an empty body. @@ -73,10 +75,24 @@ public class Request { * @param principal the user principal of the request */ public Request(String uri, byte[] body, Method method, Principal principal) { + this(uri, body, method, principal, null); + } + + /** + * Creates a Request with a message body, method and user principal. + * + * @param uri the URI of the request + * @param body the body of the request + * @param method the method of the request + * @param principal the user principal of the request + * @param remoteAddress the remote address of the request + */ + public Request(String uri, byte[] body, Method method, Principal principal, SocketAddress remoteAddress) { this.uri = uri; this.body = body; this.method = method; this.userPrincipal = principal; + this.remoteAddress = remoteAddress; } /** @@ -122,6 +138,8 @@ public class Request { return attributes; } + public Optional<SocketAddress> remoteAddress() { return Optional.ofNullable(remoteAddress); } + @Override public String toString() { String bodyStr = (body == null || body.length == 0) ? "[empty]" : "[omitted]"; |