Showing posts with label currentRequestAttributes. Show all posts
Showing posts with label currentRequestAttributes. Show all posts

Wednesday, December 18, 2013

Grails access HttpSession from service or from other src files


import org.springframework.web.context.request.RequestContextHolder; 
HttpSession session = RequestContextHolder.currentRequestAttributes().getSession();

##### 
/* Code */
session.properties.each {
    println it;
}

/* Output from above code */
creationTime=1387331940863
maxInactiveInterval=1800
sessionContext=org.apache.catalina.session.StandardSessionContext@1ff04376
attributeNames=java.util.Collections$2@2aec16fa
class=class org.codehaus.groovy.grails.web.servlet.mvc.GrailsHttpSession
servletContext=org.apache.catalina.core.ApplicationContextFacade@3dc6e9f8
new=false
id=A2791167D1EC3D21025078895357147D
valueNames=[Ljava.lang.String;@71d88d19
lastAccessedTime=1387332146960

#####
/* Code */
session.attributeNames.each {
    println it;
}

/* Output from above code */
SETTING
org.codehaus.groovy.grails.FLASH_SCOPE
USER

#####
/* Code */
session.attributeNames.each {
    println session.getAttribute(it.toString());
}

/* Output from above code */
[paginationCount:10, generateClientID:On]
[:]
[name:Admin, id:1, username:admin, isSystemAdmin:true]