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);
        ...
    }
}

Monday, January 9, 2012

WebLogic server domain creation

Goto WebLogic server home directory
in my case
/home/shamim/Oracle/Middleware/wlserver_10.3
Run
./common/bin/config.sh
Type [1] to choose Create a new WebLogic domain
Type [1] to Choose Weblogic Platform components. You can also choose [2] the custom template option.
Application Template Selection:
In my case I want deploy EJB service beans on webLogic server so I choose Basic WebLogic Server Domain and Type [Next]
Edit Domain Information:
the default domain name is 'base_domain' you can change the name or type [Next]
Select the target domain directory for this domain:
you can change the location or type [Next] to use default one.
Configure Administrator User Name and Password:
The default user name for Administrator user is 'weblogic'. Type [1] to change this or not.
Type [2] to set "User password". Minimum length of the password should be 8. This password will be used to login into console.
Type [3] to confirm password.
Type [Next]
Domain Mode Configuration:
Type [1] for Development Mode which dose not include some security features.
Java SDK Selection:
You should see a list of available JDK and choose one from them.
Select Optional Configuration:
Type [1] because if you have only one server it should be the Administration Server.
Configure the Administration Server:
...
Remember the port number and type [Next] if you don't like to change it.

In few seconds domain creation should be completed. And you will find the server instance ready for use into server domain. in my case [/home/shamim/Oracle/Middleware/user_projects/domains/ejb_services] this is the admin server home.
Following command will start the server.
./bin/startWebLogic.sh
Console url
http://localhost:7001/console

WebLogic server installation guide for Debian 6 (64-bit)

Download Web Logic Server from:

1. Weblogic server Installers from here
OR
2. JDevStudio which includes JDeveloper IDE and WebLogic Server, download.

Run The installer:
    In my case [./jdevstudio11113install.bin]
    You should see this message
    [Unable to instantiate GUI, defaulting to console mode.]
    Type [Next]

Choose Oracle Middleware Home Directory:
    You can change the default home dir or not.

Choose Install Type:
    For Complete installation type [1]
    For custom installation type [2] in this case you add/remove components from installation

Confirm Product Installation Directories:
    Remember the server home directory and type [Next].

The following Products will be installed:
    ...
    Type [Next]

Installation should start and complete in few moments and we not done yet. To start the WebLogic server we need to create an instance first. It is called domain which creates an instance of the server for use. You can see more information about domain from here. Please see my next post for creating an WebLogic domain.

Sunday, January 8, 2012

iPhone like segment-control button for Android


This implementation of segment buttons for android is based on custom styled button. Here four button styles are used for button's state and position changes. And With a few tweaks you can add more buttons to the group.
Activity Code:
offlineBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
onlineFlag = 0;
offlineBtn.setBackgroundResource(R.drawable.segment_button_left_on);
onlineBtn.setBackgroundResource(R.drawable.segment_button_right);
}
});

onlineBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
onlineFlag = 1;
offlineBtn.setBackgroundResource(R.drawable.segment_button_left);
onlineBtn.setBackgroundResource(R.drawable.segment_button_right_on);
}
});

Layout(View) File:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"  android:layout_height="wrap_content"    
    android:layout_marginTop="0dip"  android:layout_marginBottom="0dip" 
    android:orientation="horizontal" android:baselineAligned="false">
        <Button android:id="@+id/offline_button" 
        android:layout_height="wrap_content" 
        android:text="Offline" android:textColor="#ffffff"    
                android:textSize="13dip" android:singleLine="true"
        android:background="@drawable/segment_button_left_on"
        android:layout_marginTop="5dp" android:layout_width="wrap_content">
        </Button>
        <Button android:id="@+id/online_button" 
        android:layout_height="wrap_content" 
        android:text="Online" android:textColor="#ffffff"    
                android:textSize="13dip" android:singleLine="true"
        android:background="@drawable/segment_button_right"
        android:layout_marginTop="5dp" android:layout_width="wrap_content">
        </Button>
</LinearLayout>

res/drawable-hdpi/segment_button_left_on.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_focused="true" >
<shape>
<gradient
android:endColor="#7E3117" android:startColor="#7E3817"
android:angle="270" />
<stroke android:width="1dp" android:color="#646060" />
<corners android:topLeftRadius="6dp" android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="6dp" android:topRightRadius="0.1dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>

<item>
<shape>
<gradient
android:startColor="#99009900" android:endColor="#FF009900"
android:angle="270" />
<stroke android:width="0.5dp" android:color="#646060" />
<corners android:topLeftRadius="6dp" android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="6dp" android:topRightRadius="0.1dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>
</selector>

res/drawable-hdpi/segment_button_left.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_focused="true" >
<shape>
<gradient
android:endColor="#7E3117" android:startColor="#7E3817"
android:angle="270" />
<stroke android:width="1dp" android:color="#646060" />
<corners android:topLeftRadius="6dp" android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="6dp" android:topRightRadius="0.1dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>

<item>
<shape>
<gradient
android:startColor="#991A1111" android:endColor="#991A1111"
android:angle="270" />
<stroke android:width="0.5dp" android:color="#646060" />
<corners android:topLeftRadius="6dp" android:bottomLeftRadius="0.1dp"
android:bottomRightRadius="6dp" android:topRightRadius="0.1dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>
</selector>

res/drawable-hdpi/segment_button_right_on.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_focused="true" >
<shape>
<gradient
android:endColor="#7E3117" android:startColor="#7E3817"
android:angle="270" />
<stroke android:width="1dp" android:color="#646060" />
<corners android:topLeftRadius="0.1dp" android:bottomLeftRadius="6dp"
android:bottomRightRadius="0.1dp" android:topRightRadius="6dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>

<item>
<shape>
<gradient
android:startColor="#99009900" android:endColor="#FF009900"
android:angle="270" />
<stroke android:width="0.5dp" android:color="#646060" />
<corners android:topLeftRadius="0.1dp" android:bottomLeftRadius="6dp"
android:bottomRightRadius="0.1dp" android:topRightRadius="6dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>
</selector>

res/drawable-hdpi/segment_button_right.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">

<item android:state_focused="true" >
<shape>
<gradient
android:endColor="#7E3117" android:startColor="#7E3817"
android:angle="270" />
<stroke android:width="1dp" android:color="#646060" />
<corners android:topLeftRadius="0.1dp" android:bottomLeftRadius="6dp"
android:bottomRightRadius="0.1dp" android:topRightRadius="6dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>

<item>
<shape>
<gradient
android:startColor="#991A1111" android:endColor="#991A1111"
android:angle="270" />
<stroke android:width="0.5dp" android:color="#646060" />
<corners android:topLeftRadius="0.1dp" android:bottomLeftRadius="6dp"
android:bottomRightRadius="0.1dp" android:topRightRadius="6dp"/>
<padding
android:left="7dp" android:top="7dp"
android:right="7dp" android:bottom="7dp" />
</shape>
</item>
</selector>