0

I tried binding N numbers of parameters in a URL like this

/web/appl/<applname>/rule/<rulename>/<attrname1>/<attrval1>/<attrname2>/<attrval2>/.../<attrnameN>/<attrvalN>

with

@RequestMapping(value = "/web/appl/{applname}/rule/{rulename}/{attributes}", method = RequestMethod.GET)
public Object GetService(HttpServletRequest request, @PathVariable("attributes") Map<String, Object> map,
                @PathVariable("applname") String applname, @PathVariable("rulename") String rulename)
                throws Exception {
                  ...
                }

but could not get values of <attrval1>/<attrname2>/<attrval2>/.../<attrnameN>/<attrvalN>

1

2 Answers 2

0

Unfortunately Spring MVC does not provide such a solution. You can consider the Matrix Variables as an alternative.

If you prefer sticking to your current URI scheme then you have to implement a solution yourself. One approach is to use a path pattern. Example:

@RequestMapping(value = "/web/appl/{applname}/rule/{rule name}/**")
public Object getService(HttpServletRequest request,
            @PathVariable("applname") String applname ...) {
    String attributesPart = new AntPathMatcher()
        .extractPathWithinPattern("/web/appl/{applname}/rule/{rule name}/**", 
            request.getServletPath());
    ...

You could implement your argument resolver that does that. Something like

@RequestMapping(value = "/web/appl/{applname}/rule/{rule name}/**")
public Object getService(@MyAttributes Map<String, String> attributes,
            @PathVariable("applname") String applname ...) {
Sign up to request clarification or add additional context in comments.

Comments

0

Use

String urlAttributes = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE);

and get whole URL. After that parse this URL according to your needs like if you did not get

<attrval1>/<attrname2>/<attrval2>/.../<attrnameN>/<attrvalN>

in proper sequence then you can throw exception.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.