Follow by Email

Friday, April 5, 2013

org.springframework.expression.spel.SpelEvaluationException: EL1027E:(pos ): Indexing into type


Cause Of Exception

I faced this probleme and found out that a getter method for a field in  my JPA Entity class was not following the proper java bean naming convention , when I was trying to fetch that column in my list page using below Spring MVC code

Code Causing Problem

< table:column label="My Property Label" property="myProperty" id="myclass_myProperty" z="user-managed" / >

Solution

The getter method was defined as getmyProperty() , notice "m" I changed it to getMyProperty() and was able to get rid of this exception.

There could be other causes but for me once I understood the problem the solution was very simple.

Sunday, March 10, 2013

cannot run eclipse on windows 7



I faced a problem today where my eclipse suddenly stopped working.
I was trying to run eclipse on my machine but I saw below alert  

"The Publisher could not be varified are you sure you want to run this software?
Publisher : Unknown Publisher"
 
I press ok and just nothing happens , eclipse didn’t start 
First of all try to run eclipsec.exe file in your eclipse installation folder if you see an error message like below

“Error occurred during initialization of VM java/lang/NoClassDefFoundError: java/lang/Object”

You won’t be able to run eclipse using the eclipse.exe file

Solution

Make sure that you have Jdk1.6 installed on your machine  , open the eclipse.ini file and add “-vm” argument to it like below

-vm

D:\software\jdk1.6.0_20\bin\javaw.exe

Please make sure you replace the path to your javaw.exe file according to the JDK installation at your machine. Now try to run eclipse and you should be able to run it now.

Note :
If you still see the above alert message when you try to start eclipse , try to copy your jdk folder from program files to your  D (or C) drive and update the “-vm” argument in eclipse.ini accordingly.

I was able to run eclipse after doing the above  steps. 

 

 

Friday, January 25, 2013

Benefits Of Going Towards SOA And Avoiding Software Silos


Many Organizations believe in shift of approach from creating individual applications to creating software baskets having many modules inside them integrated with each other.

This is good but I believe we have to take care of some good design principles here which if we don’t we will end up having big silos instead of small ones like we have now.
I believe SOA (Service Oriented Architecture) is the natural choice here, which simply says stop integrating and begin service enabling.
So what does Service enabling your software mean? It means your software should be publishing services which can then be used by any other application in your organization.
Service enabling basically means both , integration and flexibility or reusability.

To understand the concept let’s look into the traditional approach, whenever an application needs data from another application we do one of below things
1.       Directly communicate with the database and get the data from it.
Advantages:
·         It’s quick
·         No need to go through painful process of approvals
·         No need to wait for someone else to provide you the data or to develop something in his application you can use.
Disadvantages
·         Since you are not the owner of this data , and nobody knows that you are using it.The owner may change the data or it’s nature at any time without informing you and you will start getting all sort of errors in your application.
·         Let’s say you applied some business rules on the data which you discussed with the owner of that application you applied the rules in your application. Now in future if the rules change you will have to keep track of where else you are using the same rules and it would become night mare in some cases.
·         The ownership of business rules should be with a proper person/group , but in this case it’s not.
2.       Force the user to open the other application, login again and view the needed information.
a.       What if your user needs more information then shown in that page?
b.      What if they want to see less information? Or wants to add more stuff to the same page?
c.       In many cases you can’t just wait for the project lead of that application to create the page you want.

A much Better Approach:
While designing new Applications
We keep in our mind the service enabling principles , we can easily judge that this functionality of our application can be opened as a service or a web service. And then keep on creating those web services.
Of course we will need to maintain an inventory for those web services in future , but we can even continue  developing web services and then organize those in an inventory in future.
Having Service Inventory will help in easily finding an already written service , organize services in proper categories , finding and approaching the owner of the service. Making sure we don’t redo anything.

What If an application was already developed and now you need to integrate it with other applications
We need to be very careful in these cases , many times reinvention of the wheel (developing whole application from scratch) is not needed , instead you can decide to keep using whatever there is since user is already utilizing the software with almost no problems and do all the new enhancements in a way that where ever you see an integration between two system you don’t integrate you service enable it.
Which simply means instead of writing tightly coupled code between the two applications , write the integration as service open for other systems in future if needed.
See this is the difference , if we decide to go by creating bigger systems integrated all the related modules inside one basket and ignore the service enabling principle we will end up having bigger problems J.
However sometimes based on the requirement it can be decided to rewrite the whole application , and this brings us to another point if the same application was being developed in a way that it had reusable services , re writing the same application will be less painful because you can still reuse a lot of service made for old application.

The below pictures will help us understand Silos and what can happen in future J




 




Friday, December 28, 2012

corejava: File Upload example using spring

corejava: File Upload example using spring: Below is a running example to upload a file using spring , please add the below lone in your application-context file to add CommonsMulti...

Spring Security Implement Logout Handler

In your applicationContext-security.xml file add the success-handler like below
 <logout logout-url="/resources/j_spring_security_logout" success-handler-ref="com.mycompany.security.SpringSecurityLogoutHandler" />

