Skip to content

Commit 441bae9

Browse files
committed
add more informative statuses
1 parent 7b31e6e commit 441bae9

File tree

7 files changed

+45
-36
lines changed

7 files changed

+45
-36
lines changed

astm-http-lib/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>org.itech</groupId>
66
<artifactId>astm-http-lib</artifactId>
7-
<version>2.3.2</version>
7+
<version>2.3.3</version>
88

99
<properties>
1010
<java.version>21</java.version>

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/ASTMHandlerMarshaller.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public ASTMMarshallerResponse handle(ASTMMessage message, Set<ASTMForwardingHand
6666
matchingMessageHandlers.getKey(),
6767
e
6868
);
69-
handleResponses.add(new ASTMHandlerResponse("", HandleStatus.FAIL, false, messageHandler));
69+
handleResponses.add(new ASTMHandlerResponse("", HandleStatus.GENERIC_FAIL, false, messageHandler));
7070
// TODO add some handle exception handling. retry queue? db save?
7171
// handler.handleError();
7272
}

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/DefaultForwardingASTMToHTTPHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public ASTMHandlerResponse handle(ASTMMessage message) {
5656
if (response.statusCode() == 200) {
5757
return new ASTMHandlerResponse(response.body(), HandleStatus.SUCCESS, false, this);
5858
}
59-
return new ASTMHandlerResponse(response.body(), HandleStatus.FAIL, false, this);
59+
return new ASTMHandlerResponse(response.body(), HandleStatus.FORWARD_FAIL_BAD_RESPONSE, false, this);
6060
} catch (IOException | InterruptedException e) {
6161
log.error("error occurred communicating with http server at " + forwardingUri.toString(), e);
62+
return new ASTMHandlerResponse("", HandleStatus.GENERIC_FAIL, false, this);
6263
}
63-
return new ASTMHandlerResponse("", HandleStatus.FAIL, false, this);
6464
}
6565

6666
@Override

astm-http-lib/src/main/java/org/itech/ahb/lib/common/HandleStatus.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
public enum HandleStatus {
44
SUCCESS,
5-
FAIL,
5+
GENERIC_FAIL,
6+
FORWARD_FAIL_BAD_RESPONSE,
7+
FORWARD_FAIL_ERROR,
8+
FAIL_TOO_MANY_ATTEMPTS,
9+
FAIL_LINE_CONTESTED,
10+
INTERRUPTED,
11+
FAIL_FRAME_PARSING,
612
@Deprecated
713
UNHANDLED
814
}

