use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class QueryParamProvider method get.
@Override
public T get() {
final MinijaxRequestContext context = MinijaxRequestContext.getThreadLocal();
String value = context.getUriInfo().getQueryParameters().getFirst(key.getName());
if (value == null && key.getDefaultValue() != null) {
value = key.getDefaultValue().value();
}
return context.getApplication().convertParamToType(value, key.getType(), key.getAnnotations());
}
use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class MinijaxInvocationBuilder method method.
@Override
public Response method(final String name) {
final Minijax container = target.getServer();
final MinijaxApplication application = container.getApplication(target.getUri());
try {
final MockHttpServletRequest request = new MockHttpServletRequest(name, target.getUri(), headers, getEntityInputStream(), CookieUtils.convertJaxToServlet(cookies));
final MockHttpServletResponse response = new MockHttpServletResponse();
try (final MinijaxRequestContext context = new MinijaxRequestContext(application, request, response)) {
return application.handle(context);
}
} catch (final IOException ex) {
throw ExceptionUtils.toWebAppException(ex);
}
}
use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class ExceptionMapperTest method testNotFound.
@Test
public void testNotFound() throws IOException {
try (final MinijaxRequestContext ctx = createRequestContext()) {
final MinijaxMustacheExceptionMapper mapper = new MinijaxMustacheExceptionMapper();
final Response response = mapper.toResponse(new NotFoundException());
assertNotNull(response);
assertEquals(404, response.getStatus());
assertEquals("error", ((View) response.getEntity()).getTemplateName());
}
}
use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class CsrfFilterTest method setUpCsrfFilterTest.
@BeforeClass
@SuppressWarnings("unchecked")
public static void setUpCsrfFilterTest() throws IOException {
register(PersistenceFeature.class);
register(new SecurityFeature(User.class, Dao.class));
register(CsrfFilterTest.class);
try (MinijaxRequestContext ctx = createRequestContext()) {
user = new User();
user.setName("Alice");
user.setEmail("alice@example.com");
user.setRoles("user");
final Dao dao = ctx.get(Dao.class);
user = dao.create(user);
final Security<User> security = ctx.get(Security.class);
cookie = security.loginAs(user);
}
}
use of org.minijax.MinijaxRequestContext in project minijax by minijax.
the class RolesAllowedTest method setUpSecurityTest.
@BeforeClass
public static void setUpSecurityTest() throws IOException {
resetServer();
getServer().register(PersistenceFeature.class).register(new SecurityFeature(User.class, Dao.class)).register(RolesAllowedTest.class);
try (final MinijaxRequestContext ctx = createRequestContext()) {
final Dao dao = ctx.get(Dao.class);
alice = new User();
alice.setName("Alice");
alice.setEmail("alice@example.com");
alice.setHandle("alice");
alice.setPassword("alicepwd");
alice.setRoles("user", "admin");
dao.create(alice);
bob = new User();
bob.setName("Bob");
bob.setEmail("bob@example.com");
bob.setHandle("bob");
bob.setPassword("bobpwd");
bob.setRoles("user");
dao.create(bob);
aliceCookie = ctx.get(Security.class).loginAs(alice);
bobCookie = ctx.get(Security.class).loginAs(bob);
}
}
Aggregations