use of software.amazon.awssdk.crt.eventstream.ServerConnectionContinuationHandler in project aws-iot-device-sdk-java-v2 by aws.
the class TestIpcServiceHandler method getOperationHandler.
@Override
public Function<OperationContinuationHandlerContext, ? extends ServerConnectionContinuationHandler> getOperationHandler(final String operationName) {
final EventStreamRPCServiceModel svcModel = this.serviceModel;
System.out.println("Operation handler retrieved for operation name: " + operationName);
return (context) -> {
final TestOperationContinuationHandler handler = new TestOperationContinuationHandler(context) {
@Override
public OperationModelContext getOperationModelContext() {
return svcModel.getOperationModelContext(operationName);
}
@Override
protected void onStreamClosed() {
streamClosed = true;
}
@Override
public EventStreamJsonMessage handleRequest(EventStreamJsonMessage request) {
System.out.println("Handling request...");
return requestHandler.apply(request);
}
@Override
public void handleStreamEvent(EventStreamJsonMessage streamRequestEvent) {
System.out.println("Handling request stream event...");
}
};
continuationHandlerQueue.offer(new AbstractMap.SimpleImmutableEntry<>(operationName, handler));
return handler;
};
}
use of software.amazon.awssdk.crt.eventstream.ServerConnectionContinuationHandler in project aws-iot-device-sdk-java-v2 by aws.
the class ServiceOperationMappingContinuationHandler method onIncomingStream.
@Override
protected ServerConnectionContinuationHandler onIncomingStream(ServerConnectionContinuation continuation, String operationName) {
final OperationContinuationHandlerContext operationContext = new OperationContinuationHandlerContext(connection, continuation, authenticationData);
final Function<OperationContinuationHandlerContext, ? extends ServerConnectionContinuationHandler> registeredOperationHandlerFn = serviceHandler.getOperationHandler(operationName);
if (registeredOperationHandlerFn != null) {
return registeredOperationHandlerFn.apply(operationContext);
} else {
return new ServerConnectionContinuationHandler(continuation) {
@Override
protected void onContinuationClosed() {
close();
}
@Override
protected void onContinuationMessage(List<Header> headers, byte[] payload, MessageType messageType, int messageFlags) {
int responseMessageFlag = MessageFlags.TerminateStream.getByteValue();
MessageType responseMessageType = MessageType.ApplicationError;
String responsePayload = "{ \"error\": \"Unsupported Operation\", " + "\"message\": \"" + operationName + " is an unsupported operation.\" }";
Header contentTypeHeader = Header.createHeader(":content-type", "application/json");
List<Header> responseHeaders = new ArrayList<>();
responseHeaders.add(contentTypeHeader);
continuation.sendMessage(responseHeaders, responsePayload.getBytes(StandardCharsets.UTF_8), responseMessageType, responseMessageFlag);
}
};
}
}
Aggregations