Tuesday, September 8, 2015

Tomcat Miscs



https://stackoverflow.com/questions/33576979/why-have-a-shutdown-port-in-tomcat
The shutdown port provides an OS neutral, scriptable way to shutdown a Tomcat instance. Once you remove the shutdown port you are almost certainly into the realms of OS specific code (or at least different code for Windows vs Unix plus derivatives). By default, Tomcat aims for common configuration and behaviour across all platforms.

http://stackoverflow.com/questions/20670310/why-would-java-lang-illegalstateexception-the-resource-configuration-is-not-mo
One possible cause is that you have two or more applicable mappings for that URL call.
For example:
@Path("/{myParam}")
And somewhere else:
@Path("/{differentParam}")
Now Jersey have no way of telling what method is actually supposed to be called and gives this error.
- check tomcat log
contains multiple parameters with no annotation. Unable to resolve the injection source


How to determine your version of Tomcat and Java
https://confluence.atlassian.com/confkb/how-to-determine-your-version-of-tomcat-and-java-331914173.html
java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo

http://crunchify.com/how-to-change-jvm-heap-setting-xms-xmx-of-tomcat/
  1. Go to <Tomcat Directory>/bin directory
  2. Execute command: ./catalina.sh run
http://stackoverflow.com/questions/2947683/httprequest-maximum-allowable-size-in-tomcat
The connector section has the parameter
maxPostSize
The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).
Another Limit is:
maxHttpHeaderSize The maximum size of the request and response HTTP header, specified in bytes. If not specified, this attribute is set to 4096 (4 KB).
You find them in
$TOMCAT_HOME/conf/server.xml
http://stackoverflow.com/questions/2943477/is-there-a-max-size-for-post-parameter-content
As per this the default is 2 MB for your <Connector>.
maxPostSize = The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).
Edit Tomcat's server.xml. In the <Connector> element, add an attribute maxPostSize and set a larger value (in bytes) to increase the limit.
Having said that, if this is the issue, you should have got an exception on the lines of Post data too big in tomcat
https://tomcat.apache.org/tomcat-7.0-doc/config/http.html#Proxy_Support
The proxyName and proxyPort attributes can be used when Tomcat is run behind a proxy server. These attributes modify the values returned to web applications that call the request.getServerName() and request.getServerPort() methods, which are often used to construct absolute URLs for redirects. Without configuring these attributes, the values returned would reflect the server name and port on which the connection from the proxy server was received, rather than the server name and port to whom the client directed the original request.
https://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html
  1. Include two directives in your httpd.conf file for each web application that you wish to forward to Tomcat. For example, to forward an application at context path/myapp:
    
    ProxyPass         /myapp  http://localhost:8081/myapp
    ProxyPassReverse  /myapp  http://localhost:8081/myapp
    
    which tells Apache to forward URLs of the form http://localhost/myapp/* to the Tomcat connector listening on port 8081.
  2. Configure your copy of Tomcat to include a special <Connector> element, with appropriate proxy settings, for example:
    
    <Connector port="8081" ...
                  proxyName="www.mycompany.com"
                  proxyPort="80"/>
    
    which will cause servlets inside this web application to think that all proxied requests were directed to www.mycompany.com on port 80.
Apache Tomcat with SSL behind Amazon ELB

<Connector
    port="8080"
    protocol="HTTP/1.1"
    proxyPort="443"
    scheme="https"
    secure="true"
    proxyName="myapp.example.com"
    connectionTimeout="20000"
    URIEncoding="UTF-8"
    redirectPort="8443" />
Set this attribute to true if you wish to have calls torequest.isSecure() to return true for requests received by thisConnector.
http://blog.dreamlu.net/blog/78
session依赖于cookie,当cookie被禁用的时候将尝试使用url传递jsessionid
例如:/sign_in;jsessionid=7ba49c313a84295770fecbd01e86f116166sc5feg5yhzwis9zayzx492

二、tomcat中的实现

tomcat的核心jar:lib/catalina.jar,session的实现位于org.apache.catalina.session包中。

Session默认储存在内存中、file、db(以上三种tomcat、jetty均有实现,具体配置请百度)或者继承StoreBase扩展到cache中。
session核心代码列举(ManagerBase.java):
可以看出session实际是存储于一个map中,以sessionid作为key,value则为一个session对象。

