How to send the mock response as request to a url

1,103 views
Skip to first unread message

Sri Divi

unread,
Jul 28, 2017, 9:11:15 AM7/28/17
to wiremock-user
Hi,

I started working on wiremock recently and I got struck with the below issue

1. I have a soap service which I am mocking through wiremock.
2. I am doing response templating and preparing a dynamic soap response (response should contain some of the request data).
3. whenever this mock service is hit, it has to call another soap service( the service url will be present in the soap requst) with the response(generated in step2)of the mock service as input
4. below is my json.

```
{  
   "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"
      }
   }
}
```

Could you please suggest me how can I achieve this with wiremock.

Thanks,

Tom Akehurst

unread,
Jul 28, 2017, 1:16:31 PM7/28/17
to wiremock-user
So the issue is that you need to pull the webhook URL from the original response body, rather than it being fixed?

If that's the case, you'll need to write some code as the webhooks extension doesn't support this at the moment. Your best bet might be to fork the extension and add this behaviour to it.

Sri Divi

unread,
Aug 16, 2017, 11:55:09 AM8/16/17
to wiremock-user
Hi Tom,

Thank you for the quick reply.
i am trying to run my standardalone wiremock with wiremock-webhooks-extension.
 like below

```
java -jar target/wiremock-1.0-SNAPSHOT.jar -verbose --extensions com.opentable.extension.BodyTransformer, org.wiremock.webhooks.Webhooks

```
i am getting class not found exception while running this command.

when i hit an end point i am getting "No extension was found named "webhook"

Please suggest me what i am missing here.

Thanks,
Sri

Tom Akehurst

unread,
Aug 16, 2017, 12:09:14 PM8/16/17
to wiremock-user
What does your JAR file contain?

Sri Divi

unread,
Aug 16, 2017, 12:11:06 PM8/16/17
to wiremock-user
it contains the below dependancies

<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>

Tom Akehurst

unread,
Aug 16, 2017, 1:45:54 PM8/16/17
to wiremock-user
And did you build it with a fat jar plugin or manifest referring to those dependencies?

Sri Divi

unread,
Aug 17, 2017, 7:58:00 AM8/17/17
to wiremock-user
Hi tom,

This is how i am building the jar using assembly plugin


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>wiremock.group</groupId>
<artifactId>wiremock</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<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>

</project>

Sri Divi

unread,
Aug 17, 2017, 9:09:17 PM8/17/17
to wiremock-user
Hi Tom,
Can you please suggest me how to run webhooks extension.

Thanks,
Sri

Tom Akehurst

unread,
Aug 18, 2017, 3:31:04 AM8/18/17
to wiremock-user
If you're seeing a classnotfoundexception on startup that suggests that something has gone wrong in the build process and the classes aren't available.

I can only suggest trying it with the standard WireMock jar and adding the plugins via the -cp parameter at startup.

Sri Divi

unread,
Aug 18, 2017, 1:32:11 PM8/18/17
to wiremock-user
Hi Tom,

i am running like below

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

still getting class not found Exception in thread "main" java.lang.ClassNotFoundException: org.wiremock.webhooks.Webhooks

also i want to deploy this on to server through bamboo. could you please suggest me the best approach. 

Tom Akehurst

unread,
Aug 21, 2017, 4:35:02 PM8/21/17
to wiremock-user
I've replicated this now. The problem is that currently the webhooks JAR isn't a fat JAR i.e. doesn't include its dependencies. This means you can only use it from within a project as described in the README, or build your own JAR as you were originally trying.

I'll release a fat JAR version of it next time I do some work on it, but in the meantime I suggest reverting to trying the fat JAR approach you were taking, but depend on the WireMock thin JAR, not the standalone one.

Sri Divi

unread,
Aug 22, 2017, 9:09:08 PM8/22/17
to wiremock-user
Thank you Tom.

I tried with wiremock instead of wiremock-standard alone artifact and it is working now.
Reply all
Reply to author
Forward
0 new messages