I want to use webservice feature of a website by using SOAP approach.
The methods below are the things written in the manual ;
WSDL Address: http://dev.gittigidiyor.com:8080/listingapi/ws/CategoryService?wsdl
Service Method Signature:
CategoryServiceResponse getCategories(int startOffSet, int rowCount, boolean withSpecs, boolean withDeepest, boolean withCatalog, String lang)
Request Example
<cat:getCategories>
<startOffSet>0</startOffSet>
<rowCount>4</rowCount>
<withSpecs>true</withSpecs>
<withDeepest>true</withDeepest>
<withCatalog>true</withCatalog>
<lang>tr</lang>
</cat:getCategories>
Here is what I have tried in R.
library(RCurl)
headerFields =
c(Accept = "text/xml",
'Content-Type' = "text/xml; charset=utf-8",
SOAPAction = "")
body <- '<cat:getCategories>
<startOffSet>0</startOffSet>
<rowCount>4</rowCount>
<withSpecs>true</withSpecs>
<withDeepest>true</withDeepest>
<withCatalog>true</withCatalog>
<lang>tr</lang>
</cat:getCategories>'
curlPerform(url = "http://dev.gittigidiyor.com:8080/listingapi/ws/CategoryService?wsdl",
httpheader = headerFields,
postfields = body
)
But at the end, only output I have is that ;
OK
0
However, it should be like that wrt the manual ;
<cat:getCategoriesResponse xmlns:cat="http://category.anonymous.ws.listingapi.gg.com">
<return>
<ackCode>success</ackCode>
<responseTime>29/06/2010 13:39:19</responseTime>
<timeElapsed>2 ms</timeElapsed>
<categoryCount>3849</categoryCount>
<categories>
<category hasCatalog="false" deepest="false">
<categoryCode>a</categoryCode>
<categoryName>Antikalar & Sanat</categoryName>
</category>
<category hasCatalog="false" deepest="false">
<categoryCode>aa</categoryCode>
<categoryName>Antika Ahşap Objeler</categoryName>
<specs>
<spec type="Combo" name="Menşei (Orijin)">
<values>
<value>Avrupa</value>
<value>Osmanlı</value>
<value>Türkiye</value>
<value>Uzakdoğu</value>
<value>Diğer</value>
<value>Rusya</value>
</values>
</spec>
<spec type="Combo" required="true" name="Kondisyon">
<values>
<value>Yüksek</value>
<value>Orta</value>
<value>Düşük</value>
</values>
</spec>
<spec type="Combo" required="true" name="Durumu">
<values>
<value>Yeni</value>
<value>Kullanılmış</value>
<value>Diğer</value>
</values>
</spec>
<spec type="Combo" required="true" name="Antika / Modern">
<values>
<value>Antika</value>
<value>Modern</value>
</values>
</spec>
<spec type="Combo" name="Dönemler">
<values>
<value>1800 öncesi</value>
<value>1800 - 1849</value>
<value>1850 - 1899</value>
<value>1900 - 1940</value>
<value>1940 sonrası</value>
</values>
</spec>
</specs>
</category>
<category hasCatalog="false" deepest="true">
<categoryCode>az</categoryCode>
<categoryName>Diğer Antikalar & Sanat</categoryName>
</category>
<category hasCatalog="false" deepest="false">
<categoryCode>b</categoryCode>
<categoryName>Bilgisayar</categoryName>
<specs>
<spec type="Combo" required="true" name="Durumu">
<values>
<value>Yeni, Açılmamış Kutusunda</value>
<value>Kullanılmış</value>
<value>Yeni, Kutusuz</value>
</values>
</spec>
</specs>
</category>
</categories>
</return>
</cat:getCategoriesResponse>
What am I missing? Can you help please?
This may help you,
library(RCurl)
headerFields = c(Accept = "text/xml",
'Content-Type' = "text/xml; charset=utf-8", SOAPAction = "")
body <- '<cat:getCategories>
<startOffSet>0</startOffSet>
<rowCount>4</rowCount>
<withSpecs>true</withSpecs>
<withDeepest>true</withDeepest>
<withCatalog>true</withCatalog>
<lang>tr</lang>
</cat:getCategories>'
reader <- basicTextGatherer()
curlPerform(url = "http://dev.gittigidiyor.com:8080/listingapi/ws/CategoryService?wsdl",
httpheader = headerFields,
postfields = body,
writefunction = reader$update
)
xml <- reader$value()
xml
Related
I have an XML of SAML assertion and I can't figure out what is wrong with this verification. Also I cannot use any libraries from the full .Net Framework (here I use Microsoft.IdentityModel.Tokens and Microsoft.IdentityModel.Tokens.Saml packages).
XmlReader xmlReader = XmlReader.Create(new StringReader(xml));
RsaSecurityKey key = new RsaSecurityKey(RSA.Create());
SamlSerializer ser = new SamlSerializer();
var assertion = ser.ReadAssertion(xmlReader);
assertion.Signature.Verify(key);
The ReadAssertion is OK and the certificate is there inside Signature.KeyInfo.X509Data.
Or maybe I'm using a wrong SecurityKey and RsaSecurityKey is not the right choice for this? I'm not really sure how to interpret the Signature part of this:
<saml:Assertion MajorVersion="1" MinorVersion="1" AssertionID="_466e5c77-b0d7-4c5e-a652-ec66f520302e" Issuer="http://www.example.com/sts.6" IssueInstant="2021-11-02T12:55:44.273Z" xmlns:saml="urn:oasis:names:tc:SAML:1.0:assertion">
<saml:Conditions NotBefore="2021-11-02T12:55:44.273Z" NotOnOrAfter="2021-11-02T16:55:44.273Z">
<saml:AudienceRestrictionCondition>
<saml:Audience>https://www.example.com/prod</saml:Audience>
</saml:AudienceRestrictionCondition>
</saml:Conditions>
<saml:AttributeStatement>
...
</saml:AttributeStatement>
<saml:AuthenticationStatement AuthenticationMethod="URN:IVIS:100001:AM.BANK-SWED" AuthenticationInstant="2021-11-02T12:55:44.085Z">
<saml:Subject>
<saml:NameIdentifier Format="urn:ivis:100001:name.id-viss">PK:08028710315</saml:NameIdentifier>
<saml:SubjectConfirmation>
<saml:ConfirmationMethod>urn:oasis:names:tc:SAML:1.0:cm:bearer</saml:ConfirmationMethod>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:SubjectLocality IPAddress="87.242.186.212"/>
</saml:AuthenticationStatement>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
<SignedInfo>
<CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
<SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
<Reference URI="#_466e5c77-b0d7-4c5e-a652-ec66f520302e">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>VAOQYRxyrO+pJs9+pGjQWOXoR5SFTKHhG3lmpFS0TeQ=</DigestValue>
</Reference>
</SignedInfo>
<SignatureValue>BjslVMuLfUcbNMiJPpTiqmr/WgI/ZuzXfRV...gGFrdW/cH/BFrJfiq9oWlQcFLVD/GFsq3XQw==</SignatureValue>
<KeyInfo>
<X509Data>
<X509Certificate>MIIF7jCCBNagAwIBAgIKEqni0gABAAABQz...4LsBscidh0/nNcAJwOVlCfw==</X509Certificate>
</X509Data>
</KeyInfo>
</Signature>
</saml:Assertion>
I would like to turn this xml response into something more easily readable.
<?xml version="1.0" encoding="ISO-8859-1"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
<soap:Body>
<executeResponse xmlns="urn:GCE">
<BusinessViewServiceexecuteOut xmlns="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" xmlns:ns2="http://www.generixgroup.com/processus/configuration/scheduler" xmlns:ns3="http://www.generix.fr/technicalframework/business/service/common">
<xmlpres><?xml version = '1.0' encoding = 'UTF-8'?> <VueTable type="View" name="Table" habctr="true" total_business_row="2" nbline="400" confNbline="400" numpage="1" nbpage="1">
<JTblView name="JTblView" type="ViewObject" maxfetchsize="999" maxfetchsizeexceeded="false">
<JTblViewRow current="true" type="ViewRow" index="1" business_row_index="1">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>N</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Non</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Non</business_data>
</Lir>
</JTblViewRow>
<JTblViewRow type="ViewRow" index="2" business_row_index="2">
<Cletbl precision="6" type="VARCHAR" pk="true">
<business_data>O</business_data>
</Cletbl>
<Codtbl precision="6" type="VARCHAR" pk="true">
<business_data>001</business_data>
</Codtbl>
<Lib1 precision="30" type="VARCHAR">
<business_data>Oui</business_data>
</Lib1>
<Lib2 precision="30" type="VARCHAR">
<business_data/>
</Lib2>
<Lir precision="10" type="VARCHAR">
<business_data>Oui</business_data>
</Lir>
</JTblViewRow>
</JTblView>
</VueTable></xmlpres>
</BusinessViewServiceexecuteOut>
</executeResponse>
</soap:Body></soap:Envelope>
At least if I could extract what's in the value of "xmlpres", the better I could do:
<table><row><code></code><libelle></libelle/></row></table>
To then turn it into a json response but I can't see ... I just get all the output or in json stream but with everything , which is not usable.
Create an out-mediation sequence with the following content and attach it to the respective API and try out the scenario. This is to extract the xmlpres content and send that as the response to the client
<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="out-sequence">
<!-- extract the xmlpres content and store as OM element -->
<property name="XMLBody"
expression="$body//soap:Body//generic:xmlpres"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:gce="urn:GCE"
xmlns:generic="http://www.generix.fr/technicalframework/businesscomponent/applicationmodule/common" type="OM" />
<!-- pass the extracted property as response body -->
<enrich>
<source type="property" property="XMLBody" />
<target type="body" />
</enrich>
</sequence>
Hope this helps you to extract and send the response accordingly.
How to access attributes including headers, queryparams in Munit set Event processor. I am using Anypoint Studio 7.5
I have tried with <munit:attributes value="#[{headers : {'token' :'value1'}}]" encoding="UTF-16" /> but it didn't worked.
<sub-flow name="setUserAndPass">
<choice doc:name="Choice" >
<when expression='attributes."headers"."authorization" != null'>
<ee:transform doc:name="Transform Message" >
<ee:message >
</ee:message>
<ee:variables >
<ee:set-variable variableName="userAndPass" ><![CDATA[%dw 2.0
import * from dw::core::Binaries
output text/json
var auth = attributes."headers"."authorization"
---
(fromBase64((auth splitBy(" "))[1] as Binary)) splitBy(":")]]></ee:set-variable>
</ee:variables>
</ee:transform>
<set-variable value='#[vars.userAndPass[0]]' doc:name="Set lvUSERNAME Variable" variableName="lvUSERNAME"/>
<set-variable value='#[vars.userAndPass[1]]' doc:name="Set lvPASSWORD variable" variableName="lvPASSWORD "/>
</when>
<otherwise >
<set-variable value='#[attributes."headers"."username"]' doc:name="Set lvUSERNAME Variable" variableName="lvUSERNAME" />
<set-variable value='#[attributes."headers"."password"]' doc:name="Set lvPASSWORD Variable" variableName="lvPASSWORD" />
</otherwise>
</choice>
</sub-flow>
Munit Flow:
<munit:test name="appname-test-suite-setUserAndPassTest" description="Test">
<munit:behavior >
<munit:set-event doc:name="Set Event">
<munit:attributes value="#[
{
headers : {'authorization': 'authvalue'}
}]" />
</munit:set-event>
</munit:behavior>
<munit:execution >
<flow-ref doc:name="Flow-ref to setUserAndPass" name="setUserAndPass"/>
</munit:execution>
<munit:validation >
<munit-tools:assert-equals doc:name="Assert equals" actual="#[vars.lvUSERNAME]" expected="usernamevalue"/>
</munit:validation>
</munit:test>
It should like this:
<munit:set-event doc:name="Set Event">
<munit:payload value="#['..']" encoding="UTF-16" />
<munit:attributes value="#[
{
headers : {'token': 'value1'},
queryParams : {'queryParam1': 'value2'}
}]" encoding="UTF-16" />
</munit:set-event>
I am reading in the following XML as a text file in R:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
"-//Recordare//DTD MusicXML 3.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.0">
<part-list>
<score-part id="P1">
<part-name>Music</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<type>whole</type>
</note>
</measure>
</part>
</score-partwise>
R:
library(readtext)
xml <- readtext("musicxml.txt")$text
I am then trying to render this in Javascript via Shiny by feeding my XML text to a Javascript function. NB: Working outside of R.
shiny::tags$script(paste0('var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay(\"sheet-music\", {drawingParameters: "compact",
drawPartNames: false, drawMeasureNumbers: false, drawMetronomeMarks: false, drawTitle: false});
var loadPromise = osmd.load(\'',xml,'\');
loadPromise.then(function(){
osmd.render();
});
'))
However, when I concatenate the XML string above, it does not work because characters are escaped, e.g one line:
<note>
I tried using the unescape_xml function here (with and without the tags removed), but this does not solve the problem. It leaves me with:
"Music1044G2C44whole"
So how can I end up with a concatenated string with none of the escaped characters? It must just be a string and not another R object.
You need to wrap the contents of the tag call with shiny::HTML to ensure it is passed unescaped:
shiny::tags$script(shiny::HTML(paste0(
'var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay(\"sheet-music\",
{ drawingParameters: "compact",
drawPartNames: false,
drawMeasureNumbers: false,
drawMetronomeMarks: false,
drawTitle: false});
var loadPromise = osmd.load(\'',xml,'\');
loadPromise.then(function(){ osmd.render() });')))
Which gives you:
<script>var osmd = new opensheetmusicdisplay.OpenSheetMusicDisplay("sheet-music",
{ drawingParameters: "compact",
drawPartNames: false,
drawMeasureNumbers: false,
drawMetronomeMarks: false,
drawTitle: false});
var loadPromise = osmd.load('<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE score-partwise PUBLIC
"-//Recordare//DTD MusicXML 3.0 Partwise//EN"
"http://www.musicxml.org/dtds/partwise.dtd">
<score-partwise version="3.0">
<part-list>
<score-part id="P1">
<part-name>Music</part-name>
</score-part>
</part-list>
<part id="P1">
<measure number="1">
<attributes>
<divisions>1</divisions>
<key>
<fifths>0</fifths>
</key>
<time>
<beats>4</beats>
<beat-type>4</beat-type>
</time>
<clef>
<sign>G</sign>
<line>2</line>
</clef>
</attributes>
<note>
<pitch>
<step>C</step>
<octave>4</octave>
</pitch>
<duration>4</duration>
<type>whole</type>
</note>
</measure>
</part>
</score-partwise>');
loadPromise.then(function(){ osmd.render() });</script>
I have the following XML file test.graphml that I am trying to manipulate using the XML package in R.
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graph id="G" edgedefault="directed">
<node id="n0"/>
<node id="n1"/>
<node id="n2"/>
<node id="n3"/>
<node id="n4"/>
<edge source="n0" target="n1"/>
<edge source="n0" target="n2"/>
<edge source="n2" target="n3"/>
<edge source="n1" target="n3"/>
<edge source="n3" target="n4"/>
</graph>
</graphml>
I would like to nest nodes n0, n1, n2, and n3 into a new graph node as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<graph id="G" edgedefault="directed">
<graph id="g1">
<node id="n0"/>
<node id="n1"/>
<node id="n2"/>
<node id="n3"/>
</graph>
<node id="n4"/>
<edge source="n0" target="n1"/>
<edge source="n0" target="n2"/>
<edge source="n2" target="n3"/>
<edge source="n1" target="n3"/>
<edge source="n3" target="n4"/>
</graph>
</graphml>
The code I have written has unknowns and errors that I am unable to resolve due to lack of experience with XML processing. I would greatly appreciate some pointers to that will help me proceed.
library(XML)
# Read file
x <- xmlParse("test.graphml")
ns <- c(graphml ="http://graphml.graphdrawing.org/xmlns")
# Create new graph node
ng <- xmlNode("graph", attrs = c("id" = "g1"))
# Add n0-n3 as children of new graph node
n0_n1_n2_n3 <- getNodeSet(x,"//graphml:node[#id = 'n0' or #id='n1' or #id='n2' or #id='n3']", namespaces = ns)
ng <- append.xmlNode(ng, n0_n1_n2_n3)
# Get only graph node
g <- getNodeSet(x,"//graphml:graph", namespaces = ns)
# Remove nodes n0-n3 from the only graph node
# How I do this?
# This did not work: removeNodes(g, n0_n1_n2_n3)
# Add new graph node as child of only graph node
g <- append.xmlNode(g, ng)
#! Error message:
Error in UseMethod("append") :
no applicable method for 'append' applied to an object of class "XMLNodeSet"
Consider XSLT, the special-purpose language to transform XML files. Since you require modification of the XML (adding parent node in a select group of children) and have to navigate through an undeclared namespace prefix (xmlns="http://graphml.graphdrawing.org/xmlns"), XSLT is an optimal solution.
However, to date R does not have a fully compliant XSL module to run XSLT 1.0 scripts like other general purpose languages (Java, PHP, Python). Nonetheless, R can call external programs (including aforementioned languages), or dedicated XSLT processors (Xalan, Saxon), or call command line interpreters including PowerShell and terminal's xsltproc using system(). Below are latter solutions.
XSLT (save as .xsl, to be referenced in R script)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:doc="http://graphml.graphdrawing.org/xmlns"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="doc:graphml">
<xsl:copy>
<xsl:copy-of select="document('')/*/#xsi:schemaLocation"/>
<xsl:apply-templates select="doc:graph"/>
</xsl:copy>
</xsl:template>
<xsl:template match="doc:graph">
<xsl:element name="{local-name()}" namespace="http://graphml.graphdrawing.org/xmlns">
<xsl:apply-templates select="#*"/>
<xsl:element name="graph" namespace="http://graphml.graphdrawing.org/xmlns">
<xsl:attribute name="id">g1</xsl:attribute>
<xsl:apply-templates select="doc:node[position() < 5]"/>
</xsl:element>
<xsl:apply-templates select="doc:node[#id='n4']|doc:edge"/>
</xsl:element>
</xsl:template>
<xsl:template match="doc:graph/#*">
<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="doc:node|doc:edge">
<xsl:element name="{local-name()}" namespace="http://graphml.graphdrawing.org/xmlns">
<xsl:attribute name="{local-name(#*)}"><xsl:value-of select="#*"/></xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
PowerShell script (for Windows PC users, save as XMLTransform.ps1)
param ($xml, $xsl, $output)
if (-not $xml -or -not $xsl -or -not $output) {
Write-Host "& .\xslt.ps1 [-xml] xml-input [-xsl] xsl-input [-output] transform-output"
exit;
}
trap [Exception]{
Write-Host $_.Exception;
}
$xslt = New-Object System.Xml.Xsl.XslCompiledTransform;
$xslt.Load($xsl);
$xslt.Transform($xml, $output);
Write-Host "generated" $output;
R Script (calling command line operations)
library(XML)
# WINDOWS USERS
ps <- '"C:\\Path\\To\\XMLTransform.ps1"' # POWER SHELL SCRIPT
input <- '"C:\\Path\\To\\Input.xml"' # XML SOURCE
xsl <- '"C:\\Path\\To\\XSLTScript.xsl"' # XSLT SCRIPT
output <- '"C:\\Path\\To\\Output.xml"' # BLANK, EMPTY FILE PATH TO BE CREATED
system(paste('Powershell.exe -executionpolicy remotesigned -File',
ps, input, xsl, output)) # NOTE SECURITY BYPASS ARGS
doc <- xmlParse("C:\\Path\\To\\Output.xml")
# UNIX (MAC/LINUX) USERS
system("xsltproc /path/to/XSLTScript.xsl /path/to/input.xml -o /path/to/output.xml")
doc <- xmlParse("/path/to/output.xml")
print(doc)
# <?xml version="1.0" encoding="utf-8"?>
# <graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
# <graph id="G" edgedefault="directed">
# <graph id="g1">
# <node id="n0"/>
# <node id="n1"/>
# <node id="n2"/>
# <node id="n3"/>
# </graph>
# <node id="n4"/>
# <edge source="n0"/>
# <edge source="n0"/>
# <edge source="n2"/>
# <edge source="n1"/>
# <edge source="n3"/>
# </graph>
# </graphml>