Come for answers. Stay for best practices. All we’re missing is you.
Hi
I need to update a parameter template_name in the HttpServletRequest passed before storing the document the required item type (template_name ). I use the the request filter to obtain the values being passed on /cm/addItem.
Code:
public String[] getFilteredServices() { return new String[] {"/cm/addItem"}; } public JSONObject filter(PluginServiceCallbacks callbacks, HttpServletRequest request, JSONArtifact jsonRequest) throws Exception { final String methodName = "execute"; callbacks.getLogger().logEntry(this, methodName, request); /** Get item type name. */ final String templateName = request.getParameter("template_name"); /** Get attribute values. */ JSONArray jsonCritera = null; if (jsonRequest != null) { jsonCritera = (JSONArray) jsonRequest; } final String itemType = "NewItemType"; request.setAttribute("template_name", itemType); } callbacks.getLogger().logExit(this, methodName, request); return null; }
Any suggestions?
Have you tried to get it from jsonRequest?
String templateName = (String) jsonResponse.get("template_name");
template_name does not exist in jsonRequest in the Request Filter, only the response filter.
I managed to resolve the problem using PluginRequestUtil thanks to a colleagues assistance. A whole one liner was the solution :D
final String itemType = "NewItemType"; PluginRequestUtil.setRequestParameter(request, "template_name", itemType, false);