Coldfusion web service problem solving - web-services

On CF 9.01, Windows Web Server 2008 R2, a web service has stopped running here, so I'm trying to figure out the problem. I think the problem may have started when I applied the 9.01 hotfix.
I added a test.cfc to the server
<cfcomponent output="false">
<cffunction
name = "echoString"
output = "no"
access = "remote" returntype="any">
<cfargument required="true" name="inputString" type="string"/>
<cfreturn arguments.inputString>
</cffunction>
</cfcomponent>
and call it with
<cfinvoke webservice="https://nww.somedomain.nhs.uk/cfcs/test.cfc?wsdl"
method="echoString" returnvariable="returnedString">
<cfinvokeargument name="inputString" value="test string 2">
</cfinvoke>
and get the string response, but in the cf administrator the web service is not being added
when I invoke the web service for the first time as I think it should be.
Other than reinstalling CF or trying to roll back manually, any clues as to the problem or how I can test please?
I'm on 9,0,1,274733 . The https is not the problem I think. Firstly it was working fine then with no change to code it stopped. Secondly my test invocation of test.cfc works as expected over https.
If I hit https://nww.somedomain.nhs.uk/cfcs/test.cfc?wsdl (which works) or my problem cfc https://nww.somedomain.nhs.uk/cfcs/providerapi.cfc?wsdl directly in the browser they both correctly show the XML details.
However, invoking either of the CFCs does not add them to the active web services list in administrator.
I pasted the "echostring" method to my problem CFC (providerapi.cfc) and tried calling the method but I get a "webservice cannot be found" error. It's like the providerapi.cfc is cached , but I can't see it in administrator to delete it.

