use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfDocumentedExceptionMapperTest method testToJsonResponseWithMultipleErrors.
@Test
// FIXME : find why it return "error-type" RPC no expected APPLICATION
@Ignore
public void testToJsonResponseWithMultipleErrors() throws Exception {
final List<RestconfError> errorList = Arrays.asList(new RestconfError(ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, "mock error1"), new RestconfError(ErrorType.RPC, ErrorTag.ROLLBACK_FAILED, "mock error2"));
stageMockEx(new RestconfDocumentedException("mock", null, errorList));
final Response resp = target("/operational/foo").request(MediaType.APPLICATION_JSON).get();
final InputStream stream = verifyResponse(resp, MediaType.APPLICATION_JSON, Status.CONFLICT);
final JsonArray arrayElement = parseJsonErrorArrayElement(stream);
assertEquals("\"error\" Json array element length", 2, arrayElement.size());
verifyJsonErrorNode(arrayElement.get(0), ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, "mock error1", null, null);
verifyJsonErrorNode(arrayElement.get(1), ErrorType.RPC, ErrorTag.ROLLBACK_FAILED, "mock error2", null, null);
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfDocumentedExceptionMapperTest method testToXMLResponseWithExceptionCause.
@Test
public void testToXMLResponseWithExceptionCause() throws Exception {
final Exception cause = new Exception("mock exception cause");
testXMLResponse(new RestconfDocumentedException("mock error", cause), Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, new SimpleErrorInfoVerifier(cause.getMessage()));
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfDataServiceImpl method invokeAction.
/**
* Invoke Action operation.
*
* @param payload {@link NormalizedNodePayload} - the body of the operation
* @return {@link NormalizedNodePayload} wrapped in {@link Response}
*/
public Response invokeAction(final NormalizedNodePayload payload) {
final InstanceIdentifierContext<?> context = payload.getInstanceIdentifierContext();
final DOMMountPoint mountPoint = context.getMountPoint();
final YangInstanceIdentifier yangIIdContext = context.getInstanceIdentifier();
final NormalizedNode data = payload.getData();
if (yangIIdContext.isEmpty() && !NETCONF_BASE_QNAME.equals(data.getIdentifier().getNodeType())) {
throw new RestconfDocumentedException("Instance identifier need to contain at least one path argument", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
final List<QName> qNames = yangIIdContext.getPathArguments().stream().filter(arg -> !(arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates)).filter(arg -> !(arg instanceof YangInstanceIdentifier.AugmentationIdentifier)).map(PathArgument::getNodeType).collect(Collectors.toList());
qNames.add(context.getSchemaNode().getQName());
final Absolute schemaPath = Absolute.of(qNames);
final DOMActionResult response;
final EffectiveModelContext schemaContextRef;
if (mountPoint != null) {
response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, mountPoint);
schemaContextRef = modelContext(mountPoint);
} else {
response = invokeAction((ContainerNode) data, schemaPath, yangIIdContext, actionService);
schemaContextRef = schemaContextHandler.get();
}
final DOMActionResult result = checkActionResponse(response);
ActionDefinition resultNodeSchema = null;
ContainerNode resultData = null;
if (result != null) {
final Optional<ContainerNode> optOutput = result.getOutput();
if (optOutput.isPresent()) {
resultData = optOutput.get();
resultNodeSchema = (ActionDefinition) context.getSchemaNode();
}
}
if (resultData != null && resultData.isEmpty()) {
return Response.status(Status.NO_CONTENT).build();
}
return Response.status(Status.OK).entity(NormalizedNodePayload.ofNullable(new InstanceIdentifierContext<>(yangIIdContext, resultNodeSchema, mountPoint, schemaContextRef), resultData)).build();
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfDataServiceImpl method createAllYangNotificationStreams.
private void createAllYangNotificationStreams(final EffectiveModelContext schemaContext, final UriInfo uriInfo) {
final DOMDataTreeWriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
for (final NotificationDefinition notificationDefinition : schemaContext.getNotifications()) {
writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext, NotificationOutputType.XML));
writeNotificationStreamToDatastore(schemaContext, uriInfo, transaction, CreateStreamUtil.createYangNotifiStream(notificationDefinition, schemaContext, NotificationOutputType.JSON));
}
try {
transaction.commit().get();
} catch (final InterruptedException | ExecutionException e) {
throw new RestconfDocumentedException("Problem while putting data to DS.", e);
}
}
use of org.opendaylight.restconf.common.errors.RestconfDocumentedException in project netconf by opendaylight.
the class RestconfDataStreamServiceImpl method getSSE.
@Override
public void getSSE(final String identifier, final UriInfo uriInfo, final SseEventSink sink, final Sse sse) {
final String streamName = ListenersBroker.createStreamNameFromUri(identifier);
final BaseListenerInterface listener = listenersBroker.getListenerFor(streamName).orElseThrow(() -> {
LOG.debug("Listener for stream with name {} was not found.", streamName);
throw new RestconfDocumentedException("Data missing", ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
});
LOG.debug("Listener for stream with name {} has been found, SSE session handler will be created.", streamName);
// FIXME: invert control here: we should call 'listener.addSession()', which in turn should call
// handler.init()/handler.close()
final SSESessionHandler handler = new SSESessionHandler(executorService, sink, sse, listener, maximumFragmentLength, heartbeatInterval);
handler.init();
}
Aggregations