Package io.nitric.faas
Class AbstractResponseContext
- java.lang.Object
-
- io.nitric.faas.AbstractResponseContext
-
- Direct Known Subclasses:
HttpResponseContext
,TopicResponseContext
public abstract class AbstractResponseContext extends Object
Provides an abstract Nitric response context class.
The example below illustrates unwrapping the FaaS trigger and response context objects.
package com.example; import io.nitric.faas.Faas; import io.nitric.faas.Trigger; import io.nitric.faas.NitricFunction; import io.nitric.faas.Response; public class HelloWorld implements NitricFunction { public Response handle(Trigger trigger) { if (trigger.getContext().isHttp()) { var httpContext = trigger.getContext().asHttp(); // Extract HTTP context metadata } else if (trigger.getContext().isTopic()) { var topicContext = trigger.getContext().asTopic(); // Extract Topic context metadata } var = response trigger.buildResponse("Hello World"); if (response.getContext().isHttp()) { // Augment response with additional context var httpContext = response.getContext.asHttp(); ... } else if (response.getContext().isTopic()) { // Augment response with additional context var topicContext = response.getContext.asTopic(); ... } return response; } public static void main(String... args) { Faas.start(new HelloWorld()); } }
- See Also:
HttpResponseContext
,TopicResponseContext
-
-
Constructor Summary
Constructors Constructor Description AbstractResponseContext()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpResponseContext
asHttp()
TopicResponseContext
asTopic()
boolean
isHttp()
boolean
isTopic()
-
-
-
Method Detail
-
isHttp
public boolean isHttp()
- Returns:
- true if this is HttpResponseContext otherwise false
-
isTopic
public boolean isTopic()
- Returns:
- true if this is TopicResponseContext otherwise false
-
asHttp
public HttpResponseContext asHttp()
- Returns:
- this as HttpResponseContext or null if it isHttp() is false
-
asTopic
public TopicResponseContext asTopic()
- Returns:
- this as TopicResponseContext or null if it isTopic() is false
-
-