1

I'm trying to get a list of datasources off my server (Yes I am the server owner...this is not a hack).

I think I confused the issue by giving two examples - so I'm editing the post with ONE example and the stack trace.

Code

// Create Data Source Object
admin = new cfide.adminapi.Administrator();
admin.login("admin","[password]");

dbserv = createobject("java","coldfusion.server.ServiceFactory").getDatasourceService();
dblist = dbserv.getDatasources(); 
writedump(dblist);

Error Message

The error occurred in C:\wwwroot\[path]\[file].cfm: line 6
4 : 
5 :     dbserv = createobject("java","coldfusion.server.ServiceFactory").getDatasourceService();
6 :     dblist = dbserv.getDatasources(); 
7 :     writedump(dblist);
8 : </cfscript>

Stack Trace:

Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.
Browser     Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0
Remote Address      127.0.0.1
Referrer    
Date/Time       17-May-12 09:08 AM
Stack Trace
 at cf[file]2ecfm302094979.runPage(C:\wwwroot\[path]\[file].cfm:6)

coldfusion.security.SecurityManager$UnauthenticatedCredentialsException
at coldfusion.security.SecurityManager.authenticateAdmin(SecurityManager.java:1958)
at coldfusion.sql.Executive.getDatasources(Executive.java:96)
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:508)
at coldfusion.runtime.CfJspPage._invoke(CfJspPage.java:2393)
at cf[file]2ecfm302094979.runPage(C:\wwwroot\[path]\[file].cfm:6)
at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:381)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:94)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
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.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:200)
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.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
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)

Debugging Information
ColdFusion Server Developer     9,0,1,274733
Template    [path]/[file].cfm
Time Stamp  17-May-12 09:08 AM
Locale  English (US)
User Agent  Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0
Remote IP   127.0.0.1
Host Name   127.0.0.1

Execution Time

top level (16ms) C:\wwwroot\[path]\[file].cfm
  · arrowtop level (0ms) CFC[ C:\wwwroot\CFIDE\adminapi\administrator.cfc | login(admin, [password]) ] from C:\wwwroot\CFIDE\adminapi\administrator.cfc @ line 3

(46 ms) STARTUP, PARSING, COMPILING, LOADING, & SHUTDOWN
(62 ms) TOTAL EXECUTION TIME
red = over 250 ms execution time

Exceptions

09:08:11.011 - coldfusion.security.SecurityManager$UnauthenticatedCredentialsException - in C:\wwwroot\[path]\[file].cfm : line 6
2
  • Does this help? paulalkema.com/post.cfm/… Commented May 16, 2012 at 16:03
  • Re I get a non-descriptive error... What you posted works with CF9. Can you post the error and stacktrace? Also, what version of CF? Commented May 16, 2012 at 16:57

3 Answers 3

4
dbserv = createobject("java","coldfusion.server.ServiceFactory").getDatasourceService();
dblist = dbserv.getDatasources(); 
writedump(dblist);

This works in ColdFusion. If you are getting securitycredential exception then you need to login as admin like

admin = new cfide.adminapi.Administrator();
admin.login("password","admin");

The following code will not work

dbserv2 = createobject("java","coldfusion.server.DataSourceService");
dblist2 = dbserv2.getDatasources();

And it is rightfully throwing method not found. Mainly because DataSourceService is a java Interface and doesn't have this method implemented. It is implemented by Executive class.

Sign up to request clarification or add additional context in comments.

2 Comments

this is the correct direction Chandan, but I must have messed up the implementation as I'm still getting a security error.
@jpmyob Sry, I had messed with loign api its login(pwd,id). Edited my response. Should work now!
1

If you dump your dbserv2 variable you will see that it is not an object, it is a Java Interface, which cannot be instantiated.

To do what you want you need to request the datasource service from the service factory.

<cfscript>
    dbserv2 = createobject("java","coldfusion.server.ServiceFactory").getDataSourceService();

    dblist2 = dbserv2.getDatasources();
</cfscript>

3 Comments

um no - that is what i did first... and it resulted in a non descript error. it simply say "an error occurred" and gives the line number - but NO info.
Re it simply say "an error occurred" As mentioned in the comments, you need to post the stack trace. That is where the real error message lies.
If you look the nondescript error's stack trace you'll probably see it is an authentication error.
1

For others who may happen upon this post, another way to do what was wanted, without needing to authenticate with the CF Admin password is to use the getNames() function of the DataSourceService instead of getDatasources. It returns an array of all the datasource names registered on the server.

<cfscript>
    dbserv3 = createobject("java","coldfusion.server.ServiceFactory").getDataSourceService();
    dblist3 = dbserv3.getNames();
</cfscript>

This works on CF11

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.