use of com.sun.jersey.spi.container.servlet.WebServletConfig in project pentaho-platform by pentaho.
the class JAXRSServlet method init.
@Override
public void init() throws ServletException {
SendEmptyEntityForServicesFlag = Boolean.parseBoolean(PentahoSystem.getSystemSetting("pentaho.xml", "set-empty-entity-rest-services", "true"));
Application app = (Application) getPrivate("app", ServletContainer.class, this);
WebComponent component;
if (app == null) {
component = new InternalWebComponent();
} else {
component = new InternalWebComponent(app);
}
setPrivate("webComponent", ServletContainer.class, this, component, false);
WebServletConfig webConfig = createWebConfig(this);
component.init(webConfig);
}
use of com.sun.jersey.spi.container.servlet.WebServletConfig in project pentaho-platform by pentaho.
the class JAXRSServletTest method serviceTestWriter.
@Test
public void serviceTestWriter() throws ServletException {
callSuperIterate.set(true);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
ResourceConfig resourceConfig = mock(ResourceConfig.class);
String contextPath = "/context";
String servletPath = "/servlet";
StringBuffer requestUrl = new StringBuffer(contextPath + servletPath + URL);
ServletConfig servletConfig = mock(ServletConfig.class);
WebServletConfig webServletConfig = mock(WebServletConfig.class);
ServletContext servletContext = mock(ServletContext.class);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
String[] beans = {};
HashSet<Class> classes = new HashSet<>();
classes.add(ResourseClass.class);
when(request.getMethod()).thenReturn("POST");
when(request.getRequestURL()).thenReturn(requestUrl);
when(request.getRequestURI()).thenReturn(URL);
when(request.getContextPath()).thenReturn(contextPath);
when(request.getServletPath()).thenReturn(servletPath);
doReturn(webServletConfig).when(jaxrsServlet).createWebConfig(jaxrsServlet);
doReturn(servletConfig).when(jaxrsServlet).getServletConfig();
doReturn(context).when(jaxrsServlet).getContext();
doReturn(beans).when(context).getBeanNamesForType((Class<?>) any());
doReturn(Collections.emptyEnumeration()).when(webServletConfig).getInitParameterNames();
doReturn(null).when(servletContext).getAttribute("javax.enterprise.inject.spi.BeanManager");
doReturn(servletContext).when(webServletConfig).getServletContext();
doReturn(resourceConfig).when(webServletConfig).getDefaultResourceConfig(any());
doReturn(classes).when(resourceConfig).getRootResourceClasses();
doReturn(context).when(jaxrsServlet).getAppContext();
doReturn(Collections.emptyEnumeration()).when(request).getHeaderNames();
try {
jaxrsServlet.init();
jaxrsServlet.service(request, response);
verify((SpringServlet) jaxrsServlet).service(eq(request), eq(response));
verify(response).setStatus(404, "Not Found");
jaxrsServlet.setBackWardSendErrorCompatible(true);
jaxrsServlet.service(request, response);
verify(response, never()).setStatus(404);
verify(response, never()).sendError(404);
} catch (ServletException e) {
e.printStackTrace();
fail("ServletException appeared");
} catch (IOException e) {
e.printStackTrace();
fail("IOException appeared");
}
}
use of com.sun.jersey.spi.container.servlet.WebServletConfig in project pentaho-platform by pentaho.
the class JAXRSServletTest method initTest.
@Test
public void initTest() throws Exception {
ServletConfig servletConfig = mock(ServletConfig.class);
WebServletConfig webServletConfig = mock(WebServletConfig.class);
ServletContext servletContext = mock(ServletContext.class);
doReturn(webServletConfig).when(jaxrsServlet).createWebConfig(jaxrsServlet);
doReturn(servletConfig).when(jaxrsServlet).getServletConfig();
doReturn(Collections.emptyEnumeration()).when(webServletConfig).getInitParameterNames();
doReturn(null).when(servletContext).getAttribute("javax.enterprise.inject.spi.BeanManager");
doReturn(servletContext).when(webServletConfig).getServletContext();
doReturn(mock(ConfigurableApplicationContext.class)).when(jaxrsServlet).getAppContext();
try {
jaxrsServlet.init();
} catch (ServletException e) {
e.printStackTrace();
fail("ServletException appeared");
}
Field web = ServletContainer.class.getDeclaredField("webComponent");
web.setAccessible(true);
Object obj = web.get(jaxrsServlet);
assertTrue(obj.getClass().getCanonicalName().contains(this.getClass().getPackage().getName()));
assertFalse(obj.getClass().getCanonicalName().contains(ServletContainer.class.getPackage().getName()));
}
Aggregations