Coldfusion 9 Parse Soap results - soap

I am trying to parse:
<?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><LoginResponse xmlns="http://services.marketernet.com/application"><LoginResult><results><response value="UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA"/><exceptions></exceptions></results></LoginResult></LoginResponse></soap:Body></soap:Envelope>
So far I have:
<cfset soapResponse = xmlParse(httpResponse.fileContent) />
<cfset results = xmlSearch(soapResponse,"//*[local-name()='LoginResult' and namespace-uri()='http://services.marketernet.com/application']") />
I need the value of <response value="UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA"/>
I try looping, even try to do a deep xml path, nothing.
Please help me, if you have questions please let me know.
Update 1: "ScreenShot"
Update 2: "Screenshot long version"

I normally just use xmlSearch(soapResponse,"//*[local-name()='whatever']") and it works fine for me. It can return different types depending on how deep you search in the XML. Because of that, when developing the code I always use <cfdump> to view the results of the xmlSearch() function to know what I am dealing with.
I took the SOAP response that you shared and tested the following code successfully on ColdFusion 9.0.1. Notice that I have three different searches here each delving deeper into the XML tree. I left the <cfdump> in there so you can see what each returns.
<cftry>
<cfsavecontent variable="content">
<?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>
<LoginResponse xmlns="http://services.marketernet.com/application">
<LoginResult>
<results>
<response value="UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA"/>
<exceptions></exceptions>
</results>
</LoginResult>
</LoginResponse>
</soap:Body>
</soap:Envelope>
</cfsavecontent>
<cfset soapResponse = xmlParse(Trim(content)) />
<html>
<head><title>Test xmlParse</title></head>
<body>
<h3>xmlParse option 1</h3>
<div>
<cfset results = xmlSearch(soapResponse,"//*[local-name()='LoginResult']") />
<cfdump var="#results#" />
<cfset value = results[1].results.response.XmlAttributes.value />
<cfdump var="#value#" />
</div>
<h3>xmlParse option 2</h3>
<div>
<cfset results = xmlSearch(soapResponse,"//*[local-name()='results']") />
<cfdump var="#results#" />
<cfset value = results[1].response.XmlAttributes.value />
<cfdump var="#value#" />
</div>
<h3>xmlParse option 3</h3>
<div>
<cfset results = xmlSearch(soapResponse,"//*[local-name()='response']") />
<cfdump var="#results#" />
<cfset value = results[1].XmlAttributes.value />
<cfdump var="#value#" />
</div>
</body>
</html>
<cfcatch type="any">
<cfdump var="#cfcatch#" />
</cfcatch>
</cftry>
All of the options result in setting the value variable to UY+/9dD+Lz7DT3Oq/WG3CVJ/pFW7o6LEFNA4xOSIWr88Dh2RVAgy9qHP1BwpdiYA from the XML.

Related

How do I get the WSDL from this .asmx URL?

There's this web service I want to connect to. It's fully detailed here: https://simphonytsapi.docs.apiary.io/#reference/calculatetransactiontotals/overview/example-1?console=1
As you can see there's details on the right on how to connect to it. For example to call the CalculateTransactionTotals method of the web service there is:
This .asmx URL: https://private-102dc-simphonytsapi.apiary-mock.com/1/EGateway/SimphonyPosApiWeb.asmx
And these headers:
Content-Type text/xml;charset=UTF-8
SOAPAction http://micros-hosting.com/EGateway/CalculateTransactionTotals
And this example request body:
<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>
<CalculateTransactionTotals xmlns="http://micros-hosting.com/EGateway/">
<vendorCode />
<ppMenuItems />
<ppComboMeals>
<SimphonyPosApi_ComboMeal>
<ComboMealMainItem>
<Condiments />
<MenuItem>
<ItemDiscount>
<DiscObjectNum>0</DiscObjectNum>
</ItemDiscount>
<MiObjectNum>181020001</MiObjectNum>
<MiReference />
<MiWeight />
<MiMenuLevel>1</MiMenuLevel>
<MiSubLevel>1</MiSubLevel>
<MiPriveLevel>0</MiPriveLevel>
</MenuItem>
</ComboMealMainItem>
<ComboMealMenuItem>
<Condiments />
<MenuItem>
<ItemDiscount>
<DiscObjectNum>0</DiscObjectNum>
</ItemDiscount>
<MiObjectNum>181010001</MiObjectNum>
<MiReference />
<MiWeight />
<MiMenuLevel>1</MiMenuLevel>
<MiSubLevel>1</MiSubLevel>
<MiPriveLevel>0</MiPriveLevel>
</MenuItem>
</ComboMealMenuItem>
<ComboMealObjectNum>11</ComboMealObjectNum>
<SideItems>
<SimphonyPosApi_MenuItem>
<Condiments />
<MenuItem>
<ItemDiscount>
<DiscObjectNum>0</DiscObjectNum>
</ItemDiscount>
<MiObjectNum>181030001</MiObjectNum>
<MiReference />
<MiWeight />
<MiMenuLevel>1</MiMenuLevel>
<MiSubLevel>1</MiSubLevel>
<MiPriveLevel>0</MiPriveLevel>
</MenuItem>
</SimphonyPosApi_MenuItem>
<SimphonyPosApi_MenuItem>
<Condiments />
<MenuItem>
<ItemDiscount>
<DiscObjectNum>0</DiscObjectNum>
</ItemDiscount>
<MiObjectNum>299030001</MiObjectNum>
<MiReference />
<MiWeight />
<MiMenuLevel>1</MiMenuLevel>
<MiSubLevel>1</MiSubLevel>
<MiPriveLevel>0</MiPriveLevel>
</MenuItem>
</SimphonyPosApi_MenuItem>
</SideItems>
</SimphonyPosApi_ComboMeal>
</ppComboMeals>
<pSvcCharge>
<SvcChgObjectNum>0</SvcChgObjectNum>
</pSvcCharge>
<pSubtotalDiscount>
<DiscObjectNum>0</DiscObjectNum>
</pSubtotalDiscount>
<revenueCenter>11</revenueCenter>
<orderType>1</orderType>
<employeeNumber>900000092</employeeNumber>
<pTotalsResponse />
</CalculateTransactionTotals>
</soap:Body>
</soap:Envelope>
I need the WSDL to connect to this web service. How do I get it?

