This microservice allows performing HTTP requests and receive HTTP responses. It also can perform basic authentication
Main configuration is done via setting following properties in a custom configuration:
- https - enables HTTPS (
false
by default) - host - host for HTTP requests (e.g.
google.com
) - port - port for HTTP requests (
80
by default or443
ifhttps
=true
) - readTimeout - socket read timeout in ms (
5000
by default) - keepAliveTimeout - socket inactivity timeout in ms (
15000
by default) - validateCertificates - enables/disables server certificate validation (
true
by default) - clientCertificate - path to client X.509 certificate in PEM format (requires
certificatePrivateKey
,null
by default) - certificatePrivateKey - path to client certificate RSA private key (PKCS8 encoded) in PEM format (
null
by default) - defaultHeaders - map of default headers, and their values which will be applied to each request (existing headers are not affected, empty by default)
- sessionAlias - session alias for incoming/outgoing TH2 messages (e.g.
rest_api
) - auth - basic authentication settings (
null
by default)
Basic authentication can be configured via setting following properties in the auth
block of the main configuration
- username - basic authentication username
- password - basic authentication password
https: false
host: someapi.com
port: 334
sessionAlias: api_session
readTimeout: 5000
keepAliveTimeout: 15000
validateCertificates: true
clientCertificate: /path/to/certificate
certificatePrivateKey: /path/to/certificate/private/key
defaultHeaders:
x-api-key: [ 'apikeywashere' ]
auth:
username: coolusername
password: verystrongpassword
- input queue with
subscribe
andsend
attributes for requests - output queue with
publish
andfirst
(for responses) andsecond
(for requests) attributes
This section describes messages received and by produced by the service
This service receives HTTP requests via MQ as MessageGroup
s containing one of:
- a single
RawMessage
containing request body, which can haveuri
,method
, andcontentType
properties in its metadata, which will be used in resulting request - a single
Message
withRequest
message type containing HTTP request line and headers and aRawMessage
described above
If both Message
and RawMessage
contain uri
, method
, and contentType
, values from Message
take precedence.
If none of them contain these values /
and GET
will be used as uri
and method
values respectively
- Request
Field | Type | Description |
---|---|---|
method | String | HTTP method name (e.g. GET, POST, etc.) |
uri | String | Request URI (e.g. /some/request/path?param1=value1¶m2=value2...) |
headers | List<Header> | HTTP headers (e.g. Host, Content-Length, etc.) |
- Header
Field | Type | Description |
---|---|---|
name | String | HTTP header name |
value | String | HTTP header value |
Metadata properties prefixed with header-
(case insensitive) are put in the HTTP request as headers with header-
prefix removed
HTTP requests and responses are sent via MQ as MessageGroup
s containing a single RawMessage
with a raw request or response.
RawMessage
also has uri
, method
, and contentType
metadata properties set equal to URI, method, and content type of request (or a response received for the request). In case of response request metadata properties and parent event id
are copied into response message.
Here's an example of infra-mgr
config required to deploy this service
apiVersion: th2.exactpro.com/v1
kind: Th2Box
metadata:
name: http-client
spec:
image-name: ghcr.io/th2-net/th2-conn-http-client
image-version: 0.8.1
custom-config:
https: false
host: 127.0.0.1
port: 8080
sessionAlias: some_api
readTimeout: 5000
keepAliveTimeout: 15000
validateCertificates: true
clientCertificate: /secret/storage/cert.crt
certificatePrivateKey: /secret/storage/private.key
defaultHeaders:
x-api-key: [ 'apikeywashere' ]
auth:
username: user
password: pwds
type: th2-conn
pins:
- name: to_send
connection-type: mq
attributes:
- subscribe
- send
- group
- name: out_request
connection-type: mq
attributes:
- publish
- second
- raw
- name: out_response
connection-type: mq
attributes:
- publish
- first
- raw
extended-settings:
service:
enabled: false
- Fix problem with exceeding the limit for sockets to acquire when and exception is thrown during that process.
- Vulnerability check pipeline step
- th2-common upgrade to
3.44.0
- th2-bom upgrade to
4.1.0
- Publish
Failed to handle message group
event for each message in group with present parent event id
- Bump
com.exactpro.th2:common
dependency to3.41.1
- Ability to pass headers via message metadata
- Ability to send multiple requests in parallel
- Convert method from incoming message group to uppercase for better compatibility with some servers
- fixed bug with not sending all requests with body
- fixed bug with parent id loss inside client after sending request
- publish "sent" events for outgoing messages (requests)
- support for client-side certificate
- option to disable server certificate validation
- copying of metadata properties from request into response
- fixed bug with 'name: name' headers
- potential endless-loop if
onStart
handler tries to send something
- start/stop API to internal HTTP client
- dependencies
- removal of socket in case of network error
- response message will be with same parent event id as request message batch
- high idle CPU usage
- expired sockets weren't removed from the cache
- use separate sequences for request and response message streams
- don't overwrite
Content-Length
header if it's already present
- invalid error message in case of unexpected incoming message type