13 Replies Latest reply on Feb 23, 2015 10:35 AM by BKBK

    Mappings not working for REST

    Prem Radhakrishnan

      I am working on my first REST application in ColdFusion and I am noticing that application specific mapping defined in Application.cfc does not seem to work!

       

      Is it something that is not supposed to work because the application.cfc is only utilized when the REST service is initialized and subsequently its not utilized? Thank you for any insight.

       

       

      EDIT:


      When I had first posted this I thought it was just application specific mappings that did not work. Later on I discovered that it was mappings in general. Even if you had set a server level mapping in the administrator it did not matter. The REST service always defaulted to the wwwroot starting path. Seems like a pretty significant issue unless I am missing something very obvious.

        • 1. Re: Mappings not working for REST
          haxtbh Level 4

          Which version of Coldfusion are you using?

           

          In the latest version of Coldfusion you can registered you REST services in the Administrator under Data & Services > REST Services. I assume when you are talking about mappings, you are talking about the normal mappings.

           

          Also take a look at this RESTful Web Services in ColdFusion - ColdFusion, English documentation - Adobe Learning Resources

          • 2. Re: Mappings not working for REST
            BKBK Adobe Community Professional & MVP

            Could you show us how your Application code and REST CFC look like? It will make it easier to debug this together.

            • 3. Re: Re: Mappings not working for REST
              Prem Radhakrishnan Level 1

              I am talking about just regular ColdFusion mappings. I have the REST service working fine if my component paths are absolute.

               

              For example, if you define in your Application.cfc or in your server admin a mapping say

              /abc :  .\inetpub\wwwroot\MAINAPPLICATIONPATH

               

              Your REST application is registered at

              .\inetpub\wwwroot\RESTAPPLICATIONPATH

               

              now in your REST application if you have a component reference in the format below, I get errors saying that the component does not exist.

              abc.cfc.Component

               

              Now if I put the component in the RESTAPPLICATIONPATH and reference is like below everything works fine.

              RESTAPPLICATIONPATH.cfc.Component.

               

               

               

              I can share code but as all this is part of a much larger application, I would have to create something smaller to demonstrate the issue. I have been able to get things working by using absolute path references but just not by using mappings.

              • 4. Re: Mappings not working for REST
                BKBK Adobe Community Professional & MVP

                I fail to understand why you use MAINAPPLICATIONPATH and RESTAPPLICATIONPATH.

                • 5. Re: Mappings not working for REST
                  Prem Radhakrishnan Level 1

                  We have two different applications, one that was already existing and one that we are building. I was just using those as references. I hope that makes sense.

                  • 6. Re: Mappings not working for REST
                    BKBK Adobe Community Professional & MVP

                    The mapping /abc contains MAINAPPLICATIONPATH. If the component is in RESTAPPLICATIONPATH, and not in MAINAPPLICATIONPATH, then ColdFusion rightfully tells you there is an error.

                    • 7. Re: Mappings not working for REST
                      Prem Radhakrishnan Level 1

                      First off I have to apologize for the late response, I have not been able to work on this due to some other projects and just now getting back to it.

                       

                      I will try to explain a bit further, I have two applications, one is an application that we have been using for the past several years and the second one is new that we are building to transition to REST services for various reasons.

                       

                      Application Structures under WWWROOT on IIS

                       

                      MAIN Application Structure

                       

                      /MainApplication/

                        /cfc

                        /services

                        /view

                      index.cfm

                      Application.cfc

                       

                       

                      REST Application Structure

                       

                      /RESTApplication/

                        /services

                        /restPath1

                        /restPath2

                      Application.cfc

                       

                       

                      What I was trying to is not recreate any of the services or cfcs by creating a REST Application side by side. So in my REST application, since they are both running under wwwroot I thought I could reference the components in the MainApplication directly as MainApplicatoin.cfc.myComponent . This is where I get the error that the component does not exist. Now if I copy the component directory /cfc/ to my REST Application root I can reference them just fine. I have tried to use server level mapping from the admin, Application mapping from the RESTApplications's Application.cfc and just direct path reference following the path under wwwroot. None of these have worked for me.

                      The same thing happens with the services directory as well. Essentially any reference to MainApplication. returns an error.

                       

                      So what it appears to me is happening is that in  REST application you do not have an option to reference any components from any other directory on the server other than the its own.    

                      • 8. Re: Mappings not working for REST
                        BKBK Adobe Community Professional & MVP

                        Just to be sure, does it help when you set these mappings in the ColdFusion Administrator:

                         

                        Logical Path: /

                        Directory Path: absolute_path_of_wwwroot

                         

                        Logical Path: /abc

                        Directory Path: absolute_path_of_abc_folder

                         

                        Logical Path: /MainApplication

                        Directory Path: absolute_path_of_MainApplication_folder

                         

                        Logical Path: /RESTApplication

                        Directory Path: absolute_path_of_RESTApplication_folder

                        • 9. Re: Mappings not working for REST
                          Prem Radhakrishnan Level 1

                          Thats one of the first things I tried and it did not work.

                           

                          Also, I just want to share that I am on CF 11 Update 2. We are using secure websockets which have some issues in Update 3 so we have not applied that, we have not tested Update 4 yet. I wanted to throw that out there so theres no confusion as to the version of ColdFusion.

                          • 10. Re: Mappings not working for REST
                            BKBK Adobe Community Professional & MVP

                            With just one Application.cfc? That is, a structure like this

                             

                            Application.cfc

                            /MainApplication/

                            ...

                            ...

                            /RESTApplication/

                            ...

                            ...

                            • 11. Re: Mappings not working for REST
                              BKBK Adobe Community Professional & MVP

                              Prem Radhakrishnan wrote:

                               

                              Application Structures under WWWROOT on IIS

                               

                              MAIN Application Structure

                               

                              /MainApplication/

                                /cfc

                                /services

                                /view

                              index.cfm

                              Application.cfc

                               

                               

                              REST Application Structure

                               

                              /RESTApplication/

                                /services

                                /restPath1

                                /restPath2

                              Application.cfc

                               

                              I have just completed a test inwhich I copied this exact structure, and used the default mappings originally registered in the Administrator. Everything worked as expected. In other words, a cfc in the restPath1 directory could access the component MainApplication.cfc.myComponent. Then again, I am on Windows.

                               

                              Could you use another pair of eyes? If you send me your files by private message, I will have a look.

                              • 12. Re: Mappings not working for REST
                                Prem Radhakrishnan Level 1

                                I am going to try this again, Unfortunately I cant share any files. I am setting up a new dev server so I can try with a clean slate.

                                 

                                Did you try with custom mappings or just default directory mappings?

                                 

                                Thank you so much for helping me out    

                                • 13. Re: Mappings not working for REST
                                  BKBK Adobe Community Professional & MVP

                                  I did nothing about the mappings! This means, in effect, that I used ColdFusion's default settings. The absolute path to the wwwroot directory is therefore mapped to /, and the dotted notation for components is then relatve to this directory.

                                   

                                  Did you test my suggestion of using just one Application.cfc at the top? Just to avoid any side-effects from the interaction of two applications.