2
votes

is there a way to send parameter like "https://jira.springsource.org/browse/SPR-6164 " in @PathVariable as part of the URI path ...in Spring Web MVC

@RequestMapping(value = "/Details/{Emailaddress}/{URL}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody Status Details(@PathVariable("Emailaddress") String Emailaddress,
             @PathVariable("URL") String URL) {
try {
            bankingData.callingmethod(Emailaddress,URL);
            return new Status(1, "Details added !");
        } catch (Exception e) {
            // e.printStackTrace();
            return new Status(0, e.toString());
        }
    }

error:The requested resource is not available

2
Is the {URL} being used to identify the resource which you are going to work with? If not {URL} should be accepted as a query parameter, not as path variable. Anyways you still can send an http URL as query param or path variable by encoding the the URL portion. - Fahim Farook
try to post full method - Abdelhak
@Fahim Farook encoding the the URL portion should it must be done in client side only or can i do it in server side also.? - dafodil
@Abdelhak please check modified posted code - dafodil
Can you post the url are you using? - Abdelhak

2 Answers

4
votes

It is but you have to encode it properly. Use URLEncoder.encode() to do so:

String url = 
    "http://server/Details/"+URLEncoder.encode("http://myserver/mypath/to/url/", "UTF-8");

This code must be performed on client side when constructing the URL. The encoding must be applied to both pat elements and query parameters.

1
votes

Try to write url like {URL:.+} in your method like this:

   @RequestMapping(value = "/Details/{Emailaddress}/{URL:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public Status Details(@PathVariable("Emailaddress") String Emailaddress,
         @PathVariable("URL") String URL) {

The requestParameter with dot . is truncated.