Showing posts with label J2EE. Show all posts
Showing posts with label J2EE. Show all posts

Friday, January 6, 2012

How to apply XSLT translation on an input xml using java.xml.transform apis


Almost all applications that deal with XML will have the necessity to transform the xml from one form to another. XSLT (XML Style Sheet Language Transformations) is one of the most popular ways of defining the transformations for XML document.

A transformation defined in XSLT describes rules for transforming a source xml into a result xml. The result XML can be of a completely different structure of that of the source XML. The transformation is achieved by associating patterns with templates. A pattern is matched against elements in the source XML. The result XML is constructed from the source XML by filtering, reordering and/or by adding arbitrary structures using the data from the source xml

Let us take an example and discuss how we can apply an xslt translation on an xml file using Java XML transformation APIs



Wednesday, January 4, 2012

How to execute the XSLT functions as a part of XPath expressions in Java using Xalan parser

Executing XPath is a very common requirement in Java applications that deal with XML data. When there is a decision making requirement based on multiple data records, spanned across the xml document, it would be more efficient to use XSLT functions to extract information, than to parse and navigate the xml document back and forth.

XSLT includes several functions that help users extract information from XML data. It consists of many string, date and time, sequence manipulation, qname manipulation, aggregation and mathematical functions. Few of the most popular functions are given below


Sunday, April 3, 2011

java.io.IOException: FATAL ERRORS encountered by WSDL2Java tool

We will discuss how to resolve the below error message in Rational Application Developer (RAD) when you start the WebSphere Application Server


Error messages were issued.
java.io.IOException: FATAL ERRORS encountered by WSDL2Java tool.
at com.ibm.ws.webservices.wsdl.Parser.generate(Unknown Source)
at com.ibm.ws.webservices.wsdl.Parser.generate(Unknown Source)
at com.ibm.ws.webservices.tools.wsad.WSDL2Java._execute(Unknown Source)
at com.ibm.ws.webservices.tools.wsad.WSDL2JavaBase.execute(Unknown Source)
at com.ibm.etools.webservice.command.adapter.CommandToCommand.execute(Unknown Source)
at com.ibm.ast.ws.v7.jaxrpc.jee5.stub.WSDeployStub.execute(Unknown Source)
at sun.reflect.GeneratedMethodAccessor96.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)


In WebSphere Application Server, when you deploy or publish an application, it uses the WSDL files and generates the serializer and deserializer, even if it was already generated as a part of the proxies. This error message indicates that the WSDL file was either corrupted or not contains XSDs that does not match up. 


If you have your WSDLs changed recently, there could be chances that the server cache still has old WSDLs. We will discuss how to get rid of this error. Please follow the below steps

Sunday, March 6, 2011

Monday, January 10, 2011

How to display Arraylist elements in a grid view in JSF

I recently came across a problem where I had to display elements of an ArrayList on a JSF page, in a table. I use Tomahawk JSF implementation. After some struggle, I was able to do it as given below


Let us take an example.
In my page bean I have an ArrayList having the below String elements


List listOfObjs = new ArrayList();
listOfObjs.add(“Data1”);
listOfObjs.add(“Data2”);
listOfObjs.add(“Data3”);
listOfObjs.add(“Data4”);
listOfObjs.add(“Data5”);
listOfObjs.add(“Data6”);


I wanted to display this in a table having 5 columns


Data1   Data2   Data3   Data4   Data5
Data6


Let us see how we can do this..

Saturday, January 1, 2011

How to serialize and de-serialize CGLIB proxy objects across JVM

Most of us know how to serialize and de-serialize normal Java objects. Make the class implement the marker interface Serializable and invoke the writeObject/readObject methods, and it just works. It is pretty easy and straight forward. Even if serialization and de-serialization happens in two different JVMs, for normal java objects it is easy, because as long as you have the class definition available in both the JVM, it just works fine, without any additional work.

But the situation is a bit different for CGLIB proxy objects. Serializing and de-serializing CGLIB proxy objects across JVMs must be done in a different way. The main challenge with CGLIB proxy objects are that the proxy class itself is created during runtime, and therefore, even if we serialize it perfectly from one JVM, another JVM has no clue what the class is and therefore, the de-serialization will fail. Most people using Spring AOP in a clustered server environment might have come across the issue where CGLIB proxy objects which are created at runtime in one node could not be re-loaded in another node during a failover.

We will discuss one method using which we can successfully recreate CGLIB proxy objects across different JVM. We are assuming that the class being proxied and the logic to create the proxy object are available in both JVMs.

How to operate on another session using a session id in a J2EE application

Many times there could be a situation where, we need to obtain another session object using just the session id and invalidate/operate on that session. There is no standard way mentioned in the J2EE specs to achieve this, but we will discuss an alternate solution to this problem.

The solution we are discussing is built using a servlet. We will create a dedicated servlet which performs the action we want to perform on the "looked up" session. Then we will originate a call from within the server to this new servlet by programmatically setting the session id into the request header.


Let us see in detail. 


Tuesday, November 23, 2010

How to invoke static methods in Spring?

We can invoke static methods in Spring by using MethodInvokingFactoryBeanThis is a factoryBean which returns a value which is the result of a static or instance method invocation. To use this bean, you define the bean in the application context xml and configure three properties


1) targetClass - this is the class on which the static method need to be invoked
2) targetMethod - this is the name of the static method
3) arguments - you can list the arguments passed to the static method as parameters


The example below is taken from the Spring API reference. 

Friday, November 19, 2010

Calling response.sendRedirect creating an IllegalStateException in the JSF backing bean

This happens when you have response.sendRedirect(xxx) after the facesContext.responseComplete()
The right way to do is
 try {
         response.sendRedirect(“/ctxRoot/redirect.jsp”);
  }catch (IOException ioex) {
      ioex.printStackTrace();
 }
 FacesContext ctx = FacesContext.getCurrentInstance();
 ctx.getExternalContext().responseComplete();
 if (ctx.getViewRoot() != null) {                   
 //this step will clear any queued events
        ctx.getViewRoot().processDecodes(ctx);
 }

Wednesday, September 29, 2010

java.lang.IllegalArgumentException: Property Editor not registered with the PropertyEditorManager

If you are getting the below error message:

Caused by: com.ibm.ws.jsp.JspCoreException: Unable to convert string 'NOTBLANK' to class javax.el.ValueExpression for attribute validatorId: java.lang.IllegalArgumentException: Property Editor not registered with the PropertyEditorManager
 at org.apache.jasper.runtime.JspRuntimeLibrary.getValueFromPropertyEditorManager(JspRuntimeLibrary.java:939)
 at com.ibm._jsp._searchSummary._jspx_meth_h_selectOneMenu_7
 at com.ibm._jsp._searchSummary._jspx_meth_h_panelGroup_28
 at com.ibm._jsp._searchSummary._jspx_meth_h_panelGrid_42
 at com.ibm._jsp._searchSummary._jspx_meth_t_div_7




This error message is mainly caused because of incompatibilities between different versions of JSF. Try any or a combination of the below steps

Wednesday, September 22, 2010

Websphere 7.0 Cannot load XSL files from com.ibm.ws.runtime.jar

WebSphere 7.0 Cannot load XSL files from com.ibm.ws.runtime.jar


If you are seeing the below error when WebSphere server is started

Cannot load XSL files from <install_root>/plugins/com.ibm.ws.runtime.jar
This error is displayed because during server startup some WAS Product APIs are called to retrieve product version information. The xsl files are required in order for those APIs to work properly.


This issue is fixed in fixpack 7.0.0.1

To install fix pack follow the below steps

Blog Archive