From 274cba43d59e05a5bdfe1d9623008b041ad2559f Mon Sep 17 00:00:00 2001 From: Vanessa Zhang Date: Wed, 15 Jul 2026 16:48:49 -0700 Subject: [PATCH] MLE-31224: Support isolated HTTP and XDBC requests --- .gitignore | 1 + .../com/marklogic/mapreduce/ContentOutputFormat.java | 9 +++++++-- .../com/marklogic/mapreduce/MarkLogicInputFormat.java | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 210924b4e..5d8db2db4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ target deliverable .idea +.vscode diff --git a/src/main/java/com/marklogic/mapreduce/ContentOutputFormat.java b/src/main/java/com/marklogic/mapreduce/ContentOutputFormat.java index c7644e940..9e3a4a5e0 100644 --- a/src/main/java/com/marklogic/mapreduce/ContentOutputFormat.java +++ b/src/main/java/com/marklogic/mapreduce/ContentOutputFormat.java @@ -128,13 +128,18 @@ public class ContentOutputFormat extends + "return if (exists($f)) then $f() else ()"; // For HTTP Server public static final String HEADER_QUERY = - "fn:exists(xdmp:get-request-header('x-forwarded-for'))"; + "let $f := fn:function-lookup(xs:QName('xdmp:is-forwarded'),0)\n" + + "return if (exists($f)) then $f() " + + "else fn:exists(xdmp:get-request-header('x-forwarded-for'))"; // For XDBC Server public static final String XDBC_HEADER_QUERY = + "let $f := fn:function-lookup(xs:QName('xdmp:is-forwarded'),0)\n" + + "return if (exists($f)) then $f() " + + "else (" + "let $xdbcHeaderf := " + "fn:function-lookup(xs:QName('xdmp:get-xdbc-request-header'),1)\n" + "return if (exists($xdbcHeaderf)) " + - "then fn:exists($xdbcHeaderf('x-forwarded-for')) else false()"; + "then fn:exists($xdbcHeaderf('x-forwarded-for')) else false())"; protected AssignmentManager am = AssignmentManager.getInstance(); protected boolean fastLoad; diff --git a/src/main/java/com/marklogic/mapreduce/MarkLogicInputFormat.java b/src/main/java/com/marklogic/mapreduce/MarkLogicInputFormat.java index 31cb657b0..fe68eedf2 100644 --- a/src/main/java/com/marklogic/mapreduce/MarkLogicInputFormat.java +++ b/src/main/java/com/marklogic/mapreduce/MarkLogicInputFormat.java @@ -318,7 +318,8 @@ public List getSplits(JobContext jobContext) throws IOException, StringBuilder buf = new StringBuilder(); buf.append("xquery version \"1.0-ml\";\n"); if (getForwardHeader) { - buf.append("fn:exists(xdmp:get-request-header('x-forwarded-for'));\n"); + buf.append(ContentOutputFormat.HEADER_QUERY).append(";\n"); + buf.append(ContentOutputFormat.XDBC_HEADER_QUERY).append(";\n"); } buf.append("import module namespace hadoop = "); buf.append("\"http://marklogic.com/xdmp/hadoop\" at "); @@ -402,6 +403,8 @@ public List getSplits(JobContext jobContext) throws IOException, if (getForwardHeader) { forwardHeaderExists = item.asString().equals("true"); item = result.next(); + forwardHeaderExists |= item.asString().equals("true"); + item = result.next(); if (forwardHeaderExists) { restrictHosts = true; jobConf.setBoolean(INPUT_RESTRICT_HOSTS, true);