URL Template issue with PathVariables

I created a test controller which looks like this

  @Controller
  public class TestController {
    	
  private final Log log = LogFactory.getLog(getClass());
    	
  	@RequestMapping("/test/{id}/{resource:.+}")
	@ResponseBody
	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);
		log.info(jsonObject.toString());
		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/

<org.json.JSONObject>
<map>
<entry>
<string>id</string>
<string>b1cf27a3-8fd9-4e9f-a578-70bce21fa585</string>
</entry>
<entry>
<string>resource</string>
<string>index.htm</string>
</entry>
</map>
</org.json.JSONObject>

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" />
</bean>

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.