use of org.minijax.rs.MinijaxRequestContext 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.MinijaxRequestContext 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.MinijaxRequestContext in project minijax by minijax.
the class EntityProvider method get.
@SuppressWarnings("unchecked")
@Override
public T get(final Object obj) {
final MinijaxRequestContext context = (MinijaxRequestContext) obj;
// If you call getInputStream -- even if you don't read from it -- the input stream is moved.
if (entityClass == MultivaluedMap.class) {
return (T) context.getForm().asForm().asMap();
}
final InputStream entityStream = context.getEntityStream();
try {
return EntityUtils.readEntity(entityClass, genericType, annotations, mediaType, context, entityStream);
} catch (final IOException ex) {
throw new InjectionException(ex.getMessage(), ex);
}
}
use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.
the class AbstractParamProvider method get.
@Override
public T get(final Object obj) {
final MinijaxRequestContext context = (MinijaxRequestContext) obj;
String value = getStringValue(context);
if (value == null && defaultValue != null) {
value = defaultValue.value();
}
return context.convertParamToType(value, type, annotations);
}
use of org.minijax.rs.MinijaxRequestContext in project minijax by minijax.
the class AdapterTest method testOnOpen.
@Test
void testOnOpen() throws IOException {
try (final MinijaxRequestContext ctx = createRequestContext()) {
final MinijaxUndertowWebSocketAdapter adapter = new MinijaxUndertowWebSocketAdapter(ctx, TestSocket1.class);
adapter.onOpen(emptyMap());
adapter.onMessage(emptyMap());
adapter.onClose(emptyMap());
adapter.onError(emptyMap());
}
}
Aggregations