I am trying to make a request frome a Java app to another app that is written in Spring. Right now I am getting a 400.
This is the Spring endpoint I am trying to reach:
@GetMapping(value="/tts/{sessionid}/{fileId}/{text}")
ResponseEntity<byte[]> getAudioFile(
@ApiParam(value = "Wave SessionId", required = true) @PathVariable String sessionid,
@ApiParam(value = "File id", required = true) @PathVariable Integer fileId,
@RequestParam(value = "Text", required = true) String text
) throws Exception
and here is my attempt to make a valid request:
private void getTtsWave(String waveId, String token, int file_id, String tts_text) {
try {
URL url = new URL(this.recorderendpoint + "/api/tts/" + waveId + "/" + String.valueOf(file_id) + "/{text}?Text=" + tts_text);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", "Bearer " + token);
int status = con.getResponseCode();
System.out.println(status);
if (status == 200) {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
if (content != null && !content.equals("")) {
System.out.println(content);
}
in.close();
}
} catch (Exception e) {
log("getTtsWave error: " + e, e.toString());
}
}
{text}in the end of your url since it is not treated as a path param? Maybe this is the error?{text}in new URL() is a string literal but in Controller, it is a path Variable. so you need to change that totext.