Beispiel #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
 def moveFile(self, at, importPath):
     '''Copies file at p_at into the ODT file at p_importPath.'''
     # Has this image already been imported ?
     for imagePath, imageAt in self.fileNames.iteritems():
         if imageAt == at:
             # Yes!
             i = importPath.rfind(self.pictFolder) + 1
             return importPath[:i] + imagePath
     # The image has not already been imported: copy it.
     if not at.startswith('http'):
         shutil.copy(at, importPath)
         return importPath
     # The image must be retrieved via a URL. Try to perform a HTTP GET.
     response = Resource(at).get()
     if response.code == 200:
         # At last, I can get the file format.
         self.format = mimeTypesExts[response.headers['Content-Type']]
         importPath += self.format
         f = file(importPath, 'wb')
         f.write(response.body)
         f.close()
         return importPath
     # The HTTP GET did not work, maybe for security reasons (we probably
     # have no permission to get the file). But maybe the URL was a local
     # one, from an application server running this POD code. In this case,
     # if an image resolver has been given to POD, use it to retrieve the
     # image.
     imageResolver = self.renderer.imageResolver
     if not imageResolver:
         # Return some default image explaining that the image wasn't found.
         import appy.pod
         podFolder = os.path.dirname(appy.pod.__file__)
         img = os.path.join(podFolder, 'imageNotFound.jpg')
         self.format = 'jpg'
         importPath += self.format
         f = file(img)
         imageContent = f.read()
         f.close()
         f = file(importPath, 'wb')
         f.write(imageContent)
         f.close()
     else:
         # The imageResolver is a Zope application. From it, we will
         # retrieve the object on which the image is stored and get
         # the file to download.
         urlParts = urlparse.urlsplit(at)
         path = urlParts[2][1:].split('/')[:-1]
         try:
             obj = imageResolver.unrestrictedTraverse(path)
         except KeyError:
             # Maybe a rewrite rule as added some prefix to all URLs?
             obj = imageResolver.unrestrictedTraverse(path[1:])
         zopeFile = getattr(obj, urlParts[3].split('=')[1])
         appyFile = FileWrapper(zopeFile)
         self.format = mimeTypesExts[appyFile.mimeType]
         importPath += self.format
         appyFile.dump(importPath)
     return importPath
Beispiel #3
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
Beispiel #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
        )
          
    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()
Beispiel #5
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()