0

When trying to call getJSON like so

<script>
$("#version").keyup( function() {
    var jarName = $("#artifactId").val();
    var jarVersion = $("#version").val();

    $.getJSON("/xx/yy/zz/"+jarName+"", jarVersion, function(completion) {
        $("#version").autocomplete({
            source: completion
            });
     });
});
</script>

with a back end like this

    @RequestMapping(value = "/xx/yy/zz/{jarName}", method = {
            RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public List<JsonNode> getVersionsAssociatedwithJar(@PathVariable String jarName, @RequestBody String version) {

I get a 400 bad request error and the url looks like so

xx/yy/zz/jarName?131.31

with the 131.31 what I am typing in on the front end and what I want as the "version" Param. Am I making a simple mistake with the request mapping? I've never used spring before but am finding it difficult to debug since it doesn't even get to the back end

Logger on Back end gives this message

[nio-8080-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Required request body is missing: public java.util.List<com.fasterxml.jackson.databind.JsonNode> com.lendingclub.macgyver.dependency.AppDependencyApiController.getVersionsAssociatedwithJar(java.lang.String,java.lang.String)
sf8193
  • 575
  • 1
  • 6
  • 25

1 Answers1

0

Perhaps try changing the {jarName} to be a regex (i.e. {jarName:.+}), since there are known issues with the last @PathVariable containing dots.

Also adding TRACE logging on org.springframework.web can be useful as you will see the request coming in and any issues with it.

Tristan Perry
  • 607
  • 6
  • 14
  • I edited the post to show my logger error message. The issue is jarName doesn't have '.' in it, only the request body should – sf8193 May 03 '19 at 19:19
  • 1
    Ah okay, the error helps - this is because this is a `RequestMethod.GET`, and you cannot have `@ResponseBody` with a HTTP GET. Try changing it to `RequestMethod.POST` (and adjust your JS accordingly), or move the `version` to be in the URL as well (especially if it's just a String) so that you then have two `@PathVariable` annotations. – Tristan Perry May 03 '19 at 19:21
  • yup I was originally doing two path variables but changed to this at the request of someone else. I think the path variable is better – sf8193 May 03 '19 at 20:40