0
I’ve been trying to find solutions to this mistake and I can’t find.
Error:
2018-07-24 16:44:50.541 WARN 25695 --- [nio-8080-exec-2] .w.s.Defaulthandlerexceptionresolver : Resolved Exception caused by Handler Execution: org.springframework.web.Httpmediatypenotsupportedexception: Content type 'text/Plain;charset=UTF-8' not supported
Algorithm in tscript that is called after a button click:
uploadKeySize(e) {
let keySize = parseInt(e.target.value);
console.log(keySize);
this.fileService.sendInfoToGenKey(keySize).toPromise()
.then(
data => {
console.log(data);
});
}
file service method that is called and that communicates with the back:
sendInfoToGenKey(sizeKey: number) {
return this.http.put('http://localhost:8080/operation/request-RSA-keys', sizeKey);
}
Code:
@RequestMapping(value = "/request-RSA-keys", method = RequestMethod.PUT)
public static KeyPair generateRSAKeys(@RequestBody int sizeKey) throws NoSuchAlgorithmException {
System.out.println(sizeKey);
return KeyGenerator.generateKey("RSA", sizeKey);
}
Can you put the request being sent by the client as well? This can help identify the problem.
– Tom Melo
Only one detail that is not what you are asking, but that has to do with your code is that the
NoSuchAlgorithmException
will never be launched by the method. Therefore, I recommend involving the call ofgenerateKey
in a blocktry
and in thecatch
ofNoSuchAlgorithmException
launch aAssertionError
.– Victor Stafusa
Wait a minute, what a class
KeyGenerator
is that it? It certainly isn’tjavax.crypto.KeyGenerator
.– Victor Stafusa
Can you catch a stacktrace of your mistake? I think you will need to post more about your code so that the source of the problem and the possible solution can be pointed out.
– Victor Stafusa
The Keygenerator class is one I created. In it is just an "interface" that is called when I call the back method. In it I use the Keypairgenerator
– Daniel Boso
By default, Spring has some pre-enabled Httpmessageconverter(s) that convert a request body to Java objects. If I’m not mistaken, the conversion of a POST text/Plain to int is not enabled. You have a few options: 1 - Work with application/json. 2 - Receive a String sizeKey and convert to int. 3 - Register an Httpmessageconverter to perform the conversion of a POST Plain/text to int. Take a look here and here
– Tom Melo
@Tommelo said it all, you have to simplify your answer
– Weslley Barbosa