Search in sources :

Example 1 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project openremote by openremote.

the class AbstractHttpServerProtocol method doLinkProtocolConfiguration.

@Override
protected void doLinkProtocolConfiguration(AssetAttribute protocolConfiguration) {
    Application application = createApplication(protocolConfiguration);
    ResteasyDeployment deployment = createDeployment(application, protocolConfiguration);
    DeploymentInfo deploymentInfo = createDeploymentInfo(deployment, protocolConfiguration);
    configureDeploymentInfo(deploymentInfo);
    deploy(deploymentInfo, protocolConfiguration);
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Application(javax.ws.rs.core.Application)

Example 2 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project openremote by openremote.

the class AbstractHttpServerProtocol method createDeployment.

protected ResteasyDeployment createDeployment(Application application, AssetAttribute protocolConfiguration) {
    ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
    resteasyDeployment.setApplication(application);
    List<String> allowedOrigins;
    if (devMode) {
        allowedOrigins = Collections.singletonList("*");
    } else {
        Optional<MetaItem> allowedOriginsMeta = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_ORIGINS);
        allowedOrigins = allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsString).map(Collections::singletonList).orElseGet(() -> allowedOriginsMeta.flatMap(AbstractValueHolder::getValueAsArray).flatMap(arrayValue -> Values.getArrayElements(arrayValue, StringValue.class, true, false, StringValue::getString)).orElse(null));
    }
    if (allowedOrigins != null) {
        String allowedMethods = protocolConfiguration.getMetaItem(META_PROTOCOL_ALLOWED_METHODS).flatMap(AbstractValueHolder::getValueAsString).orElse(DEFAULT_ALLOWED_METHODS);
        if (TextUtil.isNullOrEmpty(allowedMethods)) {
            throw new IllegalArgumentException("Allowed methods meta item must be a non empty string: " + META_PROTOCOL_ALLOWED_METHODS);
        }
        CorsFilter corsFilter = new CorsFilter();
        corsFilter.getAllowedOrigins().addAll(allowedOrigins);
        corsFilter.setAllowedMethods(allowedMethods);
        resteasyDeployment.getProviders().add(corsFilter);
    }
    return resteasyDeployment;
}
Also used : java.util(java.util) ServletException(javax.servlet.ServletException) ProtocolConfiguration(org.openremote.model.asset.agent.ProtocolConfiguration) AttributeRef(org.openremote.model.attribute.AttributeRef) ArrayValue(org.openremote.model.value.ArrayValue) Application(javax.ws.rs.core.Application) ServletInfo(io.undertow.servlet.api.ServletInfo) HttpMethod(javax.ws.rs.HttpMethod) Level(java.util.logging.Level) Servlets(io.undertow.servlet.Servlets) Container(org.openremote.container.Container) Lists(com.google.common.collect.Lists) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) TextUtil(org.openremote.model.util.TextUtil) PROTOCOL_NAMESPACE(org.openremote.model.Constants.PROTOCOL_NAMESPACE) AbstractValueHolder(org.openremote.model.AbstractValueHolder) StringValue(org.openremote.model.value.StringValue) org.openremote.container.web(org.openremote.container.web) Pair(org.openremote.model.util.Pair) ModelValueMessageBodyConverter(org.openremote.container.json.ModelValueMessageBodyConverter) Logger(java.util.logging.Logger) DeploymentManager(io.undertow.servlet.api.DeploymentManager) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) AbstractProtocol(org.openremote.agent.protocol.AbstractProtocol) HttpHandler(io.undertow.server.HttpHandler) MetaItem(org.openremote.model.attribute.MetaItem) IdentityService(org.openremote.container.security.IdentityService) CorsFilter(org.jboss.resteasy.plugins.interceptors.CorsFilter) RoleBasedSecurityFeature(org.jboss.resteasy.plugins.interceptors.RoleBasedSecurityFeature) JacksonConfig(org.openremote.container.json.JacksonConfig) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) Values(org.openremote.model.value.Values) Pattern(java.util.regex.Pattern) ValueHolder(org.openremote.model.ValueHolder) AssetAttribute(org.openremote.model.asset.AssetAttribute) CorsFilter(org.jboss.resteasy.plugins.interceptors.CorsFilter) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) MetaItem(org.openremote.model.attribute.MetaItem) AbstractValueHolder(org.openremote.model.AbstractValueHolder) StringValue(org.openremote.model.value.StringValue)

Example 3 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project openremote by openremote.

the class WebService method createResteasyDeployment.

