Tuesday, 12 December 2017

WebLogic 12C EJB deployment issue

Recently I faced issue while deploying existing custom ear, while deploying on upgraded WebLogic Version 12C. The existing ear is previously compatible with older WebLogic version 10.3.4
While deploying same ear on newer version of WebLogic got following error on server and console -

weblogic.management.DeploymentException: weblogic.application.naming.ReferenceResolutionException: [J2EE:160199]Error resolving ejb-ref "com.xxx.xxx.xxx.xxx.xxx.xxx.XXXX/xxxRemote" from module
"XXX-X.X.X.war" of application "XXX-X.X.X". The ejb-ref does not have an ejb-link and the JNDI name of the target Bean has not been specified.

Solution:
To deploy it, I have removed my EJB module jar from

XXX.ear
             |__ xxx.war
                               |__ WEB-INF
                                                    |__ lib
                                                             |__ ejb jar [which causing issue]

Note, in my case the jar I removed from WAR file, is already present under EAR, and having duplicate occurrence inside the WAR/lib.

Hope this will help. 

SQL Join's Example

'Join' by word itself we get to know, it talks about something we combine together to get desired result.

In database terms, join is all about combining data from multiple tables as single record. Now days, all the data in database is normalized and to display some meaning full information we need to combine data from more than one table.

For example, let's take classic example of customer and order.
In real world, customer information will go in CUSTOMERS table and orders will go in ORDERS table having FOREIGN_KEY for CUSTOMER_ID.
Now when we have to retrieve data for one of use case say, who has placed order with ID=xyz. Here we will get the record from ORDERS, and check for respective customer from CUSTOMERS table using FOREIGN_KEY in that record, combine this data and result will be populated.
Now such operations can be done either by coding or SQL way.

Lets now talk more on SQL Join's in detail -

While talking about SQL Join's, there are 4 basic types of join's as -

  1. Inner
  2. Left
  3. Right
  4. Full
To understand this type quickly let's see below examples with diagrams -

Considering above diagram and join scenario's we might need data like -

  1. Only B              [Inner]
  2. A and B            [Left]
  3. B and C            [Right]
  4. All A, B and C    [Full]
Lets see in detail one by one -

Before going to types, see below database table example, which will be used as reference further to explain all types of Join's.


CUSTOMERS
CUST_IDCUST_NAMECUST_CONTACTCUST_CITY
11111Ram32145646Pune
11112Sarika65465812Mumbai
11113Manisha45454545Delhi
11114Vishal89295956Chennai
11115Mahesh54945956Jaipur


ORDERS
ORDER_IDO_DATEAMOUNTCUST_ID
11122-05-2017120011111
11223-05-2017350011112
11324-05-201720011114
11424-05-2017200011120