Why is a SOAP call working from CFM page but not from a CFC page?

I am working with a SOAP request in coldfusion. When the code I have is run from a .CFM file, it works. If it is run from a .CFC file, it doesn't work. The code is the same as far as possible (the .CFC needs the cfcomponent and cffunction tags for example).
Why would it work from one and not the other? When I call it from the CFC page I get the error
Does anyone have any idea why this might be happening? The SOAP request is identical on both pages. The call with the CFHTTP as well as all the CFHTTPPARAMs are the same as well.
Here is the code for the CFC file:
<cfcomponent>
<cffunction name="updateAgParcel" returntype="string" returnformat="plain" access="remote">
<cfargument name="ag_pres_nr" required="true" type="string">
<cfargument name="emp_nr" required="true" type="string">
<cfargument name="dt_rcvd" required="true" type="string">
<cfset dt_rcvd = DateFormat(#dt_rcvd#,"MMDDYYYY")>
<cfsavecontent variable="soapBody">
<cfoutput>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ass="http://XXXXXX">
<soapenv:Header/>
<soapenv:Body>
<ass:LogAgPreserveFiling>
<ass:AG.PRES.NR>#ag_pres_nr#</ass:AG.PRES.NR>
<ass:TC>04</ass:TC>
<ass:EMP.NR>#emp_nr#</ass:EMP.NR>
<ass:LCAQ.DT.RCVD>#dt_rcvd#</ass:LCAQ.DT.RCVD>
</ass:LogAgPreserveFiling>
</soapenv:Body>
</soapenv:Envelope>
</cfoutput>
</cfsavecontent>
<cfhttp url="XXXXXXXXXXXXXXX" method="post" result="httpResponse">
<cfhttpparam type="header" name="SOAPAction" value="XXXXXXXXXXXX" />
<cfhttpparam type="header" name="Authorization" value="Basic XXXXXXXXXXXXXX" />
<cfhttpparam type="header" name="accept-encoding" value="no-compression" />
<cfhttpparam type="header" name="Content-Type" value="text/xml" />
<cfhttpparam type="xml" value="#trim( soapBody )#" />
</cfhttp>
<cfif find( "200", httpResponse.statusCode )>
<cfset soapResponse = xmlParse( httpResponse.fileContent ) />
<cfset responseNodes = xmlSearch(soapResponse, "//*[ local-name() = 'VCfaultdetails'] ") />
<cfif arrayLen(responseNodes) NEQ 0>
<cfset error = #responseNodes[ 1 ].message.xmlText#>
<cfreturn error>
<cfelse>
<cfreturn "">
</cfif>
</cfif>
</cffunction>
</cfcomponent>
Code for the CFM version:
<cfsavecontent variable="soapBody">
<cfoutput>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ass="http://XXXXX">
<soapenv:Header/>
<soapenv:Body>
<ass:LogAgPreserveFiling>
<ass:AG.PRES.NR>#ag_pres_nr#</ass:AG.PRES.NR>
<ass:TC>04</ass:TC>
<ass:EMP.NR>#emp_nr#</ass:EMP.NR>
<ass:LCAQ.DT.RCVD>#dt_rcvd#</ass:LCAQ.DT.RCVD>
</ass:LogAgPreserveFiling>
</soapenv:Body>
</soapenv:Envelope>
</cfoutput>
</cfsavecontent>
<cfhttp url="XXXXXXXXXXXXX" method="post" result="httpResponse">
<cfhttpparam type="header" name="SOAPAction" value="XXXXXXXXXXXXXXX"/>
<cfhttpparam type="header" name="content-type" value="text/xml">
<cfhttpparam type="header" name="Authorization" value="Basic XXXXXXXXXXXXXXXXX" />
<cfhttpparam type="header" name="accept-encoding" value="no-compression" />
<cfhttpparam type="xml" value="#trim( soapBody )#" />
</cfhttp>
<cfif find( "200", httpResponse.statusCode )>
<cfset soapResponse = xmlParse( httpResponse.fileContent ) />
<cfset responseNodes = xmlSearch( soapResponse, "//*[ local-name() = 'VCfaultdetails'] " ) />
<cfif arrayLen(responseNodes) NEQ 0>
<cfoutput>
Code: #responseNodes[ 1 ].errorcode#
<br />
Message: #responseNodes[ 1 ].message#
</cfoutput>
<cfelse>
Success!!!!!!!!
</cfif>
</cfif>
I XXXXXX out some of the URL's and such for security. Also, sorry for the namespace the developers choose (ass:). It was the abbreviation for Assessor. Somebody was being funny...

How to pass parameter in Form Scope for REST services in ColdFusion?

Today while working with ColdFusion 10 REST, I got an issues. I am not sure how to pass data to a REST service in FORM scope.
Here is my REST enabled CFC,
<cfcomponent rest="true" restpath="/crudService" >
<cfset variable.myQuery = queryNew("Id,Name","Integer,Varchar",[[1,"Test1"],[2,"Test2"],[3,"Test3"]] )>
<cffunction name="getHandlerJSONForm" access="remote" httpmethod="GET" restpath="/formtest" returntype="query" produces="application/xml">
<cfargument name="customerID" required="true" restargsource="Form" type="numeric" >
<cfquery dbtype="query" name="local.qryGetUserName">
SELECT Name
FROM variable.myQuery
WHERE Id = <cfqueryparam cfsqltype="cf_sql_integer" value="#customerID#">
</cfquery>
<cfreturn local.qryGetUserName>
</cffunction>
</cfcomponent>
Here is the CFM code, calling the REST service,
<cfset restInitApplication("E:\Local Workspace\cfcs\rest","myfirstrest")>
<cfhttp url="http://cflocal.com/rest/myfirstrest/crudService/formtest" method="get" >
<cfhttpparam type="header" name="Content-Type" value="application/x-www-form-urlencoded" >
<cfhttpparam type="formfield" name="customerID" value="1" >
</cfhttp>
<cfdump var="#cfhttp#">
In StatusCode I am getting 500 Exception obtaining parameters ?
Please suggest whats going wrong here.

Coldfusion REST - Serialize Array of CFC

Hi I'm trying to serialize an array of CFCs from one of my REST endpoints. I found this Example: Array of CFC Serialization in the Adobe Help, which pretty much is exactly what I want to do (I can post some code if necessary) Yet when I try to use returnType="myCFC[]" it fails with:
"Message":"array element type mismatch"
The strange thing is, if I instantiate the same object and call the method from a .cfm file, the cfdump shows the array of objects with data as expected. But from my AJAX call, the object's property values are all null. However, if I use return serializeJSON(myArrayOfCFCs) the properties have data. But I don't want to have to do that because it will negate the use of content negotiation.
Just curious if anyone has gotten this to work.
update:
<cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient[]" produces="text/json" restpath="/{PatientId}">
<cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />
<cfset local.response = ArrayNew(1) />
<cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>
<cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
<cfset arrayAppend(local.response, local.patientObject) />
<cfreturn local.response />
</cffunction>
This works, but not what I want in the end:
<cffunction name="getPatient" access="remote" httpmethod="GET" returntype="Patient" produces="text/json" restpath="/{PatientId}">
<cfargument name="PatientId" type="numeric" required="true" restargsource="Path" />
<cfset local.response = ArrayNew(1) />
<cfset local.patient = getPatientGatewayObject().getPatient(PatientId)>
<cfset local.patientObject = createObject("component", "Patient").init(argumentCollection=queryRowToStruct(local.patient)) />
<cfset arrayAppend(local.response, local.patientObject) />
<cfreturn serializeJSON(local.response) />
</cffunction>

Convert XML Option element nodes to HTML Option tags

Is there a direct was to convert an Element Object to an HTMLOption Object?
Let's suppose I have this XML:
<?xml version='1.0'?>
<options>
<option value="1">Hello1</option>
<option value="2">Hello2</option>
</options>
I want to insert each option in this select
Is there a way to just convert these XML to option directly or I have to then navigate the XML then get all information I need and then create a new Option and add that option to the select?
something like:
var options = XmlCode.getElementsByTagName('option');
for(var i = 0; i < options.length; i++){
selectBox.add(options[i]);
}
as a native code would be nice ^^
Note: I don't want to use any libraries or frameworks. I want do learn and do this by myself.
XSLT is made for XML to HTML conversion. Something like this will do the trick:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml-stylesheet type="text/xsl" href="select2option.xml" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:html="http://www.w3.org/1999/xhtml"
>
<xsl:output method="html" encoding="utf-8" indent="yes" standalone="yes" media-type="text/html" omit-xml-declaration="yes" doctype-system="about:legacy-compat" />
<html:options>
<html:option name="foo">bar</html:option>
</html:options>
<xsl:template match="xsl:stylesheet">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="/">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="html:options">
<select>
<xsl:apply-templates />
</select>
</xsl:template>
<xsl:template match="html:option">
<option name="#name">
<xsl:apply-templates />
</option>
</xsl:template>
</xsl:stylesheet>