MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / onTrigger

Method onTrigger

extensions/http-curl/processors/InvokeHTTP.cpp:273–395  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271}
272
273void InvokeHTTP::onTrigger(const std::shared_ptr<core::ProcessContext> &context, const std::shared_ptr<core::ProcessSession> &session) {
274 auto flowFile = session->get();
275
276 std::string url = url_;
277
278 if (flowFile == nullptr) {
279 if (!emitFlowFile(method_)) {
280 logger_->log_debug("InvokeHTTP -- create flow file with %s", method_);
281 flowFile = session->create();
282 } else {
283 logger_->log_debug("Exiting because method is %s and there is no flowfile available to execute it, yielding", method_);
284 yield();
285 return;
286 }
287 } else {
288 logger_->log_debug("InvokeHTTP -- Received flowfile");
289 }
290
291 logger_->log_debug("onTrigger InvokeHTTP with %s to %s", method_, url_);
292
293 // create a transaction id
294 std::string tx_id = generateId();
295
296 // Note: callback must be declared before callbackObj so that they are destructed in the correct order
297 std::unique_ptr<utils::ByteInputCallBack> callback = nullptr;
298 std::unique_ptr<utils::HTTPUploadCallback> callbackObj = nullptr;
299
300 // Client declared after the callbacks to make sure the callbacks are still available when the client is destructed
301 utils::HTTPClient client(url_, ssl_context_service_);
302
303 client.initialize(method_);
304 client.setConnectionTimeout(connect_timeout_ms_);
305 client.setReadTimeout(read_timeout_ms_);
306
307 if (!content_type_.empty()) {
308 client.setContentType(content_type_);
309 }
310
311 if (use_chunked_encoding_) {
312 client.setUseChunkedEncoding();
313 }
314
315 if (disable_peer_verification_) {
316 logger_->log_debug("Disabling peer verification in HTTPClient");
317 client.setDisablePeerVerification();
318 }
319
320 client.setHTTPProxy(proxy_);
321
322 if (emitFlowFile(method_)) {
323 logger_->log_trace("InvokeHTTP -- reading flowfile");
324 std::shared_ptr<ResourceClaim> claim = flowFile->getResourceClaim();
325 if (claim) {
326 callback = std::unique_ptr<utils::ByteInputCallBack>(new utils::ByteInputCallBack());
327 session->read(flowFile, callback.get());
328 callbackObj = std::unique_ptr<utils::HTTPUploadCallback>(new utils::HTTPUploadCallback);
329 callbackObj->ptr = callback.get();
330 callbackObj->pos = 0;

Callers 1

Calls 15

IsNullOrEmptyFunction · 0.85
log_debugMethod · 0.80
setReadTimeoutMethod · 0.80
setContentTypeMethod · 0.80
setUseChunkedEncodingMethod · 0.80
log_traceMethod · 0.80
getResourceClaimMethod · 0.80
appendHeaderMethod · 0.80
setUploadCallbackMethod · 0.80
setSeekFunctionMethod · 0.80
log_errorMethod · 0.80

Tested by

no test coverage detected