All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.restconf.nb.jaxrs.JaxRsRestconfCallback Maven / Gradle / Ivy

There is a newer version: 8.0.3
Show newest version
/*
 * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.restconf.nb.jaxrs;

import static java.util.Objects.requireNonNull;

import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.core.Response;
import org.opendaylight.restconf.common.errors.RestconfCallback;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
import org.opendaylight.restconf.server.api.ServerException;

/**
 * A {@link RestconfCallback} completing an {@link AsyncResponse}.
 *
 * @param  value type
 */
abstract class JaxRsRestconfCallback extends RestconfCallback {
    private final AsyncResponse ar;

    JaxRsRestconfCallback(final AsyncResponse ar) {
        this.ar = requireNonNull(ar);
    }

    @Override
    public final void onSuccess(final V result) {
        final Response response;
        try {
            response = transform(result);
        } catch (ServerException e) {
            onFailure(e.toLegacy());
            return;
        }
        ar.resume(response);
    }

    @Override
    protected final void onFailure(final RestconfDocumentedException failure) {
        ar.resume(failure);
    }

    abstract Response transform(V result) throws ServerException;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy