Changeset 5029

Show
Ignore:
Timestamp:
01/28/10 11:48:37 (2 years ago)
Author:
mtld
Message:

support setting cookies at webservice responses

Location:
branches/release-0.14.x
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/release-0.14.x/ChangeLog

    r5007 r5029  
     12010-01-28  Martin Leidig  <mleidig@schlund.de> 
     2 
     3        Added support for setting cookies at webservice responses. 
     4 
     5        Therefore cookies set at the context during processing of a 
     6        webservice request are added to the HttpServletResponse 
     7        after the service object's method invocation and right before 
     8        writing the response. 
     9 
    1102010-01-13  Martin Leidig  <mleidig@schlund.de> 
    211 
  • branches/release-0.14.x/pustefix-core/src/main/java/de/schlund/pfixcore/workflow/ContextImpl.java

    r4512 r5029  
    1919package de.schlund.pfixcore.workflow; 
    2020 
     21import java.util.List; 
    2122import java.util.Properties; 
    2223 
     
    7071    } 
    7172     
     73    public List<Cookie> getCookies() { 
     74        return getRequestContextForCurrentThreadWithError().getCookies(); 
     75    } 
     76     
    7277    public Cookie[] getRequestCookies() { 
    7378        return getRequestContextForCurrentThreadWithError().getRequestCookies(); 
  • branches/release-0.14.x/pustefix-core/src/main/java/de/schlund/pfixcore/workflow/context/RequestContextImpl.java

    r4580 r5029  
    890890 
    891891    public void addCookie(Cookie cookie) { 
    892         if (currentpservreq == null) { 
    893             throw new IllegalStateException("Cookies are only available witihin request handling"); 
    894         } 
    895892        cookielist.add(cookie); 
     893    } 
     894     
     895    public List<Cookie> getCookies() { 
     896        return cookielist; 
    896897    } 
    897898 
  • branches/release-0.14.x/pustefix-webservices/pustefix-webservices-jaxws/src/main/java/org/pustefixframework/webservices/jaxws/JAXWSProcessor.java

    r4517 r5029  
    2626import javax.servlet.ServletContext; 
    2727import javax.servlet.ServletException; 
     28import javax.servlet.http.Cookie; 
    2829import javax.servlet.http.HttpServletRequest; 
    2930import javax.servlet.http.HttpServletResponse; 
     
    4041import org.pustefixframework.webservices.ProcessingInfo; 
    4142import org.pustefixframework.webservices.SOAPActionRequestWrapper; 
     43import org.pustefixframework.webservices.ServiceCallContext; 
    4244import org.pustefixframework.webservices.ServiceException; 
    4345import org.pustefixframework.webservices.ServiceProcessor; 
     
    5961import com.sun.xml.ws.transport.http.servlet.ServletAdapterList; 
    6062import com.sun.xml.ws.transport.http.servlet.WSServletDelegate; 
     63 
     64import de.schlund.pfixcore.workflow.Context; 
     65import de.schlund.pfixcore.workflow.ContextImpl; 
    6166 
    6267/** 
     
    220225            } finally { 
    221226                ctx.endInvocation(); 
     227                ServiceResponse res = ServiceCallContext.getCurrentContext().getServiceResponse(); 
     228                if(res.getUnderlyingResponse() instanceof HttpServletResponse) { 
     229                    HttpServletResponse httpRes = (HttpServletResponse)res.getUnderlyingResponse(); 
     230                    Context context = ServiceCallContext.getCurrentContext().getContext(); 
     231                    if(context != null) { 
     232                        List<Cookie> cookies = ((ContextImpl)context).getCookies(); 
     233                        for(Cookie cookie: cookies) { 
     234                            httpRes.addCookie(cookie); 
     235                        } 
     236                    } 
     237                } 
    222238            } 
    223239        } 
  • branches/release-0.14.x/pustefix-webservices/pustefix-webservices-jsonws/src/main/java/org/pustefixframework/webservices/jsonws/JSONWSProcessor.java

    r4517 r5029  
    2929import java.util.List; 
    3030 
     31import javax.servlet.http.Cookie; 
     32import javax.servlet.http.HttpServletResponse; 
     33 
    3134import org.apache.log4j.Logger; 
    32 import org.pustefixframework.webservices.json.JSONArray; 
    33 import org.pustefixframework.webservices.json.JSONObject; 
    34 import org.pustefixframework.webservices.json.parser.JSONParser; 
    35  
    36 import de.schlund.pfixcore.beans.BeanDescriptorFactory; 
    37 import de.schlund.pfixcore.beans.InitException; 
    38 import de.schlund.pfixcore.beans.metadata.DefaultLocator; 
    3935import org.pustefixframework.webservices.ProcessingInfo; 
    4036import org.pustefixframework.webservices.ServiceCallContext; 
     
    4945import org.pustefixframework.webservices.fault.Fault; 
    5046import org.pustefixframework.webservices.fault.FaultHandler; 
     47import org.pustefixframework.webservices.json.JSONArray; 
     48import org.pustefixframework.webservices.json.JSONObject; 
     49import org.pustefixframework.webservices.json.parser.JSONParser; 
     50 
     51import de.schlund.pfixcore.beans.BeanDescriptorFactory; 
     52import de.schlund.pfixcore.beans.InitException; 
     53import de.schlund.pfixcore.beans.metadata.DefaultLocator; 
     54import de.schlund.pfixcore.workflow.Context; 
     55import de.schlund.pfixcore.workflow.ContextImpl; 
    5156 
    5257/** 
     
    186191                } 
    187192                 
     193                if(res.getUnderlyingResponse() instanceof HttpServletResponse){ 
     194                    HttpServletResponse httpRes = (HttpServletResponse)res.getUnderlyingResponse(); 
     195                    Context context = ServiceCallContext.getCurrentContext().getContext(); 
     196                    if(context != null) { 
     197                        List<Cookie> cookies = ((ContextImpl)context).getCookies(); 
     198                        for(Cookie cookie: cookies) { 
     199                                httpRes.addCookie(cookie); 
     200                        } 
     201                    } 
     202                } 
     203                 
    188204                res.setContentType("text/plain"); 
    189205                res.setCharacterEncoding("utf-8");