Skip to content

Commit

Permalink
Merge pull request #1023 from mytang0/fix_patch_npe
Browse files Browse the repository at this point in the history
[ISSUE #1022] Two NPE problems fixes for Tcp Protocol Resolver
close #1022
  • Loading branch information
xwm1992 authored Jul 18, 2022
2 parents 002e7a6 + 7e5aa5a commit 6e70ffb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public void init() {
}

eventMeshServerTraceEnable = Boolean.parseBoolean(get(ConfKeys.KEYS_EVENTMESH_TRACE_ENABLED, () -> "false"));
eventMeshTracePluginType = checkNotEmpty(ConfKeys.KEYS_EVENTMESH_TRACE_PLUGIN_TYPE);
if (eventMeshServerTraceEnable) {
eventMeshTracePluginType = checkNotEmpty(ConfKeys.KEYS_EVENTMESH_TRACE_PLUGIN_TYPE);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ public static CloudEvent buildEvent(Header header, EventMeshMessage message) thr
.withData(content.getBytes(StandardCharsets.UTF_8));

for (String propKey : header.getProperties().keySet()) {
cloudEventBuilder.withExtension(propKey, header.getProperty(propKey).toString());
try {
cloudEventBuilder.withExtension(propKey, header.getProperty(propKey).toString());
} catch (Exception e) {
throw new ProtocolHandleException(String.format("Abnormal propKey: %s", propKey), e);
}
}

for (String propKey : message.getProperties().keySet()) {
cloudEventBuilder.withExtension(propKey, message.getProperties().get(propKey));
try {
cloudEventBuilder.withExtension(propKey, message.getProperties().get(propKey));
} catch (Exception e) {
throw new ProtocolHandleException(String.format("Abnormal propKey: %s", propKey), e);
}
}

return cloudEventBuilder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.apache.eventmesh.protocol.api.ProtocolAdaptor;
import org.apache.eventmesh.protocol.api.ProtocolPluginFactory;
import org.apache.eventmesh.runtime.acl.Acl;
import org.apache.eventmesh.runtime.boot.EventMeshServer;
import org.apache.eventmesh.runtime.boot.EventMeshTCPServer;
import org.apache.eventmesh.runtime.constants.EventMeshConstants;
import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send.EventMeshTcpSendResult;
Expand All @@ -58,7 +57,6 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.context.Context;

public class MessageTransferTask extends AbstractTask {
Expand Down Expand Up @@ -181,7 +179,9 @@ public void operationComplete(ChannelFuture future) throws Exception {
.getSeq()));
Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session);

TraceUtils.finishSpanWithException(ctx, event, "MessageTransferTask failed", e);
if (event != null) {
TraceUtils.finishSpanWithException(ctx, event, "MessageTransferTask failed", e);
}
}
}
}
Expand Down

0 comments on commit 6e70ffb

Please sign in to comment.