Topic
  • 13 replies
  • Latest Post - ‏2013-01-25T11:10:15Z by SystemAdmin
SystemAdmin
SystemAdmin
6772 Posts

Pinned topic Sharing Data Across Requests

‏2013-01-22T15:29:56Z |
Hi,

My current solution is:

A SOAP/HTTPS request comes from the client to my mpgw. The response to the request is sent as a new request to my mpgw and to a different backend and then repeated again. Not the cleanest of solutions, but one which works and fits in with the rest of the requirements.

What I wanted to find out was, is it possible to share data between the requests?

When the first request is sent to DataPower there is a field, which I need to return to the last call, is there a way that the details of this field can be passed between the requests? I was going to set the HTTP header, but it gets overwritten in the responses.
Updated on 2013-01-25T11:10:15Z at 2013-01-25T11:10:15Z by SystemAdmin
  • swlinn
    swlinn
    1348 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-22T15:44:25Z  
    >>> I was going to set the HTTP header, but it gets overwritten in the responses.

    You have request and response HTTP headers you may set. If you want to change something in the response headers from the second service, your first service can do so. Use a context variable to save data from the request and then update your response header to send it to the original client.

    Regards,
    Steve
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T11:24:16Z  
    • swlinn
    • ‏2013-01-22T15:44:25Z
    >>> I was going to set the HTTP header, but it gets overwritten in the responses.

    You have request and response HTTP headers you may set. If you want to change something in the response headers from the second service, your first service can do so. Use a context variable to save data from the request and then update your response header to send it to the original client.

    Regards,
    Steve
    HI Steve,

    Thanks for your response.

    I've got the logic, but currently having difficulty setting the response header with a dummy value.

    I'm my xslt I'm using: <dp:set-http-response-header name="'test_header_value'" value="12345"/>

    My transform action has an input of input and I've tried changing the output to Input and a dp_var, however, the response header is not being set.

    Any ideas?
  • swlinn
    swlinn
    1348 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T11:30:28Z  
    HI Steve,

    Thanks for your response.

    I've got the logic, but currently having difficulty setting the response header with a dummy value.

    I'm my xslt I'm using: <dp:set-http-response-header name="'test_header_value'" value="12345"/>

    My transform action has an input of input and I've tried changing the output to Input and a dp_var, however, the response header is not being set.

    Any ideas?
    The value attribute is an xpath, so if you want to specify the literal 12345, then it needs to be in quotes ... eg, value="'12345'", similar to how you have the name attribute specified.

    Regards,
    Steve
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T11:51:06Z  
    • swlinn
    • ‏2013-01-24T11:30:28Z
    The value attribute is an xpath, so if you want to specify the literal 12345, then it needs to be in quotes ... eg, value="'12345'", similar to how you have the name attribute specified.

    Regards,
    Steve
    Didn't realise it had to be in quotes, that worked, thank you.

    The final bit is not working now, is this correct behavior? The response header is populated successfully, this response is then sent to a new service as a request, but the when viewing the new request, the header I inserted is not available?
  • kenhygh
    kenhygh
    1522 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T12:44:04Z  
    Didn't realise it had to be in quotes, that worked, thank you.

    The final bit is not working now, is this correct behavior? The response header is populated successfully, this response is then sent to a new service as a request, but the when viewing the new request, the header I inserted is not available?
    what's your flow? From what you're describing, sounds like it's two transactions.

    client -> datapower -> backend
    <- (inserts response header) <-
    client -> some backend
    (new request) (no header)

    If this is what you're describing, then you'll need to get the 'client' system to take the response header from DataPower and put it in the new request.

    Ken
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T12:54:39Z  
    • kenhygh
    • ‏2013-01-24T12:44:04Z
    what's your flow? From what you're describing, sounds like it's two transactions.

    client -> datapower -> backend
    <- (inserts response header) <-
    client -> some backend
    (new request) (no header)

    If this is what you're describing, then you'll need to get the 'client' system to take the response header from DataPower and put it in the new request.

    Ken
    Its

    Client > DataPower > Backend > (datapower inserts header on response) > new request to DataPower (side call) > rest of processing

    So the client sends a request to DataPower, which sends onto a backend. The response DataPower receives, it adds the response header and makes a side call asynchronously, which invokes another DataPower service. Its within this 2nd DataPower service that I want access to text inserted in the response header.

    Is this possible, or would the response headers get overwritten when the new request (side call) is made to DataPower. If it does get overwritten, is it possible to send text from one request to another, without altering the message payload.
  • kenhygh
    kenhygh
    1522 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T15:50:13Z  
    Its

    Client > DataPower > Backend > (datapower inserts header on response) > new request to DataPower (side call) > rest of processing

    So the client sends a request to DataPower, which sends onto a backend. The response DataPower receives, it adds the response header and makes a side call asynchronously, which invokes another DataPower service. Its within this 2nd DataPower service that I want access to text inserted in the response header.

    Is this possible, or would the response headers get overwritten when the new request (side call) is made to DataPower. If it does get overwritten, is it possible to send text from one request to another, without altering the message payload.
    Some of this will depend on how you're making that side-call, but I think you'd want to send REQUEST headers on that side-call, not response headers.

    Ken
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T16:41:45Z  
    • kenhygh
    • ‏2013-01-24T15:50:13Z
    Some of this will depend on how you're making that side-call, but I think you'd want to send REQUEST headers on that side-call, not response headers.

    Ken
    Any ideas on what the dependencies could be?

    Before the side call, I've tried setting an attribute in the request and response header, but I am not able to retrieve this information in the new request (from the side call).
  • kenhygh
    kenhygh
    1522 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T17:03:56Z  
    Any ideas on what the dependencies could be?

    Before the side call, I've tried setting an attribute in the request and response header, but I am not able to retrieve this information in the new request (from the side call).
    so you can make side calls with results-asynch, url-open, soap-call, etc etc.

    What is it you want to do? and then we'll help you figure out the best way to do it.

    Ken
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T17:12:01Z  
    • kenhygh
    • ‏2013-01-24T17:03:56Z
    so you can make side calls with results-asynch, url-open, soap-call, etc etc.

    What is it you want to do? and then we'll help you figure out the best way to do it.

    Ken
    Appreciate the help.

    I'm using a Results Asynchronous action, which has an input of Input and method of post. This action, has an endpoint, which calls a DataPower mpgw.

    So effectively, there are 2 DataPower calls made from 1 request. The initial request has a field, which I need to be able to reference in the second DataPower request.

    That's where the idea came to populate the http header before the side call and then in the second DataPower request, read the http header and process.

    Is there any alternative way of doing this, or am I on the right path by using the HTTP header?
  • kenhygh
    kenhygh
    1522 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T18:27:43Z  
    Appreciate the help.

    I'm using a Results Asynchronous action, which has an input of Input and method of post. This action, has an endpoint, which calls a DataPower mpgw.

    So effectively, there are 2 DataPower calls made from 1 request. The initial request has a field, which I need to be able to reference in the second DataPower request.

    That's where the idea came to populate the http header before the side call and then in the second DataPower request, read the http header and process.

    Is there any alternative way of doing this, or am I on the right path by using the HTTP header?
    So, you have a response rule with a results Asynch, which is sending the response from the main backend to another service in addition to the client. In this side-call, you need something out of the client's initial request to put into the side-call request. Is this right?

    If so, this is not sharing data across requests, because you're still processing the original client's request, you're just doing stuff in the response rule.

    Context variables were built for this. In your request rule, extract the 'field' (whatever that means) and put it into a context variable. In your response rule, get that value and put it wherever the side-call backend expects it.

    Ken
  • swlinn
    swlinn
    1348 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-24T19:28:00Z  
    • kenhygh
    • ‏2013-01-24T18:27:43Z
    So, you have a response rule with a results Asynch, which is sending the response from the main backend to another service in addition to the client. In this side-call, you need something out of the client's initial request to put into the side-call request. Is this right?

    If so, this is not sharing data across requests, because you're still processing the original client's request, you're just doing stuff in the response rule.

    Context variables were built for this. In your request rule, extract the 'field' (whatever that means) and put it into a context variable. In your response rule, get that value and put it wherever the side-call backend expects it.

    Ken
    I believe in this case you need to set var://local/_extension/header/yourname = value. You code should do this in a stylesheet that takes as an input context the same context as your result action, and it will be appended to your protocol headers of your side call. Do a search for _extension in the infocenter for more details.

    Best Regards,
    Steve
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Sharing Data Across Requests

    ‏2013-01-25T11:10:15Z  
    • swlinn
    • ‏2013-01-24T19:28:00Z
    I believe in this case you need to set var://local/_extension/header/yourname = value. You code should do this in a stylesheet that takes as an input context the same context as your result action, and it will be appended to your protocol headers of your side call. Do a search for _extension in the infocenter for more details.

    Best Regards,
    Steve
    Just done some reading on _extension, and tried it. It worked perfectly, exactly what I wanted to accomplish.

    Thanks for all your help guys!!