Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement XOP more properly #2

Open
bartkl opened this issue Nov 2, 2018 · 0 comments
Open

Implement XOP more properly #2

bartkl opened this issue Nov 2, 2018 · 0 comments

Comments

@bartkl
Copy link
Owner

bartkl commented Nov 2, 2018

Currently, XOP compliant serialization is implemented in a very hacky way.

  1. First, xop=True must be true, and there should be attachments stored on the client instance. Otherwise, no XOP serialization will take place.
  2. A SOAP message body string is generated using the create_message method of the Zeep client instance. Note that all base64Binary values will have been encoded during message generation.
  3. A multipart message HTTP request is built compliant with MTOM/XOP specification. Then, for each attachment on the clilent instance a body part will be built.
  4. The only thing left to do is to create <xop:Include/> elements for the base64 fields in the body. Since I'm not too familiar with the Zeep codebase, I've achieved this in a very hacky way currently:
  5. Just before sending the generated HTTP multipart request, the body is scanned for XML nodes which have text values that might be base64 encoded (based on what character alphabet is used and string length being divisible by four).
  6. For these candidate elements, the text value is base64-decoded. If the decoded value starts with cid:, this apparently is a element in which an attachment is referenced, so for those elements a<xop:Include/> child element is generated with an href attribute that contains the cid:... value

For those familiar with SOAP UI this pattern of working should be familiar.

I'm not opposed to the SOAP UI like magic here, it's quite user-friendly and makes things somewhat easier. An improvement however would be to make better use of Zeep:

  1. There should be a better way to determine which fields are of type base64Binary. Surely somewhere within the Document instance (or something like it) this should be possible. I don't know how and when I can access this instance however.
  2. The XML manipulation is now done by parsing the body string using lxml. This is overkill, since the Document instance already contains/is an lxml Element.

Maybe more improvement is possible. I've seen Zeep is capable of handling XOP already, but it seems only in responses, and regardless: I don't know how to utilitize the code in xop.py.

@bartkl bartkl added the improvement Code needs improvement label Nov 2, 2018
@bartkl bartkl added discussion and removed improvement Code needs improvement labels Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant