Enabling REST under Windows

Hello, I tried to get this example running on my Lucee Server:

https://www.youtube.com/watch?v=R_VnRawOhhc

It works fine at 127.0.0.1:8888/rest/metrics/system/os, but it doesn’t work at mywebsite.com/rest/metrics/system/os - instead I get a 404. I added the same REST mapping there as I did under 127.0.0.1:8888/lucee/admin/web.cfm?action=resources.rest.

In the first case the demo REST cfc is located at C:\lucee\tomcat\webapps\ROOT\restservices where the REST mapping points to, in the second case the REST cfc is located at [Webroot]\restservices where the REST mapping for this website is pointing to.

I assume I am missing some basic configuration step for getting this running as desired - but which one?

Configuration: Lucee 5.3.7.47 on Windows Server 2019 with Tomcat/IIS.

Regards,
RG

@RG2021 Yeah I too checked with this, localhost:8888/rest/metrices/test/os works fine and testbox.lucee.com/rest/metrices/test/os not working. But if we give url with port(testbox.lucee.com:8888/rest/metrices/test/os) means works fine in that webcontext too.
please check with this

Welcome @RG2021 to our community!!! If you installed Lucee using Lucee’s windows installer and boncode, make sure you have set up the IIS handler mapping for boncode right to catch all that REST URLs and pass them to Lucee for that site. Take a look at that link with the “Add handler mapping” section from Hostek.

Little note: Take care by adding them just by copy and paste, because there are some tags that are marked as closing tags.

UPDATE: Found a better solution here in this forum. Please see @dawesi s solution posted here.

Special thanks to @dawesi who posted the solution to his own issue and shared it with us all. That’s why it’s always important to share solutions, even if you come up with a solution on your own.

Hello cfmitrah, hello @andreas, thank you for the warm welcome and your help!

I added the handler mapping as described in dawesi’s post - now I am one step closer, but I still get this error message:

“no rest service for [/metrics] found”

Setting for localhost:8888/rest/metrices/test/os:
<rest><mapping default=“false” physical=“C:\iis-webroot-of-domain\restservices” virtual=“/metrics”/></rest>

Setting for mywebsite.com/rest/metrics/system/os:
<rest><mapping default=“false” physical=“C:\lucee\tomcat\webapps\ROOT\restservices” virtual=“/metrics”/></rest>

Both directories contain the system.cfc that consists of:

component restpath=“/system” rest=“true” {
remote struct function getOS() httpmethod=“GET” restpath=“os” {
return server.os;
}
}

What am I still missing here? Thx again for your help!

Regards,
RG

Here is a guess:
Did you check if the rest virtual path mapping has been added to your mywebite.com web admin correctly within its own web administrator at http://mywebite.com:8888/lucee/admin/web.cfm ? If you’ve added the virtual path in the web admin of your localhost at http://localhost:8888/lucee/admin/web.cfm only, that doesn’t create it automatically for the context of mywebite.com This is what I would check.

Hello @andreas, yes, I added the rest mapping in the Lucee Web admin of my website under “Archives & Resources - Rest”. This results in the aforementioned addition to the lucee-web.xml.cfm for my website:

<rest><mapping default=“false” physical=“C:\iis-webroot-of-domain\restservices” virtual="/metrics"/></rest>

But now I found the reason for “no rest service for [/metrics] found” - I have to specify port 8888:

mydomainwhatever:8888/rest/metrics/system/os - works fine!

But of course I want to use port 80 for this - how can I solve this last problem?

Ok, then this is an IIS specific problem that is not passing the request correctly to tomcat. What is the error of IIS you are seing now, when you request http://mydomainwhatever/rest/metrics/system/os ? If you do the request from the server (not from a remote client) you should see a very specific detailed error, with a code status 404.x or similar (the “x” stands for a more specific detailed code).

I think the request is already being passed to tomcat, because the error I get (“no rest service for [/metrics] found”) sonds to come from Lucee/tomcat and not from IIS.

http://mydomain.com/REST/metrics/system/os gives a 404 from tomcat (because of the spelling REST instead of rest):

The requested resource [/REST/metrics] is not available

So we are already in the Lucee/tomcat world in both cases due to the handler mapping for rest/* in IIS, but need to get it done with port 80 instead of 8888.

If mydomainwhatever:8888/rest/metrics/system/os works fine, then Lucee is working just the way it has to work and the request is not being passed from IIS to Lucee as it should. I bet something is missimg in your IIS configuration, but I can‘t say what it is. Could you request a simple index.cfm through port 80 before setting up rest?

mydomainwhatever/index.cfm works fine via port 80, this site is in use for a long time. Only mydomainwhatever/rest/metrics/system/os I need to specify port 8888…

Related issue [LDEV-3466] - Lucee

Okay, I’ve localised this to IIS specifically, IIS is not passing the full path to the handler in the script name.

From the BonCode connector debug

< path-info : /rest/metrics/system/os/v1/v2/v3/v4
< script-name : /rest/metrics

I have tried setting the attribute allowpathinfo=“true” and this still did not enable proper rest operation.

Ideally Lucee would have to identifiy the rest call and rely on path-info instead script-name (apparantly) to identify the appropriate rest service

the work around (not ideal though) is to add multiple handlers up to the maximum expected path depth (in reverse order), IIS will then pass the full rest path to Lucee in the script-name. viz. the first path must be the longest expected rest path as below (the order matters & spaces due to forum reformatting my text) :-

rest/* /* /* /* /*
rest/* /* /* /*
rest/* /* /*
rest/* /*
rest/*

We have recently used the @damian24 solution and have our REST running now under Lucee 5.3.9.x with IIS 10.0

IIS-Rest

1 Like

For anyone else fighting with this problem (and it’s still a problem as of 5.3.9.141), the order you enter the handlers is critical. For this reason, you might want to edit your IIS webite’s web.config to add these handlers outside of the IIS management UI.

First, you’ll need to grab that BonCodeIIS.BonCodeCallHander type as described here. The value will be unique on your system. Using that value, your web.config might look like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers>
			<add name="Boncode_Tomcat_REST_11" path="/rest/*/*/*/*/*/*/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_10" path="/rest/*/*/*/*/*/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
			<add name="BonCode_Tomcat_REST_9" path="/rest/*/*/*/*/*/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_8" path="/rest/*/*/*/*/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
			<add name="BonCode_Tomcat_REST_7" path="/rest/*/*/*/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_6" path="/rest/*/*/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_5" path="/rest/*/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_4" path="/rest/*/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_3" path="/rest/*/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_2" path="/rest/*/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
            <add name="BonCode_Tomcat_REST_1" path="/rest/*" verb="*" type="BonCodeIIS.BonCodeCallHandler,BonCodeIIS,Version=1.0.0.0,Culture=neutral,PublicKeyToken=yourKeyHere" resourceType="Unspecified" preCondition="integratedMode" />
        </handlers>
    </system.webServer>
</configuration>
1 Like