Create the Class which will be implemneting "org.springframework.security.web.authentication.logout.LogoutHandler" interface and in it's logout method do all the stuff you want at the time of logout.

package com.mycompany.security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutHandler;

public class SpringSecurityLogoutHandler implements LogoutHandler {
 @Override
 public void logout(HttpServletRequest request, HttpServletResponse arg1,
   Authentication arg2) {
  // Write your logout logic here
 }
}





Spring MVC file upload example


Below is a running example to upload a file using spring , please add the below lone in your application-context file to add CommonsMultipartResolver


   <bean id="multipartResolver"

        class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>

Write your JSP page like below , Please do add HTML code if you want to run it as a seprate page

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<div  xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:page="urn:jsptagdir:/WEB-INF/tags/form" xmlns:table="urn:jsptagdir:/WEB-INF/tags/form/fields" version="2.0">

         <form id="fileuploadForm" action="fileupload" method="POST" enctype="multipart/form-data" class="cleanform">
          <c:if test="${successfull==Y}">
              <c:out value="File Was Successfully uploaded"></c:out>
          </c:if>
          <label for="file">File</label>
          <input id="file" type="file" name="file" />
          <p><button type="submit">Upload</button></p> 
         </form>
</div>

Write the controller to handle requests related to file upload
package com.aramco.peasd.dbp.web;

import java.io.IOException;
//import org.springframework.mvc.extensions.ajax.AjaxUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping("/fileupload")
public class FileUploadController {
       @ModelAttribute
       public void ajaxAttribute(WebRequest request, Model model) {

//            model.addAttribute("ajaxRequest", AjaxUtils.isAjaxRequest(request));

       }
       @RequestMapping(method=RequestMethod.GET)
       public void fileUploadForm() {
  

       }
       @RequestMapping(method=RequestMethod.POST)
       public String processUpload(@RequestParam MultipartFile file, Model model) throws IOException {
        

              model.addAttribute(  "message", "File '" + file.getOriginalFilename() + "' uploaded successfully");
              model.addAttribute("successfull", "Y");
              //**This byte array can then be sent to any content managment server  to save the file
              byte[] fileByteArray=file.getBytes();
//**Or you may want to save the file using java IO on a folder somewhere in you server             
              return "fileupload/showFileUpload";
//this will render to a page called showFileUpload.jspx
       }
       @RequestMapping(params="fileupload")
       public String showFileUploadPage(){
              return "fileupload/showFileUpload";
       }
}

 

Saturday, December 15, 2012

Deploy JPA2.0 application on weblogic10.3.3



Please note that in order to run your JPA2.0 application on weblogic10.3.3 which is JPA1.0 compliant you will have to rename your persistence.xml  to something like foo.xml and mentione the name of this xml file in your applicationContext.xml as (I am using Spring here )

   <bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
        <property value="classpath:META-INF/foo.xml" name="persistenceXmlLocation"/>
        <property name="persistenceUnitName" value="persistenceUnit"/>
        <property name="dataSource" ref="dataSource"/>
    </bean>


rename the persistenceUnit and dataSource according to the beans you have defined in your application
and you will have to define package exclusions in your weblogic.xml file as
 
 
 
<?xml version="1.0" encoding="UTF-8"?>
    <wls:weblogic-version>10.3.3</wls:weblogic-version>
 <wls:container-descriptor>
  <wls:index-directory-enabled>false</wls:index-directory-enabled>
  <!-- prefer-application-packages> <package-name>javax.persistence.spi.*</package-name>
   </prefer-application-packages -->
  <wls:prefer-application-packages>
   <wls:package-name>antlr.*</wls:package-name>
   <wls:package-name>org.apache.commons.*</wls:package-name>
   <wls:package-name>org.apache.xmlbeans.*</wls:package-name>
   <wls:package-name>org.springframework.*</wls:package-name>
   <wls:package-name>org.hibernate.*</wls:package-name>
 
   <wls:package-name>org.hibernate.validator.*</wls:package-name>
 
   <wls:package-name>javax.persistence.*</wls:package-name>
   <wls:package-name>org.joda.*</wls:package-name>
  </wls:prefer-application-packages>
 </wls:container-descriptor>
</wls:weblogic-web-app>
 

I invested few days to resolve the problem , and sharing the solution hoping it might benefit someone someday.

Below are some related threads I created for this problem , there you will find the details of problems you can face and the recomended solutions , but the solution provided above is working for me now and is gurenteed :).

https://www.coderanch.com/t/598227/Spring/Create-update-operations-ROO-causing

http://www.coderanch.com/t/599976/BEA-Weblogic/Weblogic-load-PersistenceProvider-wrong-jar

http://stackoverflow.com/questions/13806457/weblogic-10-3-3-trying-to-load-org-eclipse-persistence-jpa-persistenceprovider-i/13898999#13898999

https://forums.oracle.com/forums/thread.jspa?threadID=2474374&stqc=true

If you want to understand why we have package exclusions in our weblogic.xml file then below blog will help you alot understanding class loading in weblogic and why we need the package exclusions , I don't want to repeat the same story here , and this guy has written a great blog on it already
http://middlewaremagic.com/weblogic/?p=6725