99/*
1010==================================================================
1111First created on: Mar/15/2020
12- Last modified on: Oct/18 /2023
12+ Last modified on: Oct/20 /2023
1313
1414This Java operator is an utility operator available in the
1515streamsx.websocket toolkit. It can be used to do HTTP(S) post of
@@ -441,6 +441,8 @@ public final void process(StreamingInput<Tuple> inputStream, Tuple tuple) throws
441441
442442 int retryAttemptCnt = -1 ;
443443 long bytesSent = 0 ;
444+ int responseStatusCode = -1 ;
445+ String responseStatusReason = "" ;
444446 OperatorContext context = getOperatorContext ();
445447
446448 // Senthil added this while loop on Oct/02/2023 to support
@@ -466,12 +468,27 @@ public final void process(StreamingInput<Tuple> inputStream, Tuple tuple) throws
466468 if (maxRetryAttempts > 0 && retryAttemptCnt > maxRetryAttempts ) {
467469 // We are done with the maximum retry attempts that was
468470 // configured for this operator instance.
469- Logger .getLogger (this .getClass ()).error ("Operator=" + context .getName () + ", PE=" +
470- context .getPE ().getPEId () + ", Job=" + context .getPE ().getJobId () +
471- ", Incoming tuple number=" + httpPostCnt +
472- ". Giving up the HTTP " + httpMethod +
473- " operation for the current incoming tuple after making " +
474- maxRetryAttempts + " retry attempts." );
471+ String logMessage = "Operator=" + context .getName () + ", PE=" +
472+ context .getPE ().getPEId () + ", Job=" + context .getPE ().getJobId () +
473+ ", Incoming tuple number=" + httpPostCnt +
474+ ". Giving up the HTTP " + httpMethod +
475+ " operation for the current incoming tuple after making " +
476+ maxRetryAttempts + " retry attempts. url=" + url +
477+ ", statusCode=" + responseStatusCode +
478+ ", statusMessage=" + responseStatusReason + "." ;
479+ Logger .getLogger (this .getClass ()).error (logMessage );
480+
481+ // Since we are giving up after the maximum allowed retries,
482+ // we can also send an output tuple with the details about
483+ // our giving up.
484+ outTuple .setInt ("statusCode" , responseStatusCode );
485+ outTuple .setString ("statusMessage" , logMessage );
486+ // Set the string and blob data output attributes to none.
487+ outTuple .setString ("strData" , "" );
488+ byte [] emptyBytes = new byte [0 ];
489+ outTuple .setBlob ("blobData" ,
490+ ValueFactory .newBlob (emptyBytes , 0 , 0 ));
491+ outStream .submit (outTuple );
475492
476493 // Set this operator metrics.
477494 nHttpPostFailed .increment ();
@@ -683,22 +700,36 @@ public final void process(StreamingInput<Tuple> inputStream, Tuple tuple) throws
683700 // Update the operator metrics.
684701 nHttpPostFailed .increment ();
685702
686- if (maxRetryAttempts == 0 || retryAttemptCnt == maxRetryAttempts ) {
687- // Even in the case of an exception, we will emit an
703+ if (maxRetryAttempts == 0 ) {
704+ // Even in the case of an exception with no retry option set , we will emit an
688705 // output tuple to inform the application that invoked this operator.
689706 outTuple .setInt ("statusCode" , 12345 );
690707 outTuple .setString ("statusMessage" , ex .getMessage ());
708+ // Set the string and blob data output attributes to none.
709+ outTuple .setString ("strData" , "" );
710+ byte [] emptyBytes = new byte [0 ];
711+ outTuple .setBlob ("blobData" ,
712+ ValueFactory .newBlob (emptyBytes , 0 , 0 ));
691713 outStream .submit (outTuple );
692714 }
693715
716+ // If the user has configured retry attempts to be made, then
717+ // we will have to send additional details via an output tuple in case
718+ // all retry attempts happen to fail. We will do that in the early
719+ // sections of the while loop we are in. To aid that, let us
720+ // set these variables.
721+ if (maxRetryAttempts > 0 ) {
722+ responseStatusCode = 12345 ;
723+ responseStatusReason = ex .getMessage ();
724+ }
725+
694726 // Continue the while loop to decide if we must make a
695727 // retry attempt after this PUT/POST exception.
696728 continue ;
697729 }
698730
699- int responseStatusCode = response .getStatusLine ().getStatusCode ();
700-
701- String responseStatusReason = response .getStatusLine ().getReasonPhrase ();
731+ responseStatusCode = response .getStatusLine ().getStatusCode ();
732+ responseStatusReason = response .getStatusLine ().getReasonPhrase ();
702733 // Let us now parse all the response headers and populate them in
703734 // a map to be sent in the output tuple later in the code below.
704735 HashMap <RString , RString > responseHeadersMap = new HashMap <RString , RString >();
@@ -924,22 +955,36 @@ public final void process(StreamingInput<Tuple> inputStream, Tuple tuple) throws
924955 // Update the operator metrics.
925956 nHttpPostFailed .increment ();
926957
927- if (maxRetryAttempts == 0 || retryAttemptCnt == maxRetryAttempts ) {
928- // Even in the case of an exception, we will emit an
958+ if (maxRetryAttempts == 0 ) {
959+ // Even in the case of an exception with no retry option set , we will emit an
929960 // output tuple to inform the application that invoked this operator.
930961 outTuple .setInt ("statusCode" , 12345 );
931962 outTuple .setString ("statusMessage" , ex .getMessage ());
963+ // Set the string and blob data output attributes to none.
964+ outTuple .setString ("strData" , "" );
965+ byte [] emptyBytes = new byte [0 ];
966+ outTuple .setBlob ("blobData" ,
967+ ValueFactory .newBlob (emptyBytes , 0 , 0 ));
932968 outStream .submit (outTuple );
933969 }
934970
971+ // If the user has configured retry attempts to be made, then
972+ // we will have to send additional details via an output tuple in case
973+ // all retry attempts happen to fail. We will do that in the early
974+ // sections of the while loop we are in. To aid that, let us
975+ // set these variables.
976+ if (maxRetryAttempts > 0 ) {
977+ responseStatusCode = 12345 ;
978+ responseStatusReason = ex .getMessage ();
979+ }
980+
935981 // Continue the while loop to decide if we must make a
936982 // retry attempt after this GET exception.
937983 continue ;
938984 }
939985
940- int responseStatusCode = response .getStatusLine ().getStatusCode ();
941-
942- String responseStatusReason = response .getStatusLine ().getReasonPhrase ();
986+ responseStatusCode = response .getStatusLine ().getStatusCode ();
987+ responseStatusReason = response .getStatusLine ().getReasonPhrase ();
943988 // Let us now parse all the response headers and populate them in
944989 // a map to be sent in the output tuple later in the code below.
945990 HashMap <RString , RString > responseHeadersMap = new HashMap <RString , RString >();
0 commit comments