use of com.opensymphony.xwork2.util.reflection.ReflectionProvider in project struts by apache.
the class HttpHeaderResultTest method setUp.
protected void setUp() throws Exception {
super.setUp();
result = new HttpHeaderResult();
responseMock = new Mock(HttpServletResponse.class);
response = (HttpServletResponse) responseMock.proxy();
invocationMock = new Mock(ActionInvocation.class);
invocationMock.expectAndReturn("getInvocationContext", ActionContext.getContext());
invocationMock.expectAndReturn("getStack", ActionContext.getContext().getValueStack());
invocation = (ActionInvocation) invocationMock.proxy();
reflectionProvider = container.getInstance(ReflectionProvider.class);
ServletActionContext.setResponse(response);
}
use of com.opensymphony.xwork2.util.reflection.ReflectionProvider in project struts by apache.
the class DebuggingInterceptor method intercept.
/*
* (non-Javadoc)
*
* @see com.opensymphony.xwork2.interceptor.Interceptor#invoke(com.opensymphony.xwork2.ActionInvocation)
*/
public String intercept(ActionInvocation inv) throws Exception {
boolean actionOnly = false;
boolean cont = true;
Boolean devModeOverride = PrepareOperations.getDevModeOverride();
boolean devMode = devModeOverride != null ? devModeOverride : this.devMode;
if (devMode) {
final ActionContext ctx = ActionContext.getContext();
String type = getParameter(DEBUG_PARAM);
ctx.getParameters().remove(DEBUG_PARAM);
if (XML_MODE.equals(type)) {
inv.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation inv, String result) {
printContext();
}
});
} else if (CONSOLE_MODE.equals(type)) {
consoleEnabled = true;
inv.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation inv, String actionResult) {
String xml = "";
if (enableXmlWithConsole) {
StringWriter writer = new StringWriter();
printContext(new PrettyPrintWriter(writer));
xml = writer.toString();
xml = xml.replaceAll("&", "&");
xml = xml.replaceAll(">", ">");
xml = xml.replaceAll("<", "<");
}
ActionContext.getContext().put("debugXML", xml);
FreemarkerResult result = new FreemarkerResult();
result.setFreemarkerManager(freemarkerManager);
result.setContentType("text/html");
result.setLocation("/org/apache/struts2/interceptor/debugging/console.ftl");
result.setParse(false);
try {
result.execute(inv);
} catch (Exception ex) {
LOG.error("Unable to create debugging console", ex);
}
}
});
} else if (COMMAND_MODE.equals(type)) {
ValueStack stack = (ValueStack) ctx.getSession().get(SESSION_KEY);
if (stack == null) {
// allows it to be embedded on another page
stack = ctx.getValueStack();
ctx.getSession().put(SESSION_KEY, stack);
}
String cmd = getParameter(EXPRESSION_PARAM);
ServletActionContext.getRequest().setAttribute("decorator", "none");
HttpServletResponse res = ServletActionContext.getResponse();
res.setContentType("text/plain");
try (PrintWriter writer = ServletActionContext.getResponse().getWriter()) {
writer.print(stack.findValue(cmd));
} catch (IOException ex) {
ex.printStackTrace();
}
cont = false;
} else if (BROWSER_MODE.equals(type)) {
actionOnly = true;
inv.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation inv, String actionResult) {
String rootObjectExpression = getParameter(OBJECT_PARAM);
if (rootObjectExpression == null) {
rootObjectExpression = "action";
}
String decorate = getParameter(DECORATE_PARAM);
ValueStack stack = ctx.getValueStack();
Object rootObject = stack.findValue(rootObjectExpression);
try (StringWriter writer = new StringWriter()) {
ObjectToHTMLWriter htmlWriter = new ObjectToHTMLWriter(writer);
htmlWriter.write(reflectionProvider, rootObject, rootObjectExpression);
String html = writer.toString();
writer.close();
stack.set("debugHtml", html);
// but we need plain text on the other ones
if ("false".equals(decorate))
ServletActionContext.getRequest().setAttribute("decorator", "none");
FreemarkerResult result = new FreemarkerResult();
result.setFreemarkerManager(freemarkerManager);
result.setContentType("text/html");
result.setLocation("/org/apache/struts2/interceptor/debugging/browser.ftl");
result.execute(inv);
} catch (Exception ex) {
LOG.error("Unable to create debugging console", ex);
}
}
});
}
}
if (cont) {
try {
if (actionOnly) {
inv.invokeActionOnly();
return null;
} else {
return inv.invoke();
}
} finally {
if (devMode && consoleEnabled) {
final ActionContext ctx = ActionContext.getContext();
ctx.getSession().put(SESSION_KEY, ctx.getValueStack());
}
}
} else {
return null;
}
}
Aggregations