柑橘模拟器在接收序列化 xml 数据时抛出 Nullpointer 异常

Citrus Simulator throws Nullpointer Exception when receiving serialized xml data

我是 运行 Citrus Simulator 作为 spring-boot 应用程序来模拟 Web 服务响应 HTTP POST 调用。 在 "lab" 条件下一切正常。只要我通过 Postman、curl 或浏览器插件手动发送数据,我就没有问题和干净的答案。然而,一旦数据被另一个应用程序发送,我就会收到一个讨厌的空指针异常。

我花了一段时间才查明问题所在,但现在我知道这是发送数据的格式问题。

发送漂亮的 xml 数据会得到完美的答案。但是,一旦我序列化 xml,Citrus Simulator 就不会正确处理它,我会得到一个空指针异常 .

使用 curl 我也可以简单地通过取消发送的 xml 文件的格式来引发错误。

编辑 直接不是格式。这两个应用程序在以漂亮的打印格式发送数据时,将生成一个包含一些(奇怪的)内容的 HTTP Header 元数据 -> curl 发送 Metadata="\t\t\t",postman 发送 Metadata="\n " . 发送序列化 xml,两个应用程序都发送空元数据 Header,从而导致空指针异常 就在这里 (MessageService.java:60) -> StringUtils.abbreviate(headerEntry.getValue().toString(), 255))));

java.lang.NullPointerException: null
at com.consol.citrus.simulator.service.MessageService.lambda$saveMessage[=11=](MessageService.java:60) ~[citrus-simulator-starter-1.0.3.jar:na]
at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_201]
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_201]
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580) ~[na:1.8.0_201]
at com.consol.citrus.simulator.service.MessageService.saveMessage(MessageService.java:58) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.service.MessageService$$FastClassBySpringCGLIB$$be0e8eaa.invoke(<generated>) ~[citrus-simulator-starter-1.0.3.jar:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at com.consol.citrus.simulator.service.MessageService$$EnhancerBySpringCGLIB$$f26ac16e.saveMessage(<generated>) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.service.ActivityService.saveScenarioMessage(ActivityService.java:124) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.service.ActivityService$$FastClassBySpringCGLIB$84762a.invoke(<generated>) ~[citrus-simulator-starter-1.0.3.jar:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:671) ~[spring-aop-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at com.consol.citrus.simulator.service.ActivityService$$EnhancerBySpringCGLIB$f927ee.saveScenarioMessage(<generated>) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.endpoint.EndpointMessageHandler.saveScenarioMessage(EndpointMessageHandler.java:58) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.endpoint.EndpointMessageHandler.handleReceivedMessage(EndpointMessageHandler.java:51) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.scenario.ScenarioEndpoint.messageReceived(ScenarioEndpoint.java:111) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.scenario.ScenarioEndpoint.receive(ScenarioEndpoint.java:88) ~[citrus-simulator-starter-1.0.3.jar:na]
at com.consol.citrus.simulator.scenario.SVManagerScenario.receive(SVManagerScenario.java:60) ~[classes/:na]
at com.consol.citrus.simulator.scenario.SVManagerScenario.run(SVManagerScenario.java:24) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_201]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_201]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_201]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_201]
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:215) ~[spring-core-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at com.consol.citrus.simulator.service.ScenarioExecutionService.lambda$null(ScenarioExecutionService.java:150) ~[citrus-simulator-starter-1.0.3.jar:na]
at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:491) ~[spring-core-4.3.21.RELEASE.jar:4.3.21.RELEASE]
at com.consol.citrus.simulator.service.ScenarioExecutionService.lambda$startScenarioAsync(ScenarioExecutionService.java:111) ~[citrus-simulator-starter-1.0.3.jar:na]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[na:1.8.0_201]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_201]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_201]
at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_201]

很遗憾,我无法获得最新版本的柑橘。我的设置是 运行 java 1.8 和 citrus 2.7.1

有没有人遇到过旧版 Citrus Simulator 的类似问题?

我很感激任何帮助

我从来没有调查过这个问题的原因(好吧,这显然是一些 null-header),但是一个简单的解决方法(不是解决方案!)是覆盖com.consol.citrus.simulator.serviceMessageService bean 如下:

@Service
@Primary
@Transactional
public class NullHeaderAwareMessageService extends MessageService {

    private final MessageRepository messageRepository;

    @Autowired
    public NullHeaderAwareMessageService(MessageRepository messageRepository) {
        super(messageRepository);

        this.messageRepository = messageRepository;
    }

    @Override
    public Message saveMessage(Message.Direction direction, String payload, String citrusMessageId, Map<String, Object> headers) {
        Message message = new Message();
        message.setDate(new Date());
        message.setDirection(direction);
        message.setPayload(payload);
        message.setCitrusMessageId(citrusMessageId);
        if (headers != null) {
            headers.entrySet().stream()
                    .filter(headerEntry -> headerEntry.getValue() != null)
                    .forEach(headerEntry -> message.addHeader(
                                new MessageHeader(headerEntry.getKey(),
                                        StringUtils.abbreviate(headerEntry.getValue().toString(), 255))));
        }

        return messageRepository.save(message);
    }
}