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

org.jboss.resteasy.reactive.client.impl.InvocationImpl Maven / Gradle / Ivy

There is a newer version: 3.17.5
Show newest version
package org.jboss.resteasy.reactive.client.impl;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.WebApplicationException;
import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.client.Invocation;
import jakarta.ws.rs.client.InvocationCallback;
import jakarta.ws.rs.core.GenericType;
import jakarta.ws.rs.core.Response;

public class InvocationImpl implements Invocation {

    final AsyncInvokerImpl invoker;
    final String method;
    final Entity entity;

    public InvocationImpl(String method, AsyncInvokerImpl invoker, Entity entity) {
        this.invoker = invoker;
        this.method = method;
        this.entity = entity;
    }

    @Override
    public Invocation property(String name, Object value) {
        invoker.properties.put(name, value);
        return this;
    }

    @Override
    public Response invoke() {
        try {
            return invoker.method(method, entity).get();
        } catch (InterruptedException e) {
            throw new ProcessingException(e);
        } catch (ExecutionException e) {
            if (e.getCause() instanceof ProcessingException) {
                throw (ProcessingException) e.getCause();
            }
            throw new RuntimeException(e.getCause());
        }
    }

    @Override
    public  T invoke(Class responseType) {
        try {
            return invoker.method(method, entity, responseType).get();
        } catch (InterruptedException e) {
            throw new ProcessingException(e);
        } catch (ExecutionException e) {
            if (e.getCause() instanceof ProcessingException) {
                throw (ProcessingException) e.getCause();
            }
            if (e.getCause() instanceof WebApplicationException) {
                throw (WebApplicationException) e.getCause();
            }
            throw new RuntimeException(e.getCause());
        }
    }

    @Override
    public  T invoke(GenericType responseType) {
        try {
            return invoker.method(method, entity, responseType).get();
        } catch (InterruptedException e) {
            throw new ProcessingException(e);
        } catch (ExecutionException e) {
            if (e.getCause() instanceof ProcessingException) {
                throw (ProcessingException) e.getCause();
            }
            if (e.getCause() instanceof WebApplicationException) {
                throw (WebApplicationException) e.getCause();
            }
            throw new RuntimeException(e.getCause());
        }
    }

    @Override
    public Future submit() {
        return invoker.method(method, entity);
    }

    @Override
    public  Future submit(Class responseType) {
        return invoker.method(method, entity, responseType);
    }

    @Override
    public  Future submit(GenericType responseType) {
        return invoker.method(method, entity, responseType);
    }

    @Override
    public  Future submit(InvocationCallback callback) {
        return invoker.method(method, entity, callback);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy