Wednesday, April 4, 2012

WenLogic: EJB service ERROR: Two classes have the same XML type name

<Apr 4, 2012 3:39:04 PM BDST> <Error> <HTTP> <BEA-101216> <Servlet: "WSEE_SERVLET" 
failed to preload on startup in Web application: "/HelloEjbServiceBean".
javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:164)
at com.sun.xml.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:94)
at com.sun.xml.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:265)
at com.sun.xml.ws.server.EndpointFactory.createSEIModel(EndpointFactory.java:363)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:202)
Truncated. see log file for complete stacktrace

Caused By: java.security.PrivilegedActionException: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException:
1 counts of IllegalAnnotationExceptions
Two classes have the same XML type name ....

This is a common EJB error for the beginners like me..;)...Very often I forget the fact that EJB creates an XML type with the name [METHOD+"Response"] so there should not be any bean for service request/response with  this name.

Monday, February 20, 2012

WebLogic ERROR: No credential mapper entry found for password indirection

To solve this error follow the steps bellow..

1. Disable following flag form JDev -> application property -> deployment
Uncheck "Auto Generate and Synchronize weblogic-jdbc.xml..."

2. Carefully put the jta-data-source name in your persistence.xml.
<jta-data-source>jdbc/hello_ds</jta-data-source>
<properties>
      <property name="eclipselink.target-server" value="WebLogic_10"/>
      <property name="javax.persistence.jtaDataSource"
                value="jdbc/hello_ds"/>
</properties>
Best way to ensure this is by modifying the EAR archive.

3. Create a data source into your server and put the exact JNDI name as your jta-data-source name.

Wednesday, February 15, 2012

Spring 3 : Servlet Context and other Context beans.

Here I will try to explain following question about ServletContext and Other Context beans in a spring application.

1. Why do we need a ServletContext?
2. Why do we need an ApplicationContext?
3. Do we need them both in a spring 3 application?
4. Most Common use of a ServletContext.
5. Most Common use of an ApplicationContext.

ServletContext:
For any spring application a servlet context is must which we define in spring-servlet.xml or myapp-servlet.xml file. When a servlet starts it looks for its context definition and load the context. Most of the cases we define following components in a servlet context.

<!-- Notify the servlet to load the components using annotation, 
for example '@controller' -->
<mvc:annotation-driven/>

<!-- Load the beans/controllers into context from base-package and 
Map requests from '@RequestMapping' annotation. -->
<context:component-scan base-package="com.mycompany.helloSpring3.web" />

<!-- This defination is used to create ModelAndView object by servlet. -->
<bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass"
            value="org.springframework.web.servlet.view.JstlView" />
        <property name="prefix" value="/WEB-INF/jsp/" />
        <property name="suffix" value=".jsp" />
</bean>
ApplicationContext:
This is an optional Context. In fact there may multiple context files in an application as per need. Usually we put the dataSource related definitions in this file.

Note: If we need to use additional Context files along with the ServletContext, In that case we need to tell our servlet-descriptor(web.xml) to load them with a ContextLoaderListener.
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/*Context.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Sunday, January 29, 2012

WebLogic Error: java.lang.ClassNotFoundException: oracle.security.jps.wls.listeners.JpsApplicationLifecycleListener

If I try to deploy an EJB service application on WebLogic 10.3, I get following error message.
java.lang.ClassNotFoundException: oracle.security.jps.wls.listeners.JpsApplicationLifecycleListener
Reason: JDeveloper deployment wizard assumes any EJB application will have jsp pages so it adds JSP listeners declaration. But if we do not use jsp then we don't need the ADF faces libraries integrated.
Here is the solution of this problem.
Modify following xml file inside the EAR archive using archive manager.
/META-INF/weblogic-application.xml
Remove following declarations from the xml.
<listener>
    <listener-class>oracle.security.jps.wls.listeners.JpsApplicationLifecycleListener</listener-class>
</listener>
<listener>
    <listener-class>oracle.security.jps.wls.listeners.JpsAppVersionLifecycleListener</listener-class>
</listener>

Wednesday, January 25, 2012

Android SQLite database performance improvement for inserting rows.

I was trying to insert 2000 rows into a SQLite table and following code took almost 30s in emulator and few minuets on device which of course varies.
/* db helper class */
public void insert(ContentValues cv) throws RuntimeException{
    db.insert("my_table", null, cv);
}


/* activity class*/
while(for each rows)
  insert(data);
After handling the transaction manually for all the rows at a time the performance improved drastically and here is the code.
public void insert(List dataArr) throws RuntimeException{
    db.beginTransaction();
    for(int i=0, j=dataArr.size(); i<j; i++) {
        ContentValues cv = (ContentValues)dataArr.get(i);
        db.insert("my_table", null, cv);
    }
    db.setTransactionSuccessful();
    db.endTransaction();
}

Getting data from URL in java

public String getDataFromURL(String urlStr) throws Exception {
   URL url = new URL(urlStr);
   URLConnection urlCon = url.openConnection();
   BufferedReader in = new BufferedReader(
                           new InputStreamReader(
                           urlCon.getInputStream()));
   String data = "";
   String line = "";
        
   while ((line = in.readLine()) != null)
          data += line;

   in.close();
   return data;
}

Parsing JSON data in java

public void parseJSONObject(String jsonData) throws Exception {
    JSONTokener jsonTokener = new JSONTokener(jsonData);
    JSONObject object = (JSONObject) jsonTokener.nextValue();
    object.getString("id");
}

public void parseJSONArray(String jsonData) throws Exception {
    JSONTokener jsonTokener = new JSONTokener(jsonData);
    JSONArray arr = (JSONArray) jsonTokener.nextValue();
    for(int i=0, j=arr.length(); i < j; i++) { 
        JSONObject object = arr.getJSONObject(i);
        ...
    }
}