Migrating from tomcat to weblogic
Moving from tomcat to weblogic may sound crazy. In case you need to do it though (e.g for business reasons) here are a couple of things which may go wrong.
First of all the classloader hierarchy in weblogic do not do what you usually expect from other servers such as tomcat, resin, jetty and jboss. If your application uses hibernate (and implicitly ANTLR) you may get the following exception:
Caused by: java.lang.Throwable: Substituted for missing class org.hibernate.QueryException - ClassNotFoundException: org.hibernate.hql.ast.HqlToken [from com.example.model.Person order by id] at org.hibernate.hql.ast.HqlLexer.panic(HqlLexer.java:80) at antlr.CharScanner.setTokenObjectClass(CharScanner.java:340) at org.hibernate.hql.ast.HqlLexer.setTokenObjectClass(HqlLexer.java:54) at antlr.CharScanner.<init>(CharScanner.java:51) at antlr.CharScanner.<init>(CharScanner.java:60) at org.hibernate.hql.antlr.HqlBaseLexer.<init>(HqlBaseLexer.java:56) ...
As explained in the Hibernate3 Migration Guide Weblogic doesn’t seem to support proper class loader isolation, will not see the Hibernate classes in the application’s context
and will try to use it’s own version of ANTLR.
In the same fashion you may get the following exception for commons lang:
java.lang.NoSuchMethodError: org.apache.commons.lang.exception.ExceptionUtils.getMessage(Ljava/lang/Throwable;)Ljava/lang/String;
because weblogic internally uses commons lang 2.1 and the one you use may have more API methods.
For both these problems the solution is to instruct weblogic to prefer the jars from the WEB-INF of your application. You need to create a weblogic specific file called weblogic.xml and place it under WEB-INF:
<?xml version="1.0" encoding="UTF-8"?> <weblogic-web-app> <container-descriptor> <prefer-web-inf-classes>true</prefer-web-inf-classes> </container-descriptor> </weblogic-web-app>
Another problem is that, like in resin, the default servlet is not named “default” so if you depend on it in web.xml, your application may throw the following at the deployment phase:
Caused by: weblogic.management.DeploymentException: [HTTP:101170]The servlet default is referenced in servlet-mapping *.avi, but not defined in web.xml.
This is because the default servlet is called FileServlet in the web.xml, so you’ll need to change all references in your web.xml from “default” to “FileServlet”.
Last, but not least, tomcat will automatically issue a 302 redirect from http://localhost:8080/context to http://localhost:8080/context/ before allowing your application to do any processing. So all instances of request.getServletPath() will never return an empty string, but will always start with “/”. Weblogic doesn’t do this so http://localhost:8080/context resolves and if your code contains something like:
request.getServletPath().substring(1)
you’ll get:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
so a safer way to trim this leading slash is by doing:
request.getServletPath().replaceFirst("^/", "")
Good luck, and remember. Every time you use a full blown application server for something that a simple web container would be enough, god kills a kitten.
March 12th, 2010 at 11:22
yes with weblogic you are going to need a lot of luck :(
November 17th, 2010 at 2:12
WEBLOGIC HIBERNATE ISSUES
THANKS FOR GIVING THE WORKAROUND ANTLR ISSUE.
THANKS AGAIN
April 4th, 2011 at 20:11
“every time you use a full blown application server for something that a simple web container would be enough, god kills a kitten.”
That made me :lol:
Seriously, though, ever coder should heed that sage advise!
June 2nd, 2011 at 9:39
Nice workaround on the Antlr issue, for sure. Thanks, man
January 6th, 2012 at 0:57
I added the weblogic.xml file to WEB-INF directory and tried deploying my application EAR.
Received the following error:
<Stack trace for message 149004
weblogic.management.DeploymentException:
at weblogic.application.internal.BaseDeployment.throwAppException(BaseDeployment.java:79)
at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:186)
at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:58)
at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: javax/persistence/spi/PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:621)
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:73)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:393)
at weblogic.deployment.BasePersistenceUnitInfoImpl.initializeEntityManagerFactory(BasePersistenceUnitInfoImpl.java:386)
at weblogic.deployment.BasePersistenceUnitInfoImpl.(BasePersistenceUnitInfoImpl.java:158)
Truncated. see log file for complete stacktrace
>
May 30th, 2012 at 9:31
any idea if we can use robots.txt in a web application deployed on weblogic server?
May 30th, 2012 at 10:02
Yes you can. Just put it under /web. Of course you’ll need to deploy your application on a domain such as http://www.example.com. If you deploy it under http://www.example.com/application/ then your robots.txt will not be in the correct place for spiders to find it. It needs to be on the root of the domain.