BizTalk Server Orchestration - HTTP Post and Cookie?

This is Interesting: Free IT Magazines  
Home > Archive > BizTalk Server Orchestration > April 2005 > HTTP Post and Cookie?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author HTTP Post and Cookie?
Mike

2005-04-26, 5:49 pm

Hi,

Any help is appreciated. I'm having a problem posting data to a vendor via
the HTTP Send Adapter. The authentication is HTTP Basic Auth, but their
implementation requires a cookie. In .NET, I can get it to work by adding a
CookieContainer to the web request. How is this possible in BizTalk? Do I
have to write a custom HTTP Post Adapter or is there a way to do it via a
message property, the orchestration or other parameter on the port?

Please advise...

Michael

Jon Flanders[MVP]

2005-04-26, 5:49 pm

There is an Http.HttpCookie property. And it appears to me from looking at
the code that the HTTP Send adapter code grabs it out of the context, but
then ignores it? Seems odd to me - but there is a Http.UserHttpHeaders that
they do use - so if you set your cookie value there - I believe the HTTP
Send adapter will use it - but from looking at the code it appears that the
Send Adapter will not just accept a cookie from the Server - which is what
CookieContainer does - or do you have this cookie value?

You can use the Http.UserHttpHeaders in an expression shape from an
Orchestration or from a pipeline component - syntax for an expression looks
like this:
httpRequestMsg(HTTP.UserHttpHeaders)="Cookie: Foo=bar\r\n";

You can also HTTP.InboundHttpHeader to get a cookie value if the server sent
one - but you have to munge the whole http header string (with line feeds
etc).

str = httpResponseMsg(HTTP.InboundHttpHeaders);

in an expression shape would intialize str with all the headers coming back
from the webserver.


--
Jon Flanders
http://www.masteringbiztalk.com/blogs/jon/

"Mike" <Mike@discussions.microsoft.com> wrote in message
news:953FB7BF-124E-4410-931C-73080523B15E@microsoft.com...
> Hi,
>
> Any help is appreciated. I'm having a problem posting data to a vendor
> via
> the HTTP Send Adapter. The authentication is HTTP Basic Auth, but their
> implementation requires a cookie. In .NET, I can get it to work by adding
> a
> CookieContainer to the web request. How is this possible in BizTalk? Do
> I
> have to write a custom HTTP Post Adapter or is there a way to do it via a
> message property, the orchestration or other parameter on the port?
>
> Please advise...
>
> Michael
>



Mike

2005-04-26, 8:46 pm

Hi Jon,

I don't need the cookie! The server that I am posting to sends it and
apparently uses it to store some session information (I think this is part of
Basic Auth implemented with Siteminder). Anyway, in .NET, I would create a
CookieContainer, not do a thing with it and I would be able to post data
just fine.

When you say "looking at the code"...which code are you referring to? If I
can modify the code to put a cookie container then that would be great. Is
that possible?

Thanks Jon! I see you are an active poster to these newsgroups and I
really appreciate your expertise.

Michael



"Jon Flanders[MVP]" wrote:

> There is an Http.HttpCookie property. And it appears to me from looking at
> the code that the HTTP Send adapter code grabs it out of the context, but
> then ignores it? Seems odd to me - but there is a Http.UserHttpHeaders that
> they do use - so if you set your cookie value there - I believe the HTTP
> Send adapter will use it - but from looking at the code it appears that the
> Send Adapter will not just accept a cookie from the Server - which is what
> CookieContainer does - or do you have this cookie value?
>
> You can use the Http.UserHttpHeaders in an expression shape from an
> Orchestration or from a pipeline component - syntax for an expression looks
> like this:
> httpRequestMsg(HTTP.UserHttpHeaders)="Cookie: Foo=bar\r\n";
>
> You can also HTTP.InboundHttpHeader to get a cookie value if the server sent
> one - but you have to munge the whole http header string (with line feeds
> etc).
>
> str = httpResponseMsg(HTTP.InboundHttpHeaders);
>
> in an expression shape would intialize str with all the headers coming back
> from the webserver.
>
>
> --
> Jon Flanders
> http://www.masteringbiztalk.com/blogs/jon/
>
> "Mike" <Mike@discussions.microsoft.com> wrote in message
> news:953FB7BF-124E-4410-931C-73080523B15E@microsoft.com...
>
>
>

Jon Flanders[MVP]

2005-04-26, 8:46 pm

Thanks Mike - so the problem is that you can't add a CookieContainer - there
isn't any way to do this. I assume you are doing more than one
request/response with this server? Otherwise you probably don't need to
send the cookie on the first run - although I guess it is possible it is
doing a redirect (which would complicate things - but anyway) - what you
have to do is this to make it work (this is as far as I can tell from
looking at the HTTP Send adapter code and testing it out quickly this
afternoon) -

