Saturday, October 13, 2012

Weblogic BEA-149265 , Caused By: java.lang.ClassNotFoundException: HttpServlet


Problem Description
I am using weblogic 10.3.3 server and was trying to deploy a web based application (build in eclipse).

 I have configured weblogic 10.3.3 server in eclipse and the application had no errors. It was running from inside eclipse like a charm.
After finishing the development and to test the application outside eclipse environment, I started standalone server instance (weblogic 10.3.3 outside eclipse , from command prompt) and was trying to deploy the same application and saw this strange error

<Error> <Deployer> <BEA-149265> <Failure occurredin the execution of deployment request with ID '1350125256034' for task '6'. Error is: 'weblogic.management.DeploymentException: 'weblogic.management.DeploymentException:        at weblogic.application.internal.BaseDeployment.throwAppException(BaseDe
ployment.java:157)

Caused By: java.lang.ClassNotFoundException: HttpServlet
        at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(Generic
ClassLoader.java:280)
        at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClass
Loader.java:253)
        at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAw
areClassLoader.java:56)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        Truncated. see log file for complete stacktrace
> 

I was surprised to see it because same machine same server instance , if I run it from eclipse it works fine , outside eclipse it doesn’t work.
As you can see from the error message it was having problem loading the HTTPServlet  while deploying the application.
But the thing which wasted a lot of time was why the hell it is working on eclipse , as I was using the same weblogic server.
Ideally the servlet jar file shouldn’t be in your webapp/lib directory and it wasn’t , server will have it’s own copy of the jar file in it’s class loader.
Solution
It took some time to find the solution but it’s easy. I used eclipse to export a war file of my web project, and then started weblogic and deployed the war file instead of web app folder and it’s working now.
Similar problem encountered at test server
I saw the same problem on test even with the war file , after trying everything we can do to get rid of this problem with no success we decided to restart the Test instance.
The application was deployed successfully after Server restart.

Infect this solution should be followed as a practice
 When you export war file eclipse takes care of all the dependent jars and puts them in your war file , so if there is any possibility that you are using an external  library in your application eclipse will take care of including it in the final war when you export the project as a war file.
It is therefore highly recommended to export your eclipse project as WAR file and then send it for deployment.  

Tuesday, September 11, 2012

Spring MVC from getting started to advance level

Below are some very good resources for getting started in Spring MVC

A very good introductory article of Spring MVC

http://blog.springsource.com/2011/01/04/green-beans-getting-started-with-spring-mvc/

Spring showcase
 http://blog.springsource.org/2010/07/22/spring-mvc-3-showcase/



Thursday, August 30, 2012

Common mistakes done in applications which can give a hacker full knowledge of your database

Its a bad practice to throw the whole exception message on the client console , if the exception is a jdbc exception throwed because of an error in update,  any error in trigger execution e.t.c the raw exception stack trace has a lot of information about the tables in database fields in it and business rules implenented which caused this exception. This is a lot for a hacker he can easily build a knowledge base based on these exceptions,  validations and business rules implemented in your database,  infact your whole database can be open to him.
Its therefor a bad practice to let the presentation layer see the raw jdbc exception stack trace instead application developers should try to develop the wrapper exceptions and should try to show only relevent exception data on presentation layer.

Note : "I recently had a chance to work with a very good consultant from Mcafee, he told me that this is one of the main reasons hackers can hack the most secured applications easily once they hv access to the application they try different operations to cause the exceptions and build their knowledge by looking into the different exception". This was a very good informative session where I learnt a lot I will be writing more blogs on it so keep your fingers crossed and wait for some more good blog posts: ).

Saturday, August 4, 2012

java.sql.SQLSyntaxErrorException: ORA-01722: invalid number

One possible reason for java.sql.SQLSyntaxErrorException: ORA-01722: invalid number and it's solution



I encountered this exception today and the cause of it was very obvious and eventually I learned a very good practice out of it

Below is the query I was trying to execute

select * from a_table where bi_num= 60

Surprisingly this query was showing me some results in PL\ SQL developer initially but when I tried to fetch the complete result set it gave me this "ORA-01722: invalid number" exception.

