0

I wrote a simple application to test a RESTful API (provided by an accounting application). I have installed "Poster" in Firefox to test "GET and POST" XML and the API is behaving as it should. I wrote a simple "GET" test page to call the API from within the test CF8 application and the API returned the results I expected. I cannot POST from within the test CF8 application.

I have inserted the following into my application.cfm:

<!--- fix for HTTPS connection failures --->
<cfif NOT isDefined("Application.sslfix")>
    <cfset objSecurity = createObject("java", "java.security.Security") />
    <cfset objSecurity.removeProvider("JsafeJCE") />
    <cfset Application.sslfix = true />
</cfif>

This is the code that is failing:

<cfprocessingdirective suppressWhiteSpace = "Yes">    
    <cfxml variable="customerxml">
        <?xml version="1.0" encoding="UTF­8" standalone="yes"?>
        <dataentry>
            <interface name="Customer Edit"></interface>
            <entity>
                <attribute name="Customer Code">REP003</attribute>
                <attribute name="Customer Name">Repsol3</attribute>
                <attribute name="Address Line 1">El House</attribute>
                <attribute name="Address Line 2">El Street</attribute>
                <attribute name="Address Line 3">El Town</attribute>
            </entity>
        </dataentry>
    </cfxml>
</cfprocessingdirective>

<cfhttp 
    method="post" 
    url="https://***/wsapi/1.1/dataentry/"
    username="***"
    password="***"
    charset="utf-8">
    <cfhttpparam type="header" name="Accept-Encoding" value="*" />
    <cfhttpparam type="header" name="TE" value="deflate;q=0" />
    <cfhttpparam type="header" name="Content-Type" value="application/xml" />
    <cfhttpparam name="XML_Test" type="xml" value="#customerxml#">
</cfhttp> 

There's a lot published on this topic and I have tried most things but some of the posts are about even older CF versions than mine! Any up-to-date help appreciated.

  • 2
    Why would you remove the JsafeJCE security provider? I don't think that would help. The most likely problem is that you need to import their SSL certificate into your server's Java keystore. I have outlined the steps in [this other answer](http://stackoverflow.com/a/20475763/1636917). – Miguel-F Oct 02 '14 at 11:50
  • Can you post the actual response / error. – Nebu Oct 02 '14 at 12:21
  • Another thing to verify is that you can open a browser and connect to the URL _from your ColdFusion server_. – Miguel-F Oct 02 '14 at 12:45
  • @Miguel-F - I opened IE on my Coldfusion server and entered a URL "https://****/wsapi/..." and it failed with a suggestion that I should add the "www" - and then it did work! I included the www in the above code and did NOT get the "Connection Failure" message - instead I got an error message FROM the application I am trying to connect to. Progress!! – HitAWallAgain Oct 02 '14 at 14:55
  • Great! Glad you got passed that hurdle. I will go ahead and add an answer for you since that answers this question regarding the connection failure. If you run into something else than please post a new question. Good luck! – Miguel-F Oct 02 '14 at 17:19

2 Answers2

2

From the comments

The first thing that I try when receiving a connection failure using <cfhttp> is to verify that you can navigate to the URL using a browser from your ColdFusion server. If that request does not work then it will not work from the ColdFusion call either. Get that issue resolved first before proceeding.

Another common issue when connecting to secure sites using SSL (HTTPS) is that the certificate is not trusted or not known to ColdFusion (Java). In these cases you need to import their certificate into the Java keystore that is in use for ColdFusion.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
0

Here is a great step by step instructions on how to install self-signed certs or other ssl certs that the Java library does not have installed.

http://www.coldfusioncookbook.com/entries/How-Do-I-Consume-SSL-Encrypted-Content-with-CFHTTP.html

Has helped me out a 1000 times. Matt

Matthew Friedman
  • 491
  • 1
  • 5
  • 12