use of org.jboss.resteasy.spi.config.Configuration in project resteasy by resteasy.
the class Mime4JWorkaround method getMemThreshold.
static int getMemThreshold() {
try {
Configuration cfg = ConfigurationFactory.getInstance().getConfiguration();
int threshold = Integer.parseInt(cfg.getOptionalValue(MEM_THRESHOLD_PROPERTY, String.class).orElse(Integer.toString(DEFAULT_MEM_THRESHOLD)));
if (threshold > -1) {
return threshold;
}
LogMessages.LOGGER.debugf("Negative threshold, %s, specified. Using default value", threshold);
} catch (Exception e) {
LogMessages.LOGGER.debug("Exception caught parsing memory threshold. Using default value.", e);
}
return DEFAULT_MEM_THRESHOLD;
}
use of org.jboss.resteasy.spi.config.Configuration in project resteasy by resteasy.
the class PortProvider method getPort.
/**
* /**
* Look up the configured port number, first checking an environment variable (RESTEASY_PORT),
* then a system property (org.jboss.resteasy.port), and finally the default port (8081).
*
* @return the port number specified in either the environment or system properties
*/
public static int getPort() {
final Configuration configuration = ConfigurationFactory.getInstance().getConfiguration();
int port = -1;
String property = configuration.getOptionalValue(ENV_VAR_NAME, String.class).orElse(null);
if (property != null) {
try {
port = Integer.parseInt(property);
} catch (NumberFormatException e) {
}
}
if (port == -1) {
property = configuration.getOptionalValue(PROPERTY_NAME, String.class).orElse(null);
if (property != null) {
try {
port = Integer.parseInt(property);
} catch (NumberFormatException e) {
}
}
}
if (port == -1) {
port = DEFAULT_PORT;
}
return port;
}
use of org.jboss.resteasy.spi.config.Configuration in project resteasy by resteasy.
the class WebApplicationExceptionWrapper method wrap.
/**
* If the {@code resteasy.original.webapplicationexception.behavior} is set to {@code true} or the request is
* determined to not be a server side request, then the {@link WebApplicationException} passed in will be returned.
* If the property is not set to {@code true} and this is a server side request then the exception is wrapped and
* the response is {@linkplain #sanitize(Response) sanitized}.
*
* @param e the exception to possibly wrapped
*
* @return the wrapped exception or the original exception if the exception has already been wrapped the the
* wrapping feature is turned off
*/
static WebApplicationException wrap(final WebApplicationException e) {
final Configuration config = ConfigurationFactory.getInstance().getConfiguration();
final boolean originalBehavior = config.getOptionalValue("resteasy.original.webapplicationexception.behavior", boolean.class).orElse(false);
final boolean serverSide = ResteasyDeployment.onServer();
if (originalBehavior || !serverSide) {
return e;
}
if (e instanceof WebApplicationExceptionWrapper) {
return e;
}
if (e instanceof BadRequestException) {
return new ResteasyBadRequestException((BadRequestException) e);
}
if (e instanceof NotAuthorizedException) {
return new ResteasyNotAuthorizedException((NotAuthorizedException) e);
}
if (e instanceof ForbiddenException) {
return new ResteasyForbiddenException((ForbiddenException) e);
}
if (e instanceof NotFoundException) {
return new ResteasyNotFoundException((NotFoundException) e);
}
if (e instanceof NotAllowedException) {
return new ResteasyNotAllowedException((NotAllowedException) e);
}
if (e instanceof NotAcceptableException) {
return new ResteasyNotAcceptableException((NotAcceptableException) e);
}
if (e instanceof NotSupportedException) {
return new ResteasyNotSupportedException((NotSupportedException) e);
}
if (e instanceof InternalServerErrorException) {
return new ResteasyInternalServerErrorException((InternalServerErrorException) e);
}
if (e instanceof ServiceUnavailableException) {
return new ResteasyServiceUnavailableException((ServiceUnavailableException) e);
}
if (e instanceof ClientErrorException) {
return new ResteasyClientErrorException((ClientErrorException) e);
}
if (e instanceof ServerErrorException) {
return new ResteasyServerErrorException((ServerErrorException) e);
}
if (e instanceof RedirectionException) {
return new ResteasyRedirectionException((RedirectionException) e);
}
return new ResteasyWebApplicationException(e);
}
use of org.jboss.resteasy.spi.config.Configuration in project resteasy by resteasy.
the class ContextualExecutors method scheduledThreadPool.
/**
* Creates a new {@link ContextualScheduledExecutorService} or wraps the default {@code ManagedScheduledExecutorService}
* in a Jakarta EE environment.
* <p>
* If executed in a Jakarta EE container which includes a default {@code ManagedScheduledExecutorService}, that executor
* is wrapped an said to be managed. If the default executor service cannot be found or if not being executed in a
* Jakarta EE container a new {@linkplain Executors#newScheduledThreadPool(int) scheduled thread pool} will be
* wrapped. The size of the thread pool is retrieved via the {@code resteasy.async.timeout.scheduler.min.pool.size}
* context parameter. If not found {@code 1} is the default. The thread pool size is ignored in Jakarta EE
* environments.
* </p>
* <p>
* In a Jakarta EE container the JNDI lookup name can be overridden with the
* {@code resteasy.async.scheduled.executor.service.jndi} configuration property. By default the JNDI lookup name is
* {@code java:comp/DefaultManagedScheduledExecutorService}.
* </p>
*
* @return a new contextual executor
*/
public static ContextualScheduledExecutorService scheduledThreadPool() {
final Configuration config = ConfigurationFactory.getInstance().getConfiguration();
final int poolSize = config.getOptionalValue("resteasy.async.timeout.scheduler.min.pool.size", Integer.class).orElse(1);
return scheduledThreadPool(poolSize, new ContextualThreadFactory("contextual-scheduled-pool"));
}
use of org.jboss.resteasy.spi.config.Configuration in project resteasy by resteasy.
the class PortProvider method getHost.
/**
* Look up the configured hostname, first checking an environment variable (RESTEASY_HOST),
* then a system property (org.jboss.resteasy.host), and finally the default hostname (localhost).
*
* @return the host specified in either the environment or system properties
*/
public static String getHost() {
final Configuration configuration = ConfigurationFactory.getInstance().getConfiguration();
String host = null;
String property = configuration.getOptionalValue(ENV_VAR_HOSTNAME, String.class).orElse(null);
if (property != null) {
host = property;
}
if (host == null) {
property = configuration.getOptionalValue(PROPERTY_HOSTNAME, String.class).orElse(null);
if (property != null) {
host = property;
}
}
if (host == null) {
host = DEFAULT_HOST;
}
return host;
}
Aggregations