Skip to content

HTTP

Browse implementations

How to request a secured service

For all HTTP actions, authentication or secured connexion to a service is configured by setting properties on the target.

  • Basic Authentication:

    • To use a basic authorization header, set properties username and password on the target.
  • SSL:

    • To use an SSL context, set a keystore or truststore one the target.
      Properties keystore, keystorePassword, keyPassword, truststore and truststorePassword could be alternatively used.
  • Proxy, 2 solutions:

    • You can set a system property http.proxyHost or https.proxyHost, the HTTP client will use this as the default route planner.
    • You can set a target property proxy
      • Default port value is 3128.
      • Target property proxy override system property if set
Http target example
{
    "name": "ghibli_movies_http_service",
    "url": "https://my.http.service:443/",
    "properties": {
        "username": "myUsername",
        "user": "myUsername", // (1)
        "userPassword": "myPassword",
        "password": "myPassword", // (2)
        "trustStore": "/home/APP/security/mytruststore.jks",
        "trustStorePassword": "myTrustStorePassword",
        "keyStore": "/home/APP/security/mykeyStore.jks",
        "keyStorePassword": "mykeyStorePassword",
        "keyPassword": "myKeyStoreKeyPassword",
        "proxy": "https://myproxy:3128"
    }
}
  1. username or user to define user for basic authentification
  2. userPassword or password to define password for basic authentification

Get🔗

Required Name Type Default
* target String
* uri String
headers Map<String, String>
timeout Duration (String) "2000 ms"
Name Type
status int
body String
headers HttpHeaders

Example🔗

1
2
3
4
5
6
7
8
HttpGetAction(
    target = "HTTP_TARGET",
    uri = "https://github.com/search?q=chutney",
    headers = mapOf(
      "Content-Type" to "application/json"
    ),
    timeout = "1 sec"
)

Post🔗

Required Name Type Default
* target String
* uri String
body String {}
headers Map<String, String>
timeout Duration (String) "2000 ms"
Name Type
status int
body String
headers HttpHeaders

Example🔗

1
2
3
4
5
6
7
8
HttpPostAction(
    target = "HTTP_TARGET",
    uri = "https://github.com/search?q=chutney",
    body = "some content",
    headers = mapOf(
      "Content-Type" to "application/json"
    ),
)

Put🔗

Required Name Type Default
* target String
* uri String
body String {}
headers Map<String, String>
timeout Duration (String) "2000 ms"
Name Type
status int
body String
headers HttpHeaders

Example🔗

1
2
3
4
5
6
7
8
HttpPutAction(
    target = "HTTP_TARGET",
    uri = "https://github.com/search?q=chutney",
    body = "some content",
    headers = mapOf(
      "Content-Type" to "application/json"
    ),
)

Delete🔗

Required Name Type Default
* target String
* uri String
headers Map<String, String>
timeout Duration (String) "2000 ms"
Name Type
status int
body String
headers HttpHeaders

Example🔗

1
2
3
4
5
6
7
HttpDeleteAction(
    target = "HTTP_TARGET",
    uri = "https://github.com/search?q=chutney",
    headers = mapOf(
      "Content-Type" to "application/json"
    ),
)

Patch🔗

Required Name Type Default
* target String
* uri String
body String {}
headers Map<String, String>
timeout Duration (String) "2000 ms"
Name Type
status int
body String
headers HttpHeaders

Example🔗

1
2
3
4
5
6
7
8
HttpPatchAction(
    target = "HTTP_TARGET",
    uri = "https://github.com/search?q=chutney",
    body = "some content",
    headers = mapOf(
      "Content-Type" to "application/json"
    ),
)

Mocking an HTTP Server🔗

Start🔗

Required Name Type Default
port String "8443"
truststore-path String
truststore-password String
keystore-path String
keystore-password String
Name Type
httpsServer WireMockServer

Example🔗

1
2
3
4
5
6
7
8
HttpsServerStartAction(
    port = "8443",
    trustStorePath = "/tmp/trustore.jks",
    trustStorePassword = "password",
    keyStorePath = "/user/admin/keystore",
    keyStorePassword = "keystorepassword",
    keyPassword = "passwordkey"
)

Note

This action automatically registers a teardown to stop the server at the end of the scenario.

Listened routes🔗

This actions allows you to check which requests have been received by a wiremock server.
Available verbs are : GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD, TRACE, ANY

Warning

If this action succeeds, requests will be removed from the Wiremock server.

Required Name Type Default
* https-server WireMockServer
* uri String (regex)
* verb String
expected-message-count String 1
Name Type
requests List<LoggedRequest>

Example🔗

1
2
3
4
5
6
HttpsListenerAction(
    httpServerVarName = "\${#httpsServer}",
    uri = "https://github.com/search?q=chutney",
    verb = "GET",
    expectedMessageCount = 1,
)