login api

hello everyone

my code is :

 

public ResponseEntity Login(String address, Map map) {
        try {
            logger.info("Login : " + address);

            RestTemplate restTemplate = new RestTemplate();
            HttpHeaders requestHeaders = new HttpHeaders();
            //requestHeaders.setContentType(MediaType.APPLICATION_JSON_UTF8);
            String bodyData = new JSONObject(map).toString();
            HttpEntity requestEntity = new HttpEntity(bodyData, requestHeaders);

            ResponseEntity response = restTemplate.postForEntity(address, requestEntity, type);
            logger.info("Login.Response - " + address + " : " + response.getStatusCode() + " : " +
                    (response.hasBody() ? response.getBody() : ""));

            return response;
        } catch (Exception ex) {
            logger.error("Login : " + address, ex);
            return null;
        }
    }

and the exception is : 415 UNSUPPORTED_MEDIA_TYPE

415 : [no body]

and headers : 
Content-Length -> {LinkedList@10159}  size = 1
Date : Sat, 25 Jan 2020 19:04:01 GMT

when I call it as GET method, it works after many try, and finally I can get the Bonita Api Token. but when I call it with above code, it doesn't work.

please help. please show me your code in java. how can I login to bonita in java?

Hello,

To connect to Bonita, just use urlFormEncode like that:
 

public ResponseEntity<String> connectToBonita(String username, String password) {
        log.info("Connection à bonita en cours");
        RestTemplate restTemplate = new RestTemplate();

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
        requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
     
        MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
        body.add("username", username);
        body.add("password", password);
        body.add("redirect", "false");

        HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, requestHeaders);
        // Send request with GET method and default Headers.
        ResponseEntity<String> result = restTemplate.exchange(properties.getBonitaLoginUrl(), HttpMethod.POST, requestEntity, String.class);
        log.info("Connection OK");
        return result;
    }


Regards