Tuesday, April 10, 2018

08 - How to create WAR file to track DS session and WEB session


1.  Creating WAR file to track DB session and WEB session
Follow the below steps to create WAR file for Jboss JVM

[jbadm@jb02 ~]$ mkdir /tmp/SRIEARV3.0 ; cd /tmp/SRIEARV3.0

[jbadm@jb02 SRIEARV3.0]$ mkdir -p META-INF WEB-INF/classes WEB-INF/lib

Create /tmp/SRIEARV3.0/index.html with following content

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>INDEX.html</title>
<meta http-equiv="Refresh" content="0;url=sessionTest.jsp">
</head>
<body>

</body>
</html>

Create /tmp/SRIEARV3.0/META-INF/MANIFEST.MF with following content

Manifest-Version: 1.0
Created-By: 1.7.0_79 (Oracle Corporation)

Create /tmp/SRIEARV3.0/WEB-INF/jboss-web.xml with following content
<jboss-web>

  <replication-config>
  <!--
   Possible Values:
     ACCESS
     SET_AND_GET
     SET_AND_NON_PRIMITIVE_GET
     SET
  -->
      <replication-trigger>SET_AND_NON_PRIMITIVE_GET</replication-trigger>

   <!--
   Possible Values:
     SESSION
     ATTRIBUTE
     FIELD
  -->
      <replication-granularity>SESSION</replication-granularity>
   </replication-config>
</jboss-web>

Create /tmp/SRIEARV3.0/WEB-INF/web.xml with following content

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <distributable/>
  <display-name>cluster-test</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Create /tmp/SRIEARV3.0/sayhi2sri.jsp with the following content

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%!
String message = "Hello and Welcome to Sri NGEN LABs JBoss world";
%>
<body>
<h1><i><%= message%></i></h1>
<%= new java.util.Date() %>
</body>

<p> <font face="verdana" color="blue" size="3"> Sri NGEN Jboss World's - <u>contact</u> me on <i>email</i> at <b> S R I K A N T . A N D E @ G M A I L . C O M </b> or <i>WhatsApp/call</i> <b> + 9 1 - 9 7 6 6 5 2 5 3 1 3 !!!!!</font></p>
<p> <font face="verdana" color="blue" size="3"> Sri NGEN Jboss World's - <u>Follow</u> me on <i>blog</i> at <b> <a href="https://ngen-sri.blogspot.in"> ngen-sri.blogspot.in</a> </b> or <i>Linkedin</i> <b><a href="https://www.linkedin.com/in/srikant-swamy-ande-080383"> www.linkedin.com/in/srikant-swamy-ande-080383</a> !!!!!</font></p>

<p> <font face="verdana" color="blue" size="2"> Sri NGEN Jboss World's - Following are <b>DB Session </b>info !!!!!</font></p>

<%@page import="java.util.*, java.lang.reflect.*, javax.servlet.http.HttpSession, javax.naming.*, javax.sql.DataSource, java.sql.*"%>

<%

  DataSource ds = null;
  Connection con = null;
  DatabaseMetaData dmd = null;
  PreparedStatement pr = null;
  InitialContext ic;
  try {
  ic = new InitialContext();
  ds = (DataSource)ic.lookup( "java:jboss/datasources/SrioraclexeDS" );
  out.println("***** The DefaultDS DataSource is *****"+ds.toString());
  con = ds.getConnection();

  out.println("***** The Connection is *****"+con.toString());

  dmd=con.getMetaData();

  String databaseName=dmd.getDatabaseProductName();

  out.println("You have connected to=="+databaseName);

  }catch(Exception e){
  out.println("Exception thrown " +e);
  }finally{
  if(con != null){
  con.close();
 }
 } %>

<%
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
 String cPath = request.getContextPath();
 String sPath = request.getServletPath();
 String nodeId = System.getProperty("jboss.node.name");
 String hostName = System.getProperty("jboss.server.name");
 String hostOSname = System.getProperty("os.name");
 String hostOSarch = System.getProperty("os.arch");
 String hostOSversion = System.getProperty("os.version");
 String hostJAVAversion = System.getProperty("java.version");
 String hostJAVAvendor = System.getProperty("java.vendor");
 String hostJAVAvmName = System.getProperty("java.vm.name");
 String hostJAVAvmVersion = System.getProperty("java.vm.version");
 String hostJAVAvmVendor = System.getProperty("java.vm.vendor");

 String variableString = (String)session.getAttribute("SESSION_TEST_VARIABLE");
 int count = 0;

  if(variableString != null)
 {
  count = Integer.parseInt(variableString);
  count++;
 }

  session.setAttribute("SESSION_TEST_VARIABLE", String.valueOf(count));
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sri - NGEN LAB - Session Test</title>
</head>
<p> <font face="verdana" color="blue" size="2"> Sri NGEN Jboss World's - Following are <b>WEB Session </b>info !!!!!</font></p>
<body bgcolor=white>
  <table columns=1>

  </table>
  <table columns=2>
 <tr><td><font color=blue>The sessionId is:  </font></td><td><%=session.getId() %></td>
 <tr><td><font color=blue>The sessionObj is:   </font></td><td><%=session %></td>
 <tr><td><font color=blue>The nodeId is:  </font></td><td><%=nodeId %></td>
 <tr><td><font color=blue>The server hostName is:  </font></td><td><%=hostName %></td>
 <tr><td><font color=blue>The server hostOSname is:  </font></td><td><%=hostOSname %></td>
 <tr><td><font color=blue>The server hostOSarch is:  </font></td><td><%=hostOSarch %></td>
 <tr><td><font color=blue>The server hostOSversion is:  </font></td><td><%=hostOSversion %></td>
 <tr><td><font color=blue>The server hostJAVAversion is:  </font></td><td><%=hostJAVAversion %></td>
 <tr><td><font color=blue>The server hostJAVAvendor is:  </font></td><td><%=hostJAVAvendor %></td>
 <tr><td><font color=blue>The server hostJAVAvmName is:  </font></td><td><%=hostJAVAvmName %></td>
 <tr><td><font color=blue>The server hostJAVAvmVersion is:  </font></td><td><%=hostJAVAvmVersion %></td>
 <tr><td><font color=blue>The server hostJAVAvmVendor is:  </font></td><td><%=hostJAVAvmVendor %></td>
 <tr><td><font color=blue># of requests placed on session:  </font></td><td><%=count %></td>
  </table>
