Skip to content

Commit

Permalink
Fix possible NPE for default servlet (#234)
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <[email protected]>
  • Loading branch information
olamy authored Jan 24, 2025
1 parent e1787dd commit 37fa23f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentExcept
HTTPContext httpContext = new HTTPContext(listeningHost, listeningPort);
ServletHandler servletHandler = webAppContext.getServletHandler();
for (ServletHolder servlet : servletHandler.getServlets()) {
httpContext.add(new Servlet(servlet.getName(), servlet.getContextPath()));
if(servlet.getServletContext() == null) {
httpContext.add(new Servlet(servlet.getName(), "/"));
} else {
httpContext.add(new Servlet(servlet.getName(), servlet.getServletContext().getContextPath()));
}
}
return new ProtocolMetaData().addContext(httpContext);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentExcept
HTTPContext httpContext = new HTTPContext(listeningHost, listeningPort);
ServletHandler servletHandler = webAppContext.getServletHandler();
for (ServletHolder servlet : servletHandler.getServlets()) {
httpContext.add(new Servlet(servlet.getName(), servlet.getContextPath()));
if(servlet.getServletContext() == null) {
httpContext.add(new Servlet(servlet.getName(), "/"));
} else {
httpContext.add(new Servlet(servlet.getName(), servlet.getServletContext().getContextPath()));
}
}
return new ProtocolMetaData().addContext(httpContext);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentExcept
HTTPContext httpContext = new HTTPContext(listeningHost, listeningPort);
ServletHandler servletHandler = webAppContext.getServletHandler();
for (ServletHolder servlet : servletHandler.getServlets()) {
httpContext.add(new Servlet(servlet.getName(), servlet.getServletContext().getContextPath()));
if(servlet.getServletContext() == null) {
httpContext.add(new Servlet(servlet.getName(), "/"));
} else {
httpContext.add(new Servlet(servlet.getName(), servlet.getServletContext().getContextPath()));
}
}
return new ProtocolMetaData().addContext(httpContext);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentExcept
HTTPContext httpContext = new HTTPContext(listeningHost, listeningPort);
ServletHandler servletHandler = webAppContext.getServletHandler();
for (ServletHolder servlet : servletHandler.getServlets()) {
httpContext.add(new Servlet(servlet.getName(), servlet.getServletContext().getContextPath()));
if(servlet.getServletContext() == null) {
httpContext.add(new Servlet(servlet.getName(), "/"));
} else {
httpContext.add(new Servlet(servlet.getName(), servlet.getServletContext().getContextPath()));
}
}
return new ProtocolMetaData().addContext(httpContext);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentExcept
HTTPContext httpContext = new HTTPContext(listeningHost, listeningPort);
ServletHandler servletHandler = webAppContext.getServletHandler();
for (ServletHolder servlet : servletHandler.getServlets()) {
if(servlet.getServletContext() != null) {
if(servlet.getServletContext() == null) {
httpContext.add(new Servlet(servlet.getName(), "/"));
} else {
httpContext.add(new Servlet(servlet.getName(), servlet.getServletContext().getContextPath()));
}

}
return new ProtocolMetaData().addContext(httpContext);
} catch (Exception e) {
Expand Down

0 comments on commit 37fa23f

Please sign in to comment.