Patch to add SOAP header reading and writing

Peter Bex - August 26, 2009 - 07:47
Project:SOAP Client
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:ilo
Status:needs work
Description

The project I am currently working on requires me to set custom SOAP headers based on a SOAP header that is returned after calling an authentication method.

Currently, Drupal soapclient does not support this, so I have created a patch to allow for this. It is a bit of a quick hack; this patch allows you to provide request headers as raw XML strings because that was the simplest to get to work under both nuSOAP and PHP SoapClient. Feel free to improve this to add more sophisticated nested object handling if needed. Nested response headers should already be properly decoded by this change.

This changes the call in PHP5 soap implementation, so that the patch in issue #355616: Soap call not working is no longer needed.

AttachmentSize
soapclient.headers.diff1.67 KB

#1

Peter Bex - August 26, 2009 - 08:03

I forgot to change something; the above patch assumes the root XML node inside the header element is named 'Header'. This new patch makes no assumption and returns the same value as nuSOAP does, regardless of root element name.

Note that this patch is incremental, you will have to apply the other one first

AttachmentSize
soapclient.headers-rootnode.diff 562 bytes

#2

ilo - August 26, 2009 - 12:29
Status:needs review» needs work

I just have a simple concern.. what's the purpose of having this header included by default?

$client->__setSoapHeaders(array(new SoapHeader('example.com', 'dontcareaboutname', $sv)));

I've converted both files to a single patch.. IMO, it would be better to create a private variable in the drupal_soap_client class as 'headers' container, and create a public method (something like headers_get?) to retrieve them from your code. In some cases, the current result of the soap call could be quite big. I don't like having a little class not being usefull at all in this module.

Anyway, good work, hope this one gets commited.

AttachmentSize
soapclient_559752.patch 2.3 KB

#3

Peter Bex - August 27, 2009 - 10:32

Hi and thanks for your comment.

Yeah, the code could be improved. I just made the smallest change that could possibly work with the way the module is currently structured. This also makes it more obvious what this patch does.

I think some refactoring of soapclient is in order anyway, but I think that's a separate issue from this patch.

I'm not sure about what your concern is though. The soapheader's name and namespace are ignored when the value is a SoapVal with type XSD_ANYXML. For some iffy reason PHP's SOAPClient class wants you to do it like this, but they don't end up in the output like that. I didn't design this crap, I just have to use it :)

Like I said, I made the smallest possible change to make it work like how it's structured ATM, and because the nuSOAP implementation already supported headers as literal strings, that would be the path of least resistance. Feel free to come up with support for fancy nested XML structures that works under both implementations, but beware: it's extremely painful. You usually need to control namespaces on header elements as well, so just nested arrays with simple values are simply not enough; you need to make an abstraction over both soapval/SoapVar for drupal's soapclient.

#4

ilo - September 17, 2009 - 19:19
Assigned to:Anonymous» ilo

I just realized that the patch in the issue #372462: PHP 5 header support is similar to this one, but uses namespace and header name properly. I don't like the part about using different argument type depending the library in use, because this is supposed to be a wrapper, and the library should not affect the usage. I guess we can get these two issues into this single thread to resolve the headers question.

 
 

Drupal is a registered trademark of Dries Buytaert.