0

Issue of "Failed to read pacts: NullPointerException" while uploading pact file into the pact broker. Below is my stack trace and POM file details. Please help. Below is my stack trace

  [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 

Below is my 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>
PaChSu
  • 297
  • 3
  • 13
  • Well, it says that it can't read your pact files. Could it be some kind of permission issue? can you actually open and read the file? – J_A_X Oct 04 '17 at 22:37
  • @J_A_X : Thanks for your reply, I have found the answer will post it below. – PaChSu Oct 09 '17 at 10:28

2 Answers2

1

This issue comes if one of the below occurs : 1) There is naming conflict in the Consumer/Provider Names in the json files you are uploading. Solution : Make sure the names are unique, the matching rules are not only related to substring match but also catch "similar name".Please check the Broker matching code for more details. There is no documentation for this yet. Example : Cart_service and order_service are NOT allowed, Car-order,order-processing are NOT allowed since they have common words.

2) Running the mvn upload-pacts will return NullPointerException if there is any issue. To see the real error make sure you run mvn test or mvn install instead. It will show you the exact server response status code.

PaChSu
  • 297
  • 3
  • 13
0

See this documentation on publishing pacts for services with similar names:

409 when publishing a pact

When a pact is published normally (via a PUT to /pacts/provider/PROVIDER/consumer/CONSUMER/version/CONSUMER_APP_VERSION) the consumer, provider and consumer version resources are automatically created.

To prevent a pacticipant (consumer or provider) being created multiple times with slightly different name variants (eg. FooBar/foo-bar/foo bar/Foo Bar Service), if a new pacticipant name is deemed similar enough to an existing name, a 409 will be returned. The response body will contain instructions indicating that the pacticipant name should be corrected if it was intended to be an existing one, or that the pacticipant should be created manually if it was intended to be a new one.

Some Pact Broker clients unfortunately do not show the full error text when this happens. The full text is as follows: 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

Beth Skurrie
  • 1,333
  • 7
  • 8