Reason :


As you can see the name of the field "bi_num" gave me a feeling that it is a number field in oracle that is why I had the numeric comparison in query , but bi_num was eventually declared as varchar field in the database and in some records it had values which could have been converted to number the other records had no numeric values. When oracle was trying to fetch the data according to condition in query, because of comparison with a number oracle was trying to convert values in bi_num to number.
For few records it worked but the records having string values of course oracle couldn't convert those to number and gave me "ORA-01722: invalid number" exception.

Solution:


After understanding the problem solution was very simple , I changed the query to have a string comparison like below

select * from a_table where bi_num= '60'

So now oracle will always do the string comparison and will not convert values to numbers.

I hope this will help someone out there :).

Thursday, July 26, 2012

HTML Give border title in div

In HTML to have a table with title in it's border like we can have in swing , we can use div element like shown in below code snipet

<div  style="width:100%;">
    <fieldset>
    <legend style="color:blue;font-weight:bold;">Initiator Information</legend>


      <table  border="0" cellpadding="0" cellspacing="5" >
        <tr>
          <td width="146">User Id</td>
          <td width="216"><label for="userId"></label>
            <input type="text" name="userId" id="userId" /></td>
          <td width="122">Name</td>
          <td width="474"><input type="text" name="userName" id="userName" /></td>
        </tr>
        <tr>
          <td>Department</td>
          <td><label for="userDepartment"></label>
            <input type="text" name="userDepartment" id="userDepartment" /></td>
          <td>Division</td>
          <td><label for="userDevision"></label>
            <input type="text" name="userDevision" id="userDevision" /></td>
        </tr>
      </table>
     
    </fieldset>
    </div>


The above code will show the div in browser like below




Tuesday, July 24, 2012

Enabling HTTPS In J2EE Web Applications

If you want to enable HTTPS configuration in your J2EE web application  then you should add the following lines in web.xml file under your WEB-INF folder.

<security-constraint>

            <display-name>MyWebApp</display-name>
           
            <web-resource-collection>
           
                        <web-resource-name>MyWebApp</web-resource-name>
                       
                        <description/>
                       
                        <url-pattern>/*</url-pattern>
                        <http-method>GET</http-method>
                        <http-method>POST</http-method>
            </web-resource-collection>
            <user-data-constraint>
                        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
            </user-data-constraint>
</security-constraint>

this will redirect any attempt to use your application on HTTP to HTTPS.

Monday, July 9, 2012

Can't get basic Hello World Spring MVC project to work , Spring MVC Project , Maven: Failed to retrieve plugin descriptor error

Ok after banging my head with STS for 1 day I finally found the easy way to configure spring mvc project in STS.

 Below is the summary of easy steps to do

1) Download latest STS and install it
2) Configuring JDK and other things is easy so do that along with the wizard
3) Open STS select File --> New --> Other --> Spring Source Tool Suite --> Spring Template project --> Spring MVC Project and follow the Wizard to create a new project
4) Once it's done you will see STS showing you errors in the project code , and that is because the Maven dependencies are not downloaded yet.
5) Right click on the project select  run --> Maven Clean and then right click again on the project select run--> Maven install
If this step shows you error in console while running Maven then you have to do following steps

a) In STS click on windows --> Preferences --> General --> Maven --> Installations --> look at the folder where maven is being installed on my machine it is on

D:\Users\sajjadparacha\Downloads\springsource\apache-maven-3.0.3

b) open the Maven folder and go to conf folder , open settings.xml file and add below proxy setting xml

<proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>userName</username>
      <password>password</password>
      <host>proxy address</host>
      <port>80</port>
    </proxy>   

c) Don't forget to mention your user name , password and proxy address and save the settings.xml file.

6) Now come back to STS , right click on the project and select run --> Maven Clean and then run --> Maven Install . Now if your proxy settings are correct STS should build and install your project correctly and will download all the dependencies.
7) Right Click on your project and select run--> on server and you should see the Hello world page.

I wish this will help some one some day out there :).
Would be happy to have comments if you find it helpful or if you want to suggests any changes.