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() />
Related
I have an existing ColdFusion application in my server. What I needed is a duplicate of that application. What I did was copy the entire folder of the original application and put it into another folder.
I already edited the Application.cfm and the links across all the pages in my copy. However, .../indexc.cfm?page=a_app_checklist - in this case, the a_app_checklist is not being updated even if I changed everything on my server /Copy/pages/app/a_app_checklist.cfm
I tried to upload the updated a_app_checklist.cfm on the original application and from there, it was updated. What should I do because I want my copy of the application to be a stand-alone from the original application.
Here is a part of my Application.cfm code:
<cfapplication name="Applicationv2" sessionmanagement="yes" setclientcookies="yes" sessiontimeout="#CreateTimeSpan(00,00,30,00)#"
applicationtimeout="#CreateTimeSpan(00,01,00,00)#" clientstorage="cookie" loginstorage="session">
<cfparam name="Url.page" default="a_main_index">
<cfparam name="Url.formpage" default="">
<cfparam name="Url.resetAppCache" default="">
<!--- Set the Application variables if they aren't defined. --->
<cfset app_is_initialized = False>
<cflock scope="application" type="readonly" timeout="5">
<cfset app_is_initialized = IsDefined("Application.initialized")>
</cflock>
<cfif not app_is_initialized>
<cflock scope="application" type="exclusive" timeout=10>
<cfif not IsDefined("Application.initialized")>
<!--- Do initializations --->
<cfset Application.StudentDB = "DB">
<cfset Application.Url = "/CopyOfApplication/">
<cfset Application.NSUrl = "/CopyOfApplication/">
<cfset Application.EmailLocation = "/CopyOfApplication/pages/email/">
<cfset Application.userfilespath = "/web_assets/UserFiles/">
<cfset Application.UnauthorizedFileExtentions = "ade,adp,asx,bas,chm,cmd,cpl,crt,dbx,exe,hlp,com,hta,inf,ins,isp,jse,lnk,mda,mde,mdz,mht,msc,msi,msp,mst,nch,pcd,prf,reg,scf,scr,sct,shb,shs,url,tmp,pif,dll,vb,vbs">
<cfset Application.ReportPage = "report.cfm">
<cfset Application.PrintPage = "print.cfm">
<!---Puts an instance of the user.cfc and system.cfc in the application scope. All pages can use it. --->
<cfobject type="component" name="Application.System" component="application.system">
<cfset Application.initialized = "yes">
</cfif>
</cflock>
<cfscript>
Application.System.LogActivity("Name","IP","Application scope variables initialized.");
</cfscript>
</cfif>
Like I said, the "page" part in the URL are the only ones that are not being updated. Does it mean I have problems with my URL.Page initialization?
Please let me know if you need additional code. I appreciate any input about this question. Thank you in advance! I am still learning ColdFusion and I will appreciate it if you will help me understand what I need to know!
I'm moving away from ColdFusion 8 to ColdFusion 10.
Currently, on my Unix's root directory, I only have 1 Application.cfm and under this root directory I have about 10 sub directories (previous programmers did it this way and I'm experiencing a lot of weird things).
Now that I get the chance to redo this web application, I want to do it properly but the biggest problem with me is to properly understand how to work with Application.cfc in CF10.
Each of the sub directory represents a web application. For example, there is a web application for tracking graduate students, a web app. for tracking alumni, a web app. for formatting addresses, etc.
Users for these applications are from 10 different institutions. They all login to the application the same way (from the same interface) but then we separate them using session.usergoup & session.username to know who is who and who can see what type of things.
All Institutions share the same database, so currently only the datasource is set to application scope.
Unfortunately after reading many Application.cfc postings at this forum I got even more confused, so I hope you guys don't mind assisting me so that I can feel more comfortable working with Application.cfc in CF10.
My understanding is:
On my root dir I will create one main Application.cfc. My Main Application.cfc will only handle login/user authentication.
So under this root dir, I will have 1 Application.cfc, loginform.cfm and loginaction.cfm
In loginaction.cfm is where I set session.usergroup and session.username upon successful user authentication.
So in my main Application.cfc, I should set the following:
<cfset THIS.Name = "InstitutionMainApp" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnApplicationStart I'll do:
<cfset application.dsn = "MyDB">
and under OnSessionStart I'll do:
<cfset session.usergroup= "">
<cfset session.username= "">
Then on each of my sub-folder's Application.cfc I need to name it differently
For graduate tracking system I should have:
<cfset THIS.Name = "GraduateTrackingSystem" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnRequestStart, when I need to encrypt url variable (form example), I can set:
<cfset request.mySecretKey = application.mySecretKey />
<cfset request.algorithm = "AES" />
<cfset request.encoding = "hex" />
For alumni tracking system I should have:
<cfset THIS.Name = "AlumniTrackingSystem" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnRequestStart, when I need to encrypt url variable (form example), I can set:
<cfset request.mySecretKey = application.mySecretKey />
<cfset request.algorithm = "AES" />
<cfset request.encoding = "hex" />
For Address Formating app., I should set:
<cfset THIS.Name = "AddressFormattingSystem" />
<cfset THIS.ApplicationTimeout = CreateTimeSpan(0,0,30,0) />
<cfset THIS.SessionManagement = true />
<cfset THIS.SetClientCookies = false />
under OnRequestStart, when I need to encrypt url variable (form example), I can set:
<cfset request.mySecretKey = application.mySecretKey />
<cfset request.algorithm = "AES" />
<cfset request.encoding = "hex" />
Then since the application.dsn, session.usergroup and session.username are all set in
the Main Application.cfc under the root dir., I can freely use these scoped variables
on each application sub-folder safely because each of sub-folder application.cfc is
named differently this way I should not be concern with cross reference among usergroup
and username?
Please let me know if my understanding on how to use Application.cfc is very much a
mess.
That's a long question.
I think this is what you need: http://corfield.org/blog/index.cfm/do/blog.entry/entry/Extending_Your_Root_Applicationcfc
Once you have extended your application.cfc via some proxy to workaround the limitation of extending itself, you should be able to do almost anything your existing application.cfm was setup to do.
update: as iKnowKungFoo pointed out in the comment, once you have a different application name i.e. this.name you cannot share the vars in the Application scope since you're essentially forking a new application, you may try Server scope for those. Logic can be shared via functions you have inherited, but pay attention to whether the vars are accessible in your application.
We use GA for tracking and part of the tracking involves storing the __utmz cookie value in our DB. I have a problem in understanding why is CF 10 not able to parse the __utmz cookie.
CF10 is not parsing or properly retrieving the value of __utmz cookie Or just about any cookie value that has an 'equal (=)' sign in it other than the CFGLOBALS.
Here is the screen shot of the issue (using CFDUMP of COOKIE scope) -
What it should look like -
What it is looking like -
Server Config: CF10, IIS 7.5, Win 2k8
Ok! I found the way to mitigate this problem. By using the GetHttpRequestData() method.
<cfscript>
_cookie = GetHttpRequestData().headers.cookie;
</cfscript>
This will return an ; delimited list of cookie values. I used regEx to pick the __utmz value I needed.
I just ran into this problem. Some code that was working in CF8 stopped working in CF10. I created this function to get the raw cookie value:
<cffunction name="GetRawCookie" output="false" returntype="string">
<cfargument name="cookieName" type="string" required="true">
<cfset local.cookies = GetHttpRequestData().headers.cookie>
<cfset local.cookieValue = "">
<cfset local.match = reFindNoCase("(?:^|;)\s*" & arguments.cookieName & "=([^;]+)", local.cookies, 1, true)>
<cfif local.match.pos[1] gt 0>
<cfset local.cookieValue = mid(local.cookies, local.match.pos[2], local.match.len[2])>
</cfif>
<cfreturn local.cookieValue>
</cffunction>
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'm working with ColdFusion 9.0.1 and latest (for current date) stable build of twitter4j library - twitter4j-core-2.2.4. I'm trying to create functionality which allows users to login or register at our site using their twitter accounts.
I was able to create authorization part: user click on the link on our site and system redirects him to twitter page. On this page he able to "Authorise" our application. After that system redirecting him back using callBackURL.
But I have a problem with next step. When I'm trying to setOAuthAccessToken and for that trying to instantiate AccessToken object with follow part of code:
accessToken = createObject( 'java', 'twitter4j.auth.AccessToken' ).init( 'myStoredRequestToken', 'myStoredRequestTokenSecret' );
But I have follow error:
An exception occurred while instantiating a Java object. The class
must not be an interface or an abstract class. Error: ''.
Any ideas?
Update:
The start part of stacktrace:
'coldfusion.runtime.java.JavaObjectInstantiationException: Object instantiation exception. at coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:171) at coldfusion.runtime.java.JavaProxy.invoke(JavaProxy.java:80) at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2360) at cftwitter2ecfc2084917956$funcGETUSERCREDENTIALS.runFunction(C:\inetpub\wwwroot_test\twPlayGrnd_com\twitter.cfc:36) at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55) at ...
...cut here, not sure this is important...
the last part is
cfapplication2ecfc665259542$funcONREQUEST.runFunction(C:\inetpub\wwwroot_test\twPlayGrnd\application.cfc:55) ... 55 more Caused by: java.lang.IllegalArgumentException: Invalid access token format. at twitter4j.auth.AccessToken.(AccessToken.java:50) ... 60 more'
I saw the message about wrong format, but based on documentation at http://twitter4j.org it should accept two agruments (strings with keys). Am I wrong?
Update 2
*just find that out - I am sorry that I brought you into confusion with my first post and example... of course I used myStoredRequestToken, myStoredRequestTokenSecret, not a consumer key/secret *
*there are relevant parts of code I'm using for this functionality*
application.cfc ("onApplicationStart" function, instantiating components on start of application)
<cffunction name="onApplicationStart" access="public" returntype="boolean" output="false">
...
<cfset application.com.twitterInstance = server.javaloader.create("twitter4j.TwitterFactory").getInstance() />
<cfset application.com.twitter = createObject("component","_com.twitter").init() /> *<!--- cfc component which will be listed below --->*
...
</cffunction>
twitter.cfc (corresponding coldfusion component)
<cfcomponent displayname="twitter" output="false">
<cffunction name="init" access="public" output="false">
<cfreturn this>
</cffunction>
<cffunction name="authorizeTwitter" access="public" output="false">
<cfargument name="callBackURL" type="string" required="false" default="#request.twtCallBackURL#" />
<cfset var requestToken = "" />
<cfset application.com.twitterInstance.setOAuthConsumer(request.twtConsumerKey,request.twtConsumerSecret) />
<cfset requestToken = application.com.twitterInstance.getOAuthRequestToken(arguments.callBackURL) />
<cflock scope="session" type="exclusive" timeout="10">
<cfset session.oAuthRequestToken = requestToken.getToken()>
<cfset session.oAuthRequestTokenSecret = requestToken.getTokenSecret()>
</cflock>
<cflocation url="#vLocal.requestToken.getAuthorizationURL()#" addtoken="No" />
</cffunction>
<cffunction name="getUserCredentials" access="public" output="true">
<cfset var vLocal = {} />
<cfset vLocal.accessToken = "" />
<cfset vLocal.userData = "" />
<cfset vLocal.requestToken = "" />
<cfset vLocal.accessToken = server.javaloader.create("twitter4j.auth.AccessToken").init(session.oAuthRequestToken,session.oAuthRequestTokenSecret)>
<cfset application.com.twitterInstance.setOAuthAccessToken(vLocal.accessToken) />
<cfset vLocal.userData = application.com.twitterInstance.verifyCredentials() />
<cfdump var="#vLocal.userData#" label="User Credentials">
</cffunction>
First function is for first step - requesting twitter for autorization page (where user can autorize or deny application). Call back URL runs the page what calls the second function and I have problem only at this step (line for generation accessToken).
I have the same result if Im using createObject function instead of javaloader.
*So, my main question is still the same - to obtain the users unique Access Token? Please point me, what I'm doing wrong? What is a correct format for unique user's accessToken generation? Should I place oauth_verifier parameter there? if so, how?*
You are passing consumer key/secret instead of access token/secret.
You can generate your access token/secret at dev.twitter.com.
https://dev.twitter.com/apps ยป create my access token
Best,
Yusuke
I think I figured out what is wrong with the help of the examples 8. Sign in with Twitter and
Adding support for automated tweets with OAuth. Only tested with my own account though ..
Before you redirect to the authorization page, save the whole RequestToken object in a session variable. You will need it to extract the AccessToken. Note: I am storing the TwitterFactory in the application scope - not the instance
<cfset Twitter = application.TwitterFactory.getInstance()>
<cfset Twitter.setOAuthConsumer(application.TwitterConsumerKey, application.TwitterConsumerSecret)>
<cfset Session.RequestToken = Twitter.getOAuthRequestToken( YourCallBackURL )>
On callback, twitter adds a parameter named oauth_verifier to the URL. Use that value and the saved RequestToken to extract the AccessToken.
<cfset AccessToken = Twitter.getOAuthAccessToken(Session.RequestToken, URL.oauth_verifier)>
<cfset session.StoredAccessToken = AccessToken.getToken()>
<cfset session.StoredAccessSecret = AccessToken.getTokenSecret()>
Once you have the AccessToken/Secret you can access user details (update status,...) anywhere.
<cfset Twitter = application.TwitterFactory.getInstance()>
<cfset Twitter.setOAuthConsumer(application.TwitterConsumerKey,application.TwitterConsumerSecret)>
<cfset AccessToken = createObject("java", "twitter4j.auth.AccessToken")>
<cfset OAuthToken = AccessToken.init(session.StoredAccessToken, session.StoredAccessSecret)>
<cfset Twitter.setOAuthAccessToken(OAuthToken)>
<cfset userData = Twitter.verifyCredentials()>
<cfoutput>
id = #userData.getId()#<br>
name = #userData.getName()#<br>
followers = #userData.getFollowersCount()#<br>
friends = #userData.getFriendsCount()#<br>
</cfoutput>