Showing posts with label websphere. Show all posts
Showing posts with label websphere. Show all posts

Wednesday, July 12, 2017

Get connection pool usage in WebSphere

./wsadmin.sh -f test.jy -lang jython -port 8879 >> log.txt

Contents of test.jy will be

objectName=AdminControl.queryNames("*:type=DataSource,*")
templateArray=objectName.split('\n')
for object in templateArray: print AdminControl.invoke(object,'showPoolContents')

Now log.txt will contain the connection pool information for all the datasources.

This may be very useful when you want to know the connection pool usage of datasources.

 Usually , you will have security enabled  in your environment. In those cases, give the username and password fields as below.

 ./wsadmin.sh -f test.jy -lang jython -port 8879 -username admin -password password >> log.txt

 Otherwise  , you may keep checking the log.txt to see for any prompts . If there is any prompt for certificate acceptance or username, password.
Then you give the values accordingly on the prompt and connection pool datasource log will be generated after that.

Tuesday, January 31, 2017

Create first hibernate project

Create a Java Project



Click Next and Finish


Right Click the project and create new folder lib


Download hibernate with all dependencies  from the below link



And copy paste to the lib folder


Create a new Java Package


Create a new Class


We have a table login with two columns

Accordingly that
We write the following code in aHibClass.java
package aHibPackage;

public class aHibClass {

   private String UserId;
   private String Password;
   
   public String getUserId()
   {
   return UserId;
   }
   public void setUserId(String UserId)
   {
   this.UserId=UserId;
   }
   public String getPassword()
   {
   return Password;
   }
   public void setPassword(String Password)
   {
   this.Password=Password;
   }

The file aHibClass.class is also referred to as persistence class file .
   
Right Click the package , create a new file login.hbm.xml and click finish




The file login.hbm.xml is also referred to as mapping file .
In the mapping file , we have mentioned about the table and its columns . The id tag is used for the column which is the primary key and rest of the columns are referred as property.

Now , we will create the configuration file .

Right click the src under the project and create a new file hibernate.cfg.xml  with the contents as below
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@localhost:1521:bph
ashish
password
org.hibernate.dialect.Oracle10gDialect
false
false
update




create .If we are assigning this value as create,it will create table in database automatically when we run the application.

Download the Oracle  JDBC driver jar file and add it to the build path of the project for the driver class file.


Now , we create the test class that inserts the record
HibTest with the main method

package aHibPackage;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class HibTest {
public static void main(String[] args) {
       Configuration cfg = new Configuration();
         cfg.configure("hibernate.cfg.xml");
         SessionFactory factory = cfg.buildSessionFactory();
        Session session = factory.openSession();
        aHibClass login = new aHibClass();
        login.setUserId("Ashish1");
        login.setPassword("Password2");
         Transaction tx = session.beginTransaction();
           session.save(login);
            tx.commit();
           session.close();
           factory.close();
           System.out.println("Objectis  saved successfully");
   }

}

Right click the project and make sure all the jars added earlier into lib folder are present in the build path of the project. If not , add them manually.


Getting the error
The type java.lang.AutoCloseable cannot be resolved. It is indirectly referenced from required .class files   .



Added an alternate JRE System Library (JDK 1.7.0_80) as my default JRE System library seemed to be out of date







Getting the error

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/hibernate/cfg/Configuration : Unsupported major.minor version 52.0
   at java.lang.ClassLoader.defineClass1(Native Method)
   at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
   at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
   at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
   at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
   at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
   at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:358)



Downloaded the jdk 1.8 version and added it to the project build path .

Final build path looks as below
Earlier , I have removed the JBoss related jars but I have to add them later as I was getting few Class Not Found exceptions .


Now , we can run HibTest.java as a Java application and test the Sample Hibernate Java code.

This code is simpler in a way than EJB as in EJB , we have to define objects mapped to database also in a java class file whereas here we have the mapping in a xml file .


Hibernate is perfectly suited for creating mapping files . Later , we can use either Hibernate or J2EE ( EJB session beans ) to include logic and DML statements.









Wednesday, September 7, 2016

Disabling WebSphere administrative security

Earlier I used to go to 
WAS_INSTALL_DIR/profiles/PROFILE_NAME/config/cells/CELLNAME/
and vi the security.xml , search for first string enabled and make enabled="false"
Now, there is no need to edit the security.xml to disable security .

You can just follow the below procedure.
cd WAS_INSTALL_DIR/profiles/PROFILE_NAME/bin/

If you have multiple profiles , then its necessary to run wsadmin.sh from the profile where you want to disable the security.

./wsadmin.sh -conntype NONE
wsadmin> securityoff 
wsadmin>  exit 
Restart the servers.

Sunday, December 13, 2015

Cleaning up the EJBTimers DB


WebSphere will use an internal derby database for EJBTimers to persist .
The ejbtimers will survive the server crash as well as server restart as they are persisted in database.
EJB Timer service settings can be changed via the WebSphere console. The description for settings can be easily found in the IBM knowledge center. 
Below is one of the links for WebSphere 8.5.5
EJBTimer can also be easily configured to persist in a different database like oracle. What we need to define is just a different DataSource with an authentication alias. While server is restarted , WebSphere will automatically create the 4 tables required by EJBTimer service. You may use any DataSource available as EJBTimer tables will not interfere with other schema and table’s .You can also define a prefix for the EJBTimer tables in the EJBTimer service settings. Make sure to have the create table permission for authentication alias you are using.
There are also some other important parameters for EJBTimer like poll interval, number of timer threads which can be used to customize the behavior of EJBTimer as per your requirements.
In case, you are using the default EJBTimer DB which is derby. Then, how can you clean the DB. This is an unanswered question in IBM knowledge center.
The procedure is simple which I have found by trial and error methods.
Stop the server. This server is the server for which you are planning to clean the EJBTimer db.
Go to
WAS_INSTALL_ROOT/profiles/Profile Name/databases/EJBTimers/Server Name/EJBTimerDB
and rename the existing directory EJBTimerDB to  EJBTimerDB_bak.
Later you can remove this directory after few days of testing. I am recommending this as this is a solution I found by trial and error and there is no official documentation for it.
Start the server.
You can verify that after server is restarted, a new directory EJBTimerDB is created
Location of an example directory on windows operating system is shown below.
I have tested the proposed solution in Solaris as well as windows operating system.