Search code examples
javajsonhttpresponsehttp-method

Get Value and pass as parameter to function in Java


 ResponseEntity<String> respEntity = null;
        try {
            respEntity = getConfiguredRestTemplate().exchange(uri.toString()
                    , HttpMethod.GET
                    , entity
                    , new ParameterizedTypeReference<String>() {
                    });
            log.debug("URL to retrieve a document : {}", respEntity.getBody());
}

The respEntity.getBody() returns {"url":"https://aps-fst"}

I want to send only the value - https://aps-fst as parameter to a function to download the content in the URL. How to extract only the URL value and pass it as parameter of type URL / String ?


Solution

  •   String jsonString = respEntity.getBody();
       JSONObject obj = new JSONObject(jsonString);
       String s3urlvalue = obj.getString("url");
       log.debug("S3 URL  to retrieve a document : {} ", s3urlvalue);
    

    I am able to get value with above code