When you get the response to your first message - you'll have to parse the
Http.InboundHttpHeaders property to retrieve the http header and then parse
it looking for the set-cookie header. Take that value and then add it to
the next outgoing message by using the Http.UserHttpHeaders property like
the code in my earlier post.

It appears to be either that - or create a custom HTTP adatper. I'd
probably choose the header parsing.

--
Jon Flanders
http://www.masteringbiztalk.com/blogs/jon/

"Mike" <Mike@discussions.microsoft.com> wrote in message
news:6D889612-7642-435A-A82B-DB836DB27C61@microsoft.com...[vbcol=seagreen]
> Hi Jon,
>
> I don't need the cookie! The server that I am posting to sends it and
> apparently uses it to store some session information (I think this is part
> of
> Basic Auth implemented with Siteminder). Anyway, in .NET, I would create
> a
> CookieContainer, not do a thing with it and I would be able to post data
> just fine.
>
> When you say "looking at the code"...which code are you referring to? If
> I
> can modify the code to put a cookie container then that would be great.
> Is
> that possible?
>
> Thanks Jon! I see you are an active poster to these newsgroups and I
> really appreciate your expertise.
>
> Michael
>
>
>
> "Jon Flanders[MVP]" wrote:
>


Mike

2005-04-26, 8:46 pm

Hi Jon,

Thanks again. Okay, believe it or not, I'm only doing ONE Request/Response.
This cookie is generally used to maintain client state but is really pretty
useless when using HTTP Basic Authentication.

I have added the following code to the message in the orchestration:

msgBatchResponse(HTTP.HttpCookie) = "SMSESSION";
msgBatchResponse(HTTP.HttpCookie) = "SMCHALLENGE";

These are the names of the cookies that I think siteminder is trying to send
- so my hope was that if I put them in the orchestration, it (siteminder)
would find them and then try to populate the value! :-) Naive of me?
Likely, because it didn't work.

I don't know what good it will do for me to parse out the headers if I don't
use them for future requests.

Maybe I do have to write a custom adapter. Do you think it would be easy to
add to the CookieContainer functionality to the code you have been looking at?

Thanks again, sorry I'm so ignorant here.

Michael

Jon Flanders[MVP]

2005-04-27, 2:47 am

So I am guessing what is happening is that the site you are using is doing
basic auth and then redirecting to another url after the cookie has been
set. So my guess is that you will have to do more than one response/request
with the site to make this work. Perhaps there is some setting in
siteminder that allows you to make a request to just get the cookie?

--
Jon Flanders
http://www.masteringbiztalk.com/blogs/jon/

"Mike" <Mike@discussions.microsoft.com> wrote in message
news:3FDF10B0-E9B0-4474-BE77-8B34753FEAC0@microsoft.com...
> Hi Jon,
>
> Thanks again. Okay, believe it or not, I'm only doing ONE
> Request/Response.
> This cookie is generally used to maintain client state but is really
> pretty
> useless when using HTTP Basic Authentication.
>
> I have added the following code to the message in the orchestration:
>
> msgBatchResponse(HTTP.HttpCookie) = "SMSESSION";
> msgBatchResponse(HTTP.HttpCookie) = "SMCHALLENGE";
>
> These are the names of the cookies that I think siteminder is trying to
> send
> - so my hope was that if I put them in the orchestration, it (siteminder)
> would find them and then try to populate the value! :-) Naive of me?
> Likely, because it didn't work.
>
> I don't know what good it will do for me to parse out the headers if I
> don't
> use them for future requests.
>
> Maybe I do have to write a custom adapter. Do you think it would be easy
> to
> add to the CookieContainer functionality to the code you have been looking
> at?
>
> Thanks again, sorry I'm so ignorant here.
>
> Michael
>



Mike

2005-04-27, 2:47 am

Jon,

Thank you for your continued responses. Is the code that you looked at
today from the sdk (SDK\Samples\Adapters\HttpAdapter)?

If so, do you think it is possible for me to just put cookiecontainer code
within it? I have reviewed the code and am thinking I can just modify the
following:
File: HttpAdapterWorkItem.cs
Function: SendHttpRequest

Somewhere before the actual post, just add an empty cookie container to the
request object. Obviously, I can try this out to see if it works, but what I
am seeking here is any potential downfalls you see with this approach (other
than hardcoding the cookiecontainer)? i.e. am I going to be doing a major
"no-no" with BizTalk?

Thank you much...

