This is an automated email from the ASF dual-hosted git repository. andy pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/jena.git
commit 4ecc87dab3710e78d4aa5603dad8900a8a74a5b2 Author: Andy Seaborne <[email protected]> AuthorDate: Mon Jun 17 11:00:58 2024 +0100 Update example for jakarta.servlet API 6.1 --- .../main/examples/ExFusekiMain_3_FusekiModule.java | 25 +++++++++++++--------- .../apache/jena/test/conn/StringHolderServlet.java | 3 ++- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples/ExFusekiMain_3_FusekiModule.java b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples/ExFusekiMain_3_FusekiModule.java index fddb15d8c8..4c323c713a 100644 --- a/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples/ExFusekiMain_3_FusekiModule.java +++ b/jena-fuseki2/jena-fuseki-main/src/test/java/org/apache/jena/fuseki/main/examples/ExFusekiMain_3_FusekiModule.java @@ -26,7 +26,6 @@ import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.util.Set; -import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; @@ -41,6 +40,10 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.sys.JenaSystem; import org.apache.jena.web.HttpSC; +/** + * Example of adding a servlet that provides doPatch. + * The implementation only prints out details to show it has been called. + */ public class ExFusekiMain_3_FusekiModule { public static void main(String...a) throws Exception { @@ -87,16 +90,18 @@ public class ExFusekiMain_3_FusekiModule { @Override public void prepare(FusekiServer.Builder builder, Set<String> datasetNames, Model configModel) { System.out.println("Module adds servlet"); + // Servlet API 6.1 adds "doPatch" HttpServlet servlet = new HttpServlet() { - @Override public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { - if ( req.getMethod().equalsIgnoreCase("PATCH") ) { - doPatch(req, res); - return ; - } - super.service(req, res); - } - - private void doPatch(HttpServletRequest req, HttpServletResponse res) throws IOException { + // Servlet API 6.0 and earlier did not provide doPatch. +// @Override public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { +// if ( req.getMethod().equalsIgnoreCase("PATCH") ) { +// doPatch(req, res); +// return ; +// } +// super.service(req, res); +// } + @Override + protected void doPatch(HttpServletRequest req, HttpServletResponse res) throws IOException { String x = IO.readWholeFileAsUTF8(req.getInputStream()); System.out.println("HTTP PATCH: "+x); res.setStatus(HttpSC.OK_200); diff --git a/jena-integration-tests/src/test/java/org/apache/jena/test/conn/StringHolderServlet.java b/jena-integration-tests/src/test/java/org/apache/jena/test/conn/StringHolderServlet.java index 270bbdfccd..bd486db578 100644 --- a/jena-integration-tests/src/test/java/org/apache/jena/test/conn/StringHolderServlet.java +++ b/jena-integration-tests/src/test/java/org/apache/jena/test/conn/StringHolderServlet.java @@ -51,7 +51,8 @@ public class StringHolderServlet extends HttpServlet { super.service(req, resp); } - private void doPatch(HttpServletRequest req, HttpServletResponse resp) throws IOException { + @Override + protected void doPatch(HttpServletRequest req, HttpServletResponse resp) throws IOException { String x = IO.readWholeFileAsUTF8(req.getInputStream()); content.setOpaque(content.get() + x); resp.setStatus(HttpSC.OK_200);
