Is there a way to troubleshoot an issue with CFHTT...
# cfml-general
e
Is there a way to troubleshoot an issue with CFHTTP calls? works in postman works in powershell but when running in lucee i just get connection failure
b
TEll it to throw on error
prolly an SSL error
Adobe CF is terrible about hiding the underlying exception
but Lucee will usually show it to you
Copy code
throwonerror=true
That should show you the underlying error
@emergence
e
seems like it should be an ssl issue, thought i installed the cert last week, installed again, same error...
b
Where's the full error?
That's like 10% of it, lol
e
lucee.runtime.exp.NativeException: Connection reset at java.base/java.net.SocketInputStream.read(Unknown Source) at java.base/java.net.SocketInputStream.read(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(Unknown Source) at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(Unknown Source) at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(Unknown Source) at <http://org.apache.http.impl.io|org.apache.http.impl.io>.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137) at <http://org.apache.http.impl.io|org.apache.http.impl.io>.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153) at <http://org.apache.http.impl.io|org.apache.http.impl.io>.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) at <http://org.apache.http.impl.io|org.apache.http.impl.io>.AbstractMessageParser.parse(AbstractMessageParser.java:259) at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at lucee.runtime.tag.Executor4.execute(Http.java:1909) at lucee.runtime.tag.Executor4.run(Http.java:1896) at lucee.commons.lang.PageContextThread.run(PageContextThread.java:25) Caused by: java.net.SocketException: Connection reset ... 26 more
b
Hmm, I don't see any SSL issues there
Copy code
lucee.runtime.exp.NativeException: Connection reset 
at java.base/java.net.SocketInputStream.read(Unknown Source) 
at java.base/java.net.SocketInputStream.read(Unknown Source) 
at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source) 
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(Unknown Source) 
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(Unknown Source) 
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(Unknown Source) 
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(Unknown Source) 
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137) 
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153) 
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280) 
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) 
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) 
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) 
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) 
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157) 
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) 
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) 
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) 
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) 
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) 
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) 
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) 
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) 
at lucee.runtime.tag.Executor4.execute(Http.java:1909) 
at lucee.runtime.tag.Executor4.run(Http.java:1896) 
at lucee.commons.lang.PageContextThread.run(PageContextThread.java:25) 
Caused by: java.net.SocketException: Connection reset ... 26 more
Is a proxy required to hit this endpoint?
Can you ping the same host name from the CF server?
If the URL is generated dynamically, ensure it's valid and complete at the point where the code is calling it
There is a small chance this is related to valid SSL ciphers
Those can cause a low level reset of the socket if the client and server can't agree
e
i get an access token via a post call to same host, no issues
b
you'd need to enable the JVM's SSL debugging output
Wait, so you're saying a
POST
HTTP request works, but a
GET
to the exact same host gets the socket reset 🤔
e
nope, secondary POST call that sends over xml file throws the error
b
Ok, I'm confused then
So they both don't work?
(get and post)
If so, what did this message mean
i get an access token via a post call to same host, no issues
e
Sorry getting the access token is a POST method as well, and returns a JWT which gets passed along to the next API call
Copy code
<cfhttp url="#local.theURI#" method="post" result="local.result" timeout="#local.maxTimeout#" compression="false" throwonerror="true">
	<cfhttpparam type="xml" file="#local.xmlString#" />
	<cfhttpparam type="header" name="reference-id" value="#local.referenceID#" />
	<cfhttpparam type="header" name="authToken " value="#local.token#" />
</cfhttp>
originally i kept thinking it the xml file that i need to send over, tried to add multipart="true" to the http call along with switch the cfhttpparam type to file with the file path but no dice
powershell way would be
Copy code
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
    $headers.Add("authToken", $token)
    $headers.Add("reference-id", "IT001")

    # Create the form data with the file
    $form = @{
        file = Get-Item -Path $xmlFilePath
    }

    $response = Invoke-RestMethod $theURI  -Method 'POST' -Headers $headers  -Form $form -ContentType "multipart/form-data"
p
An XML type attribute cannot be used with additional XML type attributes, or with body, file, or formField type attributes.
Is the XML file your sending a "file" from disk?
<cfset local.xmlString = "c:\files\localfile.xml />? <cfhttpparam type="file" file="#local.xmlString#" />
Or is it XML generated string? In which case file should not be added to the <cfhttp param tag
r
☝🏼good point, server may expect proper content/type header, size header, or maybe xml file is too big for example
e
same xml file is being used in the powershell/postman version i'll try to spin up a few variations of http request
Here was an attempt at a few variations
Copy code
<cftry>
<cfhttp url="#local.theURI#" method="post" result="local.result1" timeout="#local.maxTimeout#" throwonerror="true" multipart="true">
	<cfhttpparam type="header" name="reference-id" value="#local.referenceID#" />
	<cfhttpparam type="header" name="authToken " value="#local.token#" />
	<cfhttpparam type="formfield" name="file" value="#local.xmlTempPath#" />
