JSF FacesContext and HttpServletRequest for Web Services in JSF Project
The FacesContext is created by the FacesServlet and thus only available within any Java code which is processed by the FacesServlet, which covers all JSF artifacts, such as managed beans and phase listeners. The FacesContext is just an abstraction of everything already available by standard Servlet API such as HttpServletRequest, HttpSession, ServletContext, etc. For web services, we can use them directly.
JAX RS Implementation
@Context
private ServletConfig servletConfig;
@Context
private ServletContext servletContext;
@Context
private HttpServletRequest httpServletRequest;
@Context
private HttpServletResponse httpServletResponse;
@POST
@Path("/xxxx")
@Produces("application/json")
public RestResult<XXXResult> eee(@RequestBody
inputParam parameter) throws BusinessRuleException {
httpServletRequest.getSession().setAttribute("kullanici",kullanici);
//httpServletRequest.getSession().setAttribute("JSESSIONID",parameter.getToken());
String sessionId=httpServletRequest.getSession().getId();
{
if(httpServletRequest.getCookies()!=null )
{
Cookie cSessionId=null;
Cookie[] cooks= httpServletRequest.getCookies();
for (Cookie cook:cooks)
{
if(cook.getName().equals("JSESSIONID"))
{
cSessionId=cook;
break;
}
}
if(cSessionId!=null) {
sessionId=cSessionId.getValue();
}
}
}
// Birlik model !'den önceki haliyle kontrol ediyor.
String truncatedSessionId=StringUtils.substringBeforeLast(sessionId,"!");
String truncated2String=StringUtils.substringBeforeLast(truncatedSessionId,"!");
// set redis data
ModulServisFactroyBean.getCommonServis().setSessionDataIntoRedisForBirlikModel(httpServletRequest,truncatedSessionId);
// clear redis data
ModulServisFactroyBean.getCommonServis().clearSessionDatafromRedisForBirlikModel(httpServletRequest.getSession(), truncatedSessionId);
return new RestSonuc(false, RestSonucHataKodu.DefaultException.getKod(), e.getMessage(), new ETerkinStatuBildirSonuc("BASARISIZ"));
}
Comments
Post a Comment