Skip to content

Commit

Permalink
Merge pull request #333 from wiremock/revert-285
Browse files Browse the repository at this point in the history
Revert #285
  • Loading branch information
leeturner authored Jan 16, 2025
2 parents 05fa1a5 + 04a92db commit d10591f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 212 deletions.
3 changes: 1 addition & 2 deletions _data/doc-categories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ extensibility:
- extending-wiremock
- extensibility/filtering-requests
- extensibility/transforming-responses
- extensibility/custom-request-matching
- extensibility/custom-content-matching
- extensibility/custom-matching
- extensibility/listening-for-serve-events
- extensibility/extending-the-admin-api
- extensibility/adding-template-helpers
Expand Down
65 changes: 8 additions & 57 deletions _docs/extending-wiremock.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ At present, the following extension interfaces are available:
* `ResponseTransformerV2`: Modify the response served to the client. See [Transforming responses](../extensibility/transforming-responses/).
* `ServeEventListener`: Listen for events at various points in the request processing lifecycle. See [Listening for Serve Events](../extensibility/listening-for-serve-events/).
* `AdminApiExtension`: Add admin API functions. See [Admin API Extensions](../extensibility/extending-the-admin-api/).
* `RequestMatcherExtension`: Implement custom request matching logic. See [Custom Request Matching](../extensibility/custom-request-matching/).
* `ContentPatternExtension`: Implement custom content matching logic. See [Custom Content Matching](../extensibility/custom-content-matching/).
* `RequestMatcherExtension`: Implement custom request matching logic. See [Custom matching](../extensibility/custom-matching/).
* `GlobalSettingsListener`: Listen for changes to the settings object. See [Listening for Settings Changes](../extensibility/listening-for-settings-changes/).
* `StubLifecycleListener`: Listen for changes to the stub mappings. See [Listening for Stub Changes](../extensibility/listening-for-stub-changes/).
* `TemplateHelperProviderExtension`: Provide custom Handlebars helpers to the template engine. See [Adding Template Helpers](../extensibility/adding-template-helpers/).
Expand All @@ -36,35 +35,18 @@ initialisation or cleanup tasks.

## Registering Extensions

You can directly register the extension programmatically via its class name, class or an instance.
You can directly register the extension programmatically via its class name,
class or an instance:

Server:
```java
new WireMockServer(wireMockConfig()
.extensions("com.mycorp.ClassNameOne", "com.mycorp.ClassNameTwo")
.extensions(ClassOne.class, ClassTwo.class)
.extensions(new InstanceOne(), new InstanceTwo()));
```
.extensions("com.mycorp.BodyContentTransformer", "com.mycorp.HeaderMangler"));

Client:
```java
// Only need to register extensions that change how a mapping is parsed/written (i.e. ContentPatternExtension).
WireMock.create()
.extensions("com.mycorp.ClassNameOne", "com.mycorp.ClassNameTwo")
.extensions(ClassOne.class, ClassTwo.class)
.extensions(new InstanceOne(), new InstanceTwo())
.build();
```
new WireMockServer(wireMockConfig()
.extensions(BodyContentTransformer.class, HeaderMangler.class));

Extension:
```java
@RegisterExtension
static WireMockExtension wm = WireMockExtension.newInstance()
.options(wireMockConfig()
.extensions("com.mycorp.ClassNameOne", "com.mycorp.ClassNameTwo")
.extensions(ClassOne.class, ClassTwo.class)
.extensions(new InstanceOne(), new InstanceTwo()))
.build();
new WireMockServer(wireMockConfig()
.extensions(new BodyContentTransformer(), new HeaderMangler()));
```

See [Running as a Standalone Process](../running-standalone/) for details on running with extensions from the command line.
Expand Down Expand Up @@ -94,42 +76,11 @@ Services currently available to extension factories are:
* `Extensions`: the service for creating and providing extension implementations.
* `TemplateEngine`: the Handlebars template engine.

For factories that register extensions that change how a mapping is parsed/written (i.e. ContentPatternExtension), must implement `ExtensionFactory#createForClient()`
to return those extension.

## Extension registration via service loading

Extensions that are packaged with the relevant [Java service loader framework](https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html) metadata
will be loaded automatically if they are placed on the classpath.

Server:
```java
new WireMockServer(wireMockConfig().extensionScanningEnabled(true));
```

Client:
```java
WireMock.create()
.extensionScanningEnabled(true)
.build();
```

Extension:
```java
@RegisterExtension
static WireMockExtension wm = WireMockExtension.newInstance()
.options(wireMockConfig()
.extensionScanningEnabled(true))
.build();

// or

@WireMockTest(extensionScanningEnabled = true)
public class MyTest {
...
}
```

See [https://github.com/wiremock/wiremock/tree/master/test-extension](https://github.com/wiremock/wiremock/tree/master/test-extension) for an example of such an extension.


Expand Down
150 changes: 0 additions & 150 deletions _docs/extensibility/custom-content-matching.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---
layout: docs
title: Custom Request Matching
title: Custom Matching
meta_title: Adding custom request matchers
description: Adding custom request matchers via extensions
redirect_from:
- "/docs/extensibility/custom-matching/"
---

If WireMock's standard set of request matching strategies isn't
Expand Down

0 comments on commit d10591f

Please sign in to comment.