Strategies for dealing with broken clients? (invalid documents) #670
Replies: 4 comments
-
Dealing with broken clients is just normal business for a soap server. I always thought that stuff that needs to happen before You could add a one-liner to fire an event before create_in_document but you'd have to be doing transport-specific work in it anyway. So I'm not sure that's the best thing to do. Would you agree? |
Beta Was this translation helpful? Give feedback.
-
You can have a look at |
Beta Was this translation helpful? Give feedback.
-
I may be approaching my limitations and I don't want to turn this into a help forum, but I do see value in sharing what I learned. I'm having trouble working out how I'd manipulate the context object. wsgi_call gets you an object that looks like
If I dig into the transport object, there is a req object, which has the byte stream of the payload in
The server doesn't hang, but the client connection stays open and nothing is returned to the client. You may recognize some of that from |
Beta Was this translation helpful? Give feedback.
-
you consumed the stream by reading from it. you need make sure to read everything (that's a bit tricky to do in the general case, especially when reading from sockets) modify it to your heart's content and put a new stream back. you most probably need a StringIO or BytesIO containing your modified byte array. you could also use a real file if your data is big. alternatively you could wrap the stream from wsgi enviroment in a custom file-like object that modifies and buffers data as it's being read by spyne's machinery. not the easiest thing to do, but certainly possible. |
Beta Was this translation helpful? Give feedback.
-
I have a client I can't change, which submits a malformed SOAP doc. The client assumes that there's already a namespace called
soap
with the urihttp://schemas.xmlsoap.org/soap/
. Who knows why the original server accepted this. I'm not in a position to judge or fix, only make something bug for bug compatible.Let's demonstrate the behavior in a simplified way.
I had originally gone down the path of trying to use the listeners, like
before_deserialize
, but all of those seem to occur after lxml.XMLID tries to parse the object and throws a fault (spyne/spyne/protocol/soap/soap11.py
Line 112 in 3547234
I ended up monkey patching Soap11's
_parse_xml_string
to do some nasty string manipulation with some regex's to find out if the namespace was specified in the envelope, and if not, modify the incoming string to include it.It makes sense that an invalid XML doc would cause a failure, but I'm wondering if there are other strategies I should be considering instead of this approach. Or perhaps it was the intent of those listeners in the Soap11 object to help cope with bad document and the functionality was lost over time. If it's the former, I'm all ears, if it's the later, I'm not totally sure how I would fix it.
I could see a path where
create_in_document
fires an event that allows you to manipulate the xml string beforectx.in_document
gets a parsed XML object, and I would take a swing a PR for that functionality if anyone sees merit in it.Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions