Pact文件上传到pact代理失败

时间:2017-10-03 08:55:56

标签: pact pact-broker

将pact文件上传到pact代理时出现“无法读取pacts: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>

2 个答案:

答案 0 :(得分:1)

如果出现以下情况之一,则会出现此问题: 1)您正在上传的json文件中的Consumer / Provider Name中存在命名冲突。 解决方案:确保名称是唯一的,匹配规则不仅与子串匹配相关,而且还与类似名称&#34;相似的名称&#34;。请检查代理匹配代码以获取更多详细信息。目前还没有相关文档。 示例:不允许使用Cart_service和order_service,不允许使用Car-order,order-processing,因为它们有共同的单词。

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

答案 1 :(得分:0)

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

发布契约时

409

当正常发布契约时(通过PUT转到/pacts/provider/PROVIDER/consumer/CONSUMER/version/CONSUMER_APP_VERSION),会自动创建consumerproviderconsumer 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