use of org.apache.struts2.views.util.UrlHelper in project struts by apache.
the class JSPRuntime method handle.
public static void handle(String location, boolean flush) throws Exception {
final HttpServletResponse response = ServletActionContext.getResponse();
final HttpServletRequest request = ServletActionContext.getRequest();
int i = location.indexOf("?");
if (i > 0) {
// extract params from the url and add them to the request
final UrlHelper urlHelperGetInstance = ServletActionContext.getContext().getInstance(UrlHelper.class);
final UrlHelper contextUrlHelper = (urlHelperGetInstance != null ? urlHelperGetInstance : (UrlHelper) ActionContext.getContext().get(StrutsConstants.STRUTS_URL_HELPER));
final UrlHelper urlHelper = (contextUrlHelper != null ? contextUrlHelper : new DefaultUrlHelper());
String query = location.substring(i + 1);
Map<String, Object> queryParams = urlHelper.parseQueryString(query, true);
if (queryParams != null && !queryParams.isEmpty()) {
Map<String, Parameter> newParams = new HashMap<>();
for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
newParams.put(entry.getKey(), new Parameter.Request(entry.getKey(), entry.getValue()));
}
ActionContext.getContext().getParameters().appendAll(newParams);
}
location = location.substring(0, i);
}
Servlet servlet = servletCache.get(location);
HttpJspPage page = (HttpJspPage) servlet;
page._jspService(request, response);
if (flush)
response.flushBuffer();
}
use of org.apache.struts2.views.util.UrlHelper in project entando-core by entando.
the class FrontServletActionRedirectResultIntegrationTest method executeServlet.
private void executeServlet(String expectedProtocol, String expectedAuthority, String expectedPath) throws Exception {
UrlHelper urlHelper = this.getContainerObject(UrlHelper.class);
this.initAction("/do/Api/Service", "list");
FrontServletActionRedirectResult servlet = new FrontServletActionRedirectResult();
servlet.setActionName("details");
servlet.setUrlHelper(urlHelper);
servlet.execute(super.getActionContext().getActionInvocation());
URL aURL = new URL(servlet.getLocation());
assertEquals(expectedProtocol, aURL.getProtocol());
assertEquals(expectedAuthority, aURL.getAuthority());
assertEquals(expectedPath, aURL.getPath());
List<NameValuePair> params = URLEncodedUtils.parse(aURL.getQuery(), Charset.forName("UTF-8"));
for (NameValuePair param : params) {
System.out.println(param.getName() + " : " + param.getValue());
if (param.getName().equals("internalServletActionPath")) {
assertEquals("/ExtStr2/do/Api/Service/details", param.getValue());
} else if (param.getName().equals("internalServletFrameDest")) {
assertEquals("0", param.getValue());
} else {
fail();
}
}
}
use of org.apache.struts2.views.util.UrlHelper in project struts by apache.
the class NotURLClassLoader method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
result = new EmbeddedJSPResult();
request = EasyMock.createNiceMock(HttpServletRequest.class);
response = new MockHttpServletResponse();
context = new MockServletContext();
config = new MockServletConfig(context);
final Map params = new HashMap();
HttpSession session = EasyMock.createNiceMock(HttpSession.class);
EasyMock.replay(session);
EasyMock.expect(request.getSession()).andReturn(session).anyTimes();
EasyMock.expect(request.getParameterMap()).andReturn(params).anyTimes();
EasyMock.expect(request.getParameter("username")).andAnswer(() -> ActionContext.getContext().getParameters().get("username").getValue());
EasyMock.expect(request.getAttribute("something")).andReturn("somethingelse").anyTimes();
EasyMock.replay(request);
// mock value stack
ValueStack valueStack = EasyMock.createNiceMock(ValueStack.class);
EasyMock.expect(valueStack.getActionContext()).andReturn(ActionContext.getContext()).anyTimes();
EasyMock.replay(valueStack);
// mock converter
XWorkConverter converter = new DummyConverter();
DefaultFileManager fileManager = new DefaultFileManager();
fileManager.setReloadingConfigs(false);
// mock container
Container container = EasyMock.createNiceMock(Container.class);
EasyMock.expect(container.getInstance(XWorkConverter.class)).andReturn(converter).anyTimes();
TextParser parser = new OgnlTextParser();
EasyMock.expect(container.getInstance(TextParser.class)).andReturn(parser).anyTimes();
EasyMock.expect(container.getInstanceNames(FileManager.class)).andReturn(new HashSet<>()).anyTimes();
EasyMock.expect(container.getInstance(FileManager.class)).andReturn(fileManager).anyTimes();
UrlHelper urlHelper = new DefaultUrlHelper();
EasyMock.expect(container.getInstance(UrlHelper.class)).andReturn(urlHelper).anyTimes();
FileManagerFactory fileManagerFactory = new DummyFileManagerFactory();
EasyMock.expect(container.getInstance(FileManagerFactory.class)).andReturn(fileManagerFactory).anyTimes();
EasyMock.replay(container);
ActionContext.of(new HashMap<>()).withParameters(HttpParameters.create(params).build()).withServletRequest(request).withServletResponse(response).withServletContext(context).withContainer(container).withValueStack(valueStack).bind();
}
Aggregations