astm-http-lib/src/main/java/org/itech/ahb/lib/http/servlet/DefaultForwardingHTTPToASTMHandler.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private HTTPHandlerResponse handle(ASTMMessage message, Set<HTTPHandlerInfo> han
7979
log.debug("reattempting forward to astm server...");
8080
} else if (retryAttempt > MAX_FORWARD_RETRY_ATTEMPTS) {
8181
log.error("reached max number of retries while attempting to forward http over astm");
82-
return new HTTPHandlerResponse("", HandleStatus.FAIL, false, this);
82+
return new HTTPHandlerResponse("", HandleStatus.FAIL_TOO_MANY_ATTEMPTS, false, this);
8383
}
8484
try {
8585
log.debug("connecting to forward to astm server at " + forwardingAddress + ":" + forwardingPort);
@@ -100,30 +100,7 @@ private HTTPHandlerResponse handle(ASTMMessage message, Set<HTTPHandlerInfo> han
100100
log.warn(
101101
"line was contested by the remote server, defaulting to receive information from " + forwardingAddress
102102
);
103-
// the communicator must remain open to receive the line contention. The thread
104-
// will close the socket
105-
ASTMReceiveThread receiveThread = new ASTMReceiveThread(communicator, socket, astmHandlerMarshaller, true);
106-
receiveThread.run();
107-
log.debug("waiting after line contention to see if sender has a message that needs to be received...");
108-
TimeUnit.SECONDS.sleep(LINE_CONTENTION_REATTEMPT_TIMEOUT);
109-
if (receiveThread.didReceiveEstablishmentSucceed()) {
110-
log.debug("received an establishment after the line was in contention before the timeout");
111-
} else {
112-
log.error(
113-
"a timeout occured waiting for the sender to reattempt establishment after the line was contested."
114-
);
115-
receiveThread.interrupt();
116-
throw new ASTMCommunicationException(
117-
"line contention occurred but receiver didn't receive an establishment character"
118-
);
119-
}
120-
121-
if (message.getMessageLength() == 0) {
122-
log.info("since original message request was empty, it is assumed this was a ping to trigger an action");
123-
return new HTTPHandlerResponse("", HandleStatus.SUCCESS, false, this);
124-
} else {
125-
return new HTTPHandlerResponse("", HandleStatus.FAIL, false, this);
126-
}
103+
return handleLineContention(communicator, socket, message);
127104
} else if (result.isRejected()) {
128105
return handle(message, handlerInfos, ++retryAttempt);
129106
} else {
@@ -147,7 +124,32 @@ private HTTPHandlerResponse handle(ASTMMessage message, Set<HTTPHandlerInfo> han
147124
}
148125
} catch (InterruptedException e) {
149126
log.error("thread was interrupted while handling http astm message", e);
150-
return new HTTPHandlerResponse("", HandleStatus.FAIL, false, this);
127+
return new HTTPHandlerResponse("", HandleStatus.INTERRUPTED, false, this);
128+
}
129+
}
130+
131+
private HTTPHandlerResponse handleLineContention(Communicator communicator, Socket socket, ASTMMessage message)
132+
throws ASTMCommunicationException, InterruptedException {
133+
// the communicator must remain open to receive the line contention. The thread will close the socket
134+
ASTMReceiveThread receiveThread = new ASTMReceiveThread(communicator, socket, astmHandlerMarshaller, true);
135+
receiveThread.run();
136+
log.debug("waiting after line contention to see if sender has a message that needs to be received...");
137+
TimeUnit.SECONDS.sleep(LINE_CONTENTION_REATTEMPT_TIMEOUT);
138+
if (receiveThread.didReceiveEstablishmentSucceed()) {
139+
log.debug("received an establishment after the line was in contention before the timeout");
140+
} else {
141+
log.error("a timeout occured waiting for the sender to reattempt establishment after the line was contested.");
142+
receiveThread.interrupt();
143+
throw new ASTMCommunicationException(
144+
"line contention occurred but receiver didn't receive an establishment character"
145+
);
146+
}
147+
148+
if (message.getMessageLength() == 0) {
149+
log.info("since original message request was empty, it is assumed this was a ping to trigger an action");
150+
return new HTTPHandlerResponse("", HandleStatus.SUCCESS, false, this);
151+
} else {
152+
return new HTTPHandlerResponse("", HandleStatus.FAIL_LINE_CONTESTED, false, this);
151153
}
152154
}
153155

astm-http-lib/src/main/java/org/itech/ahb/lib/http/servlet/HTTPHandlerMarshaller.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public HTTPMarshallerResponse handle(ASTMMessage message, Set<HTTPForwardingHand
6666
handleResponses.add(handleResponse);
6767
} catch (FrameParsingException e) {
6868
log.error("couldn't parse frames into a message", e);
69-
handleResponses.add(new HTTPHandlerResponse("", HandleStatus.FAIL, false, messageHandler));
69+
handleResponses.add(new HTTPHandlerResponse("", HandleStatus.FAIL_FRAME_PARSING, false, messageHandler));
7070
} catch (RuntimeException e) {
7171
log.error(
7272
"unexpected error occurred during '" +
@@ -75,11 +75,12 @@ public HTTPMarshallerResponse handle(ASTMMessage message, Set<HTTPForwardingHand
7575
matchingMessageHandlers.getKey(),
7676
e
7777
);
78-
handleResponses.add(new HTTPHandlerResponse("", HandleStatus.FAIL, false, messageHandler));
79-
// TODO add some handle exception handling. retry queue? db save?
78+
handleResponses.add(new HTTPHandlerResponse("", HandleStatus.GENERIC_FAIL, false, messageHandler));
8079
}
8180
}
8281
}
82+
// TODO add some handle exception handling. for every handleResponse not success call messageHandler.handleFailure();
83+
8384
return new HTTPMarshallerResponse(handleResponses);
8485
}
8586
}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212
<groupId>org.itech</groupId>
1313
<artifactId>astm-http-bridge</artifactId>
14-
<version>2.3.2</version>
14+
<version>2.3.3</version>
1515
<name>astm-http-bridge</name>
1616
<description>Translates astm to http and vice versa</description>
1717
<properties>
@@ -30,7 +30,7 @@
3030
<dependency>
3131
<groupId>org.itech</groupId>
3232
<artifactId>astm-http-lib</artifactId>
33-
<version>2.3.2</version>
33+
<version>2.3.3</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>org.springframework.boot</groupId>

0 commit comments

Comments
 (0)