Skip to content

Commit de43c76

Browse files
committed
adjust return type
1 parent 45625a0 commit de43c76

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

common/common-rest/src/main/java/org/apache/servicecomb/common/rest/codec/produce/ProduceEventStreamProcessor.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,36 +62,32 @@ public void doEncodeResponse(OutputStream output, Object result) throws Exceptio
6262
public Object doDecodeResponse(InputStream input, JavaType type) throws Exception {
6363
String buffer = new String(input.readAllBytes(), StandardCharsets.UTF_8);
6464
SseEventResponseEntity<?> responseEntity = new SseEventResponseEntity<>();
65+
boolean isResponseEntity = false;
6566
for (String line : buffer.split("\n")) {
6667
if (line.startsWith("eventId: ")) {
6768
responseEntity.eventId(Integer.parseInt(line.substring(9)));
6869
continue;
6970
}
7071
if (line.startsWith("event: ")) {
7172
responseEntity.event(line.substring(7));
73+
isResponseEntity = true;
7274
continue;
7375
}
7476
if (line.startsWith("retry: ")) {
7577
responseEntity.retry(Long.parseLong(line.substring(7)));
78+
isResponseEntity = true;
7679
continue;
7780
}
7881
if (line.startsWith("data: ")) {
7982
responseEntity.data(RestObjectMapperFactory.getRestObjectMapper().readValue(line.substring(6), type));
8083
}
8184
}
82-
if (isNotResponseEntity(responseEntity)) {
83-
writeIndex++;
85+
if (!isResponseEntity) {
8486
return responseEntity.getData();
8587
}
8688
return responseEntity;
8789
}
8890

89-
private boolean isNotResponseEntity(SseEventResponseEntity<?> responseEntity) {
90-
return StringUtils.isEmpty(responseEntity.getEvent())
91-
&& responseEntity.getRetry() == null
92-
&& (responseEntity.getEventId() != null && responseEntity.getEventId() == writeIndex);
93-
}
94-
9591
@Override
9692
public void refreshEventId(int index) {
9793
this.writeIndex = index;

0 commit comments

Comments
 (0)