0

My URL request is http://localhost:8080/login/verify/212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=

I need get the following part: **212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=**.

The following code doesn't work:

@RequestMapping(value = "/login/verify/{request:.+}", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    public ResponseEntity verifyLogin(@PathVariable(value = "request") String request)
            throws InvalidSignatureException
    {
}

Error: HTTP Status 404.

Spring can't handle this request.

kryger
  • 12,906
  • 8
  • 44
  • 65
FranzF
  • 113
  • 12
  • Can you write it as: (http://localhost:8080/login/verify/212/32/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=) ? where "212", "32" and "cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=" will be different parameters. Do you want so? – Afridi May 17 '17 at 04:35
  • Thanks for answer. No, i need parse entire string, which contain 4 parametrs, divided ",". Sometimes the 4 parameter can contain slash (/) – FranzF May 17 '17 at 04:46

3 Answers3

1

To match the uri with the slashes, use the double *

@RequestMapping(value = "/login/verify/**",

Then, in the body to get the value, you will use

String str = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)

Sample code:

@RequestMapping(value = "/login/verify/**", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) 
public ResponseEntity verifyLogin(HttpServletRequest httpServletRequest) throws InvalidSignatureException {
    String str = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)
}
kryger
  • 12,906
  • 8
  • 44
  • 65
eDog
  • 173
  • 1
  • 5
  • Exactly! Thanks. Where request is HttpServletRequest. @RequestMapping(value = "/login/verify/**", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) public ResponseEntity verifyLogin(HttpServletRequest httpServletRequest) throws InvalidSignatureException {String str = (String) request.getAttribute( HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE)} – FranzF May 17 '17 at 06:48
0

Try this URL instead: http://localhost:8080/login/verify?req=212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo=

And handle it like this:

@RequestMapping("/login/verify")
public String test(@RequestParam("req") String data) {
    //'data' will contains '212,32,/cntv5tag07rmy791wbme7xa8x,/SSNZclzqhhH7v6uHIkUsIcPusKo='
   String params[] = data.split(",");
}
kryger
  • 12,906
  • 8
  • 44
  • 65
Afridi
  • 6,753
  • 2
  • 18
  • 27
0

You have forward slashes in your url and those strings will be considered as path variables. Try the following code if there is a possibility that you'll have only 3 path variables. Please have a look at here and here

@RequestMapping(value = {"/login/verify/{string1:.+}",
        "/login/verify/{string1:.+}/{string2:.+}",
        "/login/verify/{string1:.+}/{string2:.+}/{string3:.+}"}, method = RequestMethod.POST)
  public ResponseEntity verifyLogin(HttpServletRequest request, HttpServletResponse httpresponse, 
        @PathVariable("string1") String string1,
        @PathVariable("string2") String string2,
        @PathVariable("string3") String string3) {
    System.out.println("***************************************************I am called: "+string1+" "+string2+" "+string3);

}

Community
  • 1
  • 1
Gopinath
  • 19
  • 2
  • 1
    I know about this solution, but in this case i get string1 = 212, string2 =32, string3 = cntv5tag07rmy791wbme7xa8x, string4 = SSNZclzqhhH7v6uHIkUsIcPusKo=. string 3 and string4 without slash(/), i need extra condition in code for handle this problem in this case – FranzF May 17 '17 at 06:32
  • You can use something like this, @RequestMapping("/login/verify/**"), use request.getRequestURI() and then parse it. – Gopinath May 17 '17 at 06:51