В функции Azure с использованием JAVA как получить полезную нагрузку запроса, которая отправляется как json
Мой код выглядит так:
@FunctionName("hello")
public HttpResponseMessage<String> hello(
@HttpTrigger(name = "req", methods = {"post"}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,final ExecutionContext context) throws Exception {
context.getLogger().info("Java HTTP trigger processed a request.");
System.out.println("**********REQUEST BODY*************"+request.getBody());
String cookie = new Authenticate().authenticateAndGetCookie();
ExecuteCommands commandsExecutor = new ExecuteCommands(cookie);
String s=commandsExecutor.control(request.toString());
System.out.println(s);
JSONObject jobj=new JSONObject(s);
if (s == null) {
return request.createResponse(400, "Please pass a name on the query string or in the request body");
} else {
return request.createResponse(200,jobj.toString());
}
}
Из-за использования HttpRequestMessage>, когда я печатаютело в консоли, как в коде, который я вставил выше, я получаю это в консоли.
**********REQUEST BODY*************Optional[{
[13-06-2018 11:40:18] Java HTTP trigger processed a request.
[13-06-2018 11:40:18] "Command": "com",
[13-06-2018 11:40:18] "Id": "id",
[13-06-2018 11:40:18] "Id2": "id2",
[13-06-2018 11:40:18] "Operation": "op"
[13-06-2018 11:40:18] }]
Но я прошел ниже полезной нагрузки:
{
"Command": "com",
"Id": "id",
"Id2": "id2",
"Operation": "op"
}
ТАК, я попытался использовать HttpRequestMessageно я получил следующее исключение
incompatible types: com.microsoft.azure.serverless.functions.HttpRequestMessage<java.util.Optional<java.lang.String>> cannot be converted to com.microsoft.azure.serverless.functions.HttpRequestMessage<java.lang.String>