diff --git a/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java b/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java index eb602bf3c5093d3d58969881f1465eb162002db9..25dadac0d4be96550c73e8a514a304efa1e4a955 100644 --- a/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java +++ b/servlet-core/src/main/java/org/smartboot/servlet/ContainerRuntime.java @@ -129,6 +129,9 @@ public class ContainerRuntime { ServletContextEvent event = new ServletContextEvent(servletContext); servletContextListener.contextDestroyed(event); }); + servletContext.getDeploymentInfo().getServlets().values().forEach(servletInfo -> { + servletInfo.getServlet().destroy(); + }); } public boolean isStarted() { diff --git a/servlet-core/src/main/java/org/smartboot/servlet/ServletHttpHandle.java b/servlet-core/src/main/java/org/smartboot/servlet/ServletHttpHandle.java index f067d039d22a64c2e4f5d94102992149f7f0a723..bfbd4a1cf69125b0a3bc1315cbc9fb8266ee56b5 100644 --- a/servlet-core/src/main/java/org/smartboot/servlet/ServletHttpHandle.java +++ b/servlet-core/src/main/java/org/smartboot/servlet/ServletHttpHandle.java @@ -115,7 +115,9 @@ public class ServletHttpHandle extends HttpHandle { return runtime; } for (ContainerRuntime matchRuntime : runtimes) { - if (StringUtils.startsWith(servletPath, matchRuntime.getServletContext().getDeploymentInfo().getContextPath())) { + //todo 兼容 请求 uri 为 servletPath结尾不带 '/' 的情况 + String contextPath = matchRuntime.getServletContext().getDeploymentInfo().getContextPath(); + if (StringUtils.startsWith(servletPath, contextPath) || servletPath.equals(contextPath.substring(0, contextPath.length() - 1))) { runtime = matchRuntime; contextCache.put(servletPath, runtime); break; diff --git a/servlet-core/src/main/java/org/smartboot/servlet/handler/ServletMatchHandler.java b/servlet-core/src/main/java/org/smartboot/servlet/handler/ServletMatchHandler.java index d1d55817aec8e427029e02b28d6542769ce0aca8..23b7de089af0c5678fa07c4d1095fa4daa3fa1d3 100644 --- a/servlet-core/src/main/java/org/smartboot/servlet/handler/ServletMatchHandler.java +++ b/servlet-core/src/main/java/org/smartboot/servlet/handler/ServletMatchHandler.java @@ -47,8 +47,11 @@ public class ServletMatchHandler extends Handler { request.setRequestUri(request.getRequestURI()); } else { int i = request.getRequestURI().length() - servletContext.getContextPath().length(); - if (i == 0) { + //todo 兼容 请求 uri 为 servletPath结尾不带 '/' 的情况 + if(i == -1){ request.setRequestUri(request.getRequestURI() + deploymentInfo.getWelcomeFile()); + }else if (i == 0) { + request.setRequestUri(request.getRequestURI() + deploymentInfo.getWelcomeFile().substring(1)); } else if (i == 1 && request.getRequestURI().charAt(request.getRequestURI().length() - 1) == '/') { request.setRequestUri(request.getRequestURI().substring(0, request.getRequestURI().length() - 1) + servletContext.getDeploymentInfo().getWelcomeFile()); } else { diff --git a/servlet-core/src/main/java/org/smartboot/servlet/impl/HttpServletRequestImpl.java b/servlet-core/src/main/java/org/smartboot/servlet/impl/HttpServletRequestImpl.java index 64c47a2e731f3a32a3f44a73fe4983680c388bb9..88a29852c145b0dfc9aac8a471e2f55ecf267fda 100644 --- a/servlet-core/src/main/java/org/smartboot/servlet/impl/HttpServletRequestImpl.java +++ b/servlet-core/src/main/java/org/smartboot/servlet/impl/HttpServletRequestImpl.java @@ -69,6 +69,8 @@ public class HttpServletRequestImpl implements HttpServletRequest { this.dispatcherType = dispatcherType; this.servletContext = runtime.getServletContext(); this.sessionManager = runtime.getSessionManager(); + //todo 设置初始uri + this.requestUri = request.getRequestURI(); } @Override diff --git a/servlet-core/src/main/java/org/smartboot/servlet/impl/ServletContextImpl.java b/servlet-core/src/main/java/org/smartboot/servlet/impl/ServletContextImpl.java index ff5f7559bd45ead404e6ce2177f5bf2a97546ef6..d7ba12cf04c326ceae02dab72c2d37a9b9973d9e 100644 --- a/servlet-core/src/main/java/org/smartboot/servlet/impl/ServletContextImpl.java +++ b/servlet-core/src/main/java/org/smartboot/servlet/impl/ServletContextImpl.java @@ -104,7 +104,8 @@ public class ServletContextImpl implements ServletContext { @Override public Set getResourcePaths(String path) { - throw new UnsupportedOperationException(); + //todo 暂时 返回 null 使org.apache.jasper.servlet.JasperInitializer#onStartup 可以执行 + return null; } @Override @@ -120,6 +121,12 @@ public class ServletContextImpl implements ServletContext { URL url = new URL(deploymentInfo.getContextUrl(), path.substring(1)); RunLogger.getLogger().log(Level.SEVERE, "path:" + url + " ,url:" + deploymentInfo.getContextUrl()); + //todo 资源不存在时,返回空,参考实现org.apache.jasper.servlet.JspCServletContext#getResource + try (InputStream is = url.openStream()) { + } catch (Throwable t) { + RunLogger.getLogger().log(Level.SEVERE, "path:" + url + " ,Err:" + t.getMessage()); + url = null; + } return url; } @@ -179,7 +186,9 @@ public class ServletContextImpl implements ServletContext { public String getRealPath(String path) { try { URL url = getResource(path); - return new File(url.toURI()).getAbsolutePath(); + if (url != null) { + return new File(url.toURI()).getAbsolutePath(); + } } catch (MalformedURLException | URISyntaxException e) { e.printStackTrace(); } @@ -358,7 +367,8 @@ public class ServletContextImpl implements ServletContext { @Override public JspConfigDescriptor getJspConfigDescriptor() { - throw new UnsupportedOperationException(); + //todo 暂时 返回 null 使org.apache.jasper.servlet.JasperInitializer#onStartup 可以执行 + return null; } @Override