Search in sources :

Example 1 with Configuration

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;
}
Also used : Configuration(org.jboss.resteasy.spi.config.Configuration) MimeException(org.apache.james.mime4j.MimeException) MimeIOException(org.apache.james.mime4j.MimeIOException) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException)

Example 2 with Configuration

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;
}
Also used : Configuration(org.jboss.resteasy.spi.config.Configuration)

Example 3 with Configuration

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);
}
Also used : Configuration(org.jboss.resteasy.spi.config.Configuration) NotAllowedException(jakarta.ws.rs.NotAllowedException) NotFoundException(jakarta.ws.rs.NotFoundException) NotAuthorizedException(jakarta.ws.rs.NotAuthorizedException) ServiceUnavailableException(jakarta.ws.rs.ServiceUnavailableException) RedirectionException(jakarta.ws.rs.RedirectionException) ForbiddenException(jakarta.ws.rs.ForbiddenException) NotAcceptableException(jakarta.ws.rs.NotAcceptableException) BadRequestException(jakarta.ws.rs.BadRequestException) InternalServerErrorException(jakarta.ws.rs.InternalServerErrorException) ClientErrorException(jakarta.ws.rs.ClientErrorException) ServerErrorException(jakarta.ws.rs.ServerErrorException) InternalServerErrorException(jakarta.ws.rs.InternalServerErrorException) NotSupportedException(jakarta.ws.rs.NotSupportedException)

Example 4 with Configuration

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"));
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Configuration(org.jboss.resteasy.spi.config.Configuration)

Example 5 with Configuration

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;
}
Also used : Configuration(org.jboss.resteasy.spi.config.Configuration)

Aggregations

Configuration (org.jboss.resteasy.spi.config.Configuration)5 BadRequestException (jakarta.ws.rs.BadRequestException)1 ClientErrorException (jakarta.ws.rs.ClientErrorException)1 ForbiddenException (jakarta.ws.rs.ForbiddenException)1 InternalServerErrorException (jakarta.ws.rs.InternalServerErrorException)1 NotAcceptableException (jakarta.ws.rs.NotAcceptableException)1 NotAllowedException (jakarta.ws.rs.NotAllowedException)1 NotAuthorizedException (jakarta.ws.rs.NotAuthorizedException)1 NotFoundException (jakarta.ws.rs.NotFoundException)1 NotSupportedException (jakarta.ws.rs.NotSupportedException)1 RedirectionException (jakarta.ws.rs.RedirectionException)1 ServerErrorException (jakarta.ws.rs.ServerErrorException)1 ServiceUnavailableException (jakarta.ws.rs.ServiceUnavailableException)1 IOException (java.io.IOException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 MimeException (org.apache.james.mime4j.MimeException)1 MimeIOException (org.apache.james.mime4j.MimeIOException)1