I have been struggling to see ATG profile in a Spring controller.
At the begining, I thought it was possible to get atg profile from spring controller by reading this document by defining like this.
<bean name="/Profile" class="atg.nucleus.spring.NucleusResolverUtil"
factory-method="resolveName" singleton="false">
<constructor-arg value="/atg/userprofiling/Profile"/>
</bean>
But, I have looked another atg documentation, and found out that session scoped neclues like /atg/userprofiling/Profile
is not available if it does not go through atg DAF pipelining.
Note:When you add your own servlets to the servlet pipeline, bear in mind that you cannot access the session object until the SessionServlet locates or creates it. So, if you add a servlet to the pipeline that needs to access the session object, make sure that your servlet appears in the pipeline after the SessionServlet.
Thus, I tried to set PageFilter
for spring servlets like the following.
<!-- ATG Services -->
<!-- any request starting with /services must be through ATG DAF pipe lining -->
<filter-mapping>
<filter-name>PageFilter</filter-name>
<url-pattern>/services/*</url-pattern>
</filter-mapping>
<!-- The following can be annotated, but we need to upgrade to servlet 3 -->
<servlet>
<servlet-name>HelloService</servlet-name>
<servlet-class>com.my.services.HelloService</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloService</servlet-name>
<url-pattern>/services/hello</url-pattern>
</servlet-mapping>
However, it failed. The reason is that spring Controller
is not a Servlet
, so that it cannot be at the end of ATG daf pipelininng.
If I use a simple HttpServlet
or DynamoServlet
, I can access user profile.
However, I really need to use Spring Framework because my company wants to use it. Another reason is we are at servlet2.3 and I really want to use Spring annotations.
Questions are;
Is there a way to get atg session scoped necleus from Spring controller without going through DAF pipelining?
Like a JSP page, is there a way to set a spring controller at the end of ATG daf pipelining?
Here I post the solution that I have found
Is there a way to get atg session scoped necleus from Spring controller without going through DAF pipelining?
NO. we need to go through ATG DAF pipelining to get session scoped nucleus.
Like a JSP page, is there a way to set a spring controller at the end of ATG daf pipelining?
YES!!!, we can let Spring DispatcherServlet at the end of ATG DAF pipeline instead of direct servlet mapping, in addition to the existing PageFilter Mapping.
The following is my web.xml
....
<filter>
<filter-name>PageFilter</filter-name>
<filter-class>atg.filter.dspjsp.PageFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PageFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>PageFilter</filter-name>
<url-pattern>/spring/*</url-pattern>
</filter-mapping>
....
<!-- Use spring DispatcherServlet with annotations i.e @Controller, etc -->
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/spring/*</url-pattern>
</servlet-mapping>
It might not be the ideal answer, but at least, it works.