</cfhttp>
<cfcatch type="any">
	<cfdump var="#cfcatch#" label="result1"/>
</cfcatch>
</cftry>
<cftry>
<cfhttp url="#local.theURI#" method="post" result="local.result2" timeout="#local.maxTimeout#" throwonerror="true" multipart="true">
	<cfhttpparam type="header" name="reference-id" value="#local.referenceID#" />
	<cfhttpparam type="header" name="authToken " value="#local.token#" />
	<cfhttpparam type="file" name="file" file="#local.xmlTempPath#" />
</cfhttp>
<cfcatch type="any">
	<cfdump var="#cfcatch#" label="result2"/>
</cfcatch>
</cftry>
<cftry>
<cfhttp url="#local.theURI#" method="post" result="local.result3" timeout="#local.maxTimeout#" throwonerror="true" multipart="true">
	<cfhttpparam type="header" name="reference-id" value="#local.referenceID#" />
	<cfhttpparam type="header" name="authToken " value="#local.token#" />
	<cfhttpparam type="formfield" name="file" value="#local.xmlTempPath#" />
</cfhttp>
<cfcatch type="any">
	<cfdump var="#cfcatch#" label="result3"/>
</cfcatch>
</cftry>
<cftry>
<cfhttp url="#local.theURI#" method="post" result="local.result4" timeout="#local.maxTimeout#" throwonerror="true" multipart="true">
	<cfhttpparam type="header" name="reference-id" value="#local.referenceID#" />
	<cfhttpparam type="header" name="authToken " value="#local.token#" />
	<cfhttpparam type="xml" value="#local.xmlTempPath#" />
</cfhttp>
<cfcatch type="any">
	<cfdump var="#cfcatch#" label="result4"/>
</cfcatch>
</cftry>
All received the same Connection Reset error, so something in the request the server must not like
Copy code
lucee.runtime.exp.NativeException: Connection reset at java.base/java.net.SocketInputStream.read(Unknown Source) at java.base/java.net.SocketInputStream.read(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.read(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(Unknown Source) at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(Unknown Source) at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(Unknown Source) at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(Unknown Source) at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137) at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153) at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138) at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56) at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259) at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163) at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157) at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273) at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at lucee.runtime.tag.Executor4.execute(Http.java:1909) at lucee.runtime.tag.Executor4.run(Http.java:1896) at lucee.commons.lang.PageContextThread.run(PageContextThread.java:25) Caused by: java.net.SocketException: Connection reset ... 26 more
s
maybe try posting back to a CF page so you can compare what the Post looks like from postman/powershell vs what CF is posting
👍 1
e
only thing that I see that is different between them is Content-type : Boundary is in quotes on the powershell version cfml on the left powershell on the right
s
the content length is also different, i assume it should be the same?
e
oh your right, let me convert the content from the byte array to something a little more useable
first characters of powershell
Copy code
--ccd8c057-34f5-4d16-856e-aa6adf95ab37 Content-Disposition: form-data; name=file; filename=34176-61421.xml; filename*=utf-8''34176-61421.xml Content-Type: application/octet-stream
first characters of lucee
Copy code
--XFuZC2y7FkKIsKMPWAmXae-hiBkrfLWB Content-Disposition: form-data; name="file" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit
but this was sending it via the formfield httpparam
Copy code
<cfhttp url="#local.theURI#" method="post" result="local.result1" timeout="#local.maxTimeout#" throwonerror="true" multipart="true">
	<cfhttpparam type="header" name="reference-id" value="#local.referenceID#" />
	<cfhttpparam type="header" name="authToken " value="#local.token#" />
	<cfhttpparam type="formfield" name="file" value="#local.xmlString#" />
</cfhttp>
swapping it over to the http param type of file, looks closer
Copy code
Content-Disposition: form-data; name="file"; filename="exportToRemote_39_2E1EA35E-32CB-4C3D-8FE6-2C70DC69B0DD.xml" Content-Type: application/octet-stream Content-Transfer-Encoding: binary
Copy code
<cfhttp url="#local.theURI#" method="post" result="local.result2" timeout="#local.maxTimeout#" throwonerror="true" multipart="true">
	<cfhttpparam type="header" name="reference-id" value="#local.referenceID#" />
	<cfhttpparam type="header" name="authToken " value="#local.token#" />
	<cfhttpparam type="file" name="file" file="#local.xmlTempPath#" mimetype="application/octet-stream"  />
</cfhttp>
s
authToken header has a trailing space in the name, i assume that's a mistake? other than that, could try the exact same token/file to reduce differences between the posts maybe if they're not already?
🙏 1
e
oh, my goodness, that was the thing that I missed, I knew it had to be something silly like that, thank you so much @s1deburn!
👍 1