Struts 2
  1. Struts 2
  2. WW-4037

Provide functionality to create cookies from an Action

    Details

      Description

      As of today Struts provides some functionality to receive cookies in an Action, but there is no way to create cookies. I solved the issue by creating a custom CookieProviderInterceptor and CookieProvider interface that provide a standard way to generate cookies. The code I provide works and has been in production for months, but it is not Struts-ready, in the sense that it needs refactoring to remove the dependency from javax.servlet in the request; It is though a starting point to adapt it to Struts.

      As a suggestion maybe it is possible to merge this funcionality in CookieInterceptor, since receiving and creating cookies are usually related.

      1. CookieProvider.java
        0.2 kB
        Jose L Martinez-Avial
      2. CookieProviderInterceptor.java
        2 kB
        Jose L Martinez-Avial

        Activity

        Jose L Martinez-Avial created issue -
        Jose L Martinez-Avial made changes -
        Field Original Value New Value
        Attachment CookieProvider.java [ 12576925 ]
        Attachment CookieProviderInterceptor.java [ 12576926 ]
        Jose L Martinez-Avial made changes -
        Description As of today Struts provides some functionality to receive cookies in an Action, but there is no way to create cookies. I solved the issue by creating a custom CookieProviderInterceptor and CookieProvider interface that provide a standard way to generate cookies. The code I provide works and has been in production for months, but it is not Struts-ready, in the sense that it needs refactoring to remove the dependency from javax.servlet in the request; It is though a starting point to adapt it to Struts. As of today Struts provides some functionality to receive cookies in an Action, but there is no way to create cookies. I solved the issue by creating a custom CookieProviderInterceptor and CookieProvider interface that provide a standard way to generate cookies. The code I provide works and has been in production for months, but it is not Struts-ready, in the sense that it needs refactoring to remove the dependency from javax.servlet in the request; It is though a starting point to adapt it to Struts.

        As a suggestion maybe it is possible to merge this funcionality in CookieInterceptor, since receiving and creating cookies are usually related.
        Lukasz Lenart made changes -
        Assignee Lukasz Lenart [ lukaszlenart ]
        Hide
        Lukasz Lenart added a comment -

        First I will introduce it as is, then we can think of merging it into CookieInterceptor.

        Show
        Lukasz Lenart added a comment - First I will introduce it as is, then we can think of merging it into CookieInterceptor.
        Hide
        Lukasz Lenart added a comment -

        Classes introduced, thanks for you effort!

        Show
        Lukasz Lenart added a comment - Classes introduced, thanks for you effort!
        Lukasz Lenart made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Show
        Lukasz Lenart added a comment - Some docs https://cwiki.apache.org/confluence/display/WW/CookieProvider+Interceptor
        Hide
        Hudson added a comment -

        Integrated in Struts2-JDK6 #711 (See https://builds.apache.org/job/Struts2-JDK6/711/)
        WW-4037 Adds functionality to create Cookies in action and apply them to response (Revision 1485719)

        Result = SUCCESS
        lukaszlenart :
        Files :

        • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieProvider.java
        • /struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieProviderInterceptor.java
        • /struts/struts2/trunk/core/src/main/resources/struts-default.xml
        • /struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CookieProviderInterceptorTest.java
        Show
        Hudson added a comment - Integrated in Struts2-JDK6 #711 (See https://builds.apache.org/job/Struts2-JDK6/711/ ) WW-4037 Adds functionality to create Cookies in action and apply them to response (Revision 1485719) Result = SUCCESS lukaszlenart : Files : /struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieProvider.java /struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/CookieProviderInterceptor.java /struts/struts2/trunk/core/src/main/resources/struts-default.xml /struts/struts2/trunk/core/src/test/java/org/apache/struts2/interceptor/CookieProviderInterceptorTest.java
        Lukasz Lenart made changes -
        Issue Type Improvement [ 4 ] New Feature [ 2 ]
        Lukasz Lenart made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Jose L Martinez-Avial
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 72h
              72h
              Remaining:
              Remaining Estimate - 72h
              72h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development