Link to home
Start Free TrialLog in
Avatar of Shawn
ShawnFlag for Canada

asked on

finding country of user

is there a way in cf to find the country (eg via ip) of a user who submits a form?
in a hidden field I'd like to record this if possible.

somethnig like
<input type="Hidden" name="UserCountry" value="#not sure what would go here#
SOLUTION
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shawn

ASKER

thanks for the links.

agx, I like this one the best. I,m just struggling a little getting it to work.

I won't be able to put in the cf server's classpath so I've opted to "try the remoteClasspath_geoLocator.cfc which uses Mark Mandel's javaLoader CFC. you can obtain this CFC here: http://javaloader.riaforge.org/"

I have put remoteClasspath_geoLocator.cfc and JavaLoader.cfc in the root but am getting an error.
Can you post the error message?
Avatar of Shawn

ASKER

Error Occurred While Processing Request  
com.compoundtheory.classloader.NetworkClassLoader  
 
The error occurred in C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaLoader.cfc: line 59

line 59 >> networkClassLoaderClass = getServerURLClassLoader().loadClass("com.compoundtheory.classloader.NetworkClassLoader");
Avatar of Shawn

ASKER

I'm probably missing a file or have put something in the wrong place :(
Avatar of Shawn

ASKER

\lib folder is in the web root
No, place the entire JavaLoader directory beneath the webroot.  So it would look something like this:

{drive}/wwwroot/javaLoader (folder)
{drive}/wwwroot/javaLoader/JavaLoader.cfc
{drive}/wwwroot/javaLoader/JavaProxy.cfc
{drive}/wwwroot/javaLoader/lib (folder)
> No, place the entire JavaLoader directory

... ie  Just extract the zip file and copy the entire folder beneath the webroot
Avatar of Shawn

ASKER

OK, did that and am now getting the error below.
Could not find the ColdFusion Component or Interface javaLoader.  
Ensure that the name is correct and that the component or interface exists.  
  
The error occurred in C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClassPath_geoLocator.cfc: line 90
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClassPath_geoLocator.cfc: line 79
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\cgi101.cfm: line 17
 
88 : 	<cfset var paths=listToArray(GetDirectoryFromPath(expandpath("*.*")) & "\InetAddressLocator.jar")>
89 : 	<!--- modify to point to where you placed javaLoader CFC--->
90 : 	<cfset var javaLoader=createObject("component","javaLoader").init(paths)>
91 : 	<cftry>
92 : 		<cfset variables.geoLocator = javaLoader.create("net.sf.javainetlocator.InetAddressLocator")>
 

Open in new window

check the mapping
Avatar of Shawn

ASKER

mapping yes, but where?

looks like remoteClassPath_geoLocator.cfc can't find the javaLoader folder

would I change this?
90 :       <cfset var javaLoader=createObject("component","javaLoader").init(paths)>
Oh, yes.  I forgot the author does have the javaloader.cfc beneath the root.  You could either:

- Change line 90 of the remoteClasspath_geoLoader.cfc from something like this:

    <cfset var javaLoader=createObject("component","javaLoader").init(paths)>
   ...   to this ...
    <cfset var javaLoader=createObject("component","javaLoader.javaLoader").init(paths)>

- OR, try moving the javaLoader files again:

          {drive}/wwwroot/ (folder)
         {drive}/wwwroot/JavaLoader.cfc
         {drive}/wwwroot/JavaProxy.cfc
          {drive}/wwwroot/lib (folder)
