Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for index.jsp tokens not being replaced #1457

Merged
merged 2 commits into from
Jul 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ public void indexPageCanBeAccessed() throws Exception
then(appServer).requestForUrlReturns("/app/", "aspect index.html");
}

@Test
public void tokensInIndexJspAreReplaced() throws Exception
{
given(app).hasBeenPopulated("default")
.and(app).containsFileWithContents("app.conf", "localeCookieName: BRJS.LOCALE\n"
+ "locales: en\n"
+ "requirePrefix: appns")
.and(aspect).containsFileWithContents("index.jsp", "<@tagToken @/>")
.and(appServer).started();
then(appServer).requestForUrlReturns("/app/", "dev replacement");
}

@Test
public void localeForwarderPageCanBeAccessedWithoutEndingInForwardSlash() throws Exception
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.bladerunnerjs.api.Aspect;
import org.bladerunnerjs.api.BladerunnerConf;
import org.bladerunnerjs.api.spec.engine.SpecTest;
import org.bladerunnerjs.spec.brjs.appserver.MockTagHandler;
import org.bladerunnerjs.testing.utility.MockContentPlugin;
import org.bladerunnerjs.testing.utility.ScriptedContentPlugin;
import org.bladerunnerjs.testing.utility.ScriptedRequestGeneratingTagHandlerPlugin;
Expand All @@ -29,6 +30,7 @@ public void initTestObjects() throws Exception {
given(brjs).automaticallyFindsBundlerPlugins()
.and(brjs).automaticallyFindsMinifierPlugins()
.and(brjs).hasContentPlugins(new MockContentPlugin())
.and(brjs).hasTagHandlerPlugins(new MockTagHandler("tagToken", "dev replacement", "prod replacement"))
.and(brjs).hasBeenCreated();
app = brjs.app("app1");
appConf = app.appConf();
Expand Down Expand Up @@ -88,14 +90,22 @@ public void builtAppHasLocalizedIndexPagePerLocale() throws Exception {
}

@Test
public void jspIndexPagesAreUnprocessedAndKeepTheJspSuffix() throws Exception {
public void indexJspIndexPagesAreUnprocessedAndKeepTheJspSuffix() throws Exception {
given(defaultAspect).containsFileWithContents("index.jsp", "<%= 1 + 2 %>\n<@js.bundle@/>")
.and(brjs).localeSwitcherHasContents("")
.and(app).hasBeenBuilt(targetDir);
then(targetDir).containsFileWithContents("/index.jsp", "<%= 1 + 2 %>")
.and(targetDir).containsFileWithContents("/index.jsp", "/js/prod/combined/bundle.js");
}

@Test
public void tokensInIndexJspAreReplaced() throws Exception
{
given(defaultAspect).containsFileWithContents("index.jsp", "<@tagToken @/>")
.and(app).hasBeenBuilt(targetDir);
then(targetDir).containsFileWithContents("/index.jsp", "prod replacement");
}

@Test
public void nonDefaultAspectsHaveTheSameIndexPagesButWithinANamedDirectory() throws Exception {
given(appConf).supportsLocales("en", "de")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ public ServletContentAccessor(App app, ServletContext servletContext, HttpServle

@Override
public void writeLocalUrlContentsToOutputStream(String urlPath, OutputStream output) throws IOException {
try {
if (urlPath.endsWith(".jsp")) {
urlPath = (!urlPath.startsWith("/")) ? "/"+urlPath : urlPath;
CharResponseWrapper responseWrapper = new CharResponseWrapper(response);
servletContext.getRequestDispatcher(urlPath).include(request, responseWrapper);
IOUtils.copy(responseWrapper.getReader(), output);
} else {
super.writeLocalUrlContentsToOutputStream(urlPath, output);
}
} catch (ServletException ex) {
throw new IOException(ex);
}
handleRequest(urlPath, output);
}

@Override
Expand All @@ -50,7 +39,9 @@ public void handleRequest(String urlPath, OutputStream output) throws IOExceptio
if (urlPath.endsWith(".jsp")) {
urlPath = (!urlPath.startsWith("/")) ? "/"+urlPath : urlPath;
request.setAttribute(BRJSDevServletFilter.IGNORE_REQUEST_ATTRIBUTE, true);
servletContext.getRequestDispatcher(urlPath).forward(request, response);
CharResponseWrapper responseWrapper = new CharResponseWrapper(response);
servletContext.getRequestDispatcher(urlPath).forward(request, responseWrapper);
IOUtils.copy(responseWrapper.getReader(), output);
} else {
super.writeLocalUrlContentsToOutputStream(urlPath, output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ public abstract class UrlContentAccessor
{

/**
*
* Write the contents of the reply from the given URL to the output stream.
* @deprecated Use handleRequest(String, OutputStream) instead
*/
public abstract void writeLocalUrlContentsToOutputStream(String urlPath, OutputStream output) throws IOException;

/**
* Attempts to handle the request using the server. If a server context isn't available writes the content of the local url path to the output stream, otherwise
* use the server context directly to handle the request.
* Attempts to handle the request using the server.
* If a server context isn't available writes the content of the local URL path to the output stream, otherwise
* uses the server context to handle the request and write to the output stream.
*/
public abstract void handleRequest(String urlPath, OutputStream output) throws IOException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public Map<String,Map<String,String>> getTagsAndAttributesFromIndexPage(Browsabl

String pathRelativeToApp = app.dir().getRelativePath(indexPage);
ByteArrayOutputStream indexPageContent = new ByteArrayOutputStream();
contentAccessor.writeLocalUrlContentsToOutputStream(pathRelativeToApp, indexPageContent);
contentAccessor.handleRequest(pathRelativeToApp, indexPageContent);

return TagPluginUtility.getUsedTagsAndAttributes(indexPageContent.toString(), browsableNode.getBundleSet(), requestMode, locale);
}
Expand Down