cfhttp peer not authenticated error in coldfusion 9 enterprise - coldfusion

I am working on a old server which is running CF9 and is still a part of the development of the company. I have to make a <cfhttp> call to get a response from a website. If I run it in a browser, I get the expected response in XML. However, when I make a <cfhttp> call, it just throws an error.
Code:
<cfset objSecurity = createObject("java", "java.security.Security") />
<cfset storeProvider = objSecurity.getProvider("JsafeJCE") />
<cfset objSecurity.removeProvider("JsafeJCE") />
<cfhttp url="https://apiwebsite/api/integration/v1/events/a200363c-6b8f-4876-8cd0-105d41bb2fdf?oauth_version=1.0&oauth_nonce=73aa7a7d2bfdff27fd04e3967e313d5d&oauth_timestamp=1495298341&oauth_consumer_key=consumer_key&oauth_signature_method=HMAC-SHA1&oauth_signature=btkwYPlWGuquUOpwUNPFcLA17q8%3D"/>
<cfset objSecurity.insertProviderAt(storeProvider, 1) />
<cfdump var="#cfhttp#">
Error from cfdump:
ErrorDetail I/O Exception: peer not authenticated
Filecontent Connection Failure
Header [empty string]
Mimetype Unable to determine MIME type of file.
It is so frustrating as I do not know how to fix it. I am open to looking around at custom tags if needed.

Related

Coldfusion 9 webservice error

I am trying to run a webservice using coldfusion. I can run the wsdl in the browser fine. When I try to run it via coldfusion I get:
Unable to parse WSDL as an XML document.
Parsing error: Fatal Error: URI=null Line=-1: Premature end of file.
It is recommended that you use a web browser to retrieve and examine the requested WSDL document to ensure it is correct.
I have tried multiple methods:
wsargs.login='******';
wsargs.password='******';
ws = CreateObject("webservice", "https://correcturl.com/dswsbobje/qaawsservices/biws?WSDL=1&cuid-******", wsargs);
req = getSOAPRequest(ws);
</cfscript>
<cfdump var="#req#">
<cfset wsargs = structNew()>
<cfset wsargs["login"]="******">
<cfset wsargs["password"]="******">
<cfinvoke webservice="https://correcturl.com/dswsbobje/qaawsservices/biws?WSDL=1&cuid=******"
method="runQueryAsAService"
returnvariable="results"
argumentCollection="#wsargs#">
</cfinvoke>
<cfinvoke webservice="https://correcturl.com/dswsbobje/qaawsservices/biws?WSDL=1&cuid=******"
method="runQueryAsAService"
returnvariable="results">
<cfinvokeargument name="login" value="******"/>
<cfinvokeargument name="password" value="******"/>
</cfinvoke>
But all give me this error. I have see other related errors and have tried the solutions in them, such as clearing out the Application.cfc/cfm and adding refreshwsdl='true' to the cfinvoke, none of which have done anything. Can anyone help me with this?
Thanks.
I guess I didnt have a full understanding of how this works. The url I was trying to use was to what I guess was the wsdl definition. I ran url an via wizdler ran the method. That then gave me a soap request that I then saved in a cfcsave content tag. My final code that worked looks like:
<cfset strURL = "https://correcturl.com/dswsbobje/qaawsservices/biws?WSDL=1&cuid=******">
<cfsavecontent variable="strXML">
<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
<Header>
<QaaWSHeader xmlns="VendorInfo">
<sessionID>[string?]</sessionID>
<serializedSession>[string?]</serializedSession>
<ClientType>[string?]</ClientType>
<AuditingObjectID>[string?]</AuditingObjectID>
<AuditingObjectName>[string?]</AuditingObjectName>
</QaaWSHeader>
</Header>
<Body>
<runQueryAsAService xmlns="VendorInfoLR">
<login>******</login>
<password>******</password>
</runQueryAsAService>
</Body>
</Envelope>
</cfsavecontent>
<cfhttp url="#strURL#" method="post" useragent="#CGI.http_user_agent#" result="objGet">
<cfhttpparam type="XML" value="#strXML.Trim()#" />
</cfhttp>
Idea from :http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Q_24311762.html
This soap stuff is new to me, and I have more research to do to fully understand it. :)

XMLParse Coldfusion 9 - Content Not Allowed In Prolog

I am trying to parse some data from Australia Post using Coldfusion, the code works perfectly when i'm using CF10 locally but the problem is that the servers i'm using are using CF9 and i'd rather keep them with 9.
When i try the code in CF9 i get "Content not allowed in prolog" no matter what i try, i managed to do a ReReplace when then threw the error of "Premature end of file" so i'm not sure what else to try also on the server it's using IIS6 i don't know if that's contributing to the issue
I've also connected the SSL certificate through the keystore as i read that could be an issue as well
<cfhttp url="https://auspost.com.au/api/postage/parcel/domestic/service.xml?from_postcode=2128&to_postcode=6000&length=96&width=8&height=5&weight=1.5" method="get">
<cfhttpparam type="header" name="auth-key" value="*******">
</cfhttp>
<cfset objBuffer = CreateObject(
"java",
"java.lang.StringBuffer"
).Init()
/>
<cfset objBuffer.Append(cfhttp.filecontent) />
<cfset xmlDoc =XmlParse(objBuffer)>
<cfdump var="#xmlDoc#">

