Ho creato un RenderingPlugin
, per l'uso in WebSphere Portal
, che viene richiamato serveride prima di inviare markup al client. Il plug-in scorre tutti i cookie e se "test" non viene trovato, mi piacerebbe impostare quel cookie.Creare un cookie utilizzando HttpServletRequest?
So che questo è possibile con unoma il RenderingPlugin
non ha accesso a tale oggetto. Ha solo un HttpServletRequest
.
C'è un altro modo per farlo?
public class Request implements com.ibm.workplace.wcm.api.plugin.RenderingPlugin {
@Override
public boolean render(RenderingPluginModel rpm) throws RenderingPluginException {
boolean found = false;
HttpServletRequest servletRequest = (HttpServletRequest) rpm.getRequest();
Cookie[] cookie = servletRequest.getCookies();
// loop through cookies
for (int i = 0; i < cookie.length; i++) {
// if test found
if (cookie[i].getName().equals("test")) {
found = true;
}
}
if (!found){
// set cookie here
}
}
}
Non esiste alcuna API per impostare un cookie su una richiesta. Questa è solo la risposta. –
Ho lo stesso problema. Ho bisogno di creare un cookie all'interno di un endpoint. Ho solo HttpServletRequest not Response. :( – Hasanthi