Showing posts with label Server. Show all posts

How to configure Subdomain in Tomcat for localhost?

In my previous article How to configure Subdomain in Tomcat 7? , I wrote about configuring subdomain on live server with linux environment. Today I'll show how you can configure sub-domain in Apache in local system with Netbeans and without Netbeans environment.



Configure sub-domain using Netbeans environment. 
Netbeans executable bundle has Apache Tomcat server in it. You can install Apache tomcat separately add it to Netbeans. So lets check out how to create sub-domain...

Step 1: Open Services tab in Netbeans. If you can't find click on Window > Services (Ctrl + 5) .

Step 2: Navigate to Servers > Apache Tomcat > Edit server.xml


Step 3: Find an Engine tag and add following line with in Engine tag.
<!-- Changes required in following code. In this example (cdn_2b48cl2gf97hytt58p8g.mydomain.com) is my sub-domain and directory.
        1. appBase: sub-domain directory location in webapps.
        2. name: sub-domain name you want. like(cdn_2b48cl2gf97hytt58p8g.mydomain.com, m.mydomain.com)
        3. docBase: Absolute path/location of your directory. -->
<Host appBase="webapps/cdn_2b48cl2gf97hytt58p8g" autoDeploy="false" name="cdn_2b48cl2gf97hytt58p8g.mydomain.com" unpackWARs="true">
      <Context antiJARLocking="true" docBase="D:\Path_to_project\build\web\cdn_2b48cl2gf97hytt58p8g" path=""/>
</Host>

How to forward domain request using hosts file?
Using hosts file you can forward any domain request to any IP address or hosts. We'll forward sub-domain request to localhost.

Note: For this example I used windows platform. Use sudo vim /etc/hosts command in terminal for linux and mac OR http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/

Step 1: Navigate to folder C:\Windows\System32\drivers\etc.

Step 2: Open hosts file using any editor like notepad and add line like below. So now your sub-domain will point to localhost.
127.0.0.1 cdn_2b48cl2gf97hytt58p8g.mydomain.com

How to setup sub-domain in Tomcat without Netbeans environment?
I gave you example to create sub-domain using Netbeans but technically you are using Netbeans as an editor nothing else. All you need to do is open server.xml file of your tomcat server in any editor like notepad follow same steps above and you are done.

Finally you need to restart your server and you are done!. Now you can access your sub-domain by url like cdn_2b48cl2gf97hytt58p8g.mydomain.com:8084/. You need to specify your tomcat server port. 

java.lang.IllegalStateException: More than the maximum number of request parameters (GET plus POST) for a single request ([512]) were detected.


This is very unusual error thrown by Jboss server. Error it self explain that you are passing more than 512 parameters in request. Which is not good practice but if situation drives you in that way. There is solution available for it.

"To change this limit, set the maxParameterCount attribute on the Connector." this message seems informative but actually its wrong message in case of JBoss 7 or may be in future versions.

Error message you've
java.lang.IllegalStateException: More than the maximum number of request parameters (GET plus POST) for a single request ([512]) were detected. Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.
 org.apache.tomcat.util.http.Parameters.addParameter(Parameters.java:199)
 org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:383)
 org.apache.tomcat.util.http.Parameters.processParameters(Parameters.java:229)
 org.apache.catalina.connector.Request.parseParameters(Request.java:2874)
 org.apache.catalina.connector.Request.getParameter(Request.java:1291)
 org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:363)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
Solution:
We need to use org.apache.tomcat.util.http.* library to solve this error. You don't need to import or download this library. It already available in Jboss. All you need to increase value of Parameter Count.

Jboss 7
Step 1: Open standalone.xml file available in "jboss7\standalone\configuration" folder.
Step 2: Paste below code after </extensions> tag and change value as per your requirement.
<system-properties>
   <property name="org.apache.tomcat.util.http.Parameters.MAX_COUNT" value="2000"/>
</system-properties>
Jboss 6 or lower (I didn't try but it has to work in lower version of Jboss as suggested by informative message)
Step 1: Open standalone.xml file available in "jboss6\standalone\configuration" folder.
Step 2: Find connector tag same as follow and add maxParameterCount attribute.
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" maxParameterCount="1000" /> 

How to increase PermSize/MaxPermSize in JBoss?


Quick definition of PermSize:
The permanent generation is used to hold reflective data of the VM itself such as class objects and method objects. These reflective objects are allocated directly into the permanent generation, and it is sized independently from the other generations

If you are working around big Enterprise Application, you may face memory issues in Jboss. In order to solve this you need to increase JVM PermSize for Jboss. Lets see the steps to increase Jboss PermSize.

Note: I tested this settings under jboss-as-7.1.1.Final

For Windows:

Step 1:
Goto bin folder of Jboss

Step 2: Open standalone.conf.bat file in notepad or other editor.

Step 3: Find set "JAVA_OPTS=-Xms64M -Xmx512M -XX:MaxPermSize=256M" and change the MaxPermSize as per your requirement and save it.

Step 4: Restart the Jboss.


For Linux:

Step 1:
Goto bin folder of Jboss either terminal or places.

Step 2: Open standalone.conf file in gedit(Ubuntu) or in terminal.

Step 3: Find JAVA_OPTS="-Xms64m -Xmx512m -XX:MaxPermSize=256m -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000" and change the MaxPermSize as per your requirement and save it.

Step 4: Restart the Jboss.

Jboss console log :
Caused by: java.lang.OutOfMemoryError: PermGen space
        at sun.misc.Unsafe.defineClass(Native Method) [rt.jar:1.6.0_24]
        at sun.reflect.ClassDefiner.defineClass(ClassDefiner.java:45) [rt.jar:1.6.0_24]
        at sun.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:381) [rt.jar:1.6.0_24]
        at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.6.0_24]
        at sun.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:377) [rt.jar:1.6.0_24]
        at sun.reflect.MethodAccessorGenerator.generateMethod(MethodAccessorGenerator.java:59) [rt.jar:1.6.0_24]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:28) [rt.jar:1.6.0_24]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_24]
        at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_24]
        at net.sf.beanlib.provider.BeanPopulator.invokeMethodAsPrivileged(BeanPopulator.java:221) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.doit(BeanPopulator.java:194) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.processSetterMethod(BeanPopulator.java:172) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.populate(BeanPopulator.java:270) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.populateBean(ReplicatorTemplate.java:174) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:173) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate3.Hibernate3JavaBeanReplicator.replicateBean(Hibernate3JavaBeanReplicator.java:71) [beanlib-hibernate-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:125) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:120) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:224) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.doit(BeanPopulator.java:201) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.processSetterMethod(BeanPopulator.java:172) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanPopulator.populate(BeanPopulator.java:270) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.populateBean(ReplicatorTemplate.java:174) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.BeanReplicator.replicateBean(BeanReplicator.java:173) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate3.Hibernate3JavaBeanReplicator.replicateBean(Hibernate3JavaBeanReplicator.java:71) [beanlib-hibernate-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicateByBeanReplicatable(ReplicatorTemplate.java:125) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.replicator.ReplicatorTemplate.replicate(ReplicatorTemplate.java:120) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.provider.BeanTransformer.transform(BeanTransformer.java:224) [beanlib-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate.HibernateBeanReplicator.copy(HibernateBeanReplicator.java:133) [beanlib-hibernate-5.0.1beta.jar:]
        at net.sf.beanlib.hibernate.HibernateBeanReplicator.copy(HibernateBeanReplicator.java:111) [beanlib-hibernate-5.0.1beta.jar:]