https://issues.apache.org/jira/browse/AMQ-3940 - REST API support for configurable response content type

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1364560 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2012-07-23 09:57:42 +00:00
parent 0227c08112
commit 51927e6f89
1 changed files with 10 additions and 12 deletions

View File

@ -60,6 +60,7 @@ public class MessageServlet extends MessageServletSupport {
private long defaultReadTimeout = -1;
private long maximumReadTimeout = 20000;
private long requestTimeout = 1000;
private String defaultContentType = "text/xml";
private HashMap<String, WebClient> clients = new HashMap<String, WebClient>();
@ -77,6 +78,10 @@ public class MessageServlet extends MessageServletSupport {
if (name != null) {
requestTimeout = asLong(name);
}
name = servletConfig.getInitParameter("defaultContentType");
if (name != null) {
defaultContentType = name;
}
}
/**
@ -236,7 +241,7 @@ public class MessageServlet extends MessageServletSupport {
try {
// write a responds
response.setContentType("text/xml");
response.setContentType(defaultContentType);
PrintWriter writer = response.getWriter();
// handle any message(s)
@ -280,11 +285,6 @@ public class MessageServlet extends MessageServletSupport {
}
}
protected boolean isRicoAjax(HttpServletRequest request) {
String rico = request.getParameter("rico");
return rico != null && rico.equals("true");
}
public WebClient getWebClient(HttpServletRequest request) {
String clientId = request.getParameter("clientId");
if (clientId != null) {
@ -305,16 +305,14 @@ public class MessageServlet extends MessageServletSupport {
}
protected String getContentType(HttpServletRequest request) {
/*
* log("Params: " + request.getParameterMap()); Enumeration iter =
* request.getHeaderNames(); while (iter.hasMoreElements()) { String
* name = (String) iter.nextElement(); log("Header: " + name + " = " +
* request.getHeader(name)); }
*/
String value = request.getParameter("xml");
if (value != null && "true".equalsIgnoreCase(value)) {
return "text/xml";
}
value = request.getParameter("json");
if (value != null && "true".equalsIgnoreCase(value)) {
return "application/json";
}
return null;
}