Use the new InternalRequest helper
diff --git a/org.apache.sling.graphql.samples.website/pom.xml b/org.apache.sling.graphql.samples.website/pom.xml
index c463bd9..b18b79c 100644
--- a/org.apache.sling.graphql.samples.website/pom.xml
+++ b/org.apache.sling.graphql.samples.website/pom.xml
@@ -105,7 +105,7 @@
<dependency>
<groupId>org.apache.sling</groupId>
<artifactId>org.apache.sling.servlet-helpers</artifactId>
- <version>1.3.0</version>
+ <version>1.4.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
diff --git a/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java b/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java
index eb79f20..bd063ae 100644
--- a/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java
+++ b/org.apache.sling.graphql.samples.website/src/main/java/org/apache/sling/scripting/handlebars/HandlebarsScriptEngine.java
@@ -40,8 +40,7 @@
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.scripting.SlingBindings;
-import org.apache.sling.servlethelpers.MockSlingHttpServletRequest;
-import org.apache.sling.servlethelpers.MockSlingHttpServletResponse;
+import org.apache.sling.servlethelpers.internalrequests.InternalRequest;
/** Minimal script engine for server-side rendering
* using Handlebars templates. Might need some changes if
@@ -88,27 +87,20 @@
/** We might do this with a BindingsValuesProvider? */
private Map<?, ?> getData(Resource r) throws ScriptException {
// Request resource.json and convert the result to Maps
- final String jsonString = internalRequest(r.getResourceResolver(), r.getPath() + ".json");
- return JsonReader.jsonToMaps(jsonString);
- }
-
- private String internalRequest(ResourceResolver resourceResolver, String path) throws ScriptException {
- final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resourceResolver);
- request.setPathInfo(path);
- final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
-
+ String jsonString = null;
try {
- factory.getSlingRequestProcessor().processRequest(request, response, resourceResolver);
- final int status = response.getStatus();
- if(status != 200) {
- throw new ScriptException ("Request to " + path + " returns HTTP status " + status);
- }
- return response.getOutputAsString();
+ jsonString = InternalRequest
+ .slingRequest(r.getResourceResolver(), factory.getSlingRequestProcessor(), r.getPath())
+ .withExtension("json")
+ .execute()
+ .getResponseAsString()
+ ;
} catch(Exception e) {
final ScriptException up = new ScriptException("Internal request failed");
up.initCause(e);
throw up;
}
+ return JsonReader.jsonToMaps(jsonString);
}
@Override
diff --git a/org.apache.sling.graphql.samples.website/src/main/resources/features/feature-graphql-example-website.json b/org.apache.sling.graphql.samples.website/src/main/resources/features/feature-graphql-example-website.json
index 17d2a33..1874f74 100644
--- a/org.apache.sling.graphql.samples.website/src/main/resources/features/feature-graphql-example-website.json
+++ b/org.apache.sling.graphql.samples.website/src/main/resources/features/feature-graphql-example-website.json
@@ -23,7 +23,7 @@
"org.antlr:antlr4-runtime:jar:4.7.2",
"com.graphql-java:java-dataloader:jar:2.2.3",
"org.reactivestreams:reactive-streams:jar:1.0.2",
- "org.apache.sling:org.apache.sling.servlet-helpers:jar:1.3.0",
+ "org.apache.sling:org.apache.sling.servlet-helpers:jar:1.4.0-SNAPSHOT",
"com.github.jknack:handlebars:4.2.0"
],
"configurations":{