Lucee 5 Rest and Application.cfc


#1

When using Lucee 4.5, all rest requests went through the root Application.cfc. This seems to have changed in 5…although I cannot locate any documentation stating this. Does anyone have any insight as to why and maybe how to get that functionality back?

I have gone through the Admin settings and tried everything. I have downloaded 5 express and started from scratch building a basic rest setup.

What’s really weird is that if I run the request as the first request after a Lucee restart, it goes through Application.cfc as expected. Each rest request afterwards does not.


#2

UPDATE:

This works if you set the Application Listener Type to “Mixed” and the rest cfcs are two folders deep from the root. Not sure this makes sense but it seems to fix the issue.

Example:
ROOT/app/services/REST_CFCs_HERE

When these services were only one folder deep in ROOT/app/REST_CFCs_HERE they did not hit the ROOT Application.cfc.

As I said, I needed Application Listener Type set to “Mixed” for this to work…although I only use Application.cfc


#3

Hi @jessewroach,

I’ve analyzed this rest & Tested with two folders deep from the root. If the lucee request hit Root application.cfc as expected. How to you set that ‘Application Listener’ mixed type ? Can you add a test application here or send it to my mail( pothys.r@mitrahsoft.com ).


#4

The Mixed Mode setting is in the Lucee Admin > Settings > Request > Application Listener > Type
Make sure both the Server Admin and the Web Admin have this set correctly

Example App: Using Lucee 5 Express

Make sure that you add a mapping to Lucee Admin > Archives & Resources > Rest

  • Virtual: /test
  • Physical: /app/services/
  • Default: checked

TEMPLATES:

Root / Application.cfc

component {

	this.Name = "RootApplication";

	public boolean function OnRequestStart( required string TargetPage )
	{
		request.testVar = "GotIt!";

		return true;
	}

}

Root / app / services / testService.cfc

component restpath="/test" rest="true" {

	remote any function testGet() httpmethod="GET"
	{
		return { application = serializeJSON( application ), requestTestVar = request.testVar };
	}

}

Browse to http://{YOURHOST}/rest/test
You should get JSON showing the application name “RootApplication” and the request tesVar.

If you move testService.cfc up one folder to

  • Root / app / testService.cfc

and change the mapping in
Lucee Admin > Archives & Resources > Rest

  • Virtual: /test
  • Physical: /app/
  • Default: checked

Browse to http://{YOURHOST}/rest/test
You will NOT get the results. In fact, it will probably error because request.testVar doesn’t exist. Remove it from testService like so:

Root / app / testService.cfc

component restpath="/test" rest="true" {

	remote any function testGet() httpmethod="GET"
	{
		return { application = serializeJSON( application ) };
	}

}

Browse to http://{YOURHOST}/rest/test
You will receive an empty serialized application scope

I hope that all makes sense. Let me know what you experience


#5

Mhhh thats weird.
I setup like you said and browser http://{YOURHOST}/rest/test, everything worked how you said.
After changing the path, i get 500 Error.
Than i changed it back and it dont find the rest-point anymore (“no rest service for [/test] found”). I didnt change the file.
Mhhh, is there any docs/guide for this?


#6

I have been unable to find any documentation on rest with Lucee 5. I was using it in 4.5 and it worked as expected. Lucee 5 is close to the same experience except for the caveats I have outlined above. The good news is that if you keep the services two folders deep and use “Mixed” mode, things should work fine.

BTW, you probably need to restart Lucee when moving rest cfcs around. Adding a method to an already existing endpoint cfc should be fine but adding a new cfc requires a restart.


#7

Hi @jessewroach,

I’ve tested above code & issues happened on both 5.2 , 4.5.5.015 lucee versions. If I’m tested ‘testService.cfc’ with two folders deep means showing text content properly. If I’m remove ‘testService’ folder from app means it throw issue like testVar doesn’t exist.

So please arise ticket for this issue on Jira (https://luceeserver.atlassian.net/).