Xml with multiple data processing in django spyne

I have a server that is running django and spyne, I want to configure spyne to accept xml like below:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:loc="http://www.csapi.org/schema/parlayx/sms/send/v4_0/local">
<soapenv:Header/>
<soapenv:Body>

<loc:sendSms>
<loc:addresses>[addresses]</loc:addresses>
<loc:senderName>[senderName]</loc:senderName>
<loc:message>[message]</loc:message>
<loc:receiptRequest>
    <endpoint></endpoint>
    <interfaceName></interfaceName>
    <correlator></correlator>
</loc:receiptRequest>
</loc:sendSms>

<loc:sendSms>
<loc:addresses>[addresses]</loc:addresses>
<loc:senderName>[senderName]</loc:senderName>
<loc:message>[message]</loc:message>
<loc:receiptRequest>
    <endpoint></endpoint>
    <interfaceName></interfaceName>
    <correlator></correlator>
</loc:receiptRequest>
</loc:sendSms>

.
.
.

</soapenv:Body>
</soapenv:Envelope>

      

Is it possible? how should i do it?

and changing the client is not possible, so I need to work with this format.

EDIT:

what i have done so far:

Model:

class ReceiptRequestItem(ComplexModel):
    __namespace__ = 'http://www.csapi.org/schema/parlayx/sms/send/v4_0/local'
    endpoint = Unicode()
    interfaceName = Unicode()
    correlator = Unicode()

      

service:

class MOMessageService(ServiceBase):
    @rpc(Unicode, Unicode, Unicode, ReceiptRequestItem,
         _returns=Unicode,
         _in_variable_names={'sender_name': 'senderName',
                             'receipt_request': 'receiptRequest'},
         _operation_name='sendSms')
    def send_sms(ctx, addresses, sender_name, message, receipt_request):
         print addresses, sender_name, message, receipt_request
         return

      

Application:

mo_message_app = Application([MOMessageService],
                             'http://www.csapi.org/schema/parlayx/sms/send/v4_0/local',
                             in_protocol=Soap11(validator='soft'),
                             out_protocol=Soap11(), )

mo_message_service = csrf_exempt(DjangoApplication(mo_message_app))

      

it works when there is only one

<loc:sendSms>

      

although the problem with namespaces and lxml validator will throw an error.

the question arises how to change the code to accept multiple tags.

PS: Also I would appreciate it if someone could tell me how to fix my namespace problem. :)

EDIT2:

this is the error i am facing when using the lxml validator:

<?xml version='1.0' encoding='UTF-8'?>
<senv:Envelope xmlns:senv="http://schemas.xmlsoap.org/soap/envelope/">
    <senv:Body>
        <senv:Fault>
            <faultcode>senv:Client.SchemaValidationError</faultcode>
            <faultstring>:1:0:ERROR:SCHEMASV:SCHEMAV_ELEMENT_CONTENT: Element 'endpoint': This element is not expected.
                Expected is one of ( {http://www.csapi.org/schema/parlayx/sms/send/v4_0/local}endpoint,
                {http://www.csapi.org/schema/parlayx/sms/send/v4_0/local}interfaceName,
                {http://www.csapi.org/schema/parlayx/sms/send/v4_0/local}correlator ).
            </faultstring>
            <faultactor></faultactor>
        </senv:Fault>
    </senv:Body>
</senv:Envelope>

      

+3


source to share


1 answer


Use this syntax when defining yours ComplexModel

for accessing external (non-Python) systems.

class ReceiptRequestItem(ComplexModel):
    __namespace__ = 'http://www.csapi.org/schema/parlayx/sms/send/v4_0/local'
    _type_info = [
        ('endpoint', Unicode)
        ('interfaceName', Unicode)
        ('correlator', Unicode)
    ]

      

See:



https://github.com/arskom/spyne/pull/313

https://github.com/arskom/spyne/pull/343

0


source







All Articles