Weichun Qian created KARAF-7548:
-----------------------------------
Summary: currentThread.contextClassLoader does not include the
Servlet bundle using http whiteboard
Key: KARAF-7548
URL: https://issues.apache.org/jira/browse/KARAF-7548
Project: Karaf
Issue Type: Bug
Components: karaf
Affects Versions: 4.4.1
Reporter: Weichun Qian
Attachments: demo.zip
Registering the servlet to http whiteboard:
{code:java}
Dictionary<String, String> props = new Hashtable<>();
props.put(HTTP_WHITEBOARD_SERVLET_PATTERN, "/hello");
props.put(HTTP_WHITEBOARD_SERVLET_NAME, "helloservlet");
props.put(HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, "true");
props.put(HTTP_WHITEBOARD_CONTEXT_SELECT,
String.format("(osgi.http.whiteboard.context.name=%s)", "default"));
context.registerService(Servlet.class, new MyServlet(), props);{code}
The following code will get an exception.
{code:java}
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.getWriter().println("<h1>it worked</h1>");
try {
Thread.currentThread().getContextClassLoader().loadClass(MyServlet.class.getName());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
} {code}
The demo project is here.[^demo.zip]
--
This message was sent by Atlassian Jira
(v8.20.10#820010)