Skip to content

Commit

Permalink
valtech#156 removed old fake request and response classes
Browse files Browse the repository at this point in the history
  • Loading branch information
gruberrolandvaltech committed Jun 10, 2021
1 parent 0f7fbb1 commit 7224ee7
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 980 deletions.
4 changes: 2 additions & 2 deletions HISTORY
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
??? 5.0.0
2021-06-11 4.1.0
- New filter methods: filterByNodeExists() and filterByNodeNotExists()

- Fixed Sonar issues (#156)

2020-12-21 4.0.0
- Update to Groovy Console 16 and require AEM 6.5 (#135)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.ResourceResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Charsets;
import com.icfolson.aem.groovy.console.api.context.ScriptContext;
import com.icfolson.aem.groovy.console.constants.GroovyConsoleConstants;

/**
* Script context to run Groovy Console scripts.
Expand All @@ -26,24 +24,20 @@ public class AecuScriptContext implements ScriptContext {
private ResourceResolver resolver;
private ByteArrayOutputStream out = new ByteArrayOutputStream();

private SlingHttpServletRequest request;

/**
* Constructor
*
* @param script script content
* @param resolver resolver
* @param request request
*/
public AecuScriptContext(String script, ResourceResolver resolver, SlingHttpServletRequest request) {
public AecuScriptContext(String script, ResourceResolver resolver) {
this.script = script;
this.resolver = resolver;
this.request = request;
}

@Override
public String getData() {
return request.getParameter(GroovyConsoleConstants.DATA);
return null;
}

@Override
Expand Down Expand Up @@ -73,7 +67,7 @@ public String getScript() {

@Override
public String getUserId() {
return request.getResourceResolver().getUserID();
return resolver.getUserID();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jackrabbit.JcrConstants;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.resource.LoginException;
import org.apache.sling.api.resource.PersistenceException;
import org.apache.sling.api.resource.Resource;
Expand Down Expand Up @@ -188,9 +187,8 @@ public ExecutionResult execute(String path) throws AecuException {
* @throws AecuException error running script
*/
private ExecutionResult executeScript(ResourceResolver resolver, String path) throws AecuException {
SlingHttpServletRequest slingRequest = new GroovyConsoleRequest(resolver);
LOG.info("Executing script " + path);
ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver, slingRequest);
ScriptContext scriptContext = new AecuScriptContext(loadScript(path, resolver), resolver);
RunScriptResponse response = groovyConsoleService.runScript(scriptContext);
boolean success = StringUtils.isBlank(response.getExceptionStackTrace());
if (success) {
Expand Down Expand Up @@ -219,9 +217,10 @@ private ExecutionResult executeScript(ResourceResolver resolver, String path) th
private String loadScript(String path, ResourceResolver resolver) throws AecuException {
Resource resource = resolver.getResource(path + "/" + JcrConstants.JCR_CONTENT);
// https://sling.apache.org/documentation/the-sling-engine/resources.html#binary-support
try (InputStream inputStream = resource.adaptTo(InputStream.class)){
try (InputStream inputStream = resource.adaptTo(InputStream.class)) {
if (inputStream == null) {
throw new IOException("Resource at '" + path +"' cannot be adapted to InputStream, it doesn't seem to contain binary data");
throw new IOException(
"Resource at '" + path + "' cannot be adapted to InputStream, it doesn't seem to contain binary data");
}
return IOUtils.toString(inputStream, StandardCharsets.UTF_8);
} catch (IOException e) {
Expand Down
Loading

0 comments on commit 7224ee7

Please sign in to comment.