Skip to content
Permalink
Browse files Browse the repository at this point in the history
XWIKI-18870: Unexpected behavior of XWiki#invokeServletAndReturnAsString
  • Loading branch information
tmortagne committed Jul 29, 2021
1 parent 9217d10 commit df8bd49
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 34 deletions.
Expand Up @@ -35,6 +35,9 @@ import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.net.smtp.SMTPClient;
import org.apache.commons.net.smtp.SMTPReply;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -78,6 +81,7 @@ import com.xpn.xwiki.util.Util;
import com.xpn.xwiki.web.Utils;
import com.xpn.xwiki.web.XWikiMessageTool;
import com.xpn.xwiki.web.XWikiRequest;
import com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString;

/**
* Add a backward compatibility layer to the {@link com.xpn.xwiki.XWiki} class.
Expand Down Expand Up @@ -1388,4 +1392,24 @@ public privileged aspect XWikiCompatibilityAspect
}
return this.configuredSyntaxes;
}

/**
* Designed to include dynamic content, such as Servlets or JSPs, inside Velocity templates; works by creating a
* RequestDispatcher, buffering the output, then returning it as a string.
*
* @deprecated since 12.10.9, 13.4.3, 13.7RC1
*/
@Deprecated
public String XWiki.invokeServletAndReturnAsString(String url, XWikiContext xwikiContext)
{
HttpServletRequest servletRequest = xwikiContext.getRequest();
HttpServletResponse servletResponse = xwikiContext.getResponse();

try {
return IncludeServletAsString.invokeServletAndReturnAsString(url, servletRequest, servletResponse);
} catch (Exception e) {
LOGGER.warn("Exception including url: " + url, e);
return "Exception including \"" + url + "\", see logs for details.";
}
}
}
Expand Up @@ -1198,4 +1198,18 @@ public privileged aspect XWikiCompatibilityAspect
{
return this.xwiki.getConfiguredSyntaxes();
}

/**
* Designed to include dynamic content, such as Servlets or JSPs, inside Velocity templates; works by creating a
* RequestDispatcher, buffering the output, then returning it as a string.
*
* @param url URL of the servlet
* @return text result of the servlet
* @deprecated since 12.10.9, 13.4.3, 13.7RC1
*/
@Deprecated
public String XWiki.invokeServletAndReturnAsString(String url)
{
return hasProgrammingRights() ? this.xwiki.invokeServletAndReturnAsString(url, getXWikiContext()) : null;
}
}
Expand Up @@ -66,8 +66,6 @@
import javax.naming.NamingException;
import javax.script.ScriptContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
Expand Down Expand Up @@ -265,7 +263,6 @@
import com.xpn.xwiki.web.XWikiURLFactory;
import com.xpn.xwiki.web.XWikiURLFactoryService;
import com.xpn.xwiki.web.XWikiURLFactoryServiceImpl;
import com.xpn.xwiki.web.includeservletasstring.IncludeServletAsString;

@Serializable(false)
public class XWiki implements EventListener
Expand Down Expand Up @@ -2578,25 +2575,6 @@ public String renderTemplate(String template, XWikiContext context)
}
}

/**
* Designed to include dynamic content, such as Servlets or JSPs, inside Velocity templates; works by creating a
* RequestDispatcher, buffering the output, then returning it as a string.
*/
public String invokeServletAndReturnAsString(String url, XWikiContext xwikiContext)
{

HttpServletRequest servletRequest = xwikiContext.getRequest();
HttpServletResponse servletResponse = xwikiContext.getResponse();

try {
return IncludeServletAsString.invokeServletAndReturnAsString(url, servletRequest, servletResponse);
} catch (Exception e) {
LOGGER.warn("Exception including url: " + url, e);
return "Exception including \"" + url + "\", see logs for details.";
}

}

/**
* @param iconName the standard name of an icon (it's not the name of the file on the filesystem, it's a generic
* name, for example "success" for a success icon
Expand Down
Expand Up @@ -1010,18 +1010,6 @@ public String renderTemplate(String template)
return this.xwiki.renderTemplate(template, getXWikiContext());
}

/**
* Designed to include dynamic content, such as Servlets or JSPs, inside Velocity templates; works by creating a
* RequestDispatcher, buffering the output, then returning it as a string.
*
* @param url URL of the servlet
* @return text result of the servlet
*/
public String invokeServletAndReturnAsString(String url)
{
return this.xwiki.invokeServletAndReturnAsString(url, getXWikiContext());
}

/**
* Return the URL of the static file provided by the current skin The file is first looked in the skin active for
* the user, the space or the wiki. If the file does not exist in that skin, the file is looked up in the "parent
Expand Down

0 comments on commit df8bd49

Please sign in to comment.