0

将协议文件上传到协议代理时出现“读取协议失败:NullPointerException”的问题。下面是我的堆栈跟踪和 POM 文件详细信息。请帮忙。下面是我的堆栈跟踪

  [INFO] loading pacts from target/pacts
[INFO] found pact file: PRODUCT-CART.json
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.476 s
[INFO] Finished at: 2017-10-03T15:09:20+08:00
[INFO] Final Memory: 11M/243M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.warmuuh:pactbroker-maven-plugin:0.0.9:upload-pacts (default-cli) on project Auth_Api_Consumer: Failed to read pacts: NullPointerException -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.warmuuh:pactbroker-maven-plugin:0.0.9:upload-pacts (default-cli) on project Auth_Api_Consumer: Failed to read pacts
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at 

下面是我的 POM.xml

                <plugin>
                    <groupId>com.github.warmuuh</groupId>
                    <artifactId>pactbroker-maven-plugin</artifactId>
                    <version>0.0.9</version>
                    <executions>
                    <!--CONSUMER Upload Pact File Starts -->    
                        <execution>
                          <id>upload-pacts</id>
                          <phase>test</phase>
                          <goals><goal>upload-pacts</goal></goals>
                          <configuration>
                           <brokerUrl>http://localhost:8080/</brokerUrl>
                           <!-- <brokerUrl>git@scm.hue.workslan:tools/hue-contract-testing.git</brokerUrl> -->
                            <pacts>${project.build.directory}/pacts</pacts>
                          </configuration>
                        </execution>
                    <!--CONSUMER Upload Pact File Ends -->
                        </executions>
                </plugin>
4

2 回答 2

1

如果发生以下情况之一,则会出现此问题: 1) 您上传的 json 文件中的消费者/提供者名称存在命名冲突。解决方案:确保名称是唯一的,匹配规则不仅与子字符串匹配有关,而且还捕获“相似名称”。请查看Broker匹配代码以获取更多详细信息。目前还没有这方面的文档。示例:不允许使用 Cart_service 和 order_service,不允许使用 Car-order、order-processing,因为它们有常用词。

2) 如果有任何问题,运行 mvn upload-pacts 将返回 NullPointerException。要查看真正的错误,请确保您运行 mvn test 或 mvn install 。它将向您显示确切的服务器响应状态代码。

于 2017-10-09T10:33:03.503 回答
0

有关为具有相似名称的服务发布协议的信息,请参阅此文档:

发布协议时出现 409

当协议正常发布(通过 PUT to /pacts/provider/PROVIDER/consumer/CONSUMER/version/CONSUMER_APP_VERSION)时consumer,会自动创建providerconsumer version资源。

为防止参与者(消费者或提供者)被多次创建并使用略有不同的名称变体(例如 FooBar/foo-bar/foo bar/Foo Bar Service),如果认为新的参与者名称与现有名称足够相似,则409 将被退回。响应正文将包含说明,如果参与者姓名打算是现有姓名,则应更正该参与者姓名,或者如果参与者姓名打算为新姓名,则应手动创建参与者姓名。

不幸的是,一些 Pact Broker 客户端在发生这种情况时不会显示完整的错误文本。全文如下: This is the first time a pact has been published for "%{new_name}". The name "%{new_name}" is very similar to the following existing consumers/providers: %{existing_names} If you meant to specify one of the above names, please correct the pact configuration, and re-publish the pact. If the pact is intended to be for a new consumer or provider, please manually create "%{new_name}" using the following command, and then re-publish the pact: $ curl -v -XPOST -H "Content-Type: application/json" -d '{"name": "%{new_name}"}' http://broker/pacticipants If the pact broker requires authentication, include '-u <username>:<password>' in the command.

https://github.com/pact-foundation/pact_broker/wiki/Troubleshooting#409-when-publishing-a-pact

于 2017-10-15T23:16:17.000 回答