Loading ...
Sorry, an error occurred while loading the content.

Question on consuming REST

Expand Messages
  • Venkat M
    Hi All,   I have a basic question on consuming a rest web service. It would be great if someone can help me out. Thanks in advance.   I have a web service
    Message 1 of 2 , Apr 2, 2012
    • 0 Attachment
      Hi All,
       
      I have a basic question on consuming a rest web service. It
      would be great if someone can help me out. Thanks in advance.
       
      I have a web service definition as below.
       
      Login Call
      definition:
       
      <resource path="/Login">
      <method id="Login" name="POST">
      <request>
      <representation mediaType="application/json"/>
      </request>
      <response>
      <representation mediaType="application/json"/>
      </response>
      </method>
      </resource>
       
      I make a JQuery
      Ajax call like
       
      $('#softlogin').click(function() {
                //alert('Login Check - With User Values');
                   var uid = $('#username').val();
                   var pwd = $('#password').val();
                $.ajax({
                   url: 'http://localhost:8080/Services/Login',
                   type: 'POST',
                   async: 'async',
                   data: JSON.stringify({'userid':uid,'password':pwd}),
                   contentType: "application/json",
                   dataType: "json",
                   success: function(data){ 
                     if (data.status == 'OK')
      {
                       key = data.key;
                       document.cookie = "session_key"+ "="+ key;
                       //alert('Success -
      finally'); 
                       $('#content').html('User:
      '+ uid + '  &  Session Key :'+data.key);
                     }
                  }
               }).error(function()
      {
                 alert('An error Occoured');
               });
            });
       
      Once the Login call is success, I am setting up the cookie
      session_key with the Key that is returned in the Login call success.
       
      And to Logout.
       
      The web service definition is like
       
      <resource path="/Logout">
      <method id="Logout" name="POST">
      <request>
      <param xmlns:xs="http://www.w3.org/2001/XMLSchema"%c2%a0name="Cookie"%c2%a0style="header"%c2%a0type="xs:string"%c2%a0path="session_key"/>
      </request>
      <response>
      <representation mediaType="*/*"/>
      </response>
      </method>
      </resource>
       
      In JQuery Ajax I write like
       
      function getCookie(c_name)
            {
            var i,x,y,ARRcookies=document.cookie.split(";");
            for (i=0;i<ARRcookies.length;i++)
            {
              x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
              y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
              x=x.replace(/^\s+|\s+$/g,"");
              if (x==c_name)
                {
                return unescape(y);
                }
              }
            }
           
            $('#termmodule').click(function()
      {
                 var session_key = getCookie("session_key");
                 //alert('Cookie fetched is:' + session_key);
                 $.ajax({
                   url: 'http://localhost:8080/Services/Logout%e2%80%99,
                   type: 'POST',
                   async: 'async',
                   data: JSON.stringify({'session_key':session_key}),
                   //headers: {'Cookie' : session_key},
                   contentType: "application/json",
                   dataType: "json",
                   success: function(data){ 
                     if (data.status == 'OK')
      {
                       alert('Session Logged out);
                       $('#content').html(data);
                     }
                  }
               }).error(function()
      {
                 alert('An error Occoured');
               });
            });
       
      This is not working out. It fails. I am not sure why.
      Is this the right way we pass cookie parameter.
       
      I was also given the testing snippet from REST web service
      developer like:
       
      Response res =
      given().cookie("session_key", session_key).post("http://localhost:8080/Services/Logout");
      It is with cookie
       
      Please help me.
       
      Cheers,
      Venkat.

      [Non-text portions of this message have been removed]
    • Dave Gamble
      I m not really sure this is the right forum for this question. Can I recommend stack overflow for questions of this kind? Cheers, Dave. ... [Non-text portions
      Message 2 of 2 , Apr 2, 2012
      • 0 Attachment
        I'm not really sure this is the right forum for this question. Can I
        recommend stack overflow for questions of this kind?

        Cheers,

        Dave.

        On Mon, Apr 2, 2012 at 9:31 PM, Venkat M <venkat_yum@...> wrote:

        > **
        >
        >
        > Hi All,
        >
        > I have a basic question on consuming a rest web service. It
        > would be great if someone can help me out. Thanks in advance.
        >
        > I have a web service definition as below.
        >
        > Login Call
        > definition:
        >
        > <resource path="/Login">
        > <method id="Login" name="POST">
        > <request>
        > <representation mediaType="application/json"/>
        > </request>
        > <response>
        > <representation mediaType="application/json"/>
        > </response>
        > </method>
        > </resource>
        >
        > I make a JQuery
        > Ajax call like
        >
        > $('#softlogin').click(function() {
        > //alert('Login Check - With User Values');
        > var uid = $('#username').val();
        > var pwd = $('#password').val();
        > $.ajax({
        > url: 'http://localhost:8080/Services/Login',
        > type: 'POST',
        > async: 'async',
        > data: JSON.stringify({'userid':uid,'password':pwd}),
        > contentType: "application/json",
        > dataType: "json",
        > success: function(data){
        > if (data.status == 'OK')
        > {
        > key = data.key;
        > document.cookie = "session_key"+ "="+ key;
        > //alert('Success -
        > finally');
        > $('#content').html('User:
        > '+ uid + ' & Session Key :'+data.key);
        > }
        > }
        > }).error(function()
        > {
        > alert('An error Occoured');
        > });
        > });
        >
        > Once the Login call is success, I am setting up the cookie
        > session_key with the Key that is returned in the Login call success.
        >
        > And to Logout.
        >
        > The web service definition is like
        >
        > <resource path="/Logout">
        > <method id="Logout" name="POST">
        > <request>
        > <param xmlns:xs="http://www.w3.org/2001/XMLSchema
        > " name="Cookie" style="header" type="xs:string" path="session_key"/>
        > </request>
        > <response>
        > <representation mediaType="*/*"/>
        > </response>
        > </method>
        > </resource>
        >
        > In JQuery Ajax I write like
        >
        > function getCookie(c_name)
        > {
        > var i,x,y,ARRcookies=document.cookie.split(";");
        > for (i=0;i<ARRcookies.length;i++)
        > {
        > x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
        > y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
        > x=x.replace(/^\s+|\s+$/g,"");
        > if (x==c_name)
        > {
        > return unescape(y);
        > }
        > }
        > }
        >
        > $('#termmodule').click(function()
        > {
        > var session_key = getCookie("session_key");
        > //alert('Cookie fetched is:' + session_key);
        > $.ajax({
        > url: 'http://localhost:8080/Services/Logout%ef%bf%bd,
        > type: 'POST',
        > async: 'async',
        > data: JSON.stringify({'session_key':session_key}),
        > //headers: {'Cookie' : session_key},
        > contentType: "application/json",
        > dataType: "json",
        > success: function(data){
        > if (data.status == 'OK')
        > {
        > alert('Session Logged out);
        > $('#content').html(data);
        > }
        > }
        > }).error(function()
        > {
        > alert('An error Occoured');
        > });
        > });
        >
        > This is not working out. It fails. I am not sure why.
        > Is this the right way we pass cookie parameter.
        >
        > I was also given the testing snippet from REST web service
        > developer like:
        >
        > Response res =
        > given().cookie("session_key", session_key).post("
        > http://localhost:8080/Services/Logout");
        > It is with cookie
        >
        > Please help me.
        >
        > Cheers,
        > Venkat.
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >


        [Non-text portions of this message have been removed]
      Your message has been successfully submitted and would be delivered to recipients shortly.