org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer Java Examples

The following examples show how to use org.jboss.resteasy.plugins.server.undertow.UndertowJaxrsServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestEasyUndertowServletRule.java    From jax-rs-pac4j with Apache License 2.0 6 votes vote down vote up
@Override
protected void before() throws Throwable {
    // Used by Jersey Client to store cookies
    CookieHandler.setDefault(new CookieManager());

    // we don't need a resteasy client, and the jersey one works better with redirect
    client = new JerseyClientBuilder().build();

    // TODO use an autogenerated port...
    System.setProperty("org.jboss.resteasy.port", "24257");
    server = new UndertowJaxrsServer().start();

    ResteasyDeployment deployment = new ResteasyDeployment();
    deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
    deployment.setApplication(new MyApp());
    DeploymentInfo di = server.undertowDeployment(deployment)
            .setContextPath("/")
            .setDeploymentName("DI")
            .setClassLoader(getClass().getClassLoader())
            .addListeners(Servlets.listener(Listener.class));
    server.deploy(di);
}
 
Example #2
Source File: Demo.java    From resteasy-examples with Apache License 2.0 6 votes vote down vote up
public static UndertowJaxrsServer buildServer() {
    UndertowJaxrsServer server;
    System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
    try {
        LogManager.getLogManager().readConfiguration(Main.class.getClassLoader().getResourceAsStream("logging.jboss.properties"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    server = new UndertowJaxrsServer().start();

    ResteasyDeployment deployment = new ResteasyDeploymentImpl();

    deployment.setApplicationClass(TracingApp.class.getName());

    DeploymentInfo di = server.undertowDeployment(deployment);
    di.setClassLoader(TracingApp.class.getClassLoader());
    di.setContextPath("");
    di.setDeploymentName("Resteasy");
    di.getServlets().get("ResteasyServlet").addInitParam(ResteasyContextParameters.RESTEASY_TRACING_TYPE, ResteasyContextParameters.RESTEASY_TRACING_TYPE_ALL)
            .addInitParam(ResteasyContextParameters.RESTEASY_TRACING_THRESHOLD, ResteasyContextParameters.RESTEASY_TRACING_LEVEL_VERBOSE);
    server.deploy(di);
    return server;
}
 
Example #3
Source File: Main.java    From Jax-RS-Performance-Comparison with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
        String host = "0.0.0.0";
        int port = 8080;
        if (args.length > 0) {
            host = args[0];
        }
        if (args.length > 1) {
            port = Integer.parseInt(args[1]);
        }

        Undertow.Builder builder = Undertow.builder().addHttpListener(port, host);
        server = new UndertowJaxrsServer().start(builder);
        server.deploy(MyApplication.class, "/");

//        DeploymentInfo di = server.undertowDeployment(MyApplication.class);
//        di.setContextPath("/rest");
//        di.setDeploymentName("rest");
//        server.deploy(di);

    }
 
Example #4
Source File: KeycloakOnUndertow.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public KeycloakUndertowJaxrsServer start(Undertow.Builder builder) {
    try {
        // Need to wrap the original handler with ProxyPeerAddressHandler. Thanks to that, if undertow is behind proxy and the proxy
        // forwards "https" request to undertow as "http" request, undertow will be able to establish protocol correctly on the request
        // based on the X-Proto headers
        Field f = UndertowJaxrsServer.class.getDeclaredField("root");
        f.setAccessible(true);
        HttpHandler origRootHandler = (HttpHandler) f.get(this);

        HttpHandler wrappedHandler = new ProxyPeerAddressHandler(origRootHandler);

        server = builder.setHandler(wrappedHandler).build();
        server.start();
        return this;
    } catch (NoSuchFieldException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example #5
Source File: KeycloakOnUndertow.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
    if (isRemoteMode()) {
        log.infof("Skipped undeployment of '%s' as we are in remote mode!", archive.getName());
        return;
    }

    Field containerField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "container");
    Reflections.setAccessible(containerField);
    ServletContainer container = (ServletContainer) Reflections.getFieldValue(containerField, undertow);

    DeploymentManager deploymentMgr = container.getDeployment(archive.getName());
    if (deploymentMgr != null) {
        DeploymentInfo deployment = deploymentMgr.getDeployment().getDeploymentInfo();

        try {
            deploymentMgr.stop();
        } catch (ServletException se) {
            throw new DeploymentException(se.getMessage(), se);
        }

        deploymentMgr.undeploy();

        Field rootField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "root");
        Reflections.setAccessible(rootField);
        PathHandler root = (PathHandler) Reflections.getFieldValue(rootField, undertow);

        String path = deployedArchivesToContextPath.get(archive.getName());
        root.removePrefixPath(path);

        container.removeDeployment(deployment);
    } else {
        log.warnf("Deployment '%s' not found", archive.getName());
    }
}
 
Example #6
Source File: UndertowAppServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void undeploy(Archive<?> archive) throws DeploymentException {
    log.info("Undeploying archive " + archive.getName());
    Field containerField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "container");
    Reflections.setAccessible(containerField);
    ServletContainer container = (ServletContainer) Reflections.getFieldValue(containerField, undertow);

    DeploymentManager deploymentMgr = container.getDeployment(archive.getName());
    if (deploymentMgr != null) {
        DeploymentInfo deployment = deploymentMgr.getDeployment().getDeploymentInfo();

        try {
            deploymentMgr.stop();
        } catch (ServletException se) {
            throw new DeploymentException(se.getMessage(), se);
        }

        deploymentMgr.undeploy();

        Field rootField = Reflections.findDeclaredField(UndertowJaxrsServer.class, "root");
        Reflections.setAccessible(rootField);
        PathHandler root = (PathHandler) Reflections.getFieldValue(rootField, undertow);

        String path = deployedArchivesToContextPath.get(archive.getName());
        root.removePrefixPath(path);

        container.removeDeployment(deployment);
    } else {
        log.warnf("Deployment '%s' not found", archive.getName());
    }
}
 
Example #7
Source File: TemplateContextTest.java    From cryptotrader with GNU Affero General Public License v3.0 4 votes vote down vote up
@Test
public void testRequest() throws IOException {

    UndertowJaxrsServer server = new UndertowJaxrsServer().start();

    try {

        String url = "http://localhost:" + TestPortProvider.getPort();

        server.deploy(TestApplication.class);

        assertEquals(target.request(url + "/foo"), "{foo:bar}");

        try {
            target.request(url + "/bar");
            fail();
        } catch (IOException e) {
            // Success
        }

    } finally {
        server.stop();
    }

}
 
Example #8
Source File: KeycloakServer.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public UndertowJaxrsServer getServer() {
    return server;
}