如何在Mule上添加1个以上的cookie?

Gab*_*iel 0 cookies mule

我能够通过Mule ESB在请求的响应中添加1个cookie.但是,当我尝试使用属性"Set-Cookie"添加多个cookie时,Mule会覆盖第一个cookie并返回第二个cookie.

例如,在下面的代码片段中,我在message属性上添加了2个cookie(这是一个映射).

`String msg =  "SSID=123;domain=localhost;Path=/";
 String msg2 =  "SSAPID=456;domain=localhost;Path=/";
 message.setProperty(HttpHeaders.Names.SET_COOKIE,msg, PropertyScope.OUTBOUND);
 message.setProperty(HttpHeaders.Names.SET_COOKIE,msg2, PropertyScope.OUTBOUND);
`
Run Code Online (Sandbox Code Playgroud)

当我收到回复时,只有一个cookie:

  Message properties:
  OUTBOUND scoped properties:
    Set-Cookie=SAPID=456
    access-control-allow-credentials=true
    access-control-allow-headers=Origin, X-Requested-With, Content-Type, Accept, Cache, X-Auth-Token
    access-control-allow-methods=PATCH, PUT, POST, GET, OPTIONS, DELETE
    access-control-allow-origin=*
    access-control-max-age=10
    cache-control=no-store
    content-encoding=gzip
    content-type=application/json;charset=UTF-8
    date=Wed, 13 Jan 2016 12:26:58 GMT
    http.reason=OK
    http.status=200
    pragma=no-cache
    server=Apache-Coyote/1.1
    transfer-encoding=chunked
    vary=[Accept-Encoding, Accept-Encoding]
    x-content-type-options=nosniff
    x-xss-protections=1; mode=block
  SESSION scoped properties:
Run Code Online (Sandbox Code Playgroud)

Set-Cookie = SAPID = 456

如您所见,请求中仅返回了第二个cookie.

我怎样才能实现我想做的事情,因为这里描述的cookie规范https://tools.ietf.org/html/rfc6265#section-3.1说我可以在响应中返回超过1个Set-Cookie头.

服务器可以通过返回两个Set-Cookie头字段来存储会话标识符以及用户的首选语言

Rya*_*ter 5

如果你设置两次相同的属性,它将覆盖它.而是添加属性一次,但将值设置为列表:

List<String> cookies = new ArrayList<String>();
cookies.add(msg1);
cookies.add(msg2);

 message.setProperty(HttpHeaders.Names.SET_COOKIE,cookies, PropertyScope.OUTBOUND);
Run Code Online (Sandbox Code Playgroud)

返回:

curl http://localhost:8087/test -i
HTTP/1.1 200
Content-Length: 3
Set-Cookie: SSAPID=456;domain=localhost;Path=/
Set-Cookie: SSID=123;domain=localhost;Path=/
Date: Wed, 13 Jan 2016 15:09:54 GMT
Run Code Online (Sandbox Code Playgroud)