use of org.mule.runtime.extension.api.annotation.execution.OnSuccess in project mule-coap-connector by teslanet-nl.
the class Listener method onSuccess.
@OnSuccess
@MediaType(value = "*/*", strict = false)
public void onSuccess(@Optional @NullSafe @Alias("response") @Placement(tab = "Response", order = 1) ResponseParams response, @Optional @NullSafe @Alias("response-options") @Expression(ExpressionSupport.SUPPORTED) @Summary("The CoAP options to send with the response.") @Placement(tab = "Response", order = 2) ResponseOptions responseOptions, SourceCallbackContext callbackContext) throws InternalInvalidByteArrayValueException, InternalInvalidResponseCodeException, IOException, InvalidETagException, InternalInvalidOptionValueException {
CoAPResponseCode defaultCoapResponseCode = (CoAPResponseCode) callbackContext.getVariable("defaultCoAPResponseCode").get();
Response coapResponse = new Response(AttributeUtils.toResponseCode(response.getResponseCode(), defaultCoapResponseCode));
// TODO give user control
TypedValue<Object> responsePayload = response.getResponsePayload();
coapResponse.getOptions().setContentFormat(MediaTypeMediator.toContentFormat(responsePayload.getDataType().getMediaType()));
if (responseOptions != null) {
MessageUtils.copyOptions(responseOptions, coapResponse.getOptions(), transformationService);
}
// TODO add streaming & blockwise cooperation
try {
coapResponse.setPayload(MessageUtils.toBytes(responsePayload, transformationService));
} catch (Exception e) {
throw new InternalInvalidByteArrayValueException("Cannot convert payload to byte[]", e);
}
((CoapExchange) callbackContext.getVariable("CoapExchange").get()).respond(coapResponse);
}
use of org.mule.runtime.extension.api.annotation.execution.OnSuccess in project mule-http-connector by mulesoft.
the class HttpListener method onSuccess.
// TODO: MULE-10900 figure out a way to have a shared group between callbacks and possibly regular params
@OnSuccess
public void onSuccess(@ParameterGroup(name = RESPONSE, showInDsl = true) HttpListenerSuccessResponseBuilder response, SourceCallbackContext callbackContext, SourceCompletionCallback completionCallback) throws Exception {
HttpResponseContext context = callbackContext.<HttpResponseContext>getVariable(RESPONSE_CONTEXT).orElseThrow(() -> new MuleRuntimeException(createStaticMessage(RESPONSE_CONTEXT_NOT_FOUND)));
responseSender.sendResponse(context, response, completionCallback);
}
Aggregations