URL Template issue with PathVariables

I created a test controller which looks like this

  public class TestController {
  private final Log log = LogFactory.getLog(getClass());
	public JSONObject onGet(@PathVariable(value = "id") String id,
	        @PathVariable(value = "resource") String resource, @RequestParam(value = "view", required = false) String view,
	        HttpServletResponse response) throws JSONException {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("id", id);
		jsonObject.put("resource", resource);
		jsonObject.put("view", view);
		return jsonObject;

http://localhost:8080/openmrs/test/b1cf27a3-8fd9-4e9f-a578-70bce21fa585/apple.jpg results in 404

and http://localhost:8080/openmrs/test/b1cf27a3-8fd9-4e9f-a578-70bce21fa585/


Am I missing something here? Do I have to add some config/filters?

Adding this doesn’t solve the problem. I tried several combinations but no luck.

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
     <property name="useDefaultSuffixPattern" value="false" />

IDE is showing DefaultAnnotationHandlerMapping is deprecated.

spring is appending index.htm to every request

Can someone please help me…?

Which version of Openmrs are you using?

Its reference 2.6

By the way, did you get a chance to look at this? https://wiki.openmrs.org/display/docs/Adding+a+Web+Service+Step+by+Step+Guide+for+Module+Developers

Thanks. This worked. I had to make few changes in gsp and js but that’s ok.

Thanks a lot.

1 Like

Late to the party. Glad you made it work.