Inner Join
    [Select all records from MyTable1 and MyTable2, for which the given join condition is valid]

    Let's say we want to display list of customers whole had made an order, along with the details of order they placed.
    If we consider above diagram, this use case will be, all the records from MyTable1 for which there is reference in MyTable2 (Portion B).
    Best fit example for Inner Join.

    Query:

    SELECT CUST_NAME, CUST_CONTACT, O_DATE, AMOUNT FROM CUSTOMERS C INNER JOIN ORDERS O ON C.CUST_ID = O.CUST_ID;



    INNER JOIN RESULT
    CUST_NAMECUST_CONTACTO_DATEAMOUNT
    Ram3214564622-05-20171200
    Sarika6546581223-05-20173500
    Vishal8929595624-05-2017200



    Left Join

    [Select all records from MyTable1 along with records from MyTable2, for which the given join condition is valid]

    Simply we want to display all the customers and their respective orders.
    i.e. All the records from MyTable1 (A) for which there is reference in MyTable2 (B) and NOT records from MyTable2 (C) for which there is no entry in MyTable1.
    This is good example for Left Join.

    Query:

    SELECT CUST_NAME, CUST_CONTACT, O_DATE, AMOUNT FROM CUSTOMERS C LEFT JOIN ORDERS O ON C.CUST_ID = O.CUST_ID;

    LEFT JOIN RESULT
    CUST_NAMECUST_CONTACTO_DATEAMOUNT
    Ram3214564622-05-20171200
    Sarika6546581223-05-20173500
    Vishal8929595624-05-2017200
    Manisha45454545NULLNULL
    Mahesh54945956NULLNULL



    Right Join

    [Select all records from MyTable2 along with records from MyTable1, for which the given join condition is valid] 
    Now consider that, we have to display all the order details along with customers who had placed the order.

    i.e. All the records from MyTable2 (C), for which there is reference in MyTable1 (B), and NOT there records from MyTable1 (A) which don't have corresponding record in MyTable2.

    Query:


    SELECT CUST_NAME, CUST_CONTACT, O_DATE, AMOUNT FROM CUSTOMERS C RIGHT JOIN ORDERS O ON C.CUST_ID = O.CUST_ID;


    RIGHT JOIN RESULT
    CUST_NAMECUST_CONTACTO_DATEAMOUNT
    Ram3214564622-05-20171200
    Sarika6546581223-05-20173500
    Vishal8929595624-05-2017200
    NULLNULL24-05-20172000




    Full Join


    [Select all records from MyTable1 along with records from MyTable2, regardless of given join condition is valid or not]

    If we have to display all the details of customer tables as well of order tables.

    Query:

    SELECT CUST_NAME, CUST_CONTACT, O_DATE, AMOUNT FROM CUSTOMERS C FULL JOIN ORDERS O ON C.CUST_ID = O.CUST_ID;


    FULL JOIN RESULT
    CUST_NAMECUST_CONTACTO_DATEAMOUNT
    Ram3214564622-05-20171200
    Sarika6546581223-05-20173500
    Vishal8929595624-05-2017200
    NULLNULL24-05-20172000
    Manisha45454545NULLNULL
    Mahesh54945956NULLNULL


    Advance Encryption Standard

    Advance Encryption Standard (AES) is a encryption algorithm which overcomes limitations of DES or Triple DES.

    As DES have -

    • Theoretical attacks that can break it.
    • Demonstrated exhaustive key search attacks.
    In order to overcome this we can use Triple-DES (3DES), but it is slow as it has small data blocks.

    US NIST issued call for ciphers in 1997, 15 candidates accepted in Jun 98. Out of which 5 were shortlisted in Aug-99. 
    Rijndael was selected as the AES in Oct-2000 issued as FIPS PUB 197 standard in Nov-2001.

    Overview:
    AES cipher was designed by Rijmen-Daemen in Belgium.
    It has 128/192/256 bit keys, 128 bit data. 
    It is an iterative rather than Feistel cipher:
    • Processes data as block of 4 columns of 4 bytes
    • Operates on entire data block in every round
    Designed to have:
    • Resistance against known attacks
    • Speed and code compactness on many CPUs
    • Design simplicity

    Application Protocol Data Unit (APDU)

    Application Protocol Data Unit i.e. APDU is a communication Protocol between the smart card and smart card reader.
    APDU can be divided into two subcategories -

    • Command APDU
               Command APDU will hold data unit, which will be sent from smart card reader to smart card.
               After receiving such APDU on smart card, it will be executed on smart card based on                           implementation and command sent.

    • Response APDU
              Response APDU will hold the data, of executed Command APDU by smart card, and sent to              smart card reader.


    The structure of command and response of APDU defined in ISO 7816-4

    Command APDU will contain 4 mandatory bytes in it, those are CLS, INS, P1 and P2


    CLASS - CLS - APDU Class - denotes type of command. This can be standard or proprietary.
    INSTRUCTION - INS - Instruction Code - denotes specific command, e.g. Update Data, Delete Data etc.
    P1 - P2 - Indicates parameters (offsets) for data to be written or updated.
    Lc - Indicates length of data passed.
    DATA - Will contain actual data, of length specified by Lc.

    Response APDU will at least contain 2 bytes
    SW1 - Status Word first byte
    SW2 - Status Word second byte

    Based on SW1 and SW2, card reader will come to know, if given Command APDU is executed on Card successfully or not, and if not what is error.
    In notmal scenario, Status word for Success is 90 00.


    PL/SQL Functions

    In this post we will see how create, use and drop PLSQL functions using the syntax.

    CREATE FUNCTION

    Like in most of programming languages we have provision to create user defined functions. Oracle also provide way to create our own custom functions to do various operations on database.

    Syntax:

    CREATE [OR REPLACE] FUNCTION function_name [parameters] 

    RETURN return_datatype;  

    IS  

    -- Declaration_section  

    BEGIN  

    -- Execution_section 

    Return return_variable;  

    EXCEPTION  

    -- exception section  

    Return return_variable;  

    END; 

    • Return Type: The header section defines the return type of the function. The return datatype can be any of the oracle datatype like varchar, number, varchar2 etc.
    • The execution section and exception section both should return a value which is of the datatype defined in the header section.
    • Function can also have parameters there are three types of parameters that can be declared
      1. IN - The parameter can be referenced by the procedure or function. The value of the parameter can not be overwritten by the procedure or function.
      2. OUT - The parameter can not be referenced by the procedure or function, but the value of the parameter can be overwritten by the procedure or function.
      3. IN OUT - The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function.

    Example

    For example, let’s create a function called ''student_age_finder' similar to the one created in stored proc

     CREATE OR REPLACE FUNCTION student_age_finder ( stdId IN varchar2 )
        RETURN number;
     IS 
        stdage  number; 
     BEGIN 
    SELECT age INTO stdage
    FROM student WHERE studentId = stdId;
    RETURN stdage;
    END;

    In the example we are retrieving the ‘age’ of Student with stdId given in function call to variable 'stdage'.
    The return type of the function is number.
    The function returns the 'stdage' which is of type NUMBER.


    How to execute a PL/SQL Function?

    A function can be executed in the following ways.

    1) As a part of a SELECT statement

    SELECT student_age_finder(100) FROM dual;

    2) Since a function returns a value we can assign it to a variable.
    student_age :=  student_age_finder(100);

    3) In a PL/SQL Statements like,
    dbms_output.put_line(student_age_finder(100));

    DROP FUNCTION

    Syntax
    The syntax to a drop a function in Oracle is:

    DROP FUNCTION function_name;

    Where function_name is name of which is to be dropped.

    Example

    DROP FUNCTION student_age_finder

    Reflection in Java Tutorial

    Introduction

    In this topic we will see what is Reflection in Java, what is it's importance and how to get started with it.

    Reflection:

    In simple words Reflection is the ability of a program to examine and modify the structure and behavior of an object at run-time.
    It is used in Programs which needs to examine or modify the run-time behavior of applications running in JVM (Java Virtual Machine).

    There is one more concept comes under it called Introspection.

    Introspection is the ability of program to examine types or the properties of an object at run-time.
    From the definition introspection is a subset of reflection.

    Some of the languages like C++ supports Introspection, but not Reflection.

    So now to conclude both these concepts,
    Introspection on unknown object helps to examine the structure of the object,
    whereas,
    Reflection on unknown object helps to examine, modify the structure and behavior of object at run-time.

    Redirection from http to https (tomcat example)

    This tutorial will explain how to enable SSL and redirection of http to https using tomcat.

    Installations used for this example:

    • JDK (7)
    • Apache Tomcat (8) 

    Create .keystore file 

    Open cmd prompt and run following command -

    "%JAVA_HOME%\bin\keytool" -genkey -alias tomcat -keyalg RSA

    After executing above command it will prompt for few questions like, password for keystore, First Name Last Name, etc. you need to provide details accordingly.

    [Above example has added some sample/test values, you specify the inputs as per requirement, also make sure that, JAVA_HOME is set before executing above command]

    Once this command is executed successfully, a .keystore file will be created at your user home folder. E.g. C:\Users\<USERNAME>\

    Tomcat Configurations to use generated keystore file

    Go to tomcat installation folder, open server.xml file under conf/
    There you can find following declaration is commented

        <!--
        <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
                   maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
                   clientAuth="false" sslProtocol="TLS" />
        -->

    Edit above entry in server.xml by uncommenting it like below -

    <Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
        disableUploadTimeout="true" enableLookups="false" maxThreads="25"
        port="8443" keystoreFile="conf/keystore/.keystore" keystorePass="test123"
        protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
        secure="true" sslProtocol="TLS" />

    Note in above part, you need update few values as per your settings 
    keystorePass - as per password you set while generating the .keystore file earlier in this tutorial.
    keystoreFile - path where your .keystore file is kept. 
                           [in this example I have copied generated .keystore file from default location to tomcat_dir/conf/keystore/] you can use either way.

    After above changes save the server.xml file

    Now open web.xml file under /conf directory in tomcat installation

    Add following snippet in this file in the end, just before </web-app>

    <security-constraint>
    <web-resource-collection>
    <web-resource-name>Protected Context</web-resource-name>
    <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
    </security-constraint>

    Save the web.xml file.

    And start the tomcat instance.

    Configure WebApplication to work with SSL

    In order to work your web application with above configured SSL. edit web.xml file of your application to add following entry in it.

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>securedapp</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    Deploy your application to tomcat, and test.
    All the http calls will now redirect to https on port 8443.



    Cheers!!