Skip to content

Commit 80f16a6

Browse files
committed
Changes done for v1.1.7.
1 parent f2b86c7 commit 80f16a6

File tree

4 files changed

+68
-19
lines changed

4 files changed

+68
-19
lines changed

com.ibm.streamsx.websocket/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Changes
22
=======
3+
## v1.1.7:
4+
* Oct/20/2023
5+
* Added new logic in the HttpPost operator to send an output tuple with details about the failure of all retry attempts along with HTTP status code and the target URL.
6+
37
## v1.1.6:
48
* Oct/18/2023
59
* Added new logic in the HttpPost operator to retry PUT, POST or GET operation in case of both for Java exceptions and for a user configured list of HTTP status codes such as 503, 408, 504 etc.

com.ibm.streamsx.websocket/impl/java/src/com/ibm/streamsx/websocket/op/HttpPost.java

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/*
1010
==================================================================
1111
First created on: Mar/15/2020
12-
Last modified on: Oct/18/2023
12+
Last modified on: Oct/20/2023
1313
1414
This Java operator is an utility operator available in the
1515
streamsx.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>();

com.ibm.streamsx.websocket/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<info:identity>
55
<info:name>com.ibm.streamsx.websocket</info:name>
66
<info:description>Provides C++ WebSocket source, analytic and sink operators</info:description>
7-
<info:version>1.1.6</info:version>
7+
<info:version>1.1.7</info:version>
88
<info:requiredProductVersion>4.2.1.0</info:requiredProductVersion>
99
</info:identity>
1010
<info:dependencies/>

websocket-tech-brief.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
============================================================
22
First created on: February/22/2020
3-
Last modified on: October/18/2023
3+
Last modified on: October/20/2023
44

55
Purpose of this toolkit
66
-----------------------

0 commit comments

Comments
 (0)