Search in sources :

Example 1 with WebServletConfig

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);
}
Also used : WebComponent(com.sun.jersey.spi.container.servlet.WebComponent) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) WebServletConfig(com.sun.jersey.spi.container.servlet.WebServletConfig) WebApplication(com.sun.jersey.spi.container.WebApplication) Application(javax.ws.rs.core.Application)

Example 2 with WebServletConfig

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");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) WebServletConfig(com.sun.jersey.spi.container.servlet.WebServletConfig) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) WebServletConfig(com.sun.jersey.spi.container.servlet.WebServletConfig) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) ServletContext(javax.servlet.ServletContext) ResourceConfig(com.sun.jersey.api.core.ResourceConfig) HashSet(java.util.HashSet) SpringServlet(com.sun.jersey.spi.spring.container.servlet.SpringServlet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with WebServletConfig

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()));
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ServletException(javax.servlet.ServletException) Field(java.lang.reflect.Field) ServletContainer(com.sun.jersey.spi.container.servlet.ServletContainer) WebServletConfig(com.sun.jersey.spi.container.servlet.WebServletConfig) ServletConfig(javax.servlet.ServletConfig) WebServletConfig(com.sun.jersey.spi.container.servlet.WebServletConfig) ServletContext(javax.servlet.ServletContext) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

WebServletConfig (com.sun.jersey.spi.container.servlet.WebServletConfig)3 ServletContainer (com.sun.jersey.spi.container.servlet.ServletContainer)2 ServletConfig (javax.servlet.ServletConfig)2 ServletContext (javax.servlet.ServletContext)2 ServletException (javax.servlet.ServletException)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 ResourceConfig (com.sun.jersey.api.core.ResourceConfig)1 WebApplication (com.sun.jersey.spi.container.WebApplication)1 WebComponent (com.sun.jersey.spi.container.servlet.WebComponent)1 SpringServlet (com.sun.jersey.spi.spring.container.servlet.SpringServlet)1 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Application (javax.ws.rs.core.Application)1