Example #1
0
    def execute(self, req, unique_id=None, dt=None):
        # ~ print 20120302
        # ~ if user_params is None:
        # ~ raise Warning(
        # ~ "Not actually sending because user_params is empty.")
        # ~ self.validate_against_xsd(req)
        from django.conf import settings

        env = settings.SITE.cbss_environment
        user_params = settings.SITE.cbss_user_params

        req = self.wrap_request(req, unique_id, dt, user_params)

        # ~ xml = etree.tostring(req,xml_declaration=True)
        xml = etree.tostring(req)

        if not env:
            raise Warning(
                """\
Not actually sending because environment is empty. Request would be:
"""
                + prettify(xml)
            )

        # ~ assert env in (ENV_TEST, ENV_ACPT, ENV_PROD)
        assert env in CBSS_ENVS

        url = self.get_url(env)

        if True:
            # ~ x = etree.tostring(elem)
            from suds.client import Client

            url += "?WSDL"
            client = Client(url)
            # ~ print 20120507, url
            # ~ print client
            res = client.service.sendXML(xml)
        else:

            if isinstance(self, NewStyleService):
                server = Resource(url, measure=True, **user_params)
            else:
                server = Resource(url, measure=True)
            res = server.soap(xml)
        return res
Example #2
0
    def execute(self, req, unique_id=None, dt=None):
        #~ print 20120302
        #~ if user_params is None:
        #~ raise Warning(
        #~ "Not actually sending because user_params is empty.")
        #~ self.validate_against_xsd(req)
        from django.conf import settings
        env = settings.SITE.cbss_environment
        user_params = settings.SITE.cbss_user_params

        req = self.wrap_request(req, unique_id, dt, user_params)

        #~ xml = etree.tostring(req,xml_declaration=True)
        xml = etree.tostring(req)

        if not env:
            raise Warning("""\
Not actually sending because environment is empty. Request would be:
""" + prettify(xml))

        #~ assert env in (ENV_TEST, ENV_ACPT, ENV_PROD)
        assert env in CBSS_ENVS

        url = self.get_url(env)

        if True:
            #~ x = etree.tostring(elem)
            from suds.client import Client
            url += '?WSDL'
            client = Client(url)
            #~ print 20120507, url
            #~ print client
            res = client.service.sendXML(xml)
        else:

            if isinstance(self, NewStyleService):
                server = Resource(url, measure=True, **user_params)
            else:
                server = Resource(url, measure=True)
            res = server.soap(xml)
        return res
Example #3
0
def main():
    allocationReq1 = """<ns1:AllocationRequest xmlns:ns1="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationRequest" xmlns:com="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationDataTypes"><ns1:ComputeAllocation><ns1:PrimaryBeneficiary><ns1:SSIN>67031703807</ns1:SSIN><ns1:Category>1</ns1:Category></ns1:PrimaryBeneficiary><ns1:Invoice><com:Amount>8390100</com:Amount><com:Quantity>1000</com:Quantity><com:HousingNumber>1</com:HousingNumber><com:DeliveryDate>2011-09-19</com:DeliveryDate><com:UnitFuel>3</com:UnitFuel></ns1:Invoice></ns1:ComputeAllocation><ns1:OCMW_CPAS><ns1:KboBceNumber>0212344876</ns1:KboBceNumber></ns1:OCMW_CPAS></ns1:AllocationRequest>"""

    ssin = '67031703807'

    allocationReq = Object(
      ComputeAllocation=Object(
        Invoice=Object(
          Amount="8390100",
          Quantity=1000,
          HousingNumber=1,
          DeliveryDate="2011-09-19",
          UnitFuel=3),
        PrimaryBeneficiary=Object(SSIN=ssin,Category="1"),
      ),
      OCMW_CPAS=Object(KboBceNumber='0212344876')
      )
      
    ns = dict(
      ns1="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationRequest",
      com="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationDataTypes")
    nst = dict()
    nst.update(AllocationRequest='ns1')  
    nst.update(ComputeAllocation='ns1')  
    nst.update(OCMW_CPAS='******')  
    nst.update(KboBceNumber='ns1')  
    nst.update(Invoice='ns1')  
    nst.update(Quantity='com')  
    nst.update(HousingNumber='com')  
    nst.update(DeliveryDate='com')  
    nst.update(UnitFuel='com')

    m = XmlMarshaller(namespaces=ns,namespacedTags=nst,dumpXmlPrologue=False,rootTag="AllocationRequest")
    allocationReq2 = m.marshall(allocationReq)
      
    #~ assert_equivalent(allocationReq1,allocationReq2)

    contenu1 = """<SSDNRequest xmlns="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
    <RequestContext><AuthorizedUser><UserID>00901732883</UserID><Email>[email protected]</Email><OrgUnit>0212344876</OrgUnit><MatrixID>17</MatrixID><MatrixSubID>1</MatrixSubID></AuthorizedUser><Message><Reference>630230001126766</Reference><TimeRequest>20110921T105230</TimeRequest></Message></RequestContext><ServiceRequest><ServiceId>OCMWCPASHeatingAllocation</ServiceId><Version>20090409</Version>
    %s
    </ServiceRequest></SSDNRequest>""" % allocationReq1

    ssdnReq = Object(
        RequestContext=Object(
          AuthorizedUser=Object(**settings.SITE.bcss_user_params),
          Message=Object(Reference='630230001126766',TimeRequest='20110921T105230')
          ),
        ServiceRequest=Object(
          ServiceId="OCMWCPASHeatingAllocation",
          Version="20090409"
        ),
        _any=allocationReq2
        )
          
    m = AnyMarshaller(dumpXmlPrologue=False,
      rootTag='SSDNRequest',
      defaultNamespace="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service")
    contenu2 = m.marshall(ssdnReq)
      
    assert_equivalent(contenu1,contenu2)

    body = Object(
        #~ xmlString="<![CDATA[%s]]>" % contenu)
        xmlString=contenu2)
          
    raise Exception("ok jusqu'ici")

    server = Resource('https://bcssksz-services-test.smals.be/connectors/webservice/KSZBCSSWebServiceConnectorPort',measure=True)

    res = server.soap(body,namespace="http://ksz-bcss.fgov.be/connectors/WebServiceConnector")

    print res.code
    print res.data

    s = str(res.data.xmlString)
    #~ s = res.data.xmlString.replace('"UTF-8"','"utf-8"')
    #~ s = s.replace('?>','?>\n')
    print s

    reply = XmlUnmarshaller().parse(s)

    import pdb
    pdb.set_trace()