I tried this verbatim on 9,0,1,274733 and it worked 100% fine. I am using Win 7 and I just tried it on my dev environment. The web service was added to the list in CF admin so you are correct to expect that.
Can you ensure that you can hit the URL direct (i.e. https://nww.somedomain.nhs.uk/cfcs/test.cfc?wsdl) in your browser and view source to see the WSDL XML?
One thing that jumps out is the use of https:// in your web service invocation. Can you try it with just http:// or even better against your localhost?

Related

How to create and use web services in ColdFusion

I tried creating a web service in ColdFusion, for that I just created a component with a function inside it having access="remote"
<cfcomponent displayname="testPost" hint="testing.." output="yes">
<cfsetting enablecfoutputonly="true" showdebugoutput="true">
<cffunction access="remote" output="true" name="testPostReq" displayname="testPostReq" description="testing" returntype="any">
<cfset p=9>
<cfreturn p>
</cffunction>
</cfcomponent>
Now I wanted to call this webservice and I am trying to hit this in my browser, https://sampleapp.xyz.com/DirectoryToCfc/CfcName.cfc?wsdl but in browser I am getting "Unsupported Operation. Check application log for more details." when I checked application logs I saw this log there:
"Warning","ajp-bio-8013-exec-4","09/27/21","12:57:55","COMPONENTUTILS","To use Component Browser, enable RDS Service using Administrator. Note: RDS is intended for development use only."
How can I deal with this, any idea? Is it possible to do without enabling RDS?
Please let me know if you know something about this, I will be really grateful.
You can create a webservice for WSDL. Here I'm going to taken an some real time demo url http://www.dneonline.com/calculator.asmx?wsdl & Coldfusion 2018. Please follow the below steps.
Step 1 : Create webservice in CFAdmin - > Data & Service - > Webservices
Step 2 : Give the Webservice name & WSDL URL value. Refer my image here (TestService.png) I've created 'TestService' for the url http://www.dneonline.com/calculator.asmx?wsdl.
Step 3 : Once you added it successfully. You can able to see that in "Active Coldfusion WebService Options"
Step 4 : With the help of createObject method & webservice value you can call your all methods in your WSDL url. For example,
<cfset myObj = createObject('webservice','TestService')>
<cfdump var='#myObj#' abort="true">
Step 5 : You can see my below dump about demo webservice url Methods & Classes. Refer image dumpService.png
I hope this will help you to know about simple Webservice.

Receive email alert when Coldfusion CFQUERY time limit exceeded

This morning our Amazon EC2 Windows server became nearly unresponsive, throwing 500 errors intermittently. In the CF log I see a bunch of these errors:
The request has exceeded the allowable time limit Tag: CFQUERY
After rebooting the server, everything is back to normal.
While I hunt down the root cause for this, is it possible to configure CF Admin to send an email when a certain Log File error begins to appear several times in a row, like this one? We have already configured Health Status Checks for outages on EC2, but they never triggered because the server was still running, just incredibly slowly. I would like to be the first responder to situations like this but didn't know because I wasn't actively monitoring the server when it occurred - a user had to alert me to the problem a couple of hours later, which is embarrassing for me.
Thanks in advance!
Don't know if this is best practice, but what I do is utilize the OnError function in the application.cfc for reporting of unhandled errors.
<cffunction name="onError" returnType="void" hint="Runs when an uncaught exception occurs in the application.">
<cfargument name="Exception" required=true/>
<cfargument name="EventName" type="String" required=true/>
<cfmail to="myemail#mydomain.edu" from="myemail#mydomain.edu" subject="Error Alert" type="html">
<cfdump var="#session#">
<cfdump var="#CGI#">
<cfdump var="#Exception#">
</cfmail>
</cffunction>
You could obviously filter down to the types of errors you want reported.
If you just want to check specifically in the function (where the time out occurred), then you should use:
<cffunction name="yourfunction">
<cftry>
...
<cfcatch>
<cfmail to="myemail#mydomain.edu" from="myemail#mydomain.edu" subject="Error:yourfunction">
<cfdump var="#session#">
<cfdump var="#CGI#">
<cfdump var="#cfcatch#">
</cfcatch>
</cftry>
<cffunction>
Query timeouts are not the only source of overwhelmed servers. You might want something more global.
What you can do on the CF Administrator app is to use Alert Configuration. Not only does this allow you to notify yourself if certain conditions are met, but you can also kill the problematic threads.
What we have done in addition to that, is to schedule a script on our development server to attempt an http request to the production server with a one second timeout. If the attempt fails, mail gets sent to people, pagers, and cell phones.

Should I use CFTHREAD to slow down bot traffic?

We recently migrated our site from application.CFM to application.CFC. The CFM version could handle our excessive bot traffic, but our CFC version can't. We are trying to figure out why the CFC problem is. In the meantime, we are trying to limit bot traffic.
Currently, I am looking for a solution within the code base to slow bot traffic. We can do this by looking at the user agent as well as IP address.
We have used the code below to successfully stop many bots.
<cffunction name="OnRequestStart">
<cfif find("bot", cgi.httP_USER_AGENT)>
<cfabort>
</cfif>
</cffunction>
Obviously, we do want some bot traffic. But right now, we can't handle all of the bot traffic. It appears that as soon as we you abort to stop a request, another request is right behind it and eventually they bring down our server.
Instead of stopping the bots, what would the ramifications be of using CFTHREAD to slow the bots?
<cffunction name="OnRequestStart">
<cfif find("bot", cgi.httP_USER_AGENT)>
<cfthread action="sleep" duration="5"></cfthread>
</cfif>
</cffunction>
Would using CFTHREAD just stack up the requests and eventually kill our server or would the bots respond with fewer requests per hour?

Cannot add the most basic RESTful web service

I'm on Windows 2008 R2 (64-bit) using CF10 (64-bit) (developer edition?)
I am trying to implement this very basic tutorial:
http://blogs.coldfusion.com/post.cfm/rest-support-in-coldfusion-part-i
I created a new website through IIS on port 8081 and then added two files:
/index.cfm (in theory, since no application.cfc containing app vars was needed, I could have skipped this)
<cfset s = "Hello World!">
<cfoutput>#s#</cfoutput>
/RestExample/HelloWorld.cfc
<cfcomponent rest="true" restPath="/hello">
<cffunction name="sayHello" access="remote" returnType="String" httpMethod="GET">
<cfset res="Hello World">
<cfreturn res>
</cffunction>
</cfcomponent>
In CF Admin:
Root Path: C:/websites/test/RestExample/
Service Mapping: Example
I get the following error:
Error registering REST service. Please ensure that you have entered a proper mapping and path.
Application Example could not be initialized.
Reason: The application does not contain any rest enabled CFCs.
The application does not contain any rest enabled CFCs.
A bit of system information:
Server Product ColdFusion
Version 10,0,8,284032
Tomcat Version 7.0.23.0
Edition Developer
Serial Number Developer
Operating System Windows Server 2008 R2
OS Version 6.1
Update Level /C:/ColdFusion10/cfusion/lib/updates/chf10000008.jar
Adobe Driver Version 4.1 (Build 0001)
JVM Details
Java Version 1.6.0_29
Java Vendor Sun Microsystems Inc.
Java Vendor URL http://java.sun.com/
Java Home C:\ColdFusion10\jre
Not sure if it's a configuration issue at this point? This is related to my previous question, and trying to simplify everything to isolate the cause.
Edit #1
I was able to add a this very simple RESTful service to a Windows 7 64-bit / CF 10 (no updates) without any issues. I wonder if it's my install that is corrupt or the update that corrupted it?
Edit #2
I reinstalled my CF server and it still gave me the same issue.
Edit #3
As per milanchandna's suggestions, I followed these steps:
Created a folder c:\websites\milanchandna
Created a new website (milanchandna using the apppool with the same name) in IIS and used c:\websites\milanchandna as root, running on port 8084
Created jakarta virtual directory (need this)
Added basic HelloWorld.cfc
Navigated to HelloWorld.cfc with success, no errors
In CF Admin, REST Services, added the following:
Root Path: C:/websites/milanchandna/
Service mapping: Example
Click Add Service
Get error:
Error registering REST service. Please ensure that you have entered a proper mapping and path.
Application Example could not be initialized.
Reason: The application does not contain any rest enabled CFCs.
The application does not contain any rest enabled CFCs.
HelloWorld.cfc:
<cfcomponent rest="true" restPath="/hello">
<cffunction name="sayHello" access="remote" returnType="String" httpMethod="GET">
<cfset res="Hello World">
<cfreturn res>
</cffunction>
</cfcomponent>
I created the files under C:\ColdFusion10\cfusion\wwwroot (instead of the site's IIS root) and was able to register the REST service via the administration console without any issue.
As this is a basic example not working, I will suggest to follow it from starting.
Create a fresh new folder in IIS webroot. This should not be inside any folder already being used for CF REST.
Just put one simple rest cfc in this folder and nothing else. The CFC example given in your problem description looks good, let's use that.
Access this CFC from browser as you would access any cfm
eg:[http://mysite:8081/mypath_to_cfc/mycfc.cfc]
Check if this throws any error. If it does, then there is a problem in CFC. If it doesn't then you are good to go.
Register this folder as REST application from administrator.

ColdFusion WSDL times out on first call

I have a web service setup for on a small part of a website and while the site overall gets a good amount of traffic this particular service does not. Once a day when I go to send a request through the web service it will fail on the first attempt, but retrying the request a second time works just fine. It's as if it was no longer cached in memory and times out while starting up.
Is there a way to keep this service active either on my end or on the web service provider's end which is also CF app (separate division of our company)? It's a bit hard to troubleshoot because it only happens once after a long period. And I don't want to setup a separate process just to keep pinging this service.
If the server is being restarted regularly between calls to the template, ensure the "save class files" setting is enabled in the administrator (under caching) to prevent the template from being recompiled after each server reload.
You can try to use following method on a webservice client side.
CF7+ got built-in coldfusion.server.ServiceFactory Java service.
Code can look like
<cftry>
<!--- here goes attempt to invoke service method, maybe dummy "ping" --->
<cfcatch type="any">
<!--- trying to refresh WSDL --->
<cfset createObject("java","coldfusion.server.ServiceFactory").XmlRpcService.refreshWebService(ServiceURL) />
</cfcatch>
</cftry>
<!--- usual code --->
Hope this helps.
Note: this factory contains a lot of useful methods, but almost zero documentation over the internet. Good idea would be to dump it and explore a bit.
Try increasing the requesttimeout and see if that helps.