I'm in the process of trying to convert an old CF script. The only problem is I am using CommandBox and I can't seem to get Fiddler to show me what this request looks like when it's actually posted. Does anyone know what the Post request this sends out would look like?
I've tried a variety of options so far and nothing has worked.
Any help would be appreciated
<!---
Cold Fusion 4.0.1
--->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head></head>
<body>
<cfif isdefined("Form.thisid")>
<!--- Input Form Parameters --->
<cfset InputPbn = Form.thisid>
<cfoutput>
<h1>Raw XML data for #thisid#</h1>
</cfoutput>
<cfelse>
<h1>A valid thisid was not provided</h1>
<cfabort>
</cfif>
<!--- Assemble the user's input into structure --->
<CFSCRIPT>
// New request structure to pass
Request = StructNew();
Request.thisid = "#Inputthisid#";
host_url = "http://myurl/get_info_wddx.cfm";
Request["LINK_KEY"] = "1234";
</CFSCRIPT>
<!--- Convert the structure to WDDX Packet --->
<CFWDDX
INPUT="#Request#"
OUTPUT="RequestAsWDDX"
ACTION="CFML2WDDX"
>
<cfoutput>RequestAsWDDX #HTMLEditFormat(RequestAsWDDX)#<br/></cfoutput>
<!--- Post the WDDX Packet to the host page as a form field --->
<CFTRY>
<CFHTTP URL="#host_url#" METHOD="POST">
<CFHTTPPARAM
NAME="WDDXContent"
VALUE="#RequestAsWDDX#"
TYPE="FORMFIELD"
>
</CFHTTP>
<CFCATCH TYPE="Any">
WDDX - HTTP Error<BR>
<CFOUTPUT>#HTMLEditFormat(CFHTTP.FileContent)#</CFOUTPUT><BR>
<CFABORT>
</CFCATCH>
</CFTRY>
<!--- Extract recordset from WDDX Packet in host's response --->
<cfif FindNoCase("<META",CFHTTP.FileContent) >
<cfset pos = FindNoCase(">",CFHTTP.FileContent)>
<cfset wddx_strg = Right(CFHTTP.FileContent,(Len(CFHTTP.FileContent)-pos-1))>
<cfelse>
<cfset wddx_strg = CFHTTP.FileContent>
</cfif>
...
</body>
</html>
I was severely overcomplicating this ha, just had to use "WDDXContent" as the Key and the WDDXContent value as the value.
Edit: I have no code for this at this point, just was able to get fiddler to reproduce it by adding a header key "WDDXContent" and value
<wddxPacket version='1.0'><header/><data><struct><var name='link_key'><string>1234</string></var><var name='id'><string>[id here]</string></var></struct></data></wddxPacket>
Related
I am downloading data from an API from one of our vendors. The data is an array but some of the fields are empty and come over as undefined. I am able to get most of the information out with a loop but when I add the field "notes" it fails with the error of:
"Element notes is undefined in a CFML structure referenced as part of an expression. The specific sequence of files included or processed is:
C:\websites\Fire\Reports\xml_parse\Crewsense_payroll_loop.cfm, line:
21 "
When I look at the dump I see that the field shows as "undefined". I've run out of ideas. Any help would be greatly appreciated. I've included the entire code and a link to the dump showing the array.
<cfhttp url="https://api.crewsense.com/v1/payroll? access_token=as;lkdfj;alskdfj;laksdfj&token_type=bearer&start=2019-01-05%2019:00:00&end=2019-01-06%2007:59:00" method="GET" resolveurl="YES" result="result">
</cfhttp>
<cfoutput>
<cfset ApiData = deserializeJSON(result.filecontent)>
<cfset API_ArrayLength = arraylen(ApiData)>
<cfloop index="i" from="1" to=#API_ArrayLength#>
#i# #ApiData[i]["name"]#
#ApiData[i]["employee_id"]#
#ApiData[i]["start"]#
#ApiData[i]["end"]#
#ApiData[i]["total_hours"]#
#ApiData[i]["work_type"]#
#ApiData[i]["work_code"]#
#ApiData[i]["user_id"]#
#ApiData[i]["notes"]# <---Fails here when added--->
<cfset i = i+1>
<br>
</cfloop>
<cfdump var="#ApiData#">
</cfoutput>
Dump
When dealing with data structures that have optional elements you will need to check for their existence before trying to access them. Otherwise you will get that error. I have added a snippet with an if condition utilizing the structKeyExists() function to your code as an example.
<cfhttp url="https://api.crewsense.com/v1/payroll? access_token=as;lkdfj;alskdfj;laksdfj&token_type=bearer&start=2019-01-05%2019:00:00&end=2019-01-06%2007:59:00" method="GET" resolveurl="YES" result="result">
</cfhttp>
<cfoutput>
<cfset ApiData = deserializeJSON(result.filecontent)>
<cfset API_ArrayLength = arraylen(ApiData)>
<cfloop index="i" from="1" to=#API_ArrayLength#>
#i# #ApiData[i]["name"]#
#ApiData[i]["employee_id"]#
#ApiData[i]["start"]#
#ApiData[i]["end"]#
#ApiData[i]["total_hours"]#
#ApiData[i]["work_type"]#
#ApiData[i]["work_code"]#
#ApiData[i]["user_id"]#
<cfif structKeyExists(ApiData[i],"notes")>
#ApiData[i]["notes"]# <!--- Show 'notes' if it exists --->
<cfelse>
'notes' is not available <!--- Do something here (or not) --->
</cfif>
<cfset i = i+1>
<br>
</cfloop>
<cfdump var="#ApiData#">
</cfoutput>
I am trying to convert the paypal response of the following code
<CFHTTP URL="#serverURL#" METHOD="POST" proxyserver=#proxyName# proxyport="#proxyPort#">
<cfloop collection=#requestData# item="key">
<CFHTTPPARAM NAME="#key#" VALUE="#requestData[key]#" TYPE="FormField" ENCODED="YES">
</cfloop>
</CFHTTP>
usingcfx_htt5 but somehow my try is going wrong:
I gave the following shot, but not working
<CFSET BODY="#key#=#requestData[key]#">
<CFX_HTTP5 METHOD="POST" URL="#serverURL#" BODY="#BODY#" OUT="RES">
at the top it is using loop and proxy and i am not sure how do i do it here
I prefer to add all of the FORM parameters to an array and then convert it to a list. Read the documentation and ensure that the values are URLEncoded. You may need to add additional headers too using. (I prefer to always use a custom user agent.) If you set SSL="5", you can additionally force the use of the TLS1.2 protocol.
<CFSET CRLF=Chr(13) & Chr(10)>
<CFSET Params = ArrayNew(1)>
<CFLOOP COLLECTION=#requestData# ITEM="key">
<CFSET ArrayAppend(Params, "#key#=#URLEncodedFormat(requestData[key])#">
</CFLOOP>
<CFSET BODY=ArrayToList(Params, "&")>
<CFSET HEADERS="Content-Type: application/x-www-form-urlencoded#CRLF#">
<CFX_HTTP5 METHOD="POST" URL="#serverURL#" BODY="#BODY#" HEADERS="#Headers#" OUT="RES" SSL="5">
Currently working with Coldfusion 10 and cfsearch.
After many hours of trial and error, I have managed to get cfindex to collect all my custom field data so that it is available to me as fields for the output on my search results page.
My only issue now, is that the search will be able to search for things like true / false strings and it will return in the search results.
I could run a QoQ to strip those out, im just wondering if anyone has any suggestions for adding fields to an index but not having them searchable.
Any ideas greatly appreciated
my current code is below
<cftry>
<!-- create new searchable collection -->
<!--- cfcollection action= "create" collection="testsearch" path= "#expandPath('/assets/scripts/server/solr/')#" ---->
<cfcollection action= "list" name="collectionlist">
<cfdump var="#collectionlist#">
<cfquery name="MyQuery" datasource="#request.DSN#" maxrows="10">
SELECT *
FROM Store_products
</cfquery>
<cfdump var="#myQuery#">
<cfset myAttr = structNew()>
<cfset variables.columns = "COST,CREATEDDATE,CUSTOM_MESSAGE,CUSTOM_MESSAGE_LENGTH,DISPLAYNAME,DONTINCLUDEINSTOCKUPDATE,FEATUREDPRODUCT,FINALDAYS,FREEDELIVERY,HEIGHT,HTMLMETADESCRIPTION,HTMLMETAKEYWORDS,IMAGE1,IMAGE10,IMAGE2,IMAGE3,IMAGE4,IMAGE5,IMAGE6,IMAGE7,IMAGE8,IMAGE9,ISBUNDLE,ISNEWPRODUCT,ISONLINE,ISONSALE,ISSILENT,LONGDESCRIPTION,MANUFACTURER,NOVOUCHERS,ONLINEEXCLUSIVE,PARTNUMBER,PRICE,PRICELEVEL1,PRICELEVEL10,PRICELEVEL11,PRICELEVEL12,PRICELEVEL13,PRICELEVEL14,PRICELEVEL15,PRICELEVEL2,PRICELEVEL3,PRICELEVEL4,PRICELEVEL5,PRICELEVEL6,PRICELEVEL7,PRICELEVEL8,PRICELEVEL9,PRODUCTCATEGORY,PRODUCTCOLOR,PRODUCTMATERIAL,PRODUCTNAME,PRODUCTSIZE,PRODUCTSTYLE,PRODUCTTITLE,PRODUCTVIEWS,RRP,SALEEND,SALEPRICE,SALESTART,SHORTDESCRIPTION,SOLDOUT,STOCKQUANTITY,STORESORTORDER,TAXEXEMPT,VOLUME,WEIGHT,WIDTH">
<cfloop from="1" to="#ListLen(variables.columns,',')#" index="idx">
<cfset myAttr[listGetAt(variables.columns,idx,',') & "_s"] = listGetAt(variables.columns,idx,',') >
</cfloop>
<cfindex attributecollection="#myAttr#" action="update" collection="testsearch" type="custom" body="DISPLAYNAME,HTMLMETADESCRIPTION,HTMLMETAKEYWORDS,LONGDESCRIPTION,MANUFACTURER,PARTNUMBER,PRODUCTNAME,PRODUCTTITLE,RRP,SHORTDESCRIPTION" query="MyQuery" key= "productname">
<cfsearch name="searchResults" collection="testsearch" criteria="false" >
<cfdump var="#searchResults#">
<cfcatch type="any">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
I'm running Coldfusion8 and am uploading files to Amazon S3.
When displaying images, I want to check whether an image is available from S3 and if not show a fallback image. My problem is, don't know how to check for existing images.
If I list the link to an image, it's something like this:
http://s3.amazonaws.com/bucket/l_138a.jpg?AWSAccessKeyId=_key_&Expires=_exp_&Signature=_signature_
I'm trying to check for existing files like this:
<cfif fileExists("http://s3.amazonaws.com/bucket/s_" & items.filename)>
<cfdump output="e:\website\test\dump.txt" label="catch" var="found!!!">
</cfif>
Question:
Do I always have to provide accesskey, expires and signature when checking for an image? If I enter the image path without credentials in the browser, the image is loaded, so I don't understand why my fileExist is not working. Any idea?
You could use cfhttp if you have a site-wide page not found message set up.
<cfhttp url="http://a.espncdn.com/photo/2012/0813/nfl_u_flynn1x_203.jpg" method="head">
<cfdump var="#cfhttp.filecontent#">
returns object of java.io.ByteArrayOutputStream
<cfhttp url="http://a.espncdn.com/photo/20notanimage3.jpg" method="head">
<cfdump var="#cfhttp.filecontent#">
returns <html> <body> <h1>Error Processing Request</h1> </body> </html>
Can also check the statuscode returned by the server
<cfhttp url="http://a.file.exists.gif" method="head">
<cfdump var="#val(cfhttp.statuscode)#">
200 is ok, 404 is not found, etc
I've used the getObjectInfo method in the S3.cfc to see if an object exists:
<cffunction name="getObjectInfo" access="public" output="false" returntype="string"
description="Creates a bucket.">
<cfargument name="bucketName" type="string" required="yes">
<cfargument name="filekey" type="string" required="true" hint="" />
<cfset var data = "">
<cfset var content = "">
<cfset var contents = "">
<cfset var thisContent = "">
<cfset var allContents = "">
<cfset var dateTimeString = GetHTTPTimeString(Now())>
<!--- Create a canonical string to send --->
<cfset var cs = "HEAD\n\n\n#dateTimeString#\n/#arguments.bucketName#/#Arguments.filekey#">
<!--- Create a proper signature --->
<cfset var signature = createSignature(cs)>
<!--- get the bucket via REST --->
<cfhttp method="HEAD" url="http://s3.amazonaws.com/#arguments.bucketName#/#Arguments.filekey#">
<cfhttpparam type="header" name="Date" value="#dateTimeString#">
<cfhttpparam type="header" name="Authorization" value="AWS #variables.accessKeyId#:#signature#">
</cfhttp>
<cfreturn cfhttp.StatusCode />
</cffunction>
If I get a 200 status back, then I know the object exists.
I haven't used Coldfusion for a long time, but I did a quick lookup and the fileExists method seems to be for filesystem lookups, not remote URLs.
There are other Coldfusion methods for requesting URLs. One forum discussion on the subject I just quickly found is here: http://forums.adobe.com/thread/765614
But, assuming you're generating HTML to be consumed by a web browser I would suggest doing an image check / fallback in HTML/CSS/JS rather than server side. You could do this with CSS background-image tricks, or directly load and check images with JS. One question dealing with this that I found is here (there are probably a bunch of similar questions on this stuff): Inputting a default image in case the src attribute of an html <img> is not valid?
CF9 +
<cfscript>
FileExists('s3://#accessKey#:#secretKey##[your bucket]/[your file]');
</cfscript>
I have an application that uses a single signon for login in ColdFusion MX 7.0. It essentially
has a cfldap in the application.cfm. But the real issue is that I am trying to use a multi-file upload third party tool that submits to a coldfusion script with cffile and stuff in it.
Both the Flash based tool and the Java based tool are cauing an issue when I try a uploading more than 3 files at the same time. First they prompt the windows based login again. Even though I type in the credentials correctly, the upload process stops completely and only 1/2
files are uploaded.
The code for the Interface(form) for multi_file upload
<body>
<div id="EAFlashUpload_placeholder"></div>
<cfparam name="session.multiUploadError" default="">
<cfif session.multiUploadError neq "">
<font color="#FF0000"><em> <strong>Error Uploading File: </strong>
<cfoutput>#session.multiUploadError#</cfoutput></em></font>
<!--- ok. now wipe the error message clean for next time --->
<cfset session.multiUploadError = "">
</cfif><p></p>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var params = {
wmode: "window"
};
var attributes = {
id: "EAFlashUpload",
name: "EAFlashUpload"
};
var flashvars = new Object();
flashvars["uploader.uploadUrl"] = "http://iapreview.ars.usda.gov/admin/sp2.5/MultiFileUpload.cfm";
flashvars["viewFile"] = "TableView.swf";
flashvars["queue.filesCountLimit"] = "30";
flashvars["uploader.retrieveBrowserCookie"] = true;
swfobject.embedSWF("EAFUpload.swf", "EAFlashUpload_placeholder", "450", "350", "9.0.0", "expressInstall.swf", flashvars, params, attributes);
</script>
</body>
The code for the backend ColdFusion script
<cftry>
<cfif isDefined("Form.Filedata")>
<cffile action="UPLOAD" filefield="Filedata" destination="#session.siteDirectory#\#session.Directory#" nameconflict="OVERWRITE">
<cfif right(cffile.clientFile, 3) neq "htm" and right(cffile.clientFile,4) neq ".htm">
<cfelse>
<cffile action="delete" file="#session.siteDirectory#\#session.Directory#\#cffile.clientFile#">
<cfset session.multiUploadError = " " & session.multiUploadError & " #cffile.clientFile# could not be uploaded, because html files are not permitted.<br> ">
</cfif>
<!---
<cffile action="APPEND" file="f:\sitepublisher_dev\sp2\juploadoutput.txt" output="#idx# - #session.siteDirectory#\#session.Directory#\#cffile.clientFile# (#cffile.fileSize#) at #cffile.timeLastModified#" addnewline="Yes">
--->
</cfif>
The file has not been saved. Please check destination folder exists and has read/write permissions.
<cftry>
<cfif isDefined("Form.Filedata")>
<cffile action="UPLOAD" filefield="Filedata" destination="#session.siteDirectory#\#session.Directory#" nameconflict="OVERWRITE">
<cfif right(cffile.clientFile, 3) neq "htm" and right(cffile.clientFile,4) neq ".htm">
<cfelse>
<cffile action="delete" file="#session.siteDirectory#\#session.Directory#\#cffile.clientFile#">
<cfset session.multiUploadError = " " & session.multiUploadError & " #cffile.clientFile# could not be uploaded, because html files are not permitted.<br> ">
</cfif>
<!---
<cffile action="APPEND" file="f:\sitepublisher_dev\sp2\juploadoutput.txt" output="#idx# - #session.siteDirectory#\#session.Directory#\#cffile.clientFile# (#cffile.fileSize#) at #cffile.timeLastModified#" addnewline="Yes">
--->
</cfif>
<cfcatch type="Any">
<cfoutput><eaferror>The file has not been saved. Please check destination folder exists and has read/write permissions.</eaferror></cfoutput>
</cfcatch>