</body>
</html>


In above content at phrase “ds = (DataSource)ic.lookup( "java:jboss/datasources/SrioraclexeDS" );”,  java:jboss/datasources/SrioraclexeDS” is DB DataSource Name.

Compile all content as WAR file which we can use in Jboss LABS.

[jbadm@jb02 SRIEARV3.0]$ /usr/java/jdk1.7.0_79/bin/jar -cvf SRIEARV3.0.war index.html META-INF sayhi2sri.jsp WEB-INF
added manifest
adding: index.html(in = 170) (out= 136)(deflated 20%)
ignoring entry META-INF/
ignoring entry META-INF/MANIFEST.MF
adding: sayhi2sri.jsp(in = 3963) (out= 1304)(deflated 67%)
adding: WEB-INF/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/lib/(in = 0) (out= 0)(stored 0%)
adding: WEB-INF/web.xml(in = 663) (out= 265)(deflated 60%)
adding: WEB-INF/jboss-web.xml(in = 389) (out= 178)(deflated 54%)
adding: WEB-INF/classes/(in = 0) (out= 0)(stored 0%)
[jbadm@jb02 SRIEARV3.0]$

Deploy WAR file any of Jboss JVM (assumed already DS “java:jboss/datasources/SrioraclexeDS” is configured & working)

[standalone@jb02:10190 /] deploy /tmp/Sources/SRIEARV3.0/SRIEARV3.0.war
[standalone@jb02:10190 /]

You can test web page in browser or using elinks.

[jbadm@jb02 ~]$ elinks --dump http://jb02:8280/SRIEARV3.0/sayhi2sri.jsp
                 Hello and Welcome to Sri NGEN LABs JBoss world

   Sat Apr 07 14:02:17 IST 2018

   Sri NGEN Jboss World's - contact me on email at S R I K A N T . A N D E @
   G M A I L . C O M or WhatsApp/call + 9 1 - 9 7 6 6 5 2 5 3 1 3 !!!!!

   Sri NGEN Jboss World's - Follow me on blog at [1]ngen-sri.blogspot.in or
   Linkedin [2]www.linkedin.com/in/srikant-swamy-ande-080383 !!!!!

   Sri NGEN Jboss World's - Following are DB Session info !!!!!

   ***** The DefaultDS DataSource is
   *****org.jboss.as.connector.subsystems.datasources.WildFlyDataSource@181d9e
   ***** The Connection is
   *****org.jboss.jca.adapters.jdbc.jdk8.WrappedConnectionJDK8@d67209 You
   have connected to==Oracle

   Sri NGEN Jboss World's - Following are WEB Session info !!!!!


   The sessionId is:        p4OpfyDfNW_X-lw_h5z31WsPnBbwUSpVvbvZhL6A
   The sessionObj is:       io.undertow.servlet.spec.HttpSessionImpl@54d23138
   The nodeId is:           Sristandalone
   The server hostName is:  jb02
   The server hostOSname    Linux
   is:
   The server hostOSarch    i386
   is:
   The server hostOSversion 2.6.32-431.el6.x86_64
   is:
   The server               1.8.0_91
   hostJAVAversion is:
   The server               Oracle Corporation
   hostJAVAvendor is:
   The server               Java HotSpot(TM) Server VM
   hostJAVAvmName is:
   The server               25.91-b14
   hostJAVAvmVersion is:
   The server               Oracle Corporation
   hostJAVAvmVendor is:
   # of requests placed on  0
   session:

References

   Visible links
   1. https://ngen-sri.blogspot.in/
   2. https://www.linkedin.com/in/srikant-swamy-ande-080383
[jbadm@jb02 ~]$



Click to download "SRIEARV3.0.war"

Comming Soon Jboss EAP 7.1

Comming Soon JBoss EAP 7.1 with Oracle XE.

1) EAP 7.1 installation in two servers.
2) Standalone setup
3) creating n installing WAR to track DB & WEB sessions.
4) creating DS with connection test.
5) http+mod_jk for traffic in round-robin.
6) SSL implementation (TLS1.2)
7) security & realm with LDAP.
8) Elytron.
9) application security with application realm.
10) Loggig & enhanced logging. Java thread dump & heap dump.