protected Map sessions;
// ManagerBase 161行
this.sessions = new ConcurrentHashMap();
public void add(Session session) {
    this.sessions.put(session.getIdInternal(), session);
    int size = getActiveSessions();
    if (size > this.maxActive) {
      synchronized (this.maxActiveUpdateLock) {
        if (size > this.maxActive) {
          this.maxActive = size;
        }
      }
    }
}
然而session又是一个key,value的对象,当然实际实现略显复杂。StandardSession为tomcat中的具体实现。我们可以简单的将他理解成一个Map<String, Map>的结构。

https://shantanusachdev.wordpress.com/2014/02/18/caused-by-java-lang-illegalstateexception-unable-to-complete-the-scan-for-annotations-for-web-application-webapp1-due-to-a-stackoverflowerror-possible-root-causes-include-a-too-low-setting-for/
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/webapp1] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.jaxen.util.AncestorAxisIterator->org.jaxen.util.AncestorOrSelfAxisIterator->org.jaxen.util.AncestorAxisIterator]
**First thing I tried of course was changing the memory settings. However this did not work. No matter how high I set it, it would always give this error.
Solution:
1. This happens in tomcat versions higher than 7.0.33, so downgrading could be one possible solution.
2. jaxen and dom4j don’t play very well together, upgrading to Jaxen-1.1.6 and dom4j-1.6.1 worked for me.

Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/megaphone-1.0.3_jbuild359] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.bouncycastle.asn1.ASN1Boolean->org.bouncycastle.asn1.DERBoolean->org.bouncycastle.asn1.ASN1Boolean]
        at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2066)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2012)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1961)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1936)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1897)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1149)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:95)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5080)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)

        ... 10 more
https://www.bouncycastle.org/

Here at the Bouncy Castle, we believe in encryption. That's something that's near and dear to our hearts. We believe so strongly in encryption, that we've gone to the effort to provide some for everybody, and we've now been doing it for over 15 years!
  • Increase the stack size -Xss4m
  • Tell Tomcat not to scan your application if you are not using any java based Servlet configuration add metadata-complete="true" to your web-app in web.xml
As it turns out Tomcat 7.0.47 has the same issue, but better reporting. When run locally the reporting showed me this:
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/api] due to a StackOverflowError. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [org.bouncycastle.asn1.ASN1Boolean->org.bouncycastle.asn1.DERBoolean->org.bouncycastle.asn1.ASN1Boolean]
Once I found the offending jar file, I added it to the catalina.properties file like this:
org.apache.catalina.startup.ContextConfig.jarsToSkip=bcprov*.jar
I think its because of two versions of JAR being referenced from classpath.
This is usually caused when different versions of bcprov-jdk*.jar being loaded.
For example, IN one of my scenario - I had 

..../webapps/FOO/WEB-INF/lib/bcprov-jdk15on-147.jar
..../webapps/FOO/WEB-INF/lib/bcprov-jdk15on-1.51.jar 
I got this resolved after removing any one of them from my classpath.

Labels

Review (572) System Design (334) System Design - Review (198) Java (189) Coding (75) Interview-System Design (65) Interview (63) Book Notes (59) Coding - Review (59) to-do (45) Linux (43) Knowledge (39) Interview-Java (35) Knowledge - Review (32) Database (31) Design Patterns (31) Big Data (29) Product Architecture (28) MultiThread (27) Soft Skills (27) Concurrency (26) Cracking Code Interview (26) Miscs (25) Distributed (24) OOD Design (24) Google (23) Career (22) Interview - Review (21) Java - Code (21) Operating System (21) Interview Q&A (20) System Design - Practice (20) Tips (19) Algorithm (17) Company - Facebook (17) Security (17) How to Ace Interview (16) Brain Teaser (14) Linux - Shell (14) Redis (14) Testing (14) Tools (14) Code Quality (13) Search (13) Spark (13) Spring (13) Company - LinkedIn (12) How to (12) Interview-Database (12) Interview-Operating System (12) Solr (12) Architecture Principles (11) Resource (10) Amazon (9) Cache (9) Git (9) Interview - MultiThread (9) Scalability (9) Trouble Shooting (9) Web Dev (9) Architecture Model (8) Better Programmer (8) Cassandra (8) Company - Uber (8) Java67 (8) Math (8) OO Design principles (8) SOLID (8) Design (7) Interview Corner (7) JVM (7) Java Basics (7) Kafka (7) Mac (7) Machine Learning (7) NoSQL (7) C++ (6) Chrome (6) File System (6) Highscalability (6) How to Better (6) Network (6) Restful (6) CareerCup (5) Code Review (5) Hash (5) How to Interview (5) JDK Source Code (5) JavaScript (5) Leetcode (5) Must Known (5) Python (5)

Popular Posts