Search in sources :

Example 6 with MinijaxApplication

use of org.minijax.rs.MinijaxApplication in project minijax by minijax.

the class PersistenceFeature method configure.

@Override
public boolean configure(final FeatureContext context) {
    if (!(context instanceof MinijaxApplication)) {
        throw new IllegalArgumentException("Minijax PersistenceFeature only compatible with MinijaxApplication");
    }
    final MinijaxApplication app = (MinijaxApplication) context;
    registerPersistence(app);
    return true;
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication)

Example 7 with MinijaxApplication

use of org.minijax.rs.MinijaxApplication in project minijax by minijax.

the class Connection method process.

private void process() throws IOException {
    final MinijaxApplication application = minijax.getDefaultApplication();
    try (final MinijaxNioRequestContext ctx = new MinijaxNioRequestContext(application, method, new MinijaxUriInfo(uri), new MinijaxNioHttpHeaders(requestHeaders), requestEntityStream)) {
        response = application.handle(ctx);
        if (onlyHeader) {
            bufferedOutputStream = null;
        } else {
            bufferedOutputStream = new ByteArrayOutputStream();
            EntityUtils.writeEntity(response.getEntity(), response.getMediaType(), ctx.getProviders(), bufferedOutputStream);
        }
    }
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MinijaxUriInfo(org.minijax.rs.MinijaxUriInfo)

Example 8 with MinijaxApplication

use of org.minijax.rs.MinijaxApplication in project minijax by minijax.

the class MinijaxTestInvocationBuilder method method.

@Override
public Response method(final String name) {
    final Minijax container = target.getServer();
    final MinijaxApplication application = container.getApplication(target.getUri());
    final MinijaxUriInfo uriInfo = new MinijaxUriInfo(target.getUri());
    if (!cookies.isEmpty()) {
        headers.add("Cookie", cookies.values().stream().map(c -> c.getName() + "=" + c.getValue()).collect(Collectors.joining("; ")));
    }
    try (final MinijaxRequestContext clientContext = new MinijaxTestRequestContext(application, name, uriInfo);
        final InputStream entityStream = EntityUtils.writeEntity(entity, clientContext.getProviders());
        final MinijaxRequestContext serverContext = new MinijaxTestRequestContext(application, name, new MinijaxUriInfo(target.getUri()), new MinijaxTestHttpHeaders(headers), entityStream)) {
        return application.handle(serverContext);
    } catch (final IOException ex) {
        throw ExceptionUtils.toWebAppException(ex);
    }
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Minijax(org.minijax.Minijax) InputStream(java.io.InputStream) IOException(java.io.IOException) MinijaxUriInfo(org.minijax.rs.MinijaxUriInfo)

Example 9 with MinijaxApplication

use of org.minijax.rs.MinijaxApplication in project minijax by minijax.

the class RequestScopedTest method testRequestScoped.

@Test
void testRequestScoped() throws IOException {
    final Minijax container = new Minijax();
    final MinijaxApplication application = container.getDefaultApplication();
    A a1;
    A a2;
    try (MinijaxRequestContext context = new MinijaxTestRequestContext(application, GET, "/")) {
        a1 = context.getResource(A.class);
        assertNotNull(a1);
        a2 = context.getResource(A.class);
        assertEquals(a1, a2);
        assertSame(a1, a2);
    }
    A a3;
    A a4;
    try (MinijaxRequestContext context = new MinijaxTestRequestContext(application, GET, "/")) {
        a3 = context.getResource(A.class);
        assertNotNull(a3);
        a4 = context.getResource(A.class);
        assertEquals(a3, a4);
        assertSame(a3, a4);
    }
    assertNotEquals(a1, a3);
    assertNotSame(a1, a3);
    container.getInjector().close();
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) Minijax(org.minijax.Minijax) MinijaxTestRequestContext(org.minijax.rs.test.MinijaxTestRequestContext) Test(org.junit.jupiter.api.Test)

Example 10 with MinijaxApplication

use of org.minijax.rs.MinijaxApplication in project minijax by minijax.

the class MinijaxUndertowServer method buildHandler.

private HttpHandler buildHandler() {
    final PathHandler result = Handlers.path();
    final MinijaxApplication application = minijax.getDefaultApplication();
    for (final Class<?> webSocketClass : application.getWebSockets()) {
        final ServerEndpoint serverEndpoint = webSocketClass.getAnnotation(ServerEndpoint.class);
        result.addPrefixPath(serverEndpoint.value(), Handlers.websocket(new MinijaxUndertowWebSocketConnectionCallback(application, webSocketClass)));
    }
    result.addPrefixPath("/", new BlockingHandler(this));
    return result;
}
Also used : MinijaxApplication(org.minijax.rs.MinijaxApplication) MinijaxUndertowWebSocketConnectionCallback(org.minijax.undertow.websocket.MinijaxUndertowWebSocketConnectionCallback) BlockingHandler(io.undertow.server.handlers.BlockingHandler) PathHandler(io.undertow.server.handlers.PathHandler) ServerEndpoint(jakarta.websocket.server.ServerEndpoint)

Aggregations

MinijaxApplication (org.minijax.rs.MinijaxApplication)12 MinijaxRequestContext (org.minijax.rs.MinijaxRequestContext)7 Minijax (org.minijax.Minijax)5 List (java.util.List)4 Test (org.junit.jupiter.api.Test)4 MediaType (jakarta.ws.rs.core.MediaType)3 Response (jakarta.ws.rs.core.Response)3 WebSocketHttpExchange (io.undertow.websockets.spi.WebSocketHttpExchange)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 MinijaxUriInfo (org.minijax.rs.MinijaxUriInfo)2 MinijaxTestRequestContext (org.minijax.rs.test.MinijaxTestRequestContext)2 DefaultMustacheFactory (com.github.mustachejava.DefaultMustacheFactory)1 ByteBuf (io.netty.buffer.ByteBuf)1 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 AsciiString (io.netty.util.AsciiString)1 BlockingHandler (io.undertow.server.handlers.BlockingHandler)1 PathHandler (io.undertow.server.handlers.PathHandler)1 HttpString (io.undertow.util.HttpString)1