如何从Jolie服务的操作中设置http cookies?

如何从Jolie服务的操作中设置http cookies?,cookies,jolie,Cookies,Jolie,我需要从朱莉服务的操作中为浏览器设置cookie,但我找不到有关如何操作的信息 我在和检查了文档,但我呈现的用例似乎还没有被涵盖 inputPort MyIP { Protocol: http { ... ??? -> myCookie; ... } Interfaces: LoginInterface } main { [login(credentials)(res) { ... myCookie=???

我需要从朱莉服务的操作中为浏览器设置cookie,但我找不到有关如何操作的信息

我在和检查了文档,但我呈现的用例似乎还没有被涵盖

inputPort MyIP {

    Protocol: http {
    ...
    ??? -> myCookie;
    ...
    }
    Interfaces: LoginInterface
}

main {

    [login(credentials)(res) {
    ...  
    myCookie=???  
    ...  
    }]
}

我希望在浏览器cookie存储中看到cookie。

您在正确的轨道上。cookie的设置是通过使用返回标题信息执行的,如所示

要在Jolie中操作响应头,您需要使用http端口配置的.addHeader节点 这是我的密码

interface MyInterface {

    RequestResponse:
     login(undefined)(undefined)
    }

    inputPort MyPort {
    Location: "socket://localhost:8000"
    Protocol: http {
      .debug= true;
      .debug.showContent= true;
      .addHeader.header[0] = "Set-Cookie";
      .addHeader.header[0].value->cookieCommand
    }
    Interfaces: MyInterface
    }

    execution{ concurrent }
    main{
      [login(request)(response){
          //doing something to control my credatiol
          cookieCommand = "yummy_cookie=myCookieValue "
        }]
    }  
你怎么读这个代码

  .addHeader.header[0] = "Set-Cookie";
  .addHeader.header[0].value->cookieCommand
这一部分向响应头添加“Set Cookie”头,该头的值为变量cookieCommand;符号->是一个

现在,可以在任何操作中设置变量cookieCommand。在我的示例中,行为是登录操作

      [login(request)(response){
          //doing something to control my credatiol
          cookieCommand = "yummy_cookie=myCookieValue "
        }]
下图显示了通话结果

这是浏览器上的结果

现在让我们来看看如何处理传入的cookie。首先,我们可以定义一个新的操作op1

interface MyInterface {
RequestResponse:
 login(undefined)(undefined),
 op1(op1RequestType)(op1ResponseType)
}
在请求类型中,我们需要添加一个包含应用程序cookie值的新节点

type op1RequestType:void{
  .cookieValue:string
}
然后,我们需要设置Http inputPort接收的cookie值与操作输入变量之间的匹配

inputPort MyPort {
Location: "socket://localhost:8000"
Protocol: http {
  .debug= true;
  .debug.showContent= true;
  .addHeader.header[0] = "Set-Cookie";
  .addHeader.header[0].value->cookieCommand;
  .osc.op1.cookies.yummy_cookie = "cookieValue"
}
Interfaces: MyInterface
}
端口配置参数

.osc.op1.cookies.yummy_cookie = "cookieValue"
读取为osc.(nameOperation).cookies.nameCookie=nameNodeInTheType

让我们看看您的浏览器中的呼叫

还有手术的痕迹(朱莉--trace

希望它有助于阅读和编写cookies 您可以使用
cookies
参数,该参数将cookie名称映射到消息中存在的字段

例如,
.cookies.auth_token=“token”
将名为
auth_token
的cookie绑定到消息中的字段
token
(读和写)

下面是一个完整的示例,
login
操作在浏览器中设置cookie
auth\u令牌

execution { concurrent }

inputPort Server {
Location: "socket://localhost:8080"
Protocol: http
  // Binds the cookie "auth_token" to the message field "token"
  { .cookies.auth_token = "token" }
RequestResponse: login
}

main
{
  login( request )( response ) {
    if ( request.pwd == "secret" )
      response << "OK" { .token = new }
    else
      response << "Invalid pwd" { .token = "" }
  }
}
要尝试,您可以导航到以下链接(按顺序):

  • 参考资料:

    • 会话和关联集:
    • 在声明之前提供:
    • 关于在朱莉中提供工作流程和web工作流的论文:(开放版本:)
    include "console.iol"
    
    execution { concurrent }
    
    type LoginRequest:void { .token?:string .pwd:string }
    type TokenMessage:void { .token:string }
    type SayRequest:void { .token:string .msg:string }
    
    interface ServerIface {
    RequestResponse:
      login(LoginRequest)(TokenMessage) throws InvalidPwd,
      say(SayRequest)(void),
      logout(TokenMessage)(TokenMessage)
    }
    
    inputPort Server {
    Location: "socket://localhost:8080"
    Protocol: http { .cookies.auth_token = "token" }
    Interfaces: ServerIface
    }
    
    cset {
      token: SayRequest.token TokenMessage.token
    }
    
    main
    {
      login( request )( response ) {
        if ( request.pwd == "secret" )
          response.token = csets.token = new
        else
          throw( InvalidPwd )
      };
      provide
        [ say( request )() {
          println@Console( csets.token + " says " + request.msg )()
        } ]
      until
        [ logout()( response ) { response.token = "" } ]
    }