use of com.opensymphony.xwork2.ognl.OgnlUtil in project struts by apache.
the class OgnlValueStackTest method reloadTestContainerConfiguration.
private void reloadTestContainerConfiguration(Boolean allowStaticMethod, Boolean allowStaticField) throws Exception {
loadConfigurationProviders(new StubConfigurationProvider() {
@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
// undefined values then should be evaluated to false
if (props.containsKey(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS)) {
props.remove(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS);
}
if (props.containsKey(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS)) {
props.remove(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS);
}
if (allowStaticMethod != null) {
props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS, "" + allowStaticMethod);
}
if (allowStaticField != null) {
props.setProperty(StrutsConstants.STRUTS_ALLOW_STATIC_FIELD_ACCESS, "" + allowStaticField);
}
}
});
ognlUtil = container.getInstance(OgnlUtil.class);
}
use of com.opensymphony.xwork2.ognl.OgnlUtil in project struts by apache.
the class StrutsAttributeEvaluator method evaluate.
@Override
public Object evaluate(String expression, Request request) {
try {
HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
ActionContext ctx = ServletActionContext.getActionContext(httpRequest);
if (ctx == null) {
LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName());
throw new ConfigurationException("There is no ActionContext for current request!");
}
OgnlUtil ognlUtil = ctx.getContainer().getInstance(OgnlUtil.class);
LOG.debug("Trying evaluate expression [{}] using OgnlUtil's getValue", expression);
Object result = ognlUtil.getValue(expression, ctx.getContextMap(), ctx.getValueStack().getRoot());
LOG.debug("Final result of evaluating expression [{}] is: {}", expression, result);
return result;
} catch (OgnlException e) {
throw new EvaluationException(e);
}
}
use of com.opensymphony.xwork2.ognl.OgnlUtil in project struts by apache.
the class DefaultActionInvocationTester method testInvokingMissingMethod.
public void testInvokingMissingMethod() throws Exception {
// given
DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
container.inject(dai);
SimpleAction action = new SimpleAction() {
@Override
public String execute() throws Exception {
return ERROR;
}
};
MockActionProxy proxy = new MockActionProxy();
proxy.setMethod("notExists");
UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {
@Override
public boolean hasUnknownHandlers() {
return false;
}
};
dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
dai.proxy = proxy;
dai.ognlUtil = new OgnlUtil();
dai.unknownHandlerManager = uhm;
// when
Throwable actual = null;
try {
dai.invokeAction(action, null);
} catch (Exception e) {
actual = e;
}
// then
assertNotNull(actual);
assertTrue(actual instanceof NoSuchMethodException);
}
use of com.opensymphony.xwork2.ognl.OgnlUtil in project struts by apache.
the class DefaultActionInvocationTester method testInvokingExistingExecuteMethod.
public void testInvokingExistingExecuteMethod() throws Exception {
// given
DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
container.inject(dai);
SimpleAction action = new SimpleAction() {
@Override
public String execute() throws Exception {
return SUCCESS;
}
};
MockActionProxy proxy = new MockActionProxy();
proxy.setMethod("execute");
dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
dai.proxy = proxy;
dai.ognlUtil = new OgnlUtil();
// when
String result = dai.invokeAction(action, null);
// then
assertEquals("success", result);
}
use of com.opensymphony.xwork2.ognl.OgnlUtil in project struts by apache.
the class DefaultActionInvocationTester method testUnknownHandlerManagerThatReturnsNull.
public void testUnknownHandlerManagerThatReturnsNull() throws Exception {
// given
DefaultActionInvocation dai = new DefaultActionInvocation(ActionContext.getContext().getContextMap(), false);
container.inject(dai);
UnknownHandlerManager uhm = new DefaultUnknownHandlerManager() {
@Override
public boolean hasUnknownHandlers() {
return true;
}
@Override
public Object handleUnknownMethod(Object action, String methodName) throws NoSuchMethodException {
return null;
}
};
MockActionProxy proxy = new MockActionProxy();
proxy.setMethod("notExists");
dai.stack = container.getInstance(ValueStackFactory.class).createValueStack();
dai.proxy = proxy;
dai.ognlUtil = new OgnlUtil();
dai.unknownHandlerManager = uhm;
// when
Throwable actual = null;
try {
dai.invokeAction(new SimpleAction(), null);
} catch (Exception e) {
actual = e;
}
// then
assertNotNull(actual);
assertTrue(actual instanceof NoSuchMethodException);
}
Aggregations