经过一些研究,我很惊讶我没有在Tomcat中找到任何有关HTTP/2支持的资源.更改日志8.0表示SPDY的实验支持,wiki将HTTP/2称为支持的规范(http://wiki.apache.org/tomcat/Specifications),但我没有找到任何教程.
你知道是否已经可以在Tomcat上启用HTTP/2了吗?如果答案是肯定的我怎么能这样做?
由于JSP 2.3(Tomcat 8)仅支持JSP的方法是GET POST或HEAD:
https://jcp.org/aboutJava/communityprocess/maintenance/jsr245/245-MR3.html http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/servlet/JspServlet.java ?查看= DIFF&R1 = 1497877&R2 = 1497878&pathrev = 1497878
但是,我想,这是一个很大的不兼容的变化,例如,对于异常处理程序,它用于转发到JSP以呈现异常和iso JSP视图,因为JSP 2.3响应是:
Method Not Allowed
HTTP Status 405 - JSPs only permit GET POST or HEAD
description The specified HTTP method is not allowed for the requested resource.
Apache Tomcat/8.0.3
Run Code Online (Sandbox Code Playgroud)
如果我们在异常的情况下使用REST和Spring HandlerExceptionResolver,我们肯定会碰到这个问题.是否有针对此问题的解决方法(iso更改http方法类型)?
我的代码正在处理tomcat 8版本8.0.33但是在8.5.4我得到:为此cookie指定了无效的域[.mydomain].
我发现Rfc6265CookieProcessor是在tomcat 8最新版本中引入的.
它在官方文档上说这可以在context.xml中恢复为LegacyCookieProcessor,但我不知道如何.
请让我知道如何做到这一点.
谢谢
尝试将应用程序从WebLogic 12.2.1迁移到Tomcat 8.5.4,Weblogic下的内容是作为LDAP连接的外部JNDI提供程序的条目已迁移到新的Resource
Tomcat下.
遵循Stack Overflow上的建议,自定义LdapContextFactory
已打包为jar
Tomcat lib
文件夹下的新文件.
在Tomcat server.xml
文件中,GlobalNamingResources/Resource
已配置以下内容:
<Resource name="ldapConnection"
auth="Container"
type="javax.naming.ldap.LdapContext"
factory="com.sample.custom.LdapContextFactory"
singleton="false"
java.naming.referral="follow"
java.naming.factory.initial="com.sun.jndi.ldap.LdapCtxFactory"
java.naming.provider.url="ldap://some.host:389"
java.naming.security.authentication="simple"
java.naming.security.principal="CN=some,OU=some,OU=some,DC=some,DC=a,DC=b"
java.naming.security.credentials="password"
com.sun.jndi.ldap.connect.pool="true"
com.sun.jndi.ldap.connect.pool.maxsize="10"
com.sun.jndi.ldap.connect.pool.prefsize="4"
com.sun.jndi.ldap.connect.pool.timeout="30000" />
Run Code Online (Sandbox Code Playgroud)
通过嵌入在Eclipse中的Apache Directory Studio/LDAP Browser等LDAP浏览器浏览LDAP目录时,上述连接可正常工作.
习惯com.sample.custom.LdapContextFactory
很简单:
public class LdapContextFactory implements ObjectFactory {
public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment)
throws Exception {
Hashtable<Object, Object> env = new Hashtable<>();
Reference reference = (Reference) obj;
Enumeration<RefAddr> …
Run Code Online (Sandbox Code Playgroud) 我在tomcat 8.0上使用java尝试了SSE(Server-Sent-Events).以下是我注意到的一些事情.
我单击一个自动向servlet发出请求的按钮.执行Servlet的GET方法,返回事件流.收到完整的流后,页面会再次自动发出另一个请求,再次接收相同的数据!我没有无限循环!!!
服务器上实际发生了什么?在正常情况下,tomcat会创建一个线程来处理每个请求.现在发生了什么?
确保事件流只发送一次到同一个连接/浏览器会话的正确方法是什么?
确保事件流关闭且服务器上不会产生资源开销的正确方法是什么?
如何区分GET和POST请求.为什么选择GET?
在Tomcat上使用SSE为时尚早?任何性能问题?
这是好奇的代码,
@WebServlet("/TestServlet")
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//content type must be set to text/event-stream
response.setContentType("text/event-stream");
//cache must be set to no-cache
response.setHeader("Cache-Control", "no-cache");
//encoding is set to UTF-8
response.setCharacterEncoding("UTF-8");
PrintWriter writer = response.getWriter();
for(int i=0; i<10; i++) {
System.out.println(i);
writer.write("data: "+ i +"\n\n");
writer.flush();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
writer.close();
}
}
Run Code Online (Sandbox Code Playgroud)
页面上的Javascript(页面上没有其他内容),
<button onclick="start()">Start</button> …
Run Code Online (Sandbox Code Playgroud) 我想在Tomcat 8下使用符号链接JSP目录.
它在Tomcat 7中也可以这样工作:
<Context allowLinking="true">
Run Code Online (Sandbox Code Playgroud)
但似乎Tomcat 8放弃了这个功能,它开始使用资源
(http://tomcat.apache.org/migration-8.html#Web_application_resources).
我的示例用法:
ROOT/jsp目录 - > linksto - >/var/tmp/realplaceofjspfiles /
配置错误:
ROOT/META-INF/context.xml的:
<Context>
<Resources allowLinking="true">
<PreResources className="org.apache.catalina.webresources.DirResourceSet" base="/var/tmp/realplaceofjspfiles" internalPath="jspdirectory"/>
</Resources>
</Context>
Run Code Online (Sandbox Code Playgroud)
它为我丢掉了这个例外:
07-Mar-2014 04:09:12.113 WARNING [localhost-startStop-1] org.apache.tomcat.util.digester.SetPropertiesRule.begin [SetPropertiesRule]{Context/Resources/PreResources} Setting property 'internalPath' to 'jspdirectory' did not find a matching
property.
07-Mar-2014 04:09:12.114 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:697)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1134)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1780)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at …
Run Code Online (Sandbox Code Playgroud) 我正在创建一些宁静的Web服务,并使用Spring-Boot创建一个嵌入式tomcat容器.
其中一个要求是实现双向SSL.我一直在查看HttpSecurity对象,并且可以使用它来仅通过SSL通道运行web服务: -
@Override
protected void configure(HttpSecurity http) throws Exception {
System.out.println("CONFIGURED");
http
// ...
.requiresChannel()
.anyRequest().requiresSecure();
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法找到的方法是只允许提供有效客户端证书的应用程序访问Web服务.
我只有SSL的基本知识,所以即使是正确方向的一般指针也会受到赞赏.
正在部署的服务器将混合使用多个应用程序 - 这是唯一需要使用双向SSL锁定的应用程序.我真正想要的是一种锁定单个应用程序只接受客户端证书的方法.
我刚刚在Ubuntu 14.04 VM上设置了Tomcat 8,我无法http://[hostname]:8080/manager/html
从浏览器访问Manager App .点击它后,我收到"403 Access Denied"错误.我正在运行Tomcat作为在配置文件中定义的服务/etc/init.d/tomcat8-dev
.该错误消息表明Tomcat设置为最初只能从localhost访问,但由于它是托管VM,因此我无法在其上运行浏览器.
我已在tomcat-users.xml
几个人推荐的文件中设置了一个用户.但是,我没有被提示为该用户提供凭据,我在默认页面上找不到任何类型的登录按钮.该文件目前看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
version="1.0">
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-gui"/>
<role rolename="manager-status"/>
<user username="(redacted)" password="(redacted)"
roles="manager-gui,manager-jmx,manager-status,manager-script"/>
</tomcat-users>
Run Code Online (Sandbox Code Playgroud)
在这里阅读了Tomcat文档页面后,我也尝试在其中添加<Valve />
标签context.xml
,如下所示:
<Context privileged="true" antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve" allow="127\.0\.0\.1" />
<!--Another valve for my local machine's IP-->
</Context>
Run Code Online (Sandbox Code Playgroud)
但是,一旦我设置privileged="true"
,当我使用浏览器连接到服务器时,无论后来提供的阀门如何,我都会得到一个空白的白页.
sudo service tomcat8-dev restart
每当我做出更改时,我都会重启我的服务.
我根据我在这里和其他网站上发布的帖子尝试过的其他事情:
address="0.0.0.0"
到标签server.xml
内部<Connector />
initctl …
在我的Spring Boot + Tomcat 8项目中,我配置了@ControllerAdvice
如下所示:
@ControllerAdvice
public class GlobalControllerExceptionHandler {
final static Logger logger = LoggerFactory.getLogger(GlobalControllerExceptionHandler.class);
private static final String ERROR = "error";
@ExceptionHandler
@ResponseBody
@ResponseStatus(HttpStatus.BAD_REQUEST)
public Map<String, ResponseError> handleException(Exception e, HttpServletRequest request, HttpServletResponse response) throws IOException {
logger.debug("API error", e);
return createResponseError(HttpStatus.BAD_REQUEST.value(), e.getMessage());
}
protected Map<String, ResponseError> createResponseError(int httpStatus, String message) {
Map<String, ResponseError> responseError = new HashMap<String, ResponseError>();
responseError.put(ERROR, new ResponseError(httpStatus, message));
return responseError;
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,除了客户端发送复杂且不正确的JSON文档并且我的服务器逻辑因以下异常而失败的情况:
2836538 WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Failed to invoke @ExceptionHandler method: …
Run Code Online (Sandbox Code Playgroud) 我的弹簧启动应用程序有一个奇怪的行为:
重新启动后端后,对控制器的第一次调用大约需要5秒,以下相同的请求只需要50ms.这在90%的情况下是可重现的,有时甚至第一次呼叫都很快.
我确定,问题是服务器上没有客户端.在浏览器上,我看到TTFB时间(到第一个字节的时间)增加到5秒.以下请求仅需要10毫秒的TTFB.
使用服务器上的监控工具(应用程序动态)我可以收集这种慢速服务器调用,在调用图上我可以看到:
org.apache.catalina.webresources.JarWarResourceSet:getArchiveEntries:117
Run Code Online (Sandbox Code Playgroud)
需要4916毫秒.我认为这是我的瓶颈.但我不知道如何解决它.
我已经尝试过的:
一切都没有影响服务器的延迟.
更新
由于战争文件被多次扫描,时间会丢失.
org.apache.catalina.webresources.CachedResource.validateResource正在检查我们是否有war文件(isPackedWarFile),并且此检查返回false.即使它是一个战争档案.对于这种行为不端,我有一个解决方法.我将tomcat.resource.cache-tt设置为较高的值.
但是现在org.apache.catalina.webresources.Cache.getResource有一个noCache方法.在此方法中,类和jar文件从缓存中排除.这就是为什么再次扫描war文件的原因.
扫描整个war文件大约需要5秒钟.而这个突破是世界休息的一站.并且这种扫描绝对是不必要的,因为war文件没有爆炸,因此其内容无法更改.
更新
如果我将war文件放入tomcat安装,一切都很快.嵌入式tomcat就是问题所在.
tomcat8 ×10
tomcat ×7
java ×4
spring-boot ×3
contextpath ×1
cookies ×1
http2 ×1
jackson ×1
jsp ×1
ldap ×1
resources ×1
spring ×1
spring-mvc ×1
ssl ×1
weblogic ×1