Weblogic Portal – Configure the Domain Datasource after creating it

You can find a config.xml file on the domain home directory \config. You can find the Data-source as the following XML snippet :

<sec:rdbms-security-store>
        <sec:username>WEBLOGIC</sec:username>
        <sec:password-encrypted>{AES}cfv0KEy9V7T7ML8uC5yBz7i1jQlLfd6ydPXELnN3hwg=</sec:password-encrypted>
        <sec:connection-url>jdbc:oracle:thin:@10.222.105.53:1521:ORCL</sec:connection-url>
        <sec:driver-name>oracle.jdbc.OracleDriver</sec:driver-name>
        <sec:connection-properties>user=WEBLOGIC</sec:connection-properties>
        <sec:jms-topic>p13n.security.RDBMSSecurityStoreTopic</sec:jms-topic>
        <sec:jms-topic-connection-factory>weblogic.jms.ConnectionFactory</sec:jms-topic-connection-factory>
        <sec:jms-exception-reconnect-attempts>15</sec:jms-exception-reconnect-attempts>
        <sec:notification-properties>java.naming.provider.url=t3://10.222.105.52:7003,java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory</sec:notification-properties>
        <sec:name>p13nRDBMSSecurityStore</sec:name>
      </sec:rdbms-security-store>

 

As you see, the password of the DB user is encrypted, but you can modify the following :

  • DB user
  • DB connection URL.
  • Driver.

JDeveloper Speed up Tips

Working on JDeveloper IDE is a nightmare especially when working on Enterprises applications or working on JSPs editing , …

I ‘v searched for tips for speeding it up and prevent it from consuming too much memory and I came out with the list below:

  • Turn off not used extensions, go to menu -> tools -> preferences -> extensions -> uncheck all extensions except “J2EE” (if you work on J2EE only, otherwise leave the technologies you work on).
  • Turn off the automatic file scan that is enabled by default. To do this, go to: Tools | Preferences | Environment and de-select: ‘Automatically Reload Externally Modified Files’ and/or: ‘Verify Project Contents Automatically on Restart’.
  • Configure the JDeveloper Preferences to open files in the Source editor
    by default (Tools | Preferences | File Types, tab Default Editors). The benefit is that you save the time of opening the Design editor if you
    are not going to need it for that particular file.

Or you can switch to Eclipse and install the “Oracle Enterprise Pack for Eclipse” which avails all the oracle technologies in the Eclipse IDE.

How to use OCX in Web, specifiying the version, and install it silently on customer machine

The problem was that our enterprise web application make use of an OCX in native image effects. Maintaining the OCX versions on the clients machines was a nightmare because every time there was a new version of the OCX, every client machine has to install it manually (over about 1000 computers for a customer).

The solution is to include additional attribute in the object HTML tag specifying where the package is and the version needed by the web application.

It worked like this : <OBJECT classid=”clsid:XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX” height=”0″ width=”0″ id=Obj CODEBASE=”../../OCXPack.cab#version=<%=X.X.X.X”>

The CAB file contains the INF file specifying how the OCX shoudl be installed in the system. You can include your installation package (MSI for example) to remove the old version and install the newer version.

 

References for the INf file, check the Packaging ActiveX Controls article on MSDN.

 

How to send Mail using SMTP Protocol in Java without using JDK JavaMail API


import java.io.*;
import java.net.*;

public class SMTPEmail {

private final static int SMTP_PORT = 25;
private final static String MAIL_SERVER = "example.com";
private final static String SENDER_EMAIL = "user1@example.com";
private final static String RECEIVER_EMAIL = "user2@example.com";
private final static String EMAIL_MESSAGE = "This is a test email agent!";

public static void main(String[] args) throws Exception {

Socket socket = null;

try
{

// Establish a TCP connection with the mail server.
socket = new Socket(MAIL_SERVER, SMTP_PORT);

// Create a BufferedReader to read a line at a time.
InputStream is = socket.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);

// Read greeting from the server.
String response = br.readLine();
if (!response.startsWith("220")) {
throw new Exception("220 reply not received from server.");
}

// Get a reference to the socket's output stream.
OutputStream os = socket.getOutputStream();

// Send HELO command and get server response.
String command = "HELO MAIL SERVER\r\n";
os.write(command.getBytes("US-ASCII"));
response = br.readLine();

System.out.println(response);
if (!response.startsWith("250")) {
throw new Exception("250 reply not received from server.");
}
// Send MAIL FROM command.
command = "MAIL FROM "+SENDER_EMAIL+"\r\n";
os.write(command.getBytes("US-ASCII"));
response = br.readLine();

// Send RCPT TO command.
command = "RCPT TO "+RECEIVER_EMAIL+"\r\n";
os.write(command.getBytes("US-ASCII"));
response = br.readLine();

// Send DATA command.
command = "DATA"+"\r\n";
os.write(command.getBytes("US-ASCII"));
response = br.readLine();

// Send message data.
command = EMAIL_MESSAGE+"\r\n";
os.write(command.getBytes("US-ASCII"));

// End with line with a single period.
command = "\r\n."+"\r\n";
os.write(command.getBytes("US-ASCII"));
response = br.readLine();

// Send QUIT command.
command = "QUIT"+"\r\n";
os.write(command.getBytes("US-ASCII"));
response = br.readLine();
}
finally
{
// close the socket
if( socket != null )
socket.close();
}
}
}

How to handle incoming calls in Android : All framework versions

This post demonstrate how to simply handle incoming call event in Android.

To handle incoming call in an android application you need to do the following :

1. Add the permission use android.permission.READ_PHONE_STATE to your application manifest. This enables the application to have permission to listen to the phone state change event.
2. Create your own PhoneStateListener class like this :

PhoneStateListener myCallListener = new PhoneStateListener(){
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
    // the variable incomingNumber holds the number calling.
    // the state variable holds the state of the phone (Ringing, Idle ...)
      switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
          // your logic here, right now the incoming caller is logged.
          Log.e("Incoming_call", incomingNumber+" is calling me ...");
        break;
        default:
        break;
    }
    super.onCallStateChanged(state, incomingNumber);
   }
};

3. Get an instance of TelephonyManager to use :
TelephonyManager phoneManager = (TelephonyManager) this.getSystemService(TELEPHONY_SERVICE);
4. Register your PhoneListner object using the TelephoneManager :
     phoneManager.listen(myCallListener, PhoneStateListener.LISTEN_CALL_STATE);

Generics in Java5

We use collections daily in our code. How we use it ??

// Removes 4-letter words from c. Elements must be strings
static void expurgate(Collection c) {
for (Iterator i = c.iterator(); i.hasNext(); )
if (((String) i.next()).length() == 4)
i.remove();
}
When you take an element out of a Collection, you must cast it to the type of element that is stored in the collection.

What is the issue in this code ?

The code is unsafe. The compiler does not check that your cast is the same as the collection’s type, so the cast can fail at run time. Plus the code is not readable.
Here is the same example modified to use generics:
// Removes the 4-letter words from c
static void expurgate(Collection<String> c) {

for (Iterator<String> i = c.iterator(); i.hasNext(); )
if (i.next().length() == 4)

i.remove();
}
The code using generics is clearer and safer. we have moved part of the specification of the method from a comment to its signature