grabbing JSON data using coldfusion

I have a URL which when run in the browser, displays JSON data, since I am new to coldfusion, I am wondering, what would be a good way to
grab the data from the web browser? Later on I will be storing the individial JSON data into MySQL database, but I need to figure out step 1
which is grabbing the data.
Please advise.
Thanks
You'll want to do a cfhttp request to load the external content.
Then you can use deserializeJSON to convert the JSON object into the appropriate cfml struct.
See the example Adobe gives in the deserializeJSON documentation.
Here is quick example:
<!--- Set the URL address. --->
<cfset urlAddress="http://ip.jsontest.com/">
<!--- Generate http request from cf --->
<cfhttp url="#urlAddress#" method="GET" resolveurl="Yes" throwOnError="Yes"/>
<!--- handle the response from the server --->
<cfoutput>
This is just a string:<br />
#CFHTTP.FileContent#<br />
</cfoutput>
<cfset cfData=DeserializeJSON(CFHTTP.FileContent)>
This is object:<br />
<cfdump var="#cfData#">
Now you can do something like this:<br />
<cfoutput>#cfData.ip#</cfoutput>
Execute this source here http://cflive.net/

how to get the coldfusion instance server name

this is my code .
<cfhttp method="head" url="http://www.sisystems.com" result="myResult">
<cfoutput>
#myResult.Statuscode#
</cfoutput>
This code gives the status code for this url . i need to know in which coldfusion server it hits.
You can get the coldfusion server instance name using coldfusion adminapi as below
runtime = createObject("component", "CFIDE.adminapi.runtime");
instanceName = runtime.getInstanceName();
Thanks
For your question in the comments of Sunny's answer - You can use the following Java methods to gather information about the particular server that ColdFusion is running on:
<cfset cfHostName = createObject("java", "java.net.InetAddress").localhost.getHostName() />
<cfset cfCanonName = createObject("java", "java.net.InetAddress").localhost.getCanonicalHostName() />
<cfset cfHostAddress = createObject("java", "java.net.InetAddress").localhost.getHostAddress() />
And prior to ColdFusion 10, when ColdFusion is running on JRun you can also use the following:
<cfset cfInstance = createObject("java", "jrunx.kernel.JRun").getServerName() />

Coldfusion GetHttpRequestData()?

Does anyone have an example of how Coldfusion's GetHttpRequestData() works? I'm looking to use this func to save data from the AJAX Upload script: http://valums.com/ajax-upload/
The script works in FireFox but not Safari, Chrome, etc...
Ideas?
What error do you get?
Maybe these links will help:
http://www.coldfusionjedi.com/index.cfm/2007/7/1/Undocumented-change-to-GetHTTPRequestData-in-ColdFusion-8
http://www.bennadel.com/blog/1602-GetHTTPRequestData-Breaks-The-SOAP-Request-Response-Cycle-In-ColdFusion.htm
You might also want to read this recent thread about that script. As valums suggested, you should be able to extract the binary data from getHttpRequestData().content (when needed).
In my very limited tests, it seemed to work okay with IE8/FF/Chrome/Opera. However, I had no luck with Safari (windows). It seemed like the request data was getting mangled (or possibly misinterpreted by CF?). So the final content-type header reported by CF was incorrect, causing an http 500 error. Granted, I did not test this extensively.
Here is my quick and dirty test script (lame by design...)
<cfset uploadError = "" />
<cfif structKeyExists(FORM, "qqFile")>
<!--- upload as normal --->
<cffile action="upload" filefield="qqFile" destination="c:/temp" />
<cfelseif structKeyExists(URL, "qqFile")>
<!--- save raw content. DON'T do this on a prod server! --->
<!--- add security checks, etc... --->
<cfset FileWrite( "c:/temp/"& url.qqFile, getHttpRequestData().content) />
<cfelse>
<!--- something is missing ...--->
<cfset uploadError = "no file detected" />
</cfif>
<!--- return status old fashioned way (for compatibility) --->
<cfif not len(uploadError)>
{"success": true}
<cfelse>
<cfoutput>{error": "#uploadError#"}</cfoutput>
</cfif>
You want to look into using cffile with action="upload" to upload the file: http://cfdocs.org/cffile
GetHttpRequestData() is intended for decoding protocols like SOAP, XML-RPC, and some of the more complex REST-ful protocols. HTTP file uploads are normally done as POSTs using the multipart/form-data MIME type. Looking at http://www.cfquickdocs.com/it doesn't appear that GetHttpRequestData() has any special support for multipart data, which means you'd have to split and decode the parts yourself. Not my idea of fun, and completely unnecessary if you're just doing file uploading.
<cffile action="upload"> or <cffile action="uploadAll"> (new for CF9) should be quite sufficient for processing file uploads, even for those done via an AJAX upload script.