I'm stuck at generating custom reports using Statistics Collector.
My scenario,
I have an BaaS DB with a collection named "icustomer" which has few name/value pair's.
I created a proxy(icustomer) to display an specific Customer(Resource name- specificcust) depending on unique "cust_id".
For Specific Customer I did "extract variable and assign variable policies" which is working fine.
Now to get custom reports I again added an Extract Variable policy to extract cust_id from JSON Path and then added and Statistic Collector policy to get stats.
Then I created an new report from Analytics and saved it. But reports aren't generated. All I get is "NO_ID" report.
Where did I go wrong?
Proxy Endpoint Code
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
<Description/>
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<Flows>
<Flow name="specficcust">
<Description/>
<Request/>
<Response/>
<Condition>(proxy.pathsuffix MatchesPath "/{cust_id}") and (request.verb = "GET")</Condition>
</Flow>
</Flows>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
<HTTPProxyConnection>
<BasePath>/icustomer</BasePath>
<VirtualHost>default</VirtualHost>
<VirtualHost>secure</VirtualHost>
</HTTPProxyConnection>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
</ProxyEndpoint>
Target Endpoint Code
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<Description/>
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<Flows>
<Flow name="specficcust">
<Description/>
<Request>
<Step>
<FaultRules/>
<Name>Extract-Variables-1</Name>
</Step>
<Step>
<FaultRules/>
<Name>Assign-Message-1</Name>
</Step>
</Request>
<Condition>(proxy.pathsuffix MatchesPath "/{cust_id}") and (request.verb = "GET")</Condition>
<Response/>
</Flow>
</Flows>
<PostFlow name="PostFlow">
<Response>
<Step>
<FaultRules/>
<Name>Extracting-for-Stats</Name>
</Step>
<Step>
<FaultRules/>
<Name>Statistics-Collector-1</Name>
</Step>
</Response>
<Request/>
</PostFlow>
<HTTPTargetConnection>
<URL>https://api.usergrid.com/siddharth1/sandbox/icustomer</URL>
</HTTPTargetConnection>
</TargetEndpoint>
Extracting for Stats code-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extracting-for-Stats">
<DisplayName>Extracting for Stats</DisplayName>
<FaultRules/>
<Properties/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<JSONPayload>
<Variable name="customer_id">
<JSONPath>$.entities[0].cust_id</JSONPath>
</Variable>
</JSONPayload>
<Source clearPayload="false">response</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>
Statistics Collector code-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<StatisticsCollector async="false" continueOnError="false" enabled="true" name="Statistics-Collector-1">
<DisplayName>Statistics Collector 1</DisplayName>
<FaultRules/>
<Properties/>
<Statistics>
<Statistic name="test_cust_id" ref="customer_id" type="STRING">NO_ID</Statistic>
</Statistics>
</StatisticsCollector>
Your ExtractVariables specifies a VariablePrefix of "apigee". I would expect the extracted field to be accessible from apigee.customer_id instead of just customer_id, which would return null in the StatisticsCollector check. I think that's why you are getting your default "NO_ID".
Related
i'm implementing a DRM server, so far HLS is working great but i have a problem with the playready key encryption, i know that i need to use the public key and License Nonce(IV) from the client request but i couldn't find the algorithm to encrypt it.
example from Microsoft playReady test server
client requst:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AcquireLicense xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols">
<challenge>
<Challenge xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/messages">
<LA xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols" Id="SignedData" xml:space="preserve">
<Version>1</Version>
<ContentHeader>
<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0">
<DATA>
<PROTECTINFO>
<KEYLEN>16</KEYLEN>
<ALGID>AESCTR</ALGID>
</PROTECTINFO>
<KID>7987aj+eE0uBlXi0N73AQw==</KID>
<CHECKSUM>s1zZSs3Wwow=</CHECKSUM>
<CUSTOMATTRIBUTES>
<IIS_DRM_VERSION>7.1.1064.0</IIS_DRM_VERSION>
</CUSTOMATTRIBUTES>
<LA_URL>http://playready.directtaps.net/pr/svc/rightsmanager.asmx</LA_URL>
<DS_ID>AH+03juKbUGbHl1V/QIwRA==</DS_ID>
</DATA>
</WRMHEADER>
</ContentHeader>
<CLIENTINFO>
<CLIENTVERSION>2.0.0.1446</CLIENTVERSION>
</CLIENTINFO>
<RevocationLists>
<RevListInfo>
<ListID>ioydTlK2p0WXkWklprR5Hw==</ListID>
<Version>11</Version>
</RevListInfo>
<RevListInfo>
<ListID>gC4IKKPHsUCCVhnlttibJw==</ListID>
<Version>11</Version>
</RevListInfo>
<RevListInfo>
<ListID>BOZ1zT1UnEqfCf5tJOi/kA==</ListID>
<Version>12</Version>
</RevListInfo>
<RevListInfo>
<ListID>Ef/RUojT3U6Ct2jqTCChbA==</ListID>
<Version>34</Version>
</RevListInfo>
</RevocationLists>
<LicenseNonce>e7NgfwBi1xX/egdgV9BrWQ==</LicenseNonce>
<EncryptedData xmlns="http://www.w3.org/2001/04/xmlenc#" Type="http://www.w3.org/2001/04/xmlenc#Element">
<EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-cbc" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<EncryptedKey xmlns="http://www.w3.org/2001/04/xmlenc#">
<EncryptionMethod Algorithm="http://schemas.microsoft.com/DRM/2007/03/protocols#ecc256" />
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyName>WMRMServer</KeyName>
</KeyInfo>
<CipherData>
<CipherValue>W13Rs+iFyn5Qgh8iAduenxsRw3w2mOTNhfOPI6Fwv5kIn93cCauDFJexka6jtQHJ+by8wyTv4u7RofeZW9G8NakvV0JpGg7d5rEg1q1XMwy267Hecnch75FKEPSiydx2NU83IambHenRhJJ5gg3/u1aVpaXsCVtnQsv5pt5L+JM=</CipherValue>
</CipherData>
</EncryptedKey>
</KeyInfo>
<CipherData>
<CipherValue>cWEqivcZkvs9Le02WXFsSnCn8W+J87cN0a0/6IXZ1OIYJ8ZgVE2Bf6J14Destd4rYxKonQiMZ5mL+LZytuq7dA8LGFASKUNGKynx887tdMDMbwJnBQAllE593kUqnD4XIyKO04APahlQ1k4ezBrTU3o0TD8ssIN2OxxW4NdoNMPc+rlrPMY31hXVoIdUV7viueMRFcokDgDk/vii3yrHfLpx+iyVINhYhye1Oh0JsKc8Fkz/O1XfSrCVQzVZHI3Hui62r/Pf9H1kblv7CXo1H7Vno8trNq2zsEj96lz2b2GgYpbbiMHBJAMmIjsR6o9z3KUbOIh0eIrupDLTTvITDXDX8Q9x1A9dsDOJJGWMgWUT2n0Ay6GIzATojlMfp9eCti2gJNWv+vWKJD0k2k/COk71mcWttGgA4dnxUqCkkr7wSI/mAmxb/ZHaNFBoF55sUTycsoYrucD60XHeZA3OB/1NIodczWfMwCE1UGiSXpafdxDsBxgdlDXQxHzlWXhQBzVWNdjpdLVv7NMteA8t6MqmD+i+xlOD/rI5ZWb9uNmBNMNF2KkgBLHx9NQx5BQReQonL1wHcEfk/SjiovRFx33aYkfDZZwx1QmIR6xhksktwpvO/z0Bud9II3gle/Is5XgQwXET25KRvJ/pZlIvwXuklpgzBFMTU71RbaKWWTeLk9zddw0bb0O/dNm8HX6JmZIv1VHz/D/p0l7L+JyG5xl1DxxIxJOIuVkhucdFJDVRlMbNXp2/hMTKpK9Ph70TQNJx2hOvSEFwOjGsUpaGOI8z6r3zFpObg3w6VpeCBQNipekxSvgcedk2DNELYsFvTn5moxPEwCrPwYurg3dBbzSvgfZm67H/h319B/spg76MGiTauXl54LkOKQC2gWF/t7e9bV0NBZR5cAPwa346d5hWPnU/s1hAEKh8k5PZfQlHX9MY4ktYHe+16y4GhlN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bwvS4Hh/42akPyA2Y8wjH+VoDesuxVzzr4g4pBMCWNVk7Q5WhfsoaA0WiV+mhK4VcPxMms8sGBGoZllQnwPh7JYy9Hz0wDg0OUAe8BLv/YwETYZwa0qlkLl4OMPAy8bSG8wo4TJeUubVF9FJeswXUt5K/FIv6S3AroecmGih9XIHNKnST9BTlcDSoxsLMfoYrQmFr8xJyJw/i+DtZr2zC1CUqBNGyvov9qFatys/HDe18KO51O/ahyUSjHEsCPCqxQfoQstvD7ZE/SN8c3ZZLNBqQ4SPY2jPqtsmzVch4HTzhpFxyqXwe2uHaccCuNwlSmewDY2VkQDbWdvRPHzLPsHOPZJdcVvRw/C8S4wJNZ03GDiYHThJjWv7wgnpIUA/i68u7t6uS33xlPAlytIefnNpXA5bc6QDTzKJW9gwJ8hlxcsHxfO8d3+oij9/vqDQMG9j0EponBs1ewNaGTg8rniisnATQwQEZo4USNTE+VneWnaY1wLOSExCIv6glJ+oMfPvZT/pq/uhz6C7u7gfvVvTG3eY3/srKRE5baKwI8MJCEEqmWonHM5C+NRboRFMpqO5AR5X27YrSsa38xen8f1VHnzYLFr0UdkprbLbm/dvFpaxivYTqfCVQEXaFMTfNp884OylSAcmvNZbUvrCyritL5xiBm/1rxypDprDv0X0C1WR9rfGilbpqc8MdqcBgmsSpJO1zW43LBBPI6U4/oBlpYKx+T2ovlq/zdgwrtmX/rp6BB+nXFtWdgJZWYN+4cwF0FooIAF8hXNiJGWR9tVPipT7s00BaL0u8udR59W/2T79vUIt0PMpuVHFmp7ZSZumsr2W1pTybmmuj5Lv54XoXryTE63GZYZRhiEE5uS3hwSWLqxd0xyCnz6ThuWaS6N0+rlxDVM+9Z1rlIhR4C5YJ5LJ2xpZFsS1apXPLm+QQ7SM1lspF/bSlHv4m3/LJqaK/sbaLAaxORDF1uE6</CipherValue>
</CipherData>
</EncryptedData>
</LA>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />
<SignatureMethod Algorithm="http://schemas.microsoft.com/DRM/2007/03/protocols#ecdsa-sha256" />
<Reference URI="#SignedData">
<DigestMethod Algorithm="http://schemas.microsoft.com/DRM/2007/03/protocols#sha256" />
<DigestValue>Y6z9FSz2qWpvIN823wrK13in0TnWGoAcPCKw9KlWZPk=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>u45hKzad6Wir2SLSY7WTkTxpziPY2w5WTiLbNSb0RyciFV8Xm2aFyLbOCpMW33ZYubN59lsaZy8fAjUsr7ManA==</SignatureValue>
<KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
<KeyValue>
<ECCKeyValue>
<PublicKey>2sumijs/TOhMhxwvkmjp4nXwJku8UXFHU+oY4fg+sRTp/pM7O3/w4k4QXAAn69pHahdLN+6OGpnQfwTv4xzGCQ==</PublicKey>
</ECCKeyValue>
</KeyValue>
</KeyInfo>
</Signature>
</Challenge>
</challenge>
</AcquireLicense>
</soap:Body>
</soap:Envelope>
server response:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<AcquireLicenseResponse xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols">
<AcquireLicenseResult>
<Response xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols/messages">
<LicenseResponse xmlns="http://schemas.microsoft.com/DRM/2007/03/protocols">
<Version>1</Version>
<Licenses>
<License>WE1SAAAAAAN7s2B/AGLXFf96B2BX0GtZAAMAAQAAAVAAAgAEAAAACAADAAIAAAAyAAAADQAAAAoAAQABADIAAAAMAAAAIgABADQAAAAKAJYAAAAzAAAACgABAAMACQAAAPIAAQAKAAAAnu/fO2o/nhNLgZV4tDe9wEMAAQADAIDB6u6Ltq5a8s2SvNkd4kAVzxDnlUysqzX6k5epsJ4iNaZaFyLTtpgVjTRQP2lgDeJaJSIObuf2yd2Qd1tWIQDk4gXxCbUPL8NJgdvl6d4z2xBIvJq4Ol3KDiHgkYn6mYEyniIm+2IWZUrUWsKo6Z2brnsoe3GoYoNmXkJ5+kyMOgAAACoAAABMAAEAQDrjNbZngMLUdzVuWakTkwXziavX6rZhzIaQJYQOWLtJSqiFpiWTutb777SRP48Zvx2FMpyqhGdjn53dLmsiRDYAAQALAAAAHAABABB8/phYFmuGw7Y3HoQs0swN</License>
</Licenses>
<Acknowledgement>
<TransactionID>5c062475-4b2c-48e6-9b0b-54fce5b2b770</TransactionID>
</Acknowledgement>
</LicenseResponse>
</Response>
</AcquireLicenseResult>
</AcquireLicenseResponse>
</soap:Body>
</soap:Envelope>
how do i create the License from the client request and my 16 byte key?
as the title says, I can successfully create a new Product via Prestashop 1.6.1 webservice. The problem is that the new product XML has an empty stock_available section:
<stock_availables nodeType="stock_available" api="stock_availables" />
so I have no idea how to set the initial quantity for that product. If I set it manually from the back office, the stock_available section is filled.
Maybe there is something I'm missing in the XML request? Here it is:
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<product>
<id/>
<id_manufacturer/>
<id_supplier/>
<id_category_default>52</id_category_default>
<new/>
<cache_default_attribute/>
<id_default_image/>
<id_default_combination/>
<id_tax_rules_group/>
<position_in_category/>
<type/>
<id_shop_default/>
<reference>A130</reference>
<supplier_reference/>
<location/>
<width/>
<height/>
<depth/>
<weight/>
<quantity_discount/>
<ean13/>
<upc/>
<cache_is_pack/>
<cache_has_attachments/>
<is_virtual/>
<on_sale/>
<online_only/>
<ecotax/>
<minimal_quantity/>
<price>1.30</price>
<wholesale_price/>
<unity/>
<unit_price_ratio/>
<additional_shipping_cost/>
<customizable/>
<text_fields/>
<uploadable_files/>
<active>1</active>
<redirect_type/>
<id_product_redirected/>
<available_for_order>1</available_for_order>
<available_date/>
<condition/>
<show_price>1</show_price>
<indexed>1</indexed>
<visibility/>
<advanced_stock_management/>
<date_add/>
<date_upd/>
<pack_stock_type/>
<meta_description>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</meta_description>
<meta_keywords>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</meta_keywords>
<meta_title>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</meta_title>
<link_rewrite>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</link_rewrite>
<name>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</name>
<description>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</description>
<description_short>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</description_short>
<available_now>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[product name]]></language>
</available_now>
<available_later>
<language id="1" xlink:href="http://www.mysite.it/prestashop/api/languages/1"><![CDATA[available later]]></language>
</available_later>
<associations>
<categories>
<category>
<id/>
</category>
<category>
<id>52</id>
</category>
</categories>
<images>
<image>
<id/>
</image>
</images>
<combinations>
<combination>
<id/>
</combination>
</combinations>
<product_option_values>
<product_option_value>
<id/>
</product_option_value>
</product_option_values>
<product_features>
<product_feature>
<id/>
<id_feature_value/>
</product_feature>
</product_features>
<tags>
<tag>
<id/>
</tag>
</tags>
<stock_availables>
<stock_available>
<id/>
<id_product_attribute/>
</stock_available>
</stock_availables>
<accessories>
<product>
<id/>
</product>
</accessories>
<product_bundle>
<product>
<id/>
<quantity/>
</product>
</product_bundle>
</associations>
</product>
</prestashop>
Thank you for any help!
Iuri
The problem was probably a bug with that version of Prestashop. With the latest version (1.6.1.17) it works correctly.
TL;DR: I have a multline CSV and I want to process line by line and generate a different XML for each line.
I have the following CSV:
Chathuri,Wimalasena,Female,25,SriLanka
Saminda,Wijerathne,Male,26,SriLanka
Dakshitha,Rathnayaka,Female,24,SriLanka
Harsha,Martin,Male,24,SriLanka
Currently I am using smooks and doing the following transformation:
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<people>
<person>
<lastname>Wimalasena</lastname>
<firstname>Chathuri</firstname>
<gender>Female</gender>
<age>25</age>
<country>SriLanka</country>
</person>
<person>
<lastname>Wijerathne</lastname>
<firstname>Saminda</firstname>
<gender>Male</gender>
<age>26</age>
<country>SriLanka</country>
</person>
<person>
<lastname>Rathnayaka</lastname>
<firstname>Dakshitha</firstname>
<gender>Female</gender>
<age>24</age>
<country>SriLanka</country>
</person>
<person>
<lastname>Martin</lastname>
<firstname>Harsha</firstname>
<gender>Male</gender>
<age>24</age>
<country>SriLanka</country>
</person>
</people>
</soapenv:Body>
</soapenv:Envelope>
The questions is: I want something like this:
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<people>
<person>
<lastname>Wimalasena</lastname>
<firstname>Chathuri</firstname>
<gender>Female</gender>
<age>25</age>
<country>SriLanka</country>
</person>
</people>
</soapenv:Body>
</soapenv:Envelope>
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<people>
<person>
<lastname>Wijerathne</lastname>
<firstname>Saminda</firstname>
<gender>Male</gender>
<age>26</age>
<country>SriLanka</country>
</person>
</people>
</soapenv:Body>
</soapenv:Envelope>
My smook.xml:
<?xml version="1.0" encoding="UTF-8"?><smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd" xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd">
<params>
<param name="stream.filter.type">SAX</param>
<param name="inputType">input.csv</param>
<param name="input.csv" type="input.type.actived">File:/C:\Users\victor.viola\Desktop\test.csv</param>
<param name="default.serialization.on">true</param>
</params>
<csv:reader fields="name,surname,gender,age,country"/>
<ftl:freemarker applyOnElement="#document">
<ftl:template><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<people>
<#list .vars["csv-set"]["csv-record"] as csv_record>
<person>
<lastname>${.vars["csv_record"]["surname"]}</lastname>
<firstname>${.vars["csv_record"]["name"]}</firstname>
<gender>${.vars["csv_record"]["gender"]}</gender>
<age>${.vars["csv_record"]["age"]}</age>
<country>${.vars["csv_record"]["country"]}</country>
</person>
</#list>
</people>]]></ftl:template>
<param name="rootElementName">people</param>
<param name="modelSrc">File:/C:\Users\victor.viola\Desktop\example.xsd</param>
<param name="modelSrcType">XSD</param>
<param name="messageType">XML</param>
<param name="templateDataProvider">input</param>
</ftl:freemarker>
<resource-config selector="#document">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
</smooks-resource-list>
With smooks, you can route messages into files or JMS queues.
Please, have a look at this sample that read the file in streaming mode and split it's content into files or JMS messages (it works in Fixed Length but this is the same with csv, just use csv:reader)
Proxy service :
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="VFSProxy" transports="vfs" startOnLoad="true" trace="disable">
<target>
<inSequence>
<property name="DISABLE_SMOOKS_RESULT_PAYLOAD" value="true"/>
<smooks config-key="SmooksSplitFileFL">
<!--smooks config-key="SmooksSplitJMSFL"-->
<input type="text"/>
<output type="xml"/>
</smooks>
</inSequence>
</target>
<parameter name="transport.vfs.FileURI">vfs:file:///C:/In</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.fl</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.Streaming">true</parameter>
<parameter name="transport.PollInterval">15</parameter>
<parameter name="transport.vfs.ActionAfterProcess">DELETE</parameter>
<parameter name="transport.vfs.ActionAfterFailure">DELETE</parameter>
</proxy>
Smooks that split into files (a local-entry, firstname is used to name the file so, if there is multiples lines with the same firstname, you will have the last one)
<?xml version="1.0" encoding="UTF-8"?>
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="SmooksSplitFileFL">
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd" xmlns:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd" xmlns:file="http://www.milyn.org/xsd/smooks/file-routing-1.1.xsd">
<params>
<param name="stream.filter.type">SAX</param>
<param name="default.serialization.on">false</param>
</params>
<fl:reader fields="LASTNAME[2],FIRSTNAME[10]" skipLines="0"/>
<resource-config selector="record">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<file:outputStream openOnElement="record" resourceName="fileSplitStream">
<file:fileNamePattern>${.vars["record"].LASTNAME}.xml</file:fileNamePattern>
<file:destinationDirectoryPattern>C:\Processed</file:destinationDirectoryPattern>
<file:highWaterMark mark="-1"/>
</file:outputStream>
<ftl:freemarker applyOnElement="record">
<ftl:template>/repository/resources/smooks/RecordToXML.ftl</ftl:template>
<ftl:use>
<ftl:outputTo outputStreamResource="fileSplitStream"/>
</ftl:use>
</ftl:freemarker>
</smooks-resource-list>
<description/>
</localEntry>
Smooks that split into JMS messages
<?xml version="1.0" encoding="UTF-8"?>
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="SmooksSplitJMSFL">
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd" xmlns:fl="http://www.milyn.org/xsd/smooks/fixed-length-1.3.xsd" xmlns:jms="http://www.milyn.org/xsd/smooks/jms-routing-1.2.xsd">
<params>
<param name="stream.filter.type">SAX</param>
<param name="default.serialization.on">false</param>
</params>
<fl:reader fields="LASTNAME[2],FIRSTNAME[10]" skipLines="0"/>
<resource-config selector="record">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<jms:router routeOnElement="record" beanId="Person" destination="dynamicQueues/TestFL">
<jms:connection factory="QueueConnectionFactory"/>
<jms:jndi contextFactory="org.apache.activemq.jndi.ActiveMQInitialContextFactory" providerUrl="nio://localhost:61616"/>
<jms:highWaterMark mark="-1"/>
</jms:router>
<ftl:freemarker applyOnElement="record">
<ftl:template>/repository/resources/smooks/RecordToXML.ftl</ftl:template>
<ftl:use>
<ftl:bindTo id="Person"/>
</ftl:use>
</ftl:freemarker>
</smooks-resource-list>
<description/>
</localEntry>
Template (create a file ESB_HOME/repository/resources/smooks/RecordToXML.ftl) :
<#assign rec = .vars["record"]>
<person>
<lastname>${rec.LASTNAME}</lastname>
<firstname>${rec.FIRSTNAME}</firstname>
</person>
My Xml as below
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order>
<class>
<about></about>
</class>
<dataset>
<subjects>
<subject>
<addresses>
<address/>
</addresses>
</subject>
</subjects>
</dataset>
</order>
To reorder the xml element and to add namespace i did it as per below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order>
<class>
<about></about>
</class>
<dataset>
<subjects>
<subject>
</subject>
</subjects>
<addresses>
<address/>
</addresses>
</dataset>
</order>
I did using below code
XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlClueReqToLexisNexis.NameTable);
nsmgr.AddNamespace("ab", "http://example.com/abc");
XmlNode order = xmlClueReqToLexisNexis.SelectSingleNode("//ab:order", nsmgr);
XmlNode dataset = xmlClueReqToLexisNexis.SelectSingleNode("//ab:order//ab:dataset", nsmgr);
var subjects = order.SelectSingleNode("//ab:order//ab:dataset//ab:subjects", nsmgr);
I am able to reorder and add namespace to it but it left behind xmlns attribute
as below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<order>
<class>
<about></about>
</class>
<dataset>
<subjects>
<subject xmlns="">
</subject>
</subjects>
<addresses xmlns="">
<address/>
</addresses>
</dataset>
</order>
I want to remove only attribute xmlns="" out of addresses and subject
Please suggest me the best way to do that.
I have been stumped by Apigee's CORS support. I setup a new proxy and made sure to tick the " Enable Direct Browser Access for Your API — Allow direct requests from a browser via CORS." box.
It appears that CORS is working for the normal GET requests, however pre-flight OPTIONS requests are not found and are returning a 404. I found this answer but was not able to resolve my problem because it seems like a different problem perhaps?
The main question I would like answered is how do I setup Access-Control-Allow-Origin=* for all requests? Even OPTIONS requests?
Proxy Endpoints
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
<Description/>
<Flows>
<Flow name="Forecast">
<Description/>
<Request/>
<Response/>
<Condition>(proxy.pathsuffix MatchesPath "/forecast") and (request.verb = "GET")</Condition>
</Flow>
</Flows>
<PreFlow name="PreFlow">
<Request/>
<Response/>
</PreFlow>
<HTTPProxyConnection>
<BasePath>/v1/weather</BasePath>
<VirtualHost>default</VirtualHost>
<VirtualHost>secure</VirtualHost>
</HTTPProxyConnection>
<RouteRule name="default">
<TargetEndpoint>default</TargetEndpoint>
</RouteRule>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
</ProxyEndpoint>
Target Endpoints
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
<Description/>
<Flows>
<Flow name="OptionsCORS">
<Description/>
<Request/>
<Response>
<Step>
<Name>CrossOriginResourceSharing</Name>
</Step>
</Response>
<Condition>request.verb equals "OPTIONS"</Condition>
</Flow>
</Flows>
<PreFlow name="PreFlow">
<Request/>
<Response>
<Step>
<Name>CrossOriginResourceSharing</Name>
</Step>
</Response>
</PreFlow>
<HTTPTargetConnection>
<URL>https://home.nest.com/api/0.1/weather</URL>
</HTTPTargetConnection>
<PostFlow name="PostFlow">
<Request/>
<Response/>
</PostFlow>
</TargetEndpoint>
Add CORS File
<AssignMessage async="false" continueOnError="false" enabled="true" name="CrossOriginResourceSharing">
<DisplayName>Add CORS</DisplayName>
<FaultRules/>
<Properties/>
<Add>
<Headers>
<Header name="Access-Control-Allow-Origin">*</Header>
<Header name="Access-Control-Allow-Headers">origin, x-requested-with, accept</Header>
<Header name="Access-Control-Max-Age">3628800</Header>
<Header name="Access-Control-Allow-Methods">GET, PUT, POST, DELETE, OPTIONS</Header>
</Headers>
</Add>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>
Just in case it helps- the following is the error I get when doing my request. I'm using Chrome and have an AngularJS app. I've been able to replicate the issue using a cURL statement as well
( curl -H "Origin: localhost" --verbose http://*********-prod.apigee.net/v1/weather/forecast/12345 -X OPTIONS )
{
"url": "/api/0.1/weather/forecast/73013",
"message": "404 Not Found"
}
Thanks!
In your proxy.xml you add one more flow specific to OPTIONS
<Flow name="OPTIONS">
<Description>This flow is for client side applications</Description>
<Response>
<Step>
<Name>CORSResponse</Name>
</Step>
</Response>
<Condition>(request.verb = "OPTIONS")</Condition>
<Request/>
</Flow>
Now the CORSResponse.xml Policy can be like below
<AssignMessage name="CORSResponse">
<AssignTo type="response" createNew="true" />
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<Set>
<Headers>
<Header name="Access-Control-Allow-Origin">yourdomain.com</Header>
<Header name="Access-Control-Allow-Headers">origin, x-requested-with, x-source-ip, Accept, Authorization, User-Agent, Host, Accept-Language, Location, Referer</Header>
<Header name="Access-Control-Allow-Methods">GET, POST</Header>
</Headers>
<StatusCode>200</StatusCode>
</Set>
</AssignMessage>
The solution was to add a RouteRule that prevented the request from passing through to my API on OPTIONS requests.
<RouteRule name="NoRoute">
<Condition>request.verb == "OPTIONS"</Condition>
</RouteRule>
Additionally I added a flow that added CORS support to the response
<Flow name="OptionsPreFlight">
<Request/>
<Response>
<Step>
<Name>Add-CORS</Name>
</Step>
</Response>
<Condition>request.verb == "OPTIONS"</Condition>
</Flow>
And my Final Add-CORS policy
<AssignMessage async="false" continueOnError="false" enabled="true" name="Add-CORS">
<DisplayName>Add CORS</DisplayName>
<FaultRules/>
<Properties/>
<Add>
<Headers>
<Header name="Access-Control-Allow-Origin">*</Header>
<Header name="Access-Control-Allow-Headers">origin, x-requested-with, accept</Header>
<Header name="Access-Control-Max-Age">3628800</Header>
<Header name="Access-Control-Allow-Methods">GET, PUT, POST, DELETE</Header>
</Headers>
</Add>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>