Example #4
0
def main():
    allocationReq1 = """<ns1:AllocationRequest xmlns:ns1="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationRequest" xmlns:com="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationDataTypes"><ns1:ComputeAllocation><ns1:PrimaryBeneficiary><ns1:SSIN>67031703807</ns1:SSIN><ns1:Category>1</ns1:Category></ns1:PrimaryBeneficiary><ns1:Invoice><com:Amount>8390100</com:Amount><com:Quantity>1000</com:Quantity><com:HousingNumber>1</com:HousingNumber><com:DeliveryDate>2011-09-19</com:DeliveryDate><com:UnitFuel>3</com:UnitFuel></ns1:Invoice></ns1:ComputeAllocation><ns1:OCMW_CPAS><ns1:KboBceNumber>0212344876</ns1:KboBceNumber></ns1:OCMW_CPAS></ns1:AllocationRequest>"""

    ssin = '67031703807'

    allocationReq = Object(ComputeAllocation=Object(
        Invoice=Object(Amount="8390100",
                       Quantity=1000,
                       HousingNumber=1,
                       DeliveryDate="2011-09-19",
                       UnitFuel=3),
        PrimaryBeneficiary=Object(SSIN=ssin, Category="1"),
    ),
                           OCMW_CPAS=Object(KboBceNumber='0212344876'))

    ns = dict(
        ns1="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationRequest",
        com="http://www.smals.be/XSD/OCMW_CPAS/HeatingAllocationDataTypes")
    nst = dict()
    nst.update(AllocationRequest='ns1')
    nst.update(ComputeAllocation='ns1')
    nst.update(OCMW_CPAS='******')
    nst.update(KboBceNumber='ns1')
    nst.update(Invoice='ns1')
    nst.update(Quantity='com')
    nst.update(HousingNumber='com')
    nst.update(DeliveryDate='com')
    nst.update(UnitFuel='com')

    m = XmlMarshaller(namespaces=ns,
                      namespacedTags=nst,
                      dumpXmlPrologue=False,
                      rootTag="AllocationRequest")
    allocationReq2 = m.marshall(allocationReq)

    #~ assert_equivalent(allocationReq1,allocationReq2)

    contenu1 = """<SSDNRequest xmlns="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service">
    <RequestContext><AuthorizedUser><UserID>00901732883</UserID><Email>[email protected]</Email><OrgUnit>0212344876</OrgUnit><MatrixID>17</MatrixID><MatrixSubID>1</MatrixSubID></AuthorizedUser><Message><Reference>630230001126766</Reference><TimeRequest>20110921T105230</TimeRequest></Message></RequestContext><ServiceRequest><ServiceId>OCMWCPASHeatingAllocation</ServiceId><Version>20090409</Version>
    %s
    </ServiceRequest></SSDNRequest>""" % allocationReq1

    ssdnReq = Object(RequestContext=Object(
        AuthorizedUser=Object(**settings.SITE.bcss_user_params),
        Message=Object(Reference='630230001126766',
                       TimeRequest='20110921T105230')),
                     ServiceRequest=Object(
                         ServiceId="OCMWCPASHeatingAllocation",
                         Version="20090409"),
                     _any=allocationReq2)

    ns = dict(xmlns="http://www.ksz-bcss.fgov.be/XSD/SSDN/Service")
    m = AnyMarshaller(namespaces=ns,
                      dumpXmlPrologue=False,
                      rootTag='SSDNRequest')
    contenu2 = m.marshall(ssdnReq)

    assert_equivalent(contenu1, contenu2)

    body = Object(
        #~ xmlString="<![CDATA[%s]]>" % contenu)
        xmlString=contenu2)

    raise Exception("ok jusqu'ici")

    server = Resource(
        'https://bcssksz-services-test.smals.be/connectors/webservice/KSZBCSSWebServiceConnectorPort',
        measure=True)

    res = server.soap(
        body,
        namespace="http://ksz-bcss.fgov.be/connectors/WebServiceConnector")

    print res.code
    print res.data

    s = str(res.data.xmlString)
    #~ s = res.data.xmlString.replace('"UTF-8"','"utf-8"')
    #~ s = s.replace('?>','?>\n')
    print s

    reply = XmlUnmarshaller().parse(s)

    import pdb
    pdb.set_trace()