Michael




"Jon Flanders[MVP]" wrote:

> So I am guessing what is happening is that the site you are using is doing
> basic auth and then redirecting to another url after the cookie has been
> set. So my guess is that you will have to do more than one response/request
> with the site to make this work. Perhaps there is some setting in
> siteminder that allows you to make a request to just get the cookie?
>
> --
> Jon Flanders
> http://www.masteringbiztalk.com/blogs/jon/
>
> "Mike" <Mike@discussions.microsoft.com> wrote in message
> news:3FDF10B0-E9B0-4474-BE77-8B34753FEAC0@microsoft.com...
>
>
>

Jon Flanders[MVP]

2005-04-27, 2:47 am

The only downside I know of - is that I do not believe that sample is as
robust or scalable as the HTTP adapter itself - and also of course there is
no support for a custom adapter. Other than that - I think your plan would
work fine.

--
Jon Flanders
http://www.masteringbiztalk.com/blogs/jon/

"Mike" <Mike@discussions.microsoft.com> wrote in message
news:2BD9067E-CD3B-4455-8934-92AA14277DB5@microsoft.com...[vbcol=seagreen]
> Jon,
>
> Thank you for your continued responses. Is the code that you looked at
> today from the sdk (SDK\Samples\Adapters\HttpAdapter)?
>
> If so, do you think it is possible for me to just put cookiecontainer code
> within it? I have reviewed the code and am thinking I can just modify
> the
> following:
> File: HttpAdapterWorkItem.cs
> Function: SendHttpRequest
>
> Somewhere before the actual post, just add an empty cookie container to
> the
> request object. Obviously, I can try this out to see if it works, but
> what I
> am seeking here is any potential downfalls you see with this approach
> (other
> than hardcoding the cookiecontainer)? i.e. am I going to be doing a major
> "no-no" with BizTalk?
>
> Thank you much...
>
> Michael
>
>
>
>
> "Jon Flanders[MVP]" wrote:
>


Mike

2005-04-27, 5:52 pm

Hi Jon,

Yes, I can see now that this adapter is very different from the native one.
I was hoping it was the same. I will have to add the BasicAuth capability
because out of the box it looks like only Kerberos or none are options.

I made my change to it, compiled the example, ran the registry file, added
it as an adapter in BizTalk explorer and have only one real issue left. Why
doesn't it show up in my Orchestration when adding a port? The only way I
see it is by opening BizTalk explorer (from within Visual Studio) and by
creating a Send Port there. Is there a way for me to see it in the
orchestration like the default HTTP adapter? I use static ports and was
hoping it would show up in the drop down list.

Any pointers?

Thanks,

Michael


"Jon Flanders[MVP]" wrote:

> The only downside I know of - is that I do not believe that sample is as
> robust or scalable as the HTTP adapter itself - and also of course there is
> no support for a custom adapter. Other than that - I think your plan would
> work fine.
>
> --
> Jon Flanders
> http://www.masteringbiztalk.com/blogs/jon/
>
> "Mike" <Mike@discussions.microsoft.com> wrote in message
> news:2BD9067E-CD3B-4455-8934-92AA14277DB5@microsoft.com...
>
>
>

Mike

2005-04-28, 5:55 pm

Jon,

Thank you for your help with this issue. I never did figure out how to get
the adapter to show up from the orchestration (by adding a port) so I ended
up creating the port manually and then binding the orchestration to it after
deployment.

I had to modify the HTTPAdapter sample. It only had Kerberos as an
authentication option. I added BasicAuth and also the Username/Password
properties to it in addition to the CookieContainer. Needless to say, I
think it is pretty cool the way the designer pulls in this information for
design time. This was the first time I had to modify a custom adapter and am
pleased with the outcome.

Thanks so much for your pointers. Your help is truly appreciated.

Michael


"Mike" wrote:
[vbcol=seagreen]
> Hi Jon,
>
> Yes, I can see now that this adapter is very different from the native one.
> I was hoping it was the same. I will have to add the BasicAuth capability
> because out of the box it looks like only Kerberos or none are options.
>
> I made my change to it, compiled the example, ran the registry file, added
> it as an adapter in BizTalk explorer and have only one real issue left. Why
> doesn't it show up in my Orchestration when adding a port? The only way I
> see it is by opening BizTalk explorer (from within Visual Studio) and by
> creating a Send Port there. Is there a way for me to see it in the
> orchestration like the default HTTP adapter? I use static ports and was
> hoping it would show up in the drop down list.
>
> Any pointers?
>
> Thanks,
>
> Michael
>
>
> "Jon Flanders[MVP]" wrote:
>
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com