public class CloudEventHttpUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static CloudEventBuilder |
fromHttp(org.springframework.http.HttpHeaders headers)
Helper method for converting
HttpHeaders to a CloudEvent. |
static org.springframework.http.HttpHeaders |
toHttp(io.cloudevents.CloudEventContext event)
Helper method for extracting
HttpHeaders from a CloudEvent. |
static MessageReader |
toReader(org.springframework.http.HttpHeaders headers,
Supplier<byte[]> body)
Create a
MessageReader to convert an HTTP request to a CloudEvent. |
static HttpMessageWriter |
toWriter(org.springframework.http.HttpHeaders headers,
Consumer<byte[]> sendBody)
Create an
HttpMessageWriter that can hand off a CloudEvent to an
HTTP response. |
public static MessageReader toReader(org.springframework.http.HttpHeaders headers, Supplier<byte[]> body) throws io.cloudevents.rw.CloudEventRWException
MessageReader to convert an HTTP request to a CloudEvent.headers - the HTTP request headersbody - the HTTP request body as a byte arrayMessageReader representing the CloudEventio.cloudevents.rw.CloudEventRWException - if something goes wrong while resolving the SpecVersion or if the message has unknown encodingpublic static HttpMessageWriter toWriter(org.springframework.http.HttpHeaders headers, Consumer<byte[]> sendBody)
HttpMessageWriter that can hand off a CloudEvent to an
HTTP response. Mainly useful in a blocking (not async) setting because the response
body has to be consumed directly.headers - the response headers (will be mutated)sendBody - a consumer for the response body that puts the bytes on the wirepublic static org.springframework.http.HttpHeaders toHttp(io.cloudevents.CloudEventContext event)
throws io.cloudevents.rw.CloudEventRWException
HttpHeaders from a CloudEvent. Can,
for instance, be used in a RequestMapping to return a
ResponseEntity that has headers copied from a CloudEvent.event - the input CloudEventio.cloudevents.rw.CloudEventRWException - if something goes wrong while writing the context to the http headerspublic static CloudEventBuilder fromHttp(org.springframework.http.HttpHeaders headers) throws io.cloudevents.rw.CloudEventRWException
HttpHeaders to a CloudEvent. The input
headers must represent a valid event in "binary" form, i.e. it must have headers
ce-id, ce-specversion etc.headers - the input request headersCloudEventBuilder that can be used to create a new CloudEventio.cloudevents.rw.CloudEventRWException - if something goes wrong while reading the context from the http headersCopyright © 2024. All rights reserved.