This isn’t possible in the general case. You can see which file extensions
are mapped to the OpenMRS servlet here:
Any URL under /ws is mapped (regardless of file extension). This is
intended for web services. So, you can map an arbitrary url, as long as it
starts with ws/
Thanks @darius, although it makes perfect sense, it hasn’t worked.
I just prefixed my former URL with /ws as you suggested and I’m still getting an error 404 on it (with or without the .form suffix this time.)
Is there anything else to configure anywhere?
I actually think it’s a bad idea to have your URLS have /ws because by convention that is reserved for webservices calls, why can’t you just append .form or .htm to your URL and not have to break conventions or go through hacks?
Well it is not a REST webservice, but it is a webservice nonetheless.
But yes sure, I can live with the .form suffix, I was just asking as I thought I was missing something (I still don’t understand why it doesn’t work with /ws though).
If it’s a web service, then I guess you need to use /ws, you shared the Controller code and not the code where you make the web service call, can you share it too?
@maurya I remember there is something that needs to be done to make this work and we had to do it at some point. If you do remember that “something” please assist us here otherwise I will have to dig somewhere
There is nothing special that needs to be done, I think you’re using an incorrect URL when making the http request, if your controller is mapped to /my/custom/url then in your browser the URL you need to enter should be /openmrs/ws/my/custom/url
As I said earlier this all works fine when the /ws prefix is not used and that I append the .form suffix.
Moreover the URL is set in one unique place in a constants class:
public class MyModuleConstants {
public static final String SERVICE_URL = "/my/custom/url";
// public static final String SERVICE_URL = "/ws/my/custom/url";
...
}
That’s the constant in use for the service-controller’s mapping:
So when the page loads, this unique URL is provided to and known by the client side as per the unique configuration through the constants class.
It is finally stored in a config objet that is used all over my Angular controllers:
All this to say that when I want to change the whole thing to using the /ws prefix, it happens in one, and only one, place.
Then I can play around in JS and add/remove the + '.form' to see whether things keep working or not. I left above the comments at the two places where I switch back & forth from a config to the other.
That’s exactly what I was saying, /ws/** is already mapped to the OpenMRS SpringDispatcherServlet, so spring based controllers under the the /ws prefix don’t have to include it again in the request mapping value since that gets stripped off by spring just like you don’t include .form in your request mapping value because spring strips it off but you need to include it in the URL you enter in the browser.
Exactly, this is something I learned the hard way when trying to use /ws/**. Unfortunately I forgot about. I think we could have it documented somewhere?