.... - OR, try moving the javaLoader files again:

     Yes, I just tried it.  The second option works as well as long as you move _all_ of the files

        c:\coldfusion8\wwwroot\ (folder)
        c:\coldfusion8\wwwroot\JavaLoader.cfc    (main cfc's ...)
        c:\coldfusion8\wwwroot\JavaProxy.cfc
        c:\coldfusion8\wwwroot\wwwroot\lib        (entire subfolder included in the zip file)
Avatar of Shawn

ASKER

if I change line 90 I get error 1 below

if I move the javaLoader files i get error 2 below
Error 1
Error Occurred While Processing Request 
com.compoundtheory.classloader.NetworkClassLoader  
   
The error occurred in C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaloader\JavaLoader.cfc: line 59
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc: line 91
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc: line 79
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\cgi101.cfm: line 17
 
57 : 
58 : 		//classLoader = createObject("java", "com.compoundtheory.classloader0.NetworkClassLoader").init();
59 : 		networkClassLoaderClass = getServerURLClassLoader().loadClass("com.compoundtheory.classloader.NetworkClassLoader");
60 : 
61 : 		networkClassLoaderProxy = createJavaProxy(networkClassLoaderClass);
 
Error2
Error Occurred While Processing Request  
com.compoundtheory.classloader.NetworkClassLoader  
  
The error occurred in C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaLoader.cfc: line 59
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc: line 90
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc: line 79
Called from C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\cgi101.cfm: line 17
 
57 : 
58 : 		//classLoader = createObject("java", "com.compoundtheory.classloader0.NetworkClassLoader").init();
59 : 		networkClassLoaderClass = getServerURLClassLoader().loadClass("com.compoundtheory.classloader.NetworkClassLoader");
60 : 
61 : 		networkClassLoaderProxy = createJavaProxy(networkClassLoaderClass);
 

Open in new window

Avatar of Shawn

ASKER

why the double root?

c:\coldfusion8\wwwroot\wwwroot\lib
i think this line is incorrect
 c:\coldfusion8\wwwroot\wwwroot\lib    
should be
 c:\coldfusion8\wwwroot\lib    
There should be more detail in the stack trace.

> C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc:

     Where did you place the javaLoader folder. Beneath the webroot:  C:\ColdFusion8\wwwroot?
Avatar of Shawn

ASKER

ok, then I'm still getting error2 mentioned above
1.  Where did you place the physical javaLoader folder?
     ie Here C:\ColdFusion8\wwwroot ?

2. Can you post the stack trace details
Avatar of Shawn

ASKER

1. I put it here: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaloader
2. stack trace below
Date/Time   30-Apr-09 02:04 PM 
 
Stack Trace (click to expand)  
at cfjavaLoader2ecfc237925674$funcINIT.runFunction(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaLoader.cfc:59) at cfremoteClasspath_geoLocator2ecfc728277938$funcINIT.runFunction(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc:90) at cfremoteClasspath_geoLocator2ecfc728277938.runPage(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc:79) at cfcgi1012ecfm875426295.runPage(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\cgi101.cfm:17) 
 
 
java.lang.ClassNotFoundException: com.compoundtheory.classloader.NetworkClassLoader
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at coldfusion.runtime.StructBean.invoke(StructBean.java:511)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2300)
	at cfjavaLoader2ecfc237925674$funcINIT.runFunction(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaLoader.cfc:59)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:418)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:360)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:324)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:192)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:448)
	at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:308)
	at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2272)
	at cfremoteClasspath_geoLocator2ecfc728277938$funcINIT.runFunction(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc:90)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:418)
	at coldfusion.filter.SilentFilter.invoke(SilentFilter.java:47)
	at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:324)
	at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:59)
	at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:277)
	at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:192)
	at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2471)
	at cfremoteClasspath_geoLocator2ecfc728277938.runPage(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc:79)
	at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196)
	at coldfusion.runtime.TemplateProxyFactory.resolveComponentHelper(TemplateProxyFactory.java:488)
	at coldfusion.runtime.TemplateProxyFactory.resolveName(TemplateProxyFactory.java:211)
	at coldfusion.runtime.TemplateProxyFactory.resolveName(TemplateProxyFactory.java:157)
	at coldfusion.runtime.TemplateProxyFactory.resolveName(TemplateProxyFactory.java:147)
	at coldfusion.runtime.TemplateProxyFactory.resolveName(TemplateProxyFactory.java:131)
	at coldfusion.runtime.TemplateProxyFactory.resolveFile(TemplateProxyFactory.java:90)
	at coldfusion.runtime.TemplateProxyFactory.resolveName(TemplateProxyFactory.java:1306)
	at coldfusion.cfc.ComponentProxyFactory.getProxy(ComponentProxyFactory.java:38)
	at coldfusion.runtime.ProxyFactory.getProxy(ProxyFactory.java:65)
	at coldfusion.runtime.CFPage.createObjectProxy(CFPage.java:4707)
	at coldfusion.runtime.CFPage.CreateObject(CFPage.java:4552)
	at cfcgi1012ecfm875426295.runPage(C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\cgi101.cfm:17)
	at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:196)
	at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:370)
	at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
	at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:279)
	at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
	at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
	at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
	at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
	at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
	at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:74)
	at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
	at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
	at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
	at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
	at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
	at coldfusion.CfmServlet.service(CfmServlet.java:175)
	at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
	at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
	at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
	at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
	at jrun.servlet.FilterChain.service(FilterChain.java:101)
	at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
	at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
	at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
	at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
	at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
	at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
	at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
	at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
	at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
 
 

Open in new window

> 1. I put it here: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaloader

No, as I was saying, it has to be beneath the webroot. This

       C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaloader

... is probably not your webroot.  Usually the webroot is:

      C:\ColdFusion8\wwwroot\
