I have a problem when try to update a controller-service at nifi instance. I try to make a "put" request to nifi instance and disable the controller-service.
this is my logic:
get a specific controller-service (controller-services/{id})
parse response message to ControllerServiceEntity object
update state of service like --> currentService.Component.State = "DISABLED"; (All part of entity same with first time i just update State poperty)
serialize modified service instance
request nifi-api put for update service (controller-services/{id})
and i get the Badrequest response with "Message body is malformed. Unable to map into expected format." message.
This is my method for put request:
public async Task<T> Put<T>(Uri url,T data) where T:IBaseEntitty
{
T resultEntity = default(T);
using (var client = new HttpClient())
{
var jsonSerializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var requestContent = new StringContent(JsonConvert.SerializeObject(data,jsonSerializerSettings), Encoding.UTF8, "application/json");
var response = client.PutAsync(url,requestContent);
var content = response.Result.Content;
using (var reader = new StreamReader(await content.ReadAsStreamAsync()))
{
var result = await reader.ReadToEndAsync();
if (response.Result.StatusCode == HttpStatusCode.OK)
{
var template = Newtonsoft.Json.JsonConvert.DeserializeObject(result, typeof(T));
if (template != null)
{
resultEntity = (T)template;
}
}
}
}
return resultEntity;
}
Any idea please ?
As i understand the request message should be short; my bad was sending whole entity back. I opened the Developer Tools on browser and checked the nifi instance's own requests and compared with mine: than i noticed the request is just include properties that will be update, not whole entity.
The request body must include just state and revision information. This is the request body that sending by nifi-instance when it disables controller-services:
{"revision":{"clientId":"644bf345-015d-1000-e82d-047f6a9f9432","version":15},"component":{"id":"015b1030-a099-13d3-812c-77772afcaeb0","state":"DISABLED"}}
I changed my codes according this informations. This is my sample code that set controll-service for disabling:
var controllerService = new ControllerServiceEntity();
controllerService.Id = existingService.Id;
controllerService.Revision = existingService.Revision;
var component = new ControllerServiceDTO();
component.Id = existingService.Component.Id;
component.State = "DISABLED";
controllerService.Component = component;
After i send the new control-service instance instead of existing one than it worked as i expected.