0

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;

  1. Is there a way to get atg session scoped necleus from Spring controller without going through DAF pipelining?

  2. Like a JSP page, is there a way to set a spring controller at the end of ATG daf pipelining?

allenhwkim
  • 27,270
  • 18
  • 89
  • 122
  • Have you considered accessing or exposing the profile via the out of the box web services? I have seen many attempts to implement so called true MVC in ATG and all of them have resulted in a world of pain, and made upgrades of ATG almost impossible. The DAF pipeline is fundamental to ATG so bypassing is risky e.g. it has XSS filtering etc etc. I would really recommend that you reconsider your strategy. – bated Sep 22 '14 at 16:54

2 Answers2

0

Here I post the solution that I have found

  1. 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.

  2. 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.

allenhwkim
  • 27,270
  • 18
  • 89
  • 122
0

Using a factory method in an application-scoped ApplicationContext does not always work as expected.

Have you considered using the Delivery Cube Common Component Resolver classes?

https://github.com/deliverycube/deliverycube-common

Vihung
  • 12,947
  • 16
  • 64
  • 90
  • Your Spring web application should be deployed as a WAR within an ATG module and should have the Page Filter and Servlet defined in the web app. – Vihung Nov 12 '14 at 12:34