Avatar of Shawn

ASKER

OK, I cn do this on my local test server but as the live site is hosted I'm not sure if I'll be able to do this.
...just moving files now
Then try constructing a dot-notation path that matches whatever folder structure they use.  

CFC paths are similar to url's. Except they use "." instead of "/".   So if c:\coldFusion8\wwwroot is your webroot locally,  but your physical javaLoader.CFC file is located:

         C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\javaloader.CFC

Then try using this for the CFC path:

      javaLoader=createObject("component","ARAXI_DEV_new_site.wwwroot.javaLoader")

If that works, you should be able to do the same thing on your hosted site.

Avatar of Shawn

ASKER

still getting errors here and am late for an out of office meeting. Will try to log on tonight for more trials.

would you mind zipping and uploading the exact files and folders that worked for your test starting from C:\ColdFusion8\wwwroot\
I'm sure it's something trivial. thanks for your help so far.

just saw your last post and will try tonight. thx agx

PS if you're interested there should be some easy points here:
https://www.experts-exchange.com/questions/24369697/looking-to-catch-the-inside-and-outside-link-referer-in-form.html
What might be even better is a screen shot.  I tested with this structure and the original geoLocator code and it worked fine.  

ie:  No changes to this line: <cfset var javaLoader=createObject("component","javaLoader").init(paths)>


GeoLocator.png
JavaLoader.png
Avatar of Shawn

ASKER

all looks the same and still no luck. do I have to change anything anywhere? in the index.cfm?

not sure if changes are needed here
"copy the icu4j.jar somewhere under your MX install dir. add its location to the Java classpath & stop & re-start the MX server service."
No, I believe that is only required you want to use icu4j_geoLocator.cfc.

What results do you get if you run this script?  It tests for the existence of the files in the screen shots above.
<cfsavecontent variable="fileNames">
C:\ColdFusion8\wwwroot\lib\classloader-20070406174551.jar
C:\ColdFusion8\wwwroot\JavaLoader.cfc
C:\ColdFusion8\wwwroot\JavaProxy.cfc
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\geoLocator.cfc
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\icu4j_geoLocator.cfc
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\index.cfm
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\InetAddressLocator.jar
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\LICENSE
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\readMe.txt
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\SAVEremoteClasspath_geoLocator.cfc
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\world.swf
C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\world_nt.swf
</cfsavecontent>
 
<cfoutput>
  <b>This is your webroot</b>  #ExpandPath("/")#<hr>
 
  <cfset fileArray = listToArray(fileNames, chr(10)&chr(13))>
  <cfloop array="#fileArray#" index="name">
 	<cfif not fileExists(trim(name))>
		<b style="color:red;">ERROR:</>  File not found where expected:  #name#<br>
	<cfelse>
		OKAY:  #name# <br>
	</cfif>
  </cfloop>
</cfoutput>

Open in new window

Avatar of Shawn

ASKER

i do get one error
 ERROR: File not found where expected: C:\ColdFusion8\wwwroot\lib\classloader-20070406174551.jar

I have classloader-20080514084644.jar instead
This is your webroot C:\ColdFusion8\wwwroot\
--------------------------------------------------------------------------------
 ERROR: File not found where expected: C:\ColdFusion8\wwwroot\lib\classloader-20070406174551.jar
OKAY: C:\ColdFusion8\wwwroot\JavaLoader.cfc 
OKAY: C:\ColdFusion8\wwwroot\JavaProxy.cfc 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\geoLocator.cfc 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\icu4j_geoLocator.cfc 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\index.cfm 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\InetAddressLocator.jar 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\LICENSE 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\readMe.txt 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\remoteClasspath_geoLocator.cfc 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\SAVEremoteClasspath_geoLocator.cfc 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\world.swf 
OKAY: C:\ColdFusion8\wwwroot\ARAXI_DEV_new_site\wwwroot\world_nt.swf 

Open in new window

> and the original geoLocator code

Did you remember to revert to the original geoLocator code from the zip file?  I just tried it with that _exact_ configuration (including classloader-20080514084644) and it worked perfectly.  
BTW, I didn't upload the files because I really don't know EE's policy on having people upload entire versions of  someone else's code :(  
Avatar of Shawn

ASKER

>>Did you remember to revert to the original geoLocator code from the zip file?
yes, I think. I can delete all and start again though

>>I didn't upload the files because I really don't know EE's policy on having people upload entire versions of  someone else's code
It's ok as long as you leave in the licence, credentials and don't claim that it's yours
Avatar of Shawn

ASKER

started from scratch and it worked.
thanks for the links.
Shawn