use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class AbstractPostOperationTest method testRemainingPostfixCausesFailure.
@Test
public void testRemainingPostfixCausesFailure() {
TestingResourceResolver resourceResolver = new TestingResourceResolver();
MockSlingHttpServlet3Request request = new MockSlingHttpServlet3Request("/test", null, null, null, null);
request.setResourceResolver(resourceResolver);
final PostOperation operation = new AbstractPostOperation() {
@Override
protected void doRun(SlingHttpServletRequest request, PostResponse response, List<Modification> changes) throws RepositoryException {
changes.add(Modification.onChange(ModificationType.CREATE, "/content/test"));
changes.add(Modification.onChange(ModificationType.CREATE, "/content/test@Postfix"));
}
};
HtmlResponse response = new HtmlResponse();
operation.run(request, response, new SlingPostProcessor[0]);
assertFalse(response.isSuccessful());
assertFalse(resourceResolver.commitCalled);
assertTrue(resourceResolver.revertCalled);
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class JspServletWrapper method service.
/**
* @param bindings
* @throws SlingIOException
* @throws SlingServletException
* @throws IllegalArgumentException if the Jasper Precompile controller
* request parameter has an illegal value.
*/
public void service(final SlingBindings bindings) {
final SlingHttpServletRequest request = bindings.getRequest();
final Object oldValue = request.getAttribute(SlingBindings.class.getName());
try {
request.setAttribute(SlingBindings.class.getName(), bindings);
service(request, bindings.getResponse());
} catch (SlingException se) {
// rethrow as is
throw se;
} catch (IOException ioe) {
throw new SlingIOException(ioe);
} catch (ServletException se) {
throw new SlingServletException(se);
} finally {
request.setAttribute(SlingBindings.class.getName(), oldValue);
}
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class SlingIncludeAttributeTagProcessor method doProcess.
@Override
protected void doProcess(final ITemplateContext templateContext, final IProcessableElementTag processableElementTag, final AttributeName attributeName, final String attributeValue, final IElementTagStructureHandler elementTagStructureHandler) {
try {
final SlingHttpServletRequest slingHttpServletRequest = (SlingHttpServletRequest) templateContext.getVariable(SlingBindings.REQUEST);
final SlingHttpServletResponse slingHttpServletResponse = (SlingHttpServletResponse) templateContext.getVariable(SlingBindings.RESPONSE);
final IEngineConfiguration configuration = templateContext.getConfiguration();
final IStandardExpressionParser expressionParser = StandardExpressions.getExpressionParser(configuration);
final IStandardExpression expression = expressionParser.parseExpression(templateContext, attributeValue);
final Object include = expression.execute(templateContext);
String path = null;
if (include instanceof String) {
path = (String) include;
}
Resource resource = null;
if (include instanceof Resource) {
resource = (Resource) include;
}
// request dispatcher options
final RequestDispatcherOptions requestDispatcherOptions = prepareRequestDispatcherOptions(expressionParser, templateContext, processableElementTag, elementTagStructureHandler);
// dispatch
final String content = dispatch(resource, path, slingHttpServletRequest, slingHttpServletResponse, requestDispatcherOptions);
// add output
final Boolean unwrap = (Boolean) parseAttribute(expressionParser, templateContext, processableElementTag, elementTagStructureHandler, UNWRAP_ATTRIBUTE_NAME);
if (unwrap != null && unwrap) {
elementTagStructureHandler.replaceWith(content, false);
} else {
elementTagStructureHandler.setBody(content, false);
}
} catch (Exception e) {
throw new RuntimeException("unable to process include attribute", e);
}
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class JavaScriptEngineFactory method callServlet.
/**
* Call the servlet.
* @param bindings The bindings for the script invocation
* @param scriptHelper The script helper.
* @param context The script context.
* @throws SlingServletException
* @throws SlingIOException
*/
private void callServlet(final Bindings bindings, final SlingScriptHelper scriptHelper, final ScriptContext context) {
// create a SlingBindings object
final SlingBindings slingBindings = new SlingBindings();
slingBindings.putAll(bindings);
ResourceResolver resolver = (ResourceResolver) context.getAttribute(SlingScriptConstants.ATTR_SCRIPT_RESOURCE_RESOLVER, SlingScriptConstants.SLING_SCOPE);
if (resolver == null) {
resolver = scriptHelper.getScript().getScriptResource().getResourceResolver();
}
ioProvider.setRequestResourceResolver(resolver);
final SlingHttpServletRequest request = slingBindings.getRequest();
final Object oldValue = request.getAttribute(SlingBindings.class.getName());
try {
final ServletWrapper servlet = getWrapperAdapter(scriptHelper);
request.setAttribute(SlingBindings.class.getName(), slingBindings);
servlet.service(request, slingBindings.getResponse());
} catch (SlingException se) {
// rethrow as is
throw se;
} catch (IOException ioe) {
throw new SlingIOException(ioe);
} catch (ServletException se) {
throw new SlingServletException(se);
} catch (Exception ex) {
throw new SlingException(null, ex);
} finally {
request.setAttribute(SlingBindings.class.getName(), oldValue);
ioProvider.resetRequestResourceResolver();
}
}
use of org.apache.sling.api.SlingHttpServletRequest in project sling by apache.
the class PlumberServletTest method testDummyTreeThroughRT.
@Test
public void testDummyTreeThroughRT() throws Exception {
SlingHttpServletRequest request = mockPlumberServletRequest(context.resourceResolver(), dummyTreePath, null, null, null, null, null);
servlet.execute(request, response, false);
assertDummyTree();
}
Aggregations