Fix GetCatalog
This commit is contained in:
1
getMetadata.data
Normal file
1
getMetadata.data
Normal file
File diff suppressed because one or more lines are too long
1
getObjects.data
Normal file
1
getObjects.data
Normal file
@@ -0,0 +1 @@
|
||||
b'{"files": [], "callback": "http://userv:8008/xmlrpc", "state": 0, "params": {"from": "tcp://kptsp_vb", "query_data": "<?xml version=\\"1.0\\" encoding=\\"utf-8\\"?><request><header parcel_id=\\"990715ba919544a98f22cc7d3b0d9e8d\\"/><objects><object object_id=\\"fc44343bd1654ee7b03ac1731567bbfd\\"/><object object_id=\\"13526ac78c574036879e1ec31bb78779\\"/><object object_id=\\"06b8a23c9a894bc5a5f9e6baa3540f87\\"/><object object_id=\\"6b02b39791064054852d5e165ff1dfc0\\"/><object object_id=\\"b81e42e704fe4054986956b2b920661d\\"/><object object_id=\\"c002a570f05745a2943a78686f3f17c0\\"/><object object_id=\\"2b15bf0f25e842b6a3b5d9762f2334a7\\"/><object object_id=\\"294ac9e83d3f4cf380cb0b99f592452b\\"/><object object_id=\\"a8901d5e642a410c909701e015644f69\\"/><object object_id=\\"1989b9dc8e114aaca0508cb9241afc5b\\"/><object object_id=\\"cf2df49a4e9143ffacf490b3138d26bd\\"/><object object_id=\\"c9861cfc30c641619ae9691f8c7d9c4d\\"/><object object_id=\\"87ebaff5ab2c411b97626b634d709f38\\"/><object object_id=\\"735e00c4211344bdaca2ac2332323613\\"/><object object_id=\\"05cff3bd9f6f4c36a51877c13fda1909\\"/><object object_id=\\"2178a4d06b6b407db826733c496a596d\\"/><object object_id=\\"8892c660d75747deaee6bab6163fde04\\"/><object object_id=\\"3be29dac7e6f45908910492967e3cb08\\"/><object object_id=\\"53667890f4f84e38a9cd7ab9a63a6193\\"/><object object_id=\\"69a3a5978f1e449f9729d5d47e0690ad\\"/><object object_id=\\"9405cc3528c345b1ad200714bb0fec32\\"/><object object_id=\\"068ab6d165004f9fb6d778a9e2593fd2\\"/><object object_id=\\"e90b6799c3a2418fa65f6e2f91c53f64\\"/><object object_id=\\"b209864a514a4d4eae7038a9585e9306\\"/><object object_id=\\"5f2287cdfeb54eddaa42cc80b21ec081\\"/><object object_id=\\"a87271f9a4e74b82bc9191cdc36c2783\\"/><object object_id=\\"bea81cc3b3e842e997594c6e95526456\\"/><object object_id=\\"13c6fc2edb544a2d98a4f3f10af4fdd1\\"/><object object_id=\\"9edb7a886d2847fbae83eba272cd3940\\"/><object object_id=\\"989e0d92955c4adfa3bfe045c6f11d82\\"/><object object_id=\\"0ebec61db2204477b4b49a20592c818a\\"/><object object_id=\\"d198d63bc9ed4dfb8f84c3fc5a4146c5\\"/><object object_id=\\"389482afd85147b2ac397a644f72e3dc\\"/><object object_id=\\"0e997a62f9c4421b93a284dad938faf4\\"/><object object_id=\\"dc29afc0ca53472d88e8b58e460ed614\\"/><object object_id=\\"ded736abc1954413b17e6d283c686b04\\"/><object object_id=\\"5de7020a497d4e119de0e6f5b869aba3\\"/><object object_id=\\"d3cfdc9e51fc489cac8a8a9e6285f292\\"/><object object_id=\\"b812ed1698e2454dbf84595a2addff8f\\"/><object object_id=\\"fa28d2774a054542a6b7c437ee68f148\\"/><object object_id=\\"b7fab9c8285f47b699cb5bb6259b7b03\\"/><object object_id=\\"f8f867f7aa964785ab1e0e84428070c2\\"/><object object_id=\\"d1cb0bb2c21e4e99b06fcda8f627c720\\"/><object object_id=\\"41f6531a611143f3a64d3e55f347ed06\\"/><object object_id=\\"6fb3b57ec8df48e4bfe6f19bef387a61\\"/><object object_id=\\"97598f541b494606a437a9b5ee5433aa\\"/><object object_id=\\"d5289e3969cc47a7b50a01ed6f4b41fd\\"/><object object_id=\\"22ba8c4cf4154874ac98ec42cd053d72\\"/><object object_id=\\"7ec173a9d51e4babbc0feae70d754c99\\"/><object object_id=\\"343cd1ee95ce4a3e9d51336a2d0291e9\\"/></objects></request>", "query_type": 1, "to": "tcp://bnd127", "user_id": "3302", "ts_added": 1679825320.653038}}'
|
||||
50
main.py
50
main.py
@@ -1,11 +1,15 @@
|
||||
import datetime
|
||||
from uuid import uuid4
|
||||
from xmlrpc.server import SimpleXMLRPCServer
|
||||
from xmlrpc.client import ServerProxy
|
||||
import logging
|
||||
import os
|
||||
import requests.graphql
|
||||
import os.path
|
||||
from requests.graphql import get_catalog
|
||||
from pygost import gost34112012256
|
||||
|
||||
import xml.etree.ElementTree as ET
|
||||
from requests.request_xml_service import RequestXmlService
|
||||
import zipfile
|
||||
|
||||
PASSWORD = 'gost_2012$a742ec53198ec2a5027086fba8814a89982a57112d1a72d02260161108f39b50'
|
||||
|
||||
@@ -29,25 +33,57 @@ def auth_response(challenge, server_id, is_server):
|
||||
|
||||
|
||||
def auth_challenge():
|
||||
logging.debug('get challenge')
|
||||
# logging.debug('get challenge')
|
||||
return uuid4().hex
|
||||
|
||||
|
||||
def accept(params, files, url):
|
||||
print(params, files, url)
|
||||
print('Accept')
|
||||
date = datetime.datetime.now()
|
||||
if params['query_type'] == 4:
|
||||
rxmls = RequestXmlService()
|
||||
req = ET.fromstring(params['query_data'])
|
||||
req_id = rxmls.get_request_uuid(req)
|
||||
res_id = uuid4().hex
|
||||
res = rxmls.get_request_document(res_id, req_id)
|
||||
rxmls.set_result(res, 0, '')
|
||||
response_params = {
|
||||
'from': params['to'],
|
||||
'to': params['from'],
|
||||
'ts_added': date.timestamp(),
|
||||
'user_id': '1',
|
||||
'user_id_to': '3302',
|
||||
'query_type': 1004,
|
||||
'query_data': ET.tostring(res, encoding='unicode', xml_declaration=True)
|
||||
}
|
||||
catalog = get_catalog()
|
||||
filename = uuid4().hex
|
||||
filepath = '/tmp/' + filename
|
||||
zipf = zipfile.ZipFile(filepath, "w")
|
||||
zipf.writestr('WF.CLL', catalog)
|
||||
zipf.close()
|
||||
response_files = [{'name': filename, 'url': filepath, 'size': os.path.getsize(filepath)}]
|
||||
proxy = ServerProxy(url)
|
||||
proxy.send(response_params, response_files, 'http://10.10.8.27:9000/')
|
||||
return True
|
||||
|
||||
|
||||
def onSent(params, files, callback_url):
|
||||
print('onSent')
|
||||
|
||||
|
||||
def main():
|
||||
print('Use Control-C to exit')
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
server = SimpleXMLRPCServer(('0.0.0.0', 9000), logRequests=True)
|
||||
server = SimpleXMLRPCServer(('0.0.0.0', 9000), logRequests=True, allow_none=True)
|
||||
server.register_function(list_contents)
|
||||
server.register_function(aud_add)
|
||||
server.register_function(auth_response)
|
||||
server.register_function(auth_challenge)
|
||||
server.register_function(accept)
|
||||
server.register_function(onSent)
|
||||
|
||||
try:
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
@@ -55,8 +91,10 @@ def main():
|
||||
|
||||
|
||||
def test():
|
||||
print(requests.graphql.get_classifier())
|
||||
# print(requests.graphql.get_catalog())
|
||||
params = {'from': 'tcp://kptsp_vb', 'query_data': '<?xml version="1.0" encoding="utf-8"?><request><header parcel_id="1665c872f24e46589f36d264a75a72dd"/><getCatalog from="1675776233.21" withRef="NO"/></request>', 'query_type': 4, 'to': 'tcp://bnd127', 'user_id': '1', 'ts_added': 1679213998.282467}
|
||||
files = []
|
||||
url = 'http://127.0.0.1:7000/xmlrpc'
|
||||
accept(params, files, url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -53,7 +53,7 @@ class Catalog:
|
||||
return ET.tostring(collections, encoding='unicode', xml_declaration=True)
|
||||
|
||||
def date_to_string(self, date):
|
||||
return ''
|
||||
return str(date.timestamp())
|
||||
|
||||
def write_collections(self, collections, date):
|
||||
collection = ET.SubElement(collections, self.COLLECTION_TAG_NAME, {
|
||||
@@ -70,7 +70,3 @@ class Catalog:
|
||||
|
||||
def write_chart(self, charts, chart):
|
||||
ch = ET.SubElement(charts, self.CHART_TAG_NAME)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -27,4 +27,4 @@ def get_catalog():
|
||||
"""
|
||||
)
|
||||
result = client.execute(query)
|
||||
return result['getClassifier']
|
||||
return result['getCatalog']
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import xml.etree.ElementTree as ET
|
||||
from messages import Messages
|
||||
from requests.messages import Messages
|
||||
|
||||
|
||||
class RequestXmlService:
|
||||
@@ -11,7 +11,7 @@ class RequestXmlService:
|
||||
SOURCE_REQUEST_ID_ATTRIBUTE_NAME: str = 'source_parcel_id'
|
||||
RESULT_CODE_ATTRIBUTE_NAME: str = 'result_code'
|
||||
RESULT_MESSAGE_ATTRIBUTE_NAME: str = 'result_message'
|
||||
HEADER_XPATH: str = '/' + REQUEST_NODE_NAME + '/' + HEADER_NODE_NAME
|
||||
HEADER_XPATH: str = HEADER_NODE_NAME
|
||||
|
||||
def get_request_uuid(self, document: ET.Element) -> str:
|
||||
return self.get_header_attribute(document, self.REQUEST_ID_ATTRIBUTE_NAME)
|
||||
@@ -27,7 +27,7 @@ class RequestXmlService:
|
||||
|
||||
def get_header_attribute(self, document: ET.Element, attribute_name: str) -> str:
|
||||
header = self.get_header_node(document)
|
||||
if not header:
|
||||
if header is None:
|
||||
raise Exception(Messages.MISSING_TAG.value)
|
||||
result = header.get(attribute_name)
|
||||
return result.strip() if result else ''
|
||||
@@ -51,6 +51,8 @@ class RequestXmlService:
|
||||
|
||||
def set_result(self, document: ET.Element, result_code: int, result_message: str):
|
||||
result = document.find(self.RESULT_NODE_NAME)
|
||||
if result is None:
|
||||
result = ET.SubElement(document, self.RESULT_NODE_NAME)
|
||||
result.set(self.RESULT_CODE_ATTRIBUTE_NAME, str(result_code))
|
||||
result.set(self.RESULT_MESSAGE_ATTRIBUTE_NAME, result_message)
|
||||
|
||||
|
||||
1
tmp.data
Normal file
1
tmp.data
Normal file
@@ -0,0 +1 @@
|
||||
{'from': 'tcp://kptsp_vb', 'query_data': '<?xml version="1.0" encoding="utf-8"?><request><header parcel_id="1665c872f24e46589f36d264a75a72dd"/><getCatalog from="1675776233.21" withRef="NO"/></request>', 'query_type': 4, 'to': 'tcp://bnd127', 'user_id': '1', 'ts_added': 1679213998.282467} [] http://127.0.0.1:7000/xmlrpc
|
||||
Reference in New Issue
Block a user