0

I've got the following:

final String notification = "{\"DATA\"}";
final String url = "http://{DATA}/create";
ResponseEntity<String> auth = create(address, name, psswd, url);

Attacking this method:

private ResponseEntity<String> create(final String address, final String name,
                                                          final String newPassword, final String url) {
        final Map<String, Object> param = new HashMap<>();
        param.put("name", name);
        param.put("password", newPassword);
        param.put("email", address);

        final HttpHeaders header = new HttpHeaders();

        final HttpEntity<?> entity = new HttpEntity<Object>(param, header);

        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.postForEntity(url, entity, String.class);
    }

I think it should work, but it's throwing me a

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Not enough variable values available to expand 'notification'

Why?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
stack man
  • 2,303
  • 9
  • 34
  • 54

2 Answers2

5

As the duplicates of your question say, you have { } in your URL.

Spring will try to fill that {notification} but since you don't provide it, it fails saying Not enough variable values available to expand 'notification'.

You just need to pass the notification string so that Spring can build the URL correctly.

Here is the javadoc for this method:

public <T> ResponseEntity<T> postForEntity(String url,
                                           Object request,
                                           Class<T> responseType,
                                           Object... uriVariables)
                                    throws RestClientException
Parameters:
    url - the URL
    request - the Object to be POSTed, may be null
    responseType - the class of the response
    uriVariables - the variables to expand the template

So, you need to pass the notification string as a 4th parameter, like this:

restTemplate.postForEntity(url, entity, String.class, notification);
ESala
  • 6,878
  • 4
  • 34
  • 55
-1

The following line was just enough to get it working. I got rid of the key characters and it's working now.

final String url = "http://DATA/create";
stack man
  • 2,303
  • 9
  • 34
  • 54