protected ResteasyDeployment createResteasyDeployment(Container container) {
    if (getApiClasses() == null && getApiSingletons() == null)
        return null;
    WebApplication webApplication = new WebApplication(container, getApiClasses(), getApiSingletons());
    ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
    resteasyDeployment.setApplication(webApplication);
    // Custom providers (these only apply to server applications, not client calls)
    resteasyDeployment.getProviders().add(new WebServiceExceptions.DefaultResteasyExceptionMapper(devMode));
    resteasyDeployment.getProviders().add(new WebServiceExceptions.ForbiddenResteasyExceptionMapper(devMode));
    resteasyDeployment.getProviders().add(new JacksonConfig());
    resteasyDeployment.getProviders().add(new CORSFilter());
    resteasyDeployment.getProviders().add(new GZIPEncodingInterceptor(!container.isDevMode()));
    resteasyDeployment.getActualProviderClasses().add(ModelValueMessageBodyConverter.class);
    resteasyDeployment.getActualProviderClasses().add(AlreadyGzippedWriterInterceptor.class);
    resteasyDeployment.getActualProviderClasses().add(ClientErrorExceptionHandler.class);
    return resteasyDeployment;
}
Also used : JacksonConfig(org.openremote.container.json.JacksonConfig) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) CORSFilter(org.openremote.container.security.CORSFilter)

Example 4 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project openremote by openremote.

the class JSAPIServlet method scanResources.

@SuppressWarnings("unchecked")
public void scanResources() throws Exception {
    ServletConfig config = getServletConfig();
    ServletContext servletContext = config.getServletContext();
    Map<String, ResteasyDeployment> deployments = (Map<String, ResteasyDeployment>) servletContext.getAttribute(ResteasyContextParameters.RESTEASY_DEPLOYMENTS);
    if (deployments == null)
        return;
    synchronized (this) {
        services = new HashMap<String, ServiceRegistry>();
        for (Map.Entry<String, ResteasyDeployment> entry : deployments.entrySet()) {
            ResourceMethodRegistry registry = (ResourceMethodRegistry) entry.getValue().getRegistry();
            ResteasyProviderFactory providerFactory = entry.getValue().getProviderFactory();
            ServiceRegistry service = new ServiceRegistry(null, registry, providerFactory, null);
            services.put(entry.getKey(), service);
        }
    }
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) ResourceMethodRegistry(org.jboss.resteasy.core.ResourceMethodRegistry) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project keycloak by keycloak.

the class KeycloakProcessor method configureResteasy.

@BuildStep
void configureResteasy(BuildProducer<ResteasyDeploymentCustomizerBuildItem> deploymentCustomizerProducer) {
    deploymentCustomizerProducer.produce(new ResteasyDeploymentCustomizerBuildItem(new Consumer<ResteasyDeployment>() {

        @Override
        public void accept(ResteasyDeployment resteasyDeployment) {
            // we need to explicitly set the application to avoid errors at build time due to the application
            // from keycloak-services also being added to the index
            resteasyDeployment.setApplicationClass(QuarkusKeycloakApplication.class.getName());
            // we need to disable the sanitizer to avoid escaping text/html responses from the server
            resteasyDeployment.setProperty(ResteasyContextParameters.RESTEASY_DISABLE_HTML_SANITIZER, Boolean.TRUE);
        }
    }));
}
Also used : ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Consumer(java.util.function.Consumer) QuarkusKeycloakApplication(org.keycloak.quarkus.runtime.integration.jaxrs.QuarkusKeycloakApplication) ResteasyDeploymentCustomizerBuildItem(io.quarkus.resteasy.server.common.deployment.ResteasyDeploymentCustomizerBuildItem) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

ResteasyDeployment (org.jboss.resteasy.spi.ResteasyDeployment)24 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)15 ServletInfo (io.undertow.servlet.api.ServletInfo)10 HttpServlet30Dispatcher (org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher)7 HttpString (io.undertow.util.HttpString)4 Application (javax.ws.rs.core.Application)4 FilterInfo (io.undertow.servlet.api.FilterInfo)3 IOException (java.io.IOException)3 Container (org.openremote.container.Container)3 JacksonConfig (org.openremote.container.json.JacksonConfig)3 HttpHandler (io.undertow.server.HttpHandler)2 PathHandler (io.undertow.server.handlers.PathHandler)2 Servlets (io.undertow.servlet.Servlets)2 DefaultServletConfig (io.undertow.servlet.api.DefaultServletConfig)2 DeploymentManager (io.undertow.servlet.api.DeploymentManager)2 InstanceHandle (io.undertow.servlet.api.InstanceHandle)2 File (java.io.File)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Filter (javax.servlet.Filter)2