API Rest Full - Problem

21 views
Skip to first unread message

Rubén V

unread,
Mar 22, 2020, 6:22:54 PM3/22/20
to CodenameOne Discussions
Hi,

I am trying to consume a webservice in Spring from my application codename.
It returns the following error:

{"timestamp": 1584914466134, "status": 400, "error": "Bad Request", "exception": "org.springframework.web.bind.MissingServletRequestParameterException", "message": "Required Long parameter 'id' is not present "," path ":" / visit / start "}

I imagine it is trivial, but so far I have not been able to correct it.

My calla in Codenameone
    public static Response inicio(Visita v) {
        Response<String> r = Rest.post(SERVER_URL + "visita/inicio").
                header("token", UsuarioService.getToken()).
                jsonContent().
                queryParam("id", Long.toString(v.visitaId.get())).
                queryParam("fecha", Long.toString(System.currentTimeMillis())).
                getAsString();
        return r;
    }

My Webservice
    @RequestMapping(method = RequestMethod.POST,value = "/inicio")
    public @ResponseBody String inicioVisita(
    @RequestHeader(name="token", required = true) String token,
    @RequestParam(value="id", required = true) Long id,
    Long fecha) {
    visitas.inicioVisita(token, id, fecha);
    return "OK";
    }

Shai Almog

unread,
Mar 23, 2020, 12:09:41 AM3/23/20
to CodenameOne Discussions
Hi,
param is problematic with post + JSON as it assumes the parameter is a JSON string embedded into the body (as is common in current REST calls).
You have several options here:

- Use get
- Use JSON post body syntax (which will work better with objects)
- Remove the json content syntax for now and use form submit mime type

I suggest trying to reproduce this in curl to see how this acts which will provide you with a 3rd party way to see where the problem lies.

Rubén V

unread,
Mar 23, 2020, 1:08:14 PM3/23/20
to CodenameOne Discussions
Thanks
Reply all
Reply to author
Forward
0 new messages