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);
}
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;
}
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;
}
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);
}
}
}
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);
}
}));
}
Aggregations