如何通过wiremock将模拟响应作为请求数据发送到另一个服务

时间:2017-08-19 18:17:05

标签: wiremock

我最近开始使用wiremock,我对以下问题感到震惊

  1. 我有肥皂服务,我正在通过线索嘲笑。
  2. 我正在做模板响应和准备动态肥皂响应(响应应该包含一些请求数据)。
  3. 每当这个模拟服务被命中时,它必须调用另一个soap服务(服务URL将出现在soap requst中),模拟服务的响应(在步骤2中生成)作为输入
  4. 我使用以下扩展作为pom中的依赖项 ```

    <dependencies>
            <dependency>
                <groupId>com.github.tomakehurst</groupId>
                <artifactId>wiremock-standalone</artifactId>
                <version>2.6.0</version>
            </dependency>
            <dependency>
                <groupId>org.wiremock</groupId>
                <artifactId>wiremock-webhooks-extension</artifactId>
                <version>0.0.1</version>
            </dependency>
            <dependency>
                <groupId>com.opentable</groupId>
                <artifactId>wiremock-body-transformer</artifactId>
                <version>1.1.6</version>
            </dependency>
        </dependencies>
    
        <build>
            <finalName>${project.artifactId}</finalName>
            <resources>
                <resource>
                    <directory>${basedir}</directory>
                    <includes>
                        <include>**/*.xml</include>
                        <include>**/*.json</include>
                    </includes>
                    <excludes>
                        <exclude>pom.xml</exclude>
                    </excludes>
                </resource>
            </resources>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <mainClass>com.github.tomakehurst.wiremock.standalone.WireMockServerRunner</mainClass>
                            </manifest>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <finalName>${project.artifactId}-${project.version}</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    

    ```

    我尝试使用webhook扩展程序运行线程,如下面两种方式

    ```

    java -jar target/wiremock-1.0-SNAPSHOT.jar -verbose --extensions com.opentable.extension.BodyTransformer, org.wiremock.webhooks.Webhooks
    
    java -cp "wiremock-standalone-2.6.0.jar:wiremock-webhooks-extension-0.0.1.jar" com.github.tomakehurst.wiremock.standalone.WireMockServerRunner --verbose --extensions org.wiremock.webhooks.Webhooks
    

    ```

    1. 下面是我的json。
    2. ```

      {  
         "priority":1,
         "request":{  
            "url":"/services/cv",
            "method":"POST",
            "headers":{  
               "SOAPAction":{  
                  "contains":"PutMessage-CV"
               }
            },
            "bodyPatterns":[  
               {  
                  "matchesXPath":"//pcc:FamilyName[text()='FRITZ']",
                  "xPathNamespaces":{  
                     "pcc":"http://www.starstandards.org/STAR"
                  }
               }
            ]
         },
         "response":{  
            "status":200,
            "headers":{  
               "Content-Type":"text/xml; charset=utf-8"
            },
            "bodyFileName":"cv/verified.xml",
            "transformers":[  
               "body-transformer"
            ]
         },
         "postServeActions":{  
            "webhook":{  
               "headers":{  
                  "Content-Type":"text/xml; charset=utf-8"
               },
               "method":"POST",
               "bodyFileName":"cv/verified.xml",
               "transformers":[  
                  "body-transformer"
               ],
               "url":"//pcc:serviceUrl"
            }
         }
      }
      

      ```

      您能否建议我如何使用wiremock实现这一目标。

      谢谢,

0 个答案:

没有答案