use of io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter in project crnk-framework by crnk-project.
the class CrnkServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ServletContext servletContext = getServletContext();
ServletRequestContext context = new ServletRequestContext(servletContext, request, response, boot.getWebPathPrefix(), defaultCharacterEncoding);
RequestDispatcher requestDispatcher = boot.getRequestDispatcher();
requestDispatcher.process(context);
if (!context.checkAbort()) {
HttpRequestContextBaseAdapter requestContext = new HttpRequestContextBaseAdapter(context);
boolean jsonApiRequest = JsonApiRequestProcessor.isJsonApiRequest(requestContext, acceptPlainJson);
response.setStatus(jsonApiRequest ? HttpStatus.NOT_FOUND_404 : HttpStatus.UNSUPPORTED_MEDIA_TYPE_415);
}
}
use of io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter in project crnk-framework by crnk-project.
the class HttpRequestProcessorImplTest method checkProcess.
@Test
public void checkProcess() throws IOException {
HttpRequestContextBase requestContextBase = Mockito.mock(HttpRequestContextBase.class);
HttpRequestContextBaseAdapter requestContext = new HttpRequestContextBaseAdapter(requestContextBase);
Mockito.when(requestContextBase.getMethod()).thenReturn("GET");
Mockito.when(requestContextBase.getPath()).thenReturn("/tasks/");
Mockito.when(requestContextBase.getRequestHeader("Accept")).thenReturn("*");
ControllerRegistry controllerRegistry = new ControllerRegistry(null);
CollectionGet controller = mock(CollectionGet.class);
when(controller.isAcceptable(any(JsonPath.class), eq("GET"))).thenCallRealMethod();
controllerRegistry.addController(controller);
QuerySpecAdapterBuilder queryAdapterBuilder = new QuerySpecAdapterBuilder(new DefaultQuerySpecDeserializer(), moduleRegistry);
RequestDispatcher sut = new HttpRequestProcessorImpl(moduleRegistry, controllerRegistry, null, queryAdapterBuilder);
sut.process(requestContext);
verify(controller, times(1)).handle(any(JsonPath.class), any(QueryAdapter.class), any(RepositoryMethodParameterProvider.class), any(Document.class));
}
use of io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter in project crnk-framework by crnk-project.
the class JsonApiRequestProcessorTest method setup.
@Before
public void setup() {
TaskRepository.clear();
boot = new CrnkBoot();
boot.addModule(new Module() {
@Override
public String getModuleName() {
return "test";
}
@Override
public void setupModule(ModuleContext context) {
moduleContext = context;
}
});
boot.setServiceUrlProvider(new ConstantServiceUrlProvider("http://localhost:8080"));
boot.setServiceDiscovery(new ReflectionsServiceDiscovery(MockConstants.TEST_MODELS_PACKAGE));
boot.boot();
Task task = new Task();
task.setId(1L);
task.setName("SomeTask");
task.setLinksInformation(new TaskLinks());
TaskRepository tasks = new TaskRepository();
tasks.save(task);
processor = new JsonApiRequestProcessor(moduleContext);
requestContextBase = Mockito.mock(HttpRequestContextBase.class);
requestContext = new HttpRequestContextBaseAdapter(requestContextBase);
HttpRequestContextProvider requestContextProvider = boot.getModuleRegistry().getHttpRequestContextProvider();
requestContextProvider.onRequestStarted(requestContext);
}
use of io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter in project crnk-framework by crnk-project.
the class ServletModuleTest method testSecurityProviderInstalled.
@Test
public void testSecurityProviderInstalled() {
HttpRequestContextProvider provider = new HttpRequestContextProvider();
ServletModule module = new ServletModule(provider);
CrnkBoot boot = new CrnkBoot();
boot.addModule(module);
boot.boot();
SecurityProvider securityProvider = boot.getModuleRegistry().getSecurityProvider();
ServletContext servletContext = Mockito.mock(ServletContext.class);
MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
MockHttpServletResponse response = new MockHttpServletResponse();
request.addUserRole("guest");
request.addUserRole("admin");
provider.onRequestStarted(new HttpRequestContextBaseAdapter(new ServletRequestContext(servletContext, request, response, "api", HttpHeaders.DEFAULT_CHARSET)));
Assert.assertFalse(securityProvider.isUserInRole("doesNotExist"));
Assert.assertTrue(securityProvider.isUserInRole("guest"));
Assert.assertTrue(securityProvider.isUserInRole("admin"));
}
use of io.crnk.core.engine.internal.http.HttpRequestContextBaseAdapter in project crnk-framework by crnk-project.
the class HttpRequestContextBaseAdapterTest method setup.
@Before
public void setup() {
base = Mockito.mock(HttpRequestContextBase.class);
adapter = new HttpRequestContextBaseAdapter(base);
}
Aggregations