java.lang.Object
io.cloudevents.spring.http.CloudEventHttpUtils
Miscellaneous utility methods to assist with Cloud Events in the context of Spring Web
frameworks. Primarily intended for the internal use within Spring-based frameworks or
integrations.
- Since:
- 2.0
- Author:
- Dave Syer
-
Method Summary
Modifier and TypeMethodDescriptionstatic io.cloudevents.core.builder.CloudEventBuilderfromHttp(HttpHeaders headers) Helper method for convertingHttpHeadersto aCloudEvent.static HttpHeaderstoHttp(io.cloudevents.CloudEventContext event) Helper method for extractingHttpHeadersfrom aCloudEvent.static io.cloudevents.core.message.MessageReadertoReader(HttpHeaders headers, Supplier<byte[]> body) Create aMessageReaderto convert an HTTP request to aCloudEvent.static io.cloudevents.http.impl.HttpMessageWritertoWriter(HttpHeaders headers, Consumer<byte[]> sendBody) Create anHttpMessageWriterthat can hand off aCloudEventto an HTTP response.
-
Method Details
-
toReader
public static io.cloudevents.core.message.MessageReader toReader(HttpHeaders headers, Supplier<byte[]> body) throws io.cloudevents.rw.CloudEventRWException Create aMessageReaderto convert an HTTP request to aCloudEvent.- Parameters:
headers- the HTTP request headersbody- the HTTP request body as a byte array- Returns:
- a
MessageReaderrepresenting theCloudEvent - Throws:
io.cloudevents.rw.CloudEventRWException- if something goes wrong while resolving theSpecVersionor if the message has unknown encoding
-
toWriter
public static io.cloudevents.http.impl.HttpMessageWriter toWriter(HttpHeaders headers, Consumer<byte[]> sendBody) Create anHttpMessageWriterthat can hand off aCloudEventto an HTTP response. Mainly useful in a blocking (not async) setting because the response body has to be consumed directly.- Parameters:
headers- the response headers (will be mutated)sendBody- a consumer for the response body that puts the bytes on the wire
-
toHttp
public static HttpHeaders toHttp(io.cloudevents.CloudEventContext event) throws io.cloudevents.rw.CloudEventRWException Helper method for extractingHttpHeadersfrom aCloudEvent. Can, for instance, be used in aRequestMappingto return aResponseEntitythat has headers copied from aCloudEvent.- Parameters:
event- the inputCloudEvent- Returns:
- the response headers represented by the event
- Throws:
io.cloudevents.rw.CloudEventRWException- if something goes wrong while writing the context to the http headers
-
fromHttp
public static io.cloudevents.core.builder.CloudEventBuilder fromHttp(HttpHeaders headers) throws io.cloudevents.rw.CloudEventRWException Helper method for convertingHttpHeadersto aCloudEvent. The input headers must represent a valid event in "binary" form, i.e. it must have headersce-id,ce-specversionetc.- Parameters:
headers- the input request headers- Returns:
- a
CloudEventBuilderthat can be used to create a newCloudEvent - Throws:
io.cloudevents.rw.CloudEventRWException- if something goes wrong while reading the context from the http headers
-