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:
- useTransport - use th2 transport or protobuf protocol to publish incoming/outgoing messages (
trueby default) - maxBatchSize - max size of outgoing message batch (
1000by default) - maxFlushTime - max message batch flush time (
1000by default) - sessionAlias - session alias for incoming/outgoing TH2 messages (e.g.
rest_apiornullby default).
This option is required whensessionsoption is missing in main config. - sessions - map session alias to session configuration (empty by default)
The options below can be specified either in the main block or in sessions blocks.
When defined in main, they act as default values for all sessions, or as the parameters for a single session when sessionAlias is specified and sessions is not.
- https - enables HTTPS (
falseby default) - host - host for HTTP requests (e.g.
google.com) - port - port for HTTP requests (
80by default or443ifhttps=true) - readTimeout - socket read timeout in ms (
5000by default) - keepAliveTimeout - socket inactivity timeout in ms (
15000by default) - validateCertificates - enables/disables server certificate validation (
trueby default) - clientCertificate - path to client X.509 certificate in PEM format (requires
certificatePrivateKey,nullby default) - certificatePrivateKey - path to client certificate RSA private key (PKCS8 encoded) in PEM format (
nullby default) - defaultHeaders - map of default headers, and their values which will be applied to each request (existing headers are not affected, empty by default)
- auth - basic authentication settings (
nullby default) - publishSentEvents - enables/disables publish of "message sent" events (
trueby 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- pin with
subscribe,sendandgroupattributes for requests using protobuf - pin with
subscribe,sendandtransport-groupattributes for requests using th2 transport
Note: least one of pins above is required, it's mean that conn can handle messages via one or both protocols at the same time
Required output pins set depends on values of the useTransport option
useTransport option is true
- output queue with
publish,transport-groupattributes for transport group batch with responses and requests
useTransport option is false
- output queue with
publish,rawattributes for transport group batch with responses and requests
This section describes messages received and by produced by the service
This service receives HTTP requests via MQ as transport message groups containing one of:
- a single
raw messagecontaining request body, which can haveuri,method, andcontentTypeproperties in its metadata, which will be used in resulting request - a single parsed message with
Requestmessage type containing HTTP request line and headers and aRawMessagedescribed above
If both parsed and raw messages contain uri, method, and contentType, values from parsed 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 transport message groups containing a single raw message with a raw
request or
response.
raw message 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: 2.2.0-dev
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
useTransport: false
maxBatchSize: 1000
maxFlushTime: 1000
publishSentEvents: true
defaultHeaders:
x-api-key: [ 'apikeywashere' ]
auth:
username: user
password: pwds
type: th2-conn
pins:
- name: to_send_protobuf
connection-type: mq
attributes:
- subscribe
- send
- group
- name: to_send_transport
connection-type: mq
attributes:
- subscribe
- send
- transport-group
- name: out_group_request
connection-type: mq
attributes:
- publish
- raw
extended-settings:
service:
enabled: false- [GH-50] Attached message ids to send event
- provided
publishSentEventsoption.
- provided
- [GH-44] Implemented multi-session feature
- provided
sessionsoption.
- provided
- Updated:
- th2 gradle plugin:
0.3.14(bom:4.14.3) - kotlin:
2.3.0 - kotlin-logging:
7.0.14 - common:
5.17.1-dev
- th2 gradle plugin:
- Produce multi-platform docker image
- migrated to amazoncorretto:11-alpine-jdk docker image as base
- Updated:
- th2 gradle plugin:
0.3.10(bom:4.14.2) - kotlin:
2.2.21
- th2 gradle plugin:
- Updated:
- th2 gradle plugin:
0.3.9(bom:4.14.1) - kotlin:
2.2.10 - kotlin-logging:
7.0.13 - common:
5.16.1-dev - common-utils:
2.4.0-dev - rawhttp-core:
2.6.0
- th2 gradle plugin:
- Update common to
5.14.0-dev - Update common utils to
2.2.3-dev - Migrate to th2 gradle plugin
0.1.1
- Fixed problem - connect reorders sequence numbers when sending messages in parallel mode by one session alias.
- Puts unique
th2-request-idproperty to metadata of request/response messages - Merged
v0.8.1
-
Supports th2 transport protocol
-
Use event / message batcher
- messages are batched by session group
- events are batched by session scope
-
owasp upgrade to
8.2.1 -
th2-common upgrade to
5.3.0
- books and pages support
- owasp plugin check
- kotlin upgrade to
1.6.21 - th2-common upgrade to
5.2.0 - th2-bom upgrade to
4.2.0
- 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
- 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 groupevent for each message in group with present parent event id
- Bump
com.exactpro.th2:commondependency 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
onStarthandler 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-Lengthheader if it's already present
- invalid error message in case of unexpected incoming message type