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

org.jboss.resteasy.reactive.common.jaxrs.RuntimeDelegateImpl Maven / Gradle / Ivy

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

import java.util.Date;
import java.util.Locale;
import java.util.ServiceLoader;
import java.util.concurrent.CompletionStage;

import jakarta.ws.rs.SeBootstrap;
import jakarta.ws.rs.core.Application;
import jakarta.ws.rs.core.CacheControl;
import jakarta.ws.rs.core.Cookie;
import jakarta.ws.rs.core.EntityPart;
import jakarta.ws.rs.core.EntityTag;
import jakarta.ws.rs.core.Link;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.NewCookie;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriBuilder;
import jakarta.ws.rs.core.Variant;
import jakarta.ws.rs.ext.RuntimeDelegate;

import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.RestResponse.ResponseBuilder;
import org.jboss.resteasy.reactive.common.core.ResponseBuilderFactory;
import org.jboss.resteasy.reactive.common.headers.CacheControlDelegate;
import org.jboss.resteasy.reactive.common.headers.CookieHeaderDelegate;
import org.jboss.resteasy.reactive.common.headers.DateDelegate;
import org.jboss.resteasy.reactive.common.headers.EntityTagDelegate;
import org.jboss.resteasy.reactive.common.headers.LinkDelegate;
import org.jboss.resteasy.reactive.common.headers.LocaleDelegate;
import org.jboss.resteasy.reactive.common.headers.MediaTypeHeaderDelegate;
import org.jboss.resteasy.reactive.common.headers.NewCookieHeaderDelegate;
import org.jboss.resteasy.reactive.common.headers.ObjectToStringDelegate;

public class RuntimeDelegateImpl extends RuntimeDelegate {

    static final ResponseBuilderFactory factory;

    static {
        ResponseBuilderFactory result = new ResponseBuilderFactory() {
            @Override
            public Response.ResponseBuilder create() {
                throw new RuntimeException("Quarkus REST server side components are not installed.");
            }

            @Override
            public int priority() {
                return 0;
            }

            @Override
            public  ResponseBuilder createRestResponse() {
                throw new RuntimeException("Quarkus REST server side components are not installed.");
            }
        };
        ServiceLoader sl = ServiceLoader.load(ResponseBuilderFactory.class,
                RuntimeDelegateImpl.class.getClassLoader());
        for (ResponseBuilderFactory i : sl) {
            if (result.priority() < i.priority()) {
                result = i;
            }
        }
        factory = result;
    }

    @Override
    public UriBuilder createUriBuilder() {
        return new UriBuilderImpl();
    }

    @Override
    public Response.ResponseBuilder createResponseBuilder() {
        return factory.create();
    }

    public  RestResponse.ResponseBuilder createRestResponseBuilder() {
        return factory.createRestResponse();
    }

    @Override
    public Variant.VariantListBuilder createVariantListBuilder() {
        return new VariantListBuilderImpl();
    }

    @Override
    public  T createEndpoint(Application application, Class endpointType)
            throws IllegalArgumentException, UnsupportedOperationException {
        throw new UnsupportedOperationException();
    }

    @Override
    public  HeaderDelegate createHeaderDelegate(Class type) throws IllegalArgumentException {
        if (type == null) {
            throw new IllegalArgumentException("type cannot be null");
        }
        if (type.equals(MediaType.class)) {
            return (HeaderDelegate) MediaTypeHeaderDelegate.INSTANCE;
        } else if (Date.class.isAssignableFrom(type)) {
            // for Date, we do subtypes too, because ORM will instantiate java.util.Date as subtypes
            // and it's extremely likely we get those here, and we still have to generate a valid
            // date representation for them, rather than Object.toString which will be wrong
            return (HeaderDelegate) DateDelegate.INSTANCE;
        } else if (type.equals(CacheControl.class)) {
            return (HeaderDelegate) CacheControlDelegate.INSTANCE;
        } else if (type.equals(NewCookie.class)) {
            return (HeaderDelegate) NewCookieHeaderDelegate.INSTANCE;
        } else if (type.equals(Cookie.class)) {
            return (HeaderDelegate) CookieHeaderDelegate.INSTANCE;
        } else if (type.equals(EntityTag.class)) {
            return (HeaderDelegate) EntityTagDelegate.INSTANCE;
        } else if (type.equals(Locale.class)) {
            return (HeaderDelegate) LocaleDelegate.INSTANCE;
        } else if (type.equals(Link.class)) {
            return (HeaderDelegate) LinkDelegate.INSTANCE;
        } else {
            return (HeaderDelegate) ObjectToStringDelegate.INSTANCE;
        }
    }

    @Override
    public Link.Builder createLinkBuilder() {
        return new LinkBuilderImpl();
    }

    @Override
    public SeBootstrap.Configuration.Builder createConfigurationBuilder() {
        // RR does not implement currently implement the bootstrapping API
        throw new UnsupportedOperationException("Pending implementation");
    }

    @Override
    public CompletionStage bootstrap(Application application,
            SeBootstrap.Configuration configuration) {
        // RR does not implement currently implement the bootstrapping API
        throw new UnsupportedOperationException("Pending implementation");
    }

    @Override
    public CompletionStage bootstrap(Class aClass,
            SeBootstrap.Configuration configuration) {
        // RR does not implement currently implement the bootstrapping API
        throw new UnsupportedOperationException("Pending implementation");
    }

    @Override
    public EntityPart.Builder createEntityPartBuilder(String s) throws IllegalArgumentException {
        // TODO: figure out how to implement this
        throw new UnsupportedOperationException("Pending implementation");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy