mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Web Scripts:
- optionally force status in response header to success regardless of actual status; status in reponse document still reflects actual status - to support the limitations of Flex runtime without Flex data services - set alf-force-success-response to true in request header git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5873 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -31,6 +31,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.alfresco.repo.jscript.Node;
|
||||
import org.alfresco.repo.jscript.ScriptableHashMap;
|
||||
import org.alfresco.repo.template.AbsoluteUrlMethod;
|
||||
@@ -358,12 +360,13 @@ public abstract class AbstractWebScript implements WebScript
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Force success status header in response: " + req.forceSuccessStatus());
|
||||
logger.debug("Sending status " + statusCode + " (Template: " + template.path + ")");
|
||||
logger.debug("Rendering response: content type=" + mimetype);
|
||||
}
|
||||
|
||||
res.reset();
|
||||
res.setStatus(statusCode);
|
||||
res.setStatus(req.forceSuccessStatus() ? HttpServletResponse.SC_OK : statusCode);
|
||||
res.setContentType(mimetype + ";charset=UTF-8");
|
||||
renderTemplate(template.path, model, res.getWriter());
|
||||
}
|
||||
|
@@ -129,8 +129,10 @@ public class DeclarativeWebScript extends AbstractWebScript
|
||||
{
|
||||
// render output
|
||||
int statusCode = status.getCode();
|
||||
if (statusCode != HttpServletResponse.SC_OK)
|
||||
if (statusCode != HttpServletResponse.SC_OK && !req.forceSuccessStatus())
|
||||
{
|
||||
logger.debug("Force success status header in response: " + req.forceSuccessStatus());
|
||||
logger.debug("Setting status " + statusCode);
|
||||
res.setStatus(statusCode);
|
||||
}
|
||||
|
||||
|
@@ -79,6 +79,9 @@ public class TestWebScriptServer
|
||||
/** Current user */
|
||||
private String username = "admin";
|
||||
|
||||
/** Current headers */
|
||||
private Map<String, String> headers = new HashMap<String, String>();
|
||||
|
||||
/** I18N Messages */
|
||||
private MessageSource m_messages;
|
||||
|
||||
@@ -391,7 +394,9 @@ public class TestWebScriptServer
|
||||
command[0].equals("delete"))
|
||||
{
|
||||
String uri = (command.length > 1) ? command[1] : null;
|
||||
MockHttpServletResponse res = submitRequest(command[0], uri);
|
||||
MockHttpServletResponse res = submitRequest(command[0], uri, headers);
|
||||
bout.write(("Response status: " + res.getStatus()).getBytes());
|
||||
out.println();
|
||||
bout.write(res.getContentAsByteArray());
|
||||
out.println();
|
||||
}
|
||||
@@ -414,16 +419,17 @@ public class TestWebScriptServer
|
||||
{
|
||||
uri += "&alf:method=" + command[2];
|
||||
}
|
||||
MockHttpServletResponse res = submitRequest("post", uri);
|
||||
MockHttpServletResponse res = submitRequest("post", uri, headers);
|
||||
bout.write(res.getContentAsByteArray());
|
||||
out.println();
|
||||
}
|
||||
|
||||
else if (command[1].equals("header"))
|
||||
{
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
headers.put("X-HTTP-Method-Override", command[2]);
|
||||
MockHttpServletResponse res = submitRequest("post", command[3], headers);
|
||||
Map<String, String> tunnelheaders = new HashMap<String, String>();
|
||||
tunnelheaders.putAll(headers);
|
||||
tunnelheaders.put("X-HTTP-Method-Override", command[2]);
|
||||
MockHttpServletResponse res = submitRequest("post", command[3], tunnelheaders);
|
||||
bout.write(res.getContentAsByteArray());
|
||||
out.println();
|
||||
}
|
||||
@@ -434,6 +440,43 @@ public class TestWebScriptServer
|
||||
}
|
||||
}
|
||||
|
||||
else if (command[0].equals("header"))
|
||||
{
|
||||
if (command.length == 1)
|
||||
{
|
||||
for (Map.Entry<String, String> entry : headers.entrySet())
|
||||
{
|
||||
out.println(entry.getKey() + " = " + entry.getValue());
|
||||
}
|
||||
}
|
||||
else if (command.length == 2)
|
||||
{
|
||||
String[] param = command[1].split("=");
|
||||
if (param.length == 0)
|
||||
{
|
||||
return "Syntax Error.\n";
|
||||
}
|
||||
if (param.length == 1)
|
||||
{
|
||||
headers.remove(param[0]);
|
||||
out.println("deleted header " + param[0]);
|
||||
}
|
||||
else if (param.length == 2)
|
||||
{
|
||||
headers.put(param[0], param[1]);
|
||||
out.println("set header " + param[0] + " = " + headers.get(param[0]));
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Syntax Error.\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return "Syntax Error.\n";
|
||||
}
|
||||
}
|
||||
|
||||
else if (command[0].equals("reset"))
|
||||
{
|
||||
registry.reset();
|
||||
|
@@ -141,13 +141,6 @@ public interface WebScriptRequest
|
||||
*/
|
||||
public FormatStyle getFormatStyle();
|
||||
|
||||
/**
|
||||
* Get the JSON callback method
|
||||
*
|
||||
* @return method (or null, if not specified)
|
||||
*/
|
||||
public String getJSONCallback();
|
||||
|
||||
/**
|
||||
* Get User Agent
|
||||
*
|
||||
@@ -157,4 +150,21 @@ public interface WebScriptRequest
|
||||
*/
|
||||
public String getAgent();
|
||||
|
||||
/**
|
||||
* Get the JSON callback method
|
||||
*
|
||||
* @return method (or null, if not specified)
|
||||
*/
|
||||
public String getJSONCallback();
|
||||
|
||||
/**
|
||||
* Force response to return SUCCESS (200) code
|
||||
*
|
||||
* Note: This is to support clients who cannot support non-success codes
|
||||
* e.g. Flash player
|
||||
*
|
||||
* @return true => force return of 200, otherwise return status explicitly set
|
||||
*/
|
||||
public boolean forceSuccessStatus();
|
||||
|
||||
}
|
||||
|
@@ -147,4 +147,12 @@ public abstract class WebScriptRequestImpl implements WebScriptRequest
|
||||
return getParameter("alf_callback");
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRequest#forceSuccessStatus()
|
||||
*/
|
||||
public boolean forceSuccessStatus()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -138,8 +138,7 @@ public abstract class WebScriptRuntime
|
||||
String reqFormat = scriptReq.getFormat();
|
||||
String format = (reqFormat == null || reqFormat.length() == 0) ? "default" : scriptReq.getFormat();
|
||||
WebScriptDescription desc = scriptReq.getServiceMatch().getWebScript().getDescription();
|
||||
logger.debug("Format style: " + desc.getFormatStyle());
|
||||
logger.debug("Default format: " + desc.getDefaultFormat());
|
||||
logger.debug("Format style: " + desc.getFormatStyle() + ", Default format: " + desc.getDefaultFormat());
|
||||
logger.debug("Invoking Web Script " + description.getId() + (user == null ? " (unauthenticated)" : " (authenticated as " + user + ") (format " + format + ") (" + locale + ")"));
|
||||
}
|
||||
|
||||
@@ -224,12 +223,13 @@ public abstract class WebScriptRuntime
|
||||
// render output
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("Force success status header in response: " + req.forceSuccessStatus());
|
||||
logger.debug("Sending status " + statusCode + " (Template: " + templatePath + ")");
|
||||
logger.debug("Rendering response: content type=" + MimetypeMap.MIMETYPE_HTML);
|
||||
}
|
||||
|
||||
res.reset();
|
||||
res.setStatus(statusCode);
|
||||
res.setStatus(req.forceSuccessStatus() ? HttpServletResponse.SC_OK : statusCode);
|
||||
res.setContentType(MimetypeMap.MIMETYPE_HTML + ";charset=UTF-8");
|
||||
try
|
||||
{
|
||||
|
@@ -248,4 +248,14 @@ public class WebScriptServletRequest extends WebScriptRequestImpl
|
||||
return port;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.web.scripts.WebScriptRequestImpl#forceSuccessStatus()
|
||||
*/
|
||||
@Override
|
||||
public boolean forceSuccessStatus()
|
||||
{
|
||||
String forceSuccess = req.getHeader("alf-force-success-response");
|
||||
return Boolean.valueOf(forceSuccess);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user