Difference between revisions of "SOAP Despatcher"
Jump to navigation
Jump to search
m (PCMS SOAP Despatcher moved to SOAP Despatcher) |
|||
| Line 37: | Line 37: | ||
payload_template = """<?xml version="1.0" encoding="UTF-8"?> | payload_template = """<?xml version="1.0" encoding="UTF-8"?> | ||
< | <XXXX xmlns="http://www.xxxx.com.au/xml/soap"> | ||
< | <SendManifest> | ||
<header> | <header> | ||
<TransactionDateTime>2008-01-10T11:30:00.0Z</TransactionDateTime> | <TransactionDateTime>2008-01-10T11:30:00.0Z</TransactionDateTime> | ||
<TransactionId> | <TransactionId>XX-0000000001</TransactionId> | ||
<TransactionSequence>1</TransactionSequence> | <TransactionSequence>1</TransactionSequence> | ||
<ApplicationId>MERCHANT</ApplicationId> | <ApplicationId>MERCHANT</ApplicationId> | ||
</header> | </header> | ||
<body> | <body> | ||
< | <Manifest> | ||
<MerchantLocationId>ALG</MerchantLocationId> | <MerchantLocationId>ALG</MerchantLocationId> | ||
<ManifestNumber>P%d</ManifestNumber> | <ManifestNumber>P%d</ManifestNumber> | ||
<DateSubmitted>2008-01-21T11:30:00.0Z</DateSubmitted> | <DateSubmitted>2008-01-21T11:30:00.0Z</DateSubmitted> | ||
<DateLodged>2008-01-21T11:30:00.0Z</DateLodged> | <DateLodged>2008-01-21T11:30:00.0Z</DateLodged> | ||
< | <Consignment> | ||
<ConsignmentNumber>ALG%07d</ConsignmentNumber> | <ConsignmentNumber>ALG%07d</ConsignmentNumber> | ||
<ChargeCode>S1</ChargeCode> | <ChargeCode>S1</ChargeCode> | ||
| Line 60: | Line 60: | ||
<DeliveryCompanyName>Joe's Garage</DeliveryCompanyName> | <DeliveryCompanyName>Joe's Garage</DeliveryCompanyName> | ||
<DeliveryAddressLine1>Level 22</DeliveryAddressLine1> | <DeliveryAddressLine1>Level 22</DeliveryAddressLine1> | ||
<DeliveryAddressLine2> | <DeliveryAddressLine2>120 Lonsdale St</DeliveryAddressLine2> | ||
<DeliveryAddressLine3>Off Russell St</DeliveryAddressLine3> | <DeliveryAddressLine3>Off Russell St</DeliveryAddressLine3> | ||
<DeliveryAddressLine4>Corner of Lonsdale St</DeliveryAddressLine4> | <DeliveryAddressLine4>Corner of Lonsdale St</DeliveryAddressLine4> | ||
<DeliveryPhoneNumber>+61398989898</DeliveryPhoneNumber> | <DeliveryPhoneNumber>+61398989898</DeliveryPhoneNumber> | ||
<DeliveryEmailAddress>joe.bloggs@ | <DeliveryEmailAddress>joe.bloggs@xxxx.com.au</DeliveryEmailAddress> | ||
<DeliverySuburb>BUSSELTON</DeliverySuburb> | <DeliverySuburb>BUSSELTON</DeliverySuburb> | ||
<DeliveryStateCode>WA</DeliveryStateCode> | <DeliveryStateCode>WA</DeliveryStateCode> | ||
| Line 83: | Line 83: | ||
<DeliverPartConsignment>N</DeliverPartConsignment> | <DeliverPartConsignment>N</DeliverPartConsignment> | ||
<ContainsDangerousGoods>false</ContainsDangerousGoods> | <ContainsDangerousGoods>false</ContainsDangerousGoods> | ||
< | <DomesticArticle> | ||
<ArticleNumber>ALG%013d</ArticleNumber> | <ArticleNumber>ALG%013d</ArticleNumber> | ||
<BarcodeArticleNumber>99700122BBD100000101011503000</BarcodeArticleNumber> | <BarcodeArticleNumber>99700122BBD100000101011503000</BarcodeArticleNumber> | ||
| Line 101: | Line 101: | ||
<Value>100</Value> | <Value>100</Value> | ||
</ContentsItem> | </ContentsItem> | ||
</ | </DomesticArticle> | ||
</ | </Consignment> | ||
</ | </Manifest> | ||
</body> | </body> | ||
</ | </SendManifest> | ||
</ | </XXXX>""" | ||
#------------------------------------------------------------------------------- | #------------------------------------------------------------------------------- | ||
soap_env = """<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:epar="http://www. | soap_env = """<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:epar="http://www.xxxx.com.au/eParcel"> | ||
<soapenv:Header/> | <soapenv:Header/> | ||
<soapenv:Body> | <soapenv:Body> | ||
Revision as of 15:02, 18 July 2008
Python HTTPLIB version
$ cat desp_02.py
#!/usr/bin/env python
import os
import binascii
import httplib
import urllib
from copy import copy
#-------------------------------------------------------------------------------
post_data = urllib.urlencode({'spam': 1, 'eggs': 2})
# "Content-type" : "application/x-www-form-urlencoded",
#-------------------------------------------------------------------------------
post_headers = {
'Content-type' : 'text/xml;charset=UTF-8',
'SOAPAction' : '',
'User-Agent' : 'Jakarta Commons-HttpClient/3.0.1',
'Host' : 'hx403'
}
payload_constants = (13, 21110, 603010230)
# post_data = {}
# ue_post_data = urllib.urlencode(post_data)
#-------------------------------------------------------------------------------
payload_template = """<?xml version="1.0" encoding="UTF-8"?>
<XXXX xmlns="http://www.xxxx.com.au/xml/soap">
<SendManifest>
<header>
<TransactionDateTime>2008-01-10T11:30:00.0Z</TransactionDateTime>
<TransactionId>XX-0000000001</TransactionId>
<TransactionSequence>1</TransactionSequence>
<ApplicationId>MERCHANT</ApplicationId>
</header>
<body>
<Manifest>
<MerchantLocationId>ALG</MerchantLocationId>
<ManifestNumber>P%d</ManifestNumber>
<DateSubmitted>2008-01-21T11:30:00.0Z</DateSubmitted>
<DateLodged>2008-01-21T11:30:00.0Z</DateLodged>
<Consignment>
<ConsignmentNumber>ALG%07d</ConsignmentNumber>
<ChargeCode>S1</ChargeCode>
<InternalChargebackAccount>Finance</InternalChargebackAccount>
<ReferenceNo1>Job #1</ReferenceNo1>
<ReferenceNo2>Invoice #1</ReferenceNo2>
<DeliveryName>Joe Bloggs</DeliveryName>
<DeliveryCompanyName>Joe's Garage</DeliveryCompanyName>
<DeliveryAddressLine1>Level 22</DeliveryAddressLine1>
<DeliveryAddressLine2>120 Lonsdale St</DeliveryAddressLine2>
<DeliveryAddressLine3>Off Russell St</DeliveryAddressLine3>
<DeliveryAddressLine4>Corner of Lonsdale St</DeliveryAddressLine4>
<DeliveryPhoneNumber>+61398989898</DeliveryPhoneNumber>
<DeliveryEmailAddress>joe.bloggs@xxxx.com.au</DeliveryEmailAddress>
<DeliverySuburb>BUSSELTON</DeliverySuburb>
<DeliveryStateCode>WA</DeliveryStateCode>
<DeliveryPostcode>6280</DeliveryPostcode>
<DeliveryCountryCode>AU</DeliveryCountryCode>
<DeliveryInstructions>Pick up parcel.</DeliveryInstructions>
<IsInternationalDelivery>false</IsInternationalDelivery>
<ReturnName>Rocket Records P/L</ReturnName>
<ReturnAddressLine1>58-76 Stephenson Rd</ReturnAddressLine1>
<ReturnSuburb>Cremorne</ReturnSuburb>
<ReturnStateCode>VIC</ReturnStateCode>
<ReturnPostcode>3121</ReturnPostcode>
<ReturnCountryCode>AU</ReturnCountryCode>
<CreatedDateTime>2008-01-21T12:18:32.106+11:00</CreatedDateTime>
<PostChargeToAccount>5903000</PostChargeToAccount>
<IsSignatureRequired>Y</IsSignatureRequired>
<CTCAmount>0.00</CTCAmount>
<DeliverPartConsignment>N</DeliverPartConsignment>
<ContainsDangerousGoods>false</ContainsDangerousGoods>
<DomesticArticle>
<ArticleNumber>ALG%013d</ArticleNumber>
<BarcodeArticleNumber>99700122BBD100000101011503000</BarcodeArticleNumber>
<Length>12</Length>
<Width>14</Width>
<Height>16</Height>
<ActualWeight>0.5</ActualWeight>
<CubicWeight>0.5</CubicWeight>
<ArticleDescription>SOAP Test Article</ArticleDescription>
<IsTransitCoverRequired>N</IsTransitCoverRequired>
<TransitCoverAmount>0</TransitCoverAmount>
<ContentsItem>
<GoodsDescription>SOAP Test Goods</GoodsDescription>
<Weight>0.5</Weight>
<Quantity>1</Quantity>
<UnitValue>100.00</UnitValue>
<Value>100</Value>
</ContentsItem>
</DomesticArticle>
</Consignment>
</Manifest>
</body>
</SendManifest>
</XXXX>"""
#-------------------------------------------------------------------------------
soap_env = """<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:epar="http://www.xxxx.com.au/eParcel">
<soapenv:Header/>
<soapenv:Body>
<epar:submitManifestForDespatch soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<string xsi:type="xsd:string"><![CDATA[%s]]></string></epar:submitManifestForDespatch></soapenv:Body>
</soapenv:Envelope>"""
#-------------------------------------------------------------------------------
cookie = binascii.b2a_base64("xxxxx:xxxxx")[:-1]
print '[%s]' % cookie
headers = copy(post_headers)
headers['Authorization'] = 'Basic %s' % cookie
headers['Content-Length'] = len(post_data)
print headers
DO = 'POST'
URL = '/despatchManifest/DespatchManifestWS'
HOST = 'HOST'
manifest = payload_template % payload_constants
print manifest
post_data = soap_env % manifest
print post_data
#-------------------------------------------------------------------------------
conn = httplib.HTTPConnection(HOST)
conn.request(DO, URL, post_data_01, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data
conn.close()
#-------------------------------------------------------------------------------