application variables in REST app in lucee and application.cfc

537 views
Skip to first unread message

Stéphane MERLE

unread,
Oct 23, 2015, 9:38:57 AM10/23/15
to Lucee
Hi,

I am using coldfusion for years now but I am still in the old way of coding with the application.cfm and the tag version of the code .... (yeah I know, I am playing the old guy but it's from the jeremy allaire old time).

I am puting together an API REST with lucee ... and I am not able to set any application variables ... getting stuck on this is just upsetting me so bad ...


so I have an application.cfc with that kind of code :

component output="false"
{
   
this.name = "apirest";//RestAPI
   
this.applicationTimeout = createTimespan(0,2,0,0);
   
this.restsettings.skipCFCWithError = true;
   
   
this.nom0='bonjour0'; //debug test
    variables
.nom1='bonjour1'; //debug test
    application
.nom2='bonjour2'; //debug test
   
   
public function onApplicationStart()
   
{
        writeLog
(file="apilog", text="Lancement REST API");
       
this.nom0_b='bonjour0_onappstart';
        variables
.nom1_b='bonjour1_onappstart';
        application
.ipgranted = "195.258.70.167";
        application
.logname = "api";
        application
.logname_error = "api_error";
       
return true;
   
}
   
   
public function onApplicationEnd()
   
{
        writeLog
(file="apilog", text="FIN REST API");
       
return;
   
}
   
   
public boolean function onRequestStart()
   
{
        writeLog
(file="apilog", text="Request START");
       
return true;
   
}
   
   
public void function onError(e){
        writeLog
(file="api_error", text="#GetFunctionCalledName()# called avec #serialize(e)#");
        writeDump
(var=e, label="ERROR");
        abort
;
   
}
}


and I have just this in a test.cfc file :

component restpath="/test" rest="true" displayname="get test"{
    remote any
function get_test(numeric id restargsource="Path") httpmethod="GET" restpath="{id}" {
       
       
dump(application);
       
dump(variables);
       
dump(super);
       
dump(REQUEST);
       
return;

   
}
}

an if I call the test page with a GET :

http://api.distrigame.com/api/1.0/test/1

(I did change REST by API in the server.xml page)
it display the variables but I see nowhere any of the variables I set !
none of them ....

whats wrong ???

Stéphane


AJ Mercer

unread,
Oct 24, 2015, 7:18:29 PM10/24/15
to lu...@googlegroups.com
Looks like you have missed a few steps
Here are some notes I started on

Some pointers
The URL for will always start with /rest (or as defined in server.xml)
Then the the rest application mapping - set up in Lucee admin or with

Then the path to the resource 

So will be something like
    /rest/api/test/1

If you want a version number in the URLs add it to restpath- most likely on the component
--
See Lucee at CFCamp Oct 22 & 23 2015 @ Munich Airport, Germany - Get your ticket NOW - http://www.cfcamp.org/
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/277bd4d5-f6f0-4a08-b22b-25714f7ad9f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Stéphane MERLE

unread,
Oct 27, 2015, 11:38:08 AM10/27/15
to Lucee
Sorry I missed your answer ...

I did manage it to work just by restarting lucee on both nodes. It triggered the application restart and reload the application variables.

this part of code doesn't do it :
if (structKeyExists(url, "refreshRestServices") or structKeyExists(url, "reset"))
        {
            restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), this.name);
        }

Thanks
Stéphane
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+unsubscribe@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/277bd4d5-f6f0-4a08-b22b-25714f7ad9f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dawesi

unread,
Nov 1, 2015, 11:00:08 PM11/1/15
to Lucee
why CFML people insist on using /rest for the url astounds me. no-one does that in the real world but cfml engines... 

Can someone tell me where this odd behaviour comes from?

Dawesi
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+unsubscribe@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/277bd4d5-f6f0-4a08-b22b-25714f7ad9f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

AJ Mercer

unread,
Nov 1, 2015, 11:24:06 PM11/1/15
to lu...@googlegroups.com
it is defined in web.xml

<servlet-mapping>
<servlet-name>RestServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>

you can change it to whatever you like

A separate mapping is required because a different servlet handles ReST calls


To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/277bd4d5-f6f0-4a08-b22b-25714f7ad9f8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages