|
9 | 9 | import org.springframework.messaging.MessageHeaders;
|
10 | 10 |
|
11 | 11 | import java.util.Base64;
|
| 12 | +import java.util.Collections; |
12 | 13 | import java.util.HashMap;
|
13 | 14 | import java.util.Map;
|
14 | 15 |
|
@@ -37,31 +38,35 @@ public void execute() {
|
37 | 38 | if (!ContextManager.needRecordOrReplay()) {
|
38 | 39 | return;
|
39 | 40 | }
|
| 41 | + executeBeforeProcess(); |
40 | 42 | doExecute();
|
41 |
| - executePostProcess(); |
| 43 | + executeAfterProcess(); |
42 | 44 | } catch (Exception e) {
|
43 | 45 | LogUtil.warn("MessageQueue.execute", e);
|
44 | 46 | }
|
45 | 47 | }
|
46 | 48 |
|
47 |
| - private void executePostProcess() { |
| 49 | + private void executeBeforeProcess() { |
48 | 50 | if (ContextManager.needRecord()) {
|
49 | 51 | adapter.addHeader(messageChannel,message, ArexConstants.RECORD_ID,ContextManager.currentContext().getCaseId());
|
50 | 52 | }
|
51 | 53 | if (ContextManager.needReplay()) {
|
52 | 54 | adapter.addHeader(messageChannel,message, ArexConstants.REPLAY_ID,ContextManager.currentContext().getReplayId());
|
53 | 55 | }
|
| 56 | + } |
| 57 | + private void executeAfterProcess(){ |
54 | 58 | // Think about other ways to replace the head
|
55 | 59 | adapter.resetMsg(message);
|
56 | 60 | }
|
57 | 61 |
|
58 | 62 | private void doExecute() {
|
59 | 63 | Mocker mocker = MockUtils.createMqttConsumer(adapter.getHeader(messageChannel,message,"mqtt_receivedTopic"));
|
60 | 64 | MessageHeaders header = adapter.getHeader(messageChannel, message);
|
61 |
| - Map<String, Object> requestAttributes = new HashMap<>(); |
| 65 | + Map<String, Object> requestOrigin = new HashMap<>(); |
62 | 66 | for (Map.Entry<String, Object> entry : header.entrySet()) {
|
63 |
| - requestAttributes.put(entry.getKey(), entry.getValue()); |
| 67 | + requestOrigin.put(entry.getKey(), entry.getValue()); |
64 | 68 | }
|
| 69 | + Map<String, Object> requestAttributes = Collections.singletonMap("Headers", requestOrigin); |
65 | 70 | mocker.getTargetRequest().setAttributes(requestAttributes);
|
66 | 71 | mocker.getTargetRequest().setBody(Base64.getEncoder().encodeToString(adapter.getMsg(messageChannel,message)));
|
67 | 72 | if (ContextManager.needReplay()) {
|
|
0 commit comments