Search in sources :

Example 11 with ResteasyDeployment

use of org.jboss.resteasy.spi.ResteasyDeployment in project indy by Commonjava.

the class SwaggerGeneratorDeployment method getDeploymentInfo.

public DeploymentInfo getDeploymentInfo(final String contextRoot, Application application) {
    // we have to disable the UI for this to work.
    uiConfiguration.setEnabled(false);
    final ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setApplication(application);
    deployment.setInjectorFactoryClass(CdiInjectorFactoryImpl.class.getName());
    final ServletInfo resteasyServlet = Servlets.servlet("Swagger Generator Servlet", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(2).addMapping("/swagger.json").addMapping("/swagger.yaml");
    final BeanConfig beanConfig = new BeanConfig();
    beanConfig.setResourcePackage("org.commonjava.indy");
    beanConfig.setBasePath("/");
    beanConfig.setLicense("ASLv2");
    beanConfig.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0");
    beanConfig.setScan(true);
    beanConfig.setVersion(versioning.getApiVersion());
    final DeploymentInfo di = new DeploymentInfo().addListener(Servlets.listener(RequestScopeListener.class)).setContextPath(contextRoot).addServletContextAttribute(ResteasyDeployment.class.getName(), deployment).addServlet(resteasyServlet).setDeploymentName("Swagger Generator Deployment").setClassLoader(ClassLoader.getSystemClassLoader());
    logger.info("\n\n\n\nReturning DeploymentInfo for Swagger generator\n\n\n\n");
    return di;
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) BeanConfig(io.swagger.jaxrs.config.BeanConfig) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo) CdiInjectorFactoryImpl(org.commonjava.indy.bind.jaxrs.util.CdiInjectorFactoryImpl)

Example 12 with ResteasyDeployment

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

the class AbstractHTTPServerProtocol method createDeployment.

protected ResteasyDeployment createDeployment(Application application) {
    ResteasyDeployment resteasyDeployment = new ResteasyDeployment();
    resteasyDeployment.setApplication(application);
    List<String> allowedOrigins;
    if (devMode) {
        allowedOrigins = Collections.singletonList("*");
    } else {
        allowedOrigins = agent.getAllowedOrigins().map(Arrays::asList).orElse(null);
    }
    if (allowedOrigins != null) {
        String allowedMethods = Arrays.stream(agent.getAllowedHTTPMethods().orElse(DEFAULT_ALLOWED_METHODS)).map(Enum::name).collect(Collectors.joining(","));
        CorsFilter corsFilter = new CorsFilter();
        corsFilter.getAllowedOrigins().addAll(allowedOrigins);
        corsFilter.setAllowedMethods(allowedMethods);
        resteasyDeployment.getProviders().add(corsFilter);
    }
    return resteasyDeployment;
}
Also used : CorsFilter(org.jboss.resteasy.plugins.interceptors.CorsFilter) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) HttpString(io.undertow.util.HttpString)

Example 13 with ResteasyDeployment

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

the class AbstractHTTPServerProtocol method createDeploymentInfo.

protected DeploymentInfo createDeploymentInfo(ResteasyDeployment resteasyDeployment) {
    String deploymentPath = getDeploymentPath();
    String deploymentName = getDeploymentName();
    boolean enableSecurity = agent.isRoleBasedSecurity().orElse(false);
    if (enableSecurity) {
        if (identityService == null) {
            throw new RuntimeException("Role based security can only be enabled when an identity service is available");
        }
    }
    resteasyDeployment.setSecurityEnabled(enableSecurity);
    ServletInfo resteasyServlet = Servlets.servlet("ResteasyServlet", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/*");
    DeploymentInfo deploymentInfo = new DeploymentInfo().setDeploymentName(deploymentName).setContextPath(deploymentPath).addServletContextAttribute(ResteasyDeployment.class.getName(), resteasyDeployment).addServlet(resteasyServlet).setClassLoader(Container.class.getClassLoader());
    if (enableSecurity) {
        identityService.secureDeployment(deploymentInfo);
    }
    return deploymentInfo;
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Container(org.openremote.model.Container) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) HttpString(io.undertow.util.HttpString) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 14 with ResteasyDeployment

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

the class WebService method createResteasyDeployment.

protected ResteasyDeployment createResteasyDeployment(Container container, Collection<Class<?>> apiClasses, Collection<Object> apiSingletons, boolean secure) {
    if (apiClasses == null && apiSingletons == null)
        return null;
    WebApplication webApplication = new WebApplication(container, apiClasses, apiSingletons);
    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 GZIPEncodingInterceptor(!container.isDevMode()));
    resteasyDeployment.getActualProviderClasses().add(AlreadyGzippedWriterInterceptor.class);
    resteasyDeployment.getActualProviderClasses().add(ClientErrorExceptionHandler.class);
    resteasyDeployment.setSecurityEnabled(secure);
    return resteasyDeployment;
}
Also used : JacksonConfig(org.openremote.container.json.JacksonConfig) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment)

Example 15 with ResteasyDeployment

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

the class WebService method createApiHandler.

protected HttpHandler createApiHandler(IdentityService identityService, ResteasyDeployment resteasyDeployment) {
    if (resteasyDeployment == null)
        return null;
    ServletInfo restServlet = Servlets.servlet("RESTEasy Servlet", HttpServlet30Dispatcher.class).setAsyncSupported(true).setLoadOnStartup(1).addMapping("/*");
    DeploymentInfo deploymentInfo = new DeploymentInfo().setDeploymentName("RESTEasy Deployment").setContextPath(API_PATH).addServletContextAttribute(ResteasyDeployment.class.getName(), resteasyDeployment).addServlet(restServlet).setClassLoader(Container.class.getClassLoader());
    if (identityService != null) {
        resteasyDeployment.setSecurityEnabled(true);
    } else {
        throw new RuntimeException("No identity service deployed, can't enable API security");
    }
    return addServletDeployment(identityService, deploymentInfo, resteasyDeployment.isSecurityEnabled());
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) ResteasyDeployment(org.jboss.resteasy.spi.ResteasyDeployment) Container(org.openremote.container.Container) HttpServlet30Dispatcher(org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

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