How to set http cookies from an operation of a Jolie service?












2















I need to set a cookie to the browser from an operation of a Jolie service, but I can't find information on how to do it.



I checked the doc at https://jolielang.gitbook.io/docs/protocols/http and https://jolielang.gitbook.io/docs/web-applications/rest-apis-publication-and-integration, but it seems the use case I presented has not yet been covered.



inputPort MyIP {

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

main {

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


I expect to see the cookie in the browser cookie store.










share|improve this question



























    2















    I need to set a cookie to the browser from an operation of a Jolie service, but I can't find information on how to do it.



    I checked the doc at https://jolielang.gitbook.io/docs/protocols/http and https://jolielang.gitbook.io/docs/web-applications/rest-apis-publication-and-integration, but it seems the use case I presented has not yet been covered.



    inputPort MyIP {

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

    main {

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


    I expect to see the cookie in the browser cookie store.










    share|improve this question

























      2












      2








      2








      I need to set a cookie to the browser from an operation of a Jolie service, but I can't find information on how to do it.



      I checked the doc at https://jolielang.gitbook.io/docs/protocols/http and https://jolielang.gitbook.io/docs/web-applications/rest-apis-publication-and-integration, but it seems the use case I presented has not yet been covered.



      inputPort MyIP {

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

      main {

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


      I expect to see the cookie in the browser cookie store.










      share|improve this question














      I need to set a cookie to the browser from an operation of a Jolie service, but I can't find information on how to do it.



      I checked the doc at https://jolielang.gitbook.io/docs/protocols/http and https://jolielang.gitbook.io/docs/web-applications/rest-apis-publication-and-integration, but it seems the use case I presented has not yet been covered.



      inputPort MyIP {

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

      main {

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


      I expect to see the cookie in the browser cookie store.







      cookies jolie






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 1 at 22:16









      Franz BFranz B

      132




      132
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Reading and Writing cookies



          You can use the cookies parameter, which maps cookie names to fields that are present in messages.



          For example, .cookies.auth_token = "token" binds the cookie called auth_token to the field token in messages (both in reading and writing).



          Here's a complete example where the login operation sets the cookie auth_token in the browser.



          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 = "" }
          }
          }


          You can try it by browsing http://localhost:8080/login?pwd=secret.





          Bonus: cookies with correlation sets



          Using cookies like this allows for combining them with workflows, to program process-aware web applications. Here is a more elaborate example with the following workflow:




          1. The user logs in;

          2. If the login is successful, operation say can be called at will, until operation logout is called;

          3. The user logs out.


          I'm using correlation sets below to track the session.



          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 = "" } ]
          }


          To try it, you can navigate to these links (in order):




          1. http://localhost:8080/login?pwd=secret

          2. http://localhost:8080/say?msg=Hello

          3. http://localhost:8080/logout


          References:




          • Sessions and correlation sets: https://jolielang.gitbook.io/docs/basics/sessions

          • provide-until statement: https://jolielang.gitbook.io/docs/basics/composing_statements#the-provide-until-statement

          • The paper on provide-until and web workflows in Jolie: https://doi.org/10.1016/j.scico.2016.05.002 (open version: https://arxiv.org/abs/1410.3712)






          share|improve this answer

































            1














            You are on the right track The setting of the cookie is carried out via the use of the return Header information as shown by the MDN Reference.



            To manipulate the response Header in Jolie you need to work on the .addHeader node of http port configuration
            Here is my code



            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 "
            }]
            }


            How do you read this code



              .addHeader.header[0] = "Set-Cookie";
            .addHeader.header[0].value->cookieCommand


            this part adds to the response header the "Set-Cookie" header that will have as value the variable cookieCommand; the symbol -> is a structure alias



            Now your variable cookieCommand can be set in any operation behaviour in my example is in the login Operation



                  [login(request)(response){
            //doing something to control my credatiol
            cookieCommand = "yummy_cookie=myCookieValue "
            }]


            The picture below shows the result of the call



            Response Header



            and this is the result on the browser



            Application Cookie Value



            Now let us look at how to handle the incoming cookie. First of all, we can define a new operation op1



            interface MyInterface {
            RequestResponse:
            login(undefined)(undefined),
            op1(op1RequestType)(op1ResponseType)
            }


            in the request type, we need to add a new node that will contain our application cookie value



            type op1RequestType:void{
            .cookieValue:string
            }


            Then we need to set the match between the cookie value received by the Http inputPort and the operation input variable



            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
            }


            the port configuration parameter



            .osc.op1.cookies.yummy_cookie = "cookieValue"


            is read as osc.(nameOperation).cookies.nameCookie = nameNodeInTheType



            Let's look at the call from your browser



            Sending Cookie



            and the trace from the operation (jolie --trace )



            Jolie Trace



            Hope it helps






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999369%2fhow-to-set-http-cookies-from-an-operation-of-a-jolie-service%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              Reading and Writing cookies



              You can use the cookies parameter, which maps cookie names to fields that are present in messages.



              For example, .cookies.auth_token = "token" binds the cookie called auth_token to the field token in messages (both in reading and writing).



              Here's a complete example where the login operation sets the cookie auth_token in the browser.



              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 = "" }
              }
              }


              You can try it by browsing http://localhost:8080/login?pwd=secret.





              Bonus: cookies with correlation sets



              Using cookies like this allows for combining them with workflows, to program process-aware web applications. Here is a more elaborate example with the following workflow:




              1. The user logs in;

              2. If the login is successful, operation say can be called at will, until operation logout is called;

              3. The user logs out.


              I'm using correlation sets below to track the session.



              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 = "" } ]
              }


              To try it, you can navigate to these links (in order):




              1. http://localhost:8080/login?pwd=secret

              2. http://localhost:8080/say?msg=Hello

              3. http://localhost:8080/logout


              References:




              • Sessions and correlation sets: https://jolielang.gitbook.io/docs/basics/sessions

              • provide-until statement: https://jolielang.gitbook.io/docs/basics/composing_statements#the-provide-until-statement

              • The paper on provide-until and web workflows in Jolie: https://doi.org/10.1016/j.scico.2016.05.002 (open version: https://arxiv.org/abs/1410.3712)






              share|improve this answer






























                1














                Reading and Writing cookies



                You can use the cookies parameter, which maps cookie names to fields that are present in messages.



                For example, .cookies.auth_token = "token" binds the cookie called auth_token to the field token in messages (both in reading and writing).



                Here's a complete example where the login operation sets the cookie auth_token in the browser.



                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 = "" }
                }
                }


                You can try it by browsing http://localhost:8080/login?pwd=secret.





                Bonus: cookies with correlation sets



                Using cookies like this allows for combining them with workflows, to program process-aware web applications. Here is a more elaborate example with the following workflow:




                1. The user logs in;

                2. If the login is successful, operation say can be called at will, until operation logout is called;

                3. The user logs out.


                I'm using correlation sets below to track the session.



                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 = "" } ]
                }


                To try it, you can navigate to these links (in order):




                1. http://localhost:8080/login?pwd=secret

                2. http://localhost:8080/say?msg=Hello

                3. http://localhost:8080/logout


                References:




                • Sessions and correlation sets: https://jolielang.gitbook.io/docs/basics/sessions

                • provide-until statement: https://jolielang.gitbook.io/docs/basics/composing_statements#the-provide-until-statement

                • The paper on provide-until and web workflows in Jolie: https://doi.org/10.1016/j.scico.2016.05.002 (open version: https://arxiv.org/abs/1410.3712)






                share|improve this answer




























                  1












                  1








                  1







                  Reading and Writing cookies



                  You can use the cookies parameter, which maps cookie names to fields that are present in messages.



                  For example, .cookies.auth_token = "token" binds the cookie called auth_token to the field token in messages (both in reading and writing).



                  Here's a complete example where the login operation sets the cookie auth_token in the browser.



                  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 = "" }
                  }
                  }


                  You can try it by browsing http://localhost:8080/login?pwd=secret.





                  Bonus: cookies with correlation sets



                  Using cookies like this allows for combining them with workflows, to program process-aware web applications. Here is a more elaborate example with the following workflow:




                  1. The user logs in;

                  2. If the login is successful, operation say can be called at will, until operation logout is called;

                  3. The user logs out.


                  I'm using correlation sets below to track the session.



                  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 = "" } ]
                  }


                  To try it, you can navigate to these links (in order):




                  1. http://localhost:8080/login?pwd=secret

                  2. http://localhost:8080/say?msg=Hello

                  3. http://localhost:8080/logout


                  References:




                  • Sessions and correlation sets: https://jolielang.gitbook.io/docs/basics/sessions

                  • provide-until statement: https://jolielang.gitbook.io/docs/basics/composing_statements#the-provide-until-statement

                  • The paper on provide-until and web workflows in Jolie: https://doi.org/10.1016/j.scico.2016.05.002 (open version: https://arxiv.org/abs/1410.3712)






                  share|improve this answer















                  Reading and Writing cookies



                  You can use the cookies parameter, which maps cookie names to fields that are present in messages.



                  For example, .cookies.auth_token = "token" binds the cookie called auth_token to the field token in messages (both in reading and writing).



                  Here's a complete example where the login operation sets the cookie auth_token in the browser.



                  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 = "" }
                  }
                  }


                  You can try it by browsing http://localhost:8080/login?pwd=secret.





                  Bonus: cookies with correlation sets



                  Using cookies like this allows for combining them with workflows, to program process-aware web applications. Here is a more elaborate example with the following workflow:




                  1. The user logs in;

                  2. If the login is successful, operation say can be called at will, until operation logout is called;

                  3. The user logs out.


                  I'm using correlation sets below to track the session.



                  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 = "" } ]
                  }


                  To try it, you can navigate to these links (in order):




                  1. http://localhost:8080/login?pwd=secret

                  2. http://localhost:8080/say?msg=Hello

                  3. http://localhost:8080/logout


                  References:




                  • Sessions and correlation sets: https://jolielang.gitbook.io/docs/basics/sessions

                  • provide-until statement: https://jolielang.gitbook.io/docs/basics/composing_statements#the-provide-until-statement

                  • The paper on provide-until and web workflows in Jolie: https://doi.org/10.1016/j.scico.2016.05.002 (open version: https://arxiv.org/abs/1410.3712)







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 13 at 15:03

























                  answered Jan 7 at 14:26









                  fmontesifmontesi

                  564




                  564

























                      1














                      You are on the right track The setting of the cookie is carried out via the use of the return Header information as shown by the MDN Reference.



                      To manipulate the response Header in Jolie you need to work on the .addHeader node of http port configuration
                      Here is my code



                      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 "
                      }]
                      }


                      How do you read this code



                        .addHeader.header[0] = "Set-Cookie";
                      .addHeader.header[0].value->cookieCommand


                      this part adds to the response header the "Set-Cookie" header that will have as value the variable cookieCommand; the symbol -> is a structure alias



                      Now your variable cookieCommand can be set in any operation behaviour in my example is in the login Operation



                            [login(request)(response){
                      //doing something to control my credatiol
                      cookieCommand = "yummy_cookie=myCookieValue "
                      }]


                      The picture below shows the result of the call



                      Response Header



                      and this is the result on the browser



                      Application Cookie Value



                      Now let us look at how to handle the incoming cookie. First of all, we can define a new operation op1



                      interface MyInterface {
                      RequestResponse:
                      login(undefined)(undefined),
                      op1(op1RequestType)(op1ResponseType)
                      }


                      in the request type, we need to add a new node that will contain our application cookie value



                      type op1RequestType:void{
                      .cookieValue:string
                      }


                      Then we need to set the match between the cookie value received by the Http inputPort and the operation input variable



                      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
                      }


                      the port configuration parameter



                      .osc.op1.cookies.yummy_cookie = "cookieValue"


                      is read as osc.(nameOperation).cookies.nameCookie = nameNodeInTheType



                      Let's look at the call from your browser



                      Sending Cookie



                      and the trace from the operation (jolie --trace )



                      Jolie Trace



                      Hope it helps






                      share|improve this answer




























                        1














                        You are on the right track The setting of the cookie is carried out via the use of the return Header information as shown by the MDN Reference.



                        To manipulate the response Header in Jolie you need to work on the .addHeader node of http port configuration
                        Here is my code



                        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 "
                        }]
                        }


                        How do you read this code



                          .addHeader.header[0] = "Set-Cookie";
                        .addHeader.header[0].value->cookieCommand


                        this part adds to the response header the "Set-Cookie" header that will have as value the variable cookieCommand; the symbol -> is a structure alias



                        Now your variable cookieCommand can be set in any operation behaviour in my example is in the login Operation



                              [login(request)(response){
                        //doing something to control my credatiol
                        cookieCommand = "yummy_cookie=myCookieValue "
                        }]


                        The picture below shows the result of the call



                        Response Header



                        and this is the result on the browser



                        Application Cookie Value



                        Now let us look at how to handle the incoming cookie. First of all, we can define a new operation op1



                        interface MyInterface {
                        RequestResponse:
                        login(undefined)(undefined),
                        op1(op1RequestType)(op1ResponseType)
                        }


                        in the request type, we need to add a new node that will contain our application cookie value



                        type op1RequestType:void{
                        .cookieValue:string
                        }


                        Then we need to set the match between the cookie value received by the Http inputPort and the operation input variable



                        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
                        }


                        the port configuration parameter



                        .osc.op1.cookies.yummy_cookie = "cookieValue"


                        is read as osc.(nameOperation).cookies.nameCookie = nameNodeInTheType



                        Let's look at the call from your browser



                        Sending Cookie



                        and the trace from the operation (jolie --trace )



                        Jolie Trace



                        Hope it helps






                        share|improve this answer


























                          1












                          1








                          1







                          You are on the right track The setting of the cookie is carried out via the use of the return Header information as shown by the MDN Reference.



                          To manipulate the response Header in Jolie you need to work on the .addHeader node of http port configuration
                          Here is my code



                          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 "
                          }]
                          }


                          How do you read this code



                            .addHeader.header[0] = "Set-Cookie";
                          .addHeader.header[0].value->cookieCommand


                          this part adds to the response header the "Set-Cookie" header that will have as value the variable cookieCommand; the symbol -> is a structure alias



                          Now your variable cookieCommand can be set in any operation behaviour in my example is in the login Operation



                                [login(request)(response){
                          //doing something to control my credatiol
                          cookieCommand = "yummy_cookie=myCookieValue "
                          }]


                          The picture below shows the result of the call



                          Response Header



                          and this is the result on the browser



                          Application Cookie Value



                          Now let us look at how to handle the incoming cookie. First of all, we can define a new operation op1



                          interface MyInterface {
                          RequestResponse:
                          login(undefined)(undefined),
                          op1(op1RequestType)(op1ResponseType)
                          }


                          in the request type, we need to add a new node that will contain our application cookie value



                          type op1RequestType:void{
                          .cookieValue:string
                          }


                          Then we need to set the match between the cookie value received by the Http inputPort and the operation input variable



                          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
                          }


                          the port configuration parameter



                          .osc.op1.cookies.yummy_cookie = "cookieValue"


                          is read as osc.(nameOperation).cookies.nameCookie = nameNodeInTheType



                          Let's look at the call from your browser



                          Sending Cookie



                          and the trace from the operation (jolie --trace )



                          Jolie Trace



                          Hope it helps






                          share|improve this answer













                          You are on the right track The setting of the cookie is carried out via the use of the return Header information as shown by the MDN Reference.



                          To manipulate the response Header in Jolie you need to work on the .addHeader node of http port configuration
                          Here is my code



                          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 "
                          }]
                          }


                          How do you read this code



                            .addHeader.header[0] = "Set-Cookie";
                          .addHeader.header[0].value->cookieCommand


                          this part adds to the response header the "Set-Cookie" header that will have as value the variable cookieCommand; the symbol -> is a structure alias



                          Now your variable cookieCommand can be set in any operation behaviour in my example is in the login Operation



                                [login(request)(response){
                          //doing something to control my credatiol
                          cookieCommand = "yummy_cookie=myCookieValue "
                          }]


                          The picture below shows the result of the call



                          Response Header



                          and this is the result on the browser



                          Application Cookie Value



                          Now let us look at how to handle the incoming cookie. First of all, we can define a new operation op1



                          interface MyInterface {
                          RequestResponse:
                          login(undefined)(undefined),
                          op1(op1RequestType)(op1ResponseType)
                          }


                          in the request type, we need to add a new node that will contain our application cookie value



                          type op1RequestType:void{
                          .cookieValue:string
                          }


                          Then we need to set the match between the cookie value received by the Http inputPort and the operation input variable



                          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
                          }


                          the port configuration parameter



                          .osc.op1.cookies.yummy_cookie = "cookieValue"


                          is read as osc.(nameOperation).cookies.nameCookie = nameNodeInTheType



                          Let's look at the call from your browser



                          Sending Cookie



                          and the trace from the operation (jolie --trace )



                          Jolie Trace



                          Hope it helps







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 2 at 9:03









                          BalintBalint

                          10114




                          10114






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53999369%2fhow-to-set-http-cookies-from-an-operation-of-a-jolie-service%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              MongoDB - Not Authorized To Execute Command

                              How to fix TextFormField cause rebuild widget in Flutter

                              Npm cannot find a required file even through it is in the searched directory