Friday Dec 27, 2013

How to Connect to WebLogic DataSource from a Java Client?

Some time ago, one of my customers had issues connecting from a client to a WebLogic Datasource.
I provided the sample code to try the functionality, here are the steps:

1. Save the code below as DataSourceClient.java in /myfolder

import java.sql.*;
import javax.sql.DataSource;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.*;
import java.io.*;
import oracle.jdbc.OracleConnection;

public class DataSourceClient {
  public static void main(String [] args) {
    OracleConnection conn=null;
    javax.sql.DataSource ds=null;
    Hashtable env = new Hashtable();
    env.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
    env.put(Context.PROVIDER_URL, "t3://localhost:7001");

    try{
      Context context=new InitialContext( env );
      //you will need to have create a Data Source with JNDI name testDS
      ds=(javax.sql.DataSource) context.lookup ("testDS");
      conn=(OracleConnection) ds.getConnection();
      java.util.Properties prop = new java.util.Properties();
      System.out.println("Connection object details : "+conn);
      conn.close();
    }catch(Exception ex){
      //handle the exception
      ex.printStackTrace();
    }
  }
}


2. Modify PROVIDER_URL if needed. The value is set to t3://localhost:7001
3. Add to WebLogic Server JAVA_OPTIONS -Dweblogic.jdbc.remoteEnabled=true
4. Start WebLogic Server
5. Open a UNIX console. In the same console run:
    i. cd <domain>/bin
    ii. . ./setDomainEnv.sh (Notice the '.' before './setDomainEnv.sh')
    iii. CLASSPATH="/myfolder:${CLASSPATH}"
    iv   cd /myfolder
    v.   javac DataSourceClient.java
    vi.  java DataSourceClient


If you succeeed, you will see something like this:

Connection object details : weblogic.jdbc.rmi.SerialConnection_weblogic_jdbc_rmi_internal_ConnectionImpl_weblogic_jdbc_wrapper_JTAConnection_weblogic_jdbc_wrapper_XAConnection_oracle_jdbc_driver_Logic
alConnection_1036_WLStub@1       

This means, you sucessfully connected to your WLS Datasource.

Do you need further help?

Please check WebLogic Documentation:
http://docs.oracle.com/cd/E23943_01/web.1111/e13726/programming.htm

Tuesday Dec 17, 2013

How to review a FileStore?

You might be interested in reviewing what is inside your FileStore, below is shown a good way to start with it.

First of all, we need to create the environment:
1. Create a Persistent  Store (FileStore) FileStore-0
2. Create JMS server target to manage server MS1, persistent Store FileStore-0
3. Create a JMS Module target to  MS1
4. Create a Connection factory JNDI name: CF  (default targeting)
5. Create a Queue JNDI name Queue-0  (subdeployment target to the JMS server)
6. Restart Managed Server


Then, lets add some messages to your queue:
1. Add QueueSend to classpath
   set CLASSPATH=C:\jms\queue send transaction;%CLASSPATH%
2. <wls_domain>/bin/. ./setDonmainEnv.sh
3. java QueueSendTX t3://localhost:7003 QueuePS1 ConnectionFactoryPS1

Finally, lets dump the FileStore to a xml file, make sure your MS1 is stopped and then execute:

1. java weblogic.store.Admin
2. openfile -store FileStore-0
3. dump -store FileStore-0 -out MyStore.xml -conn -deep
4. close -store FileStore-0
5. quit

Below you can see,
QueueSendTX.java: source code of QueueSendTX.java.
beforeConsumption.xml: is the dump when I added 9 messages to my Queue.
consumed.xml: is the dump after messages were removed from the queue.


https://blogs.oracle.com/LuzMestre/resource/QueueSendTX.java
https://blogs.oracle.com/LuzMestre/resource/beforeConsumption.xml
https://blogs.oracle.com/LuzMestre/resource/consumed.xml

Enjoy!
About


My name is Luz Mestre. I work as Principal Technical Support Engineer at Oracle Support. I'll post here the most interesting challenges I have in my daily work. The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Search

Categories
Archives
« December 2013 »
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
18
19
20
21
22
23
24
25
26
28
29
30
31
    
       
Today