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;
}
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);
}
}
}
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);
}
}
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();
}
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;
}
Aggregations