Wednesday, October 19, 2016

Install-Configure Jenkins for ADF/Java/J2EE Application - Part 2

In the last post, i explained how to install, the jenkins with Admin Console.

This post deals mainly with configuring the jenkins to build projects.

I have split this post in 2 Sections, Section A explains the settings one shall perform in Jenkins Global settings, Section B will explain how to create a new item that would checkout the code from svn and prepare the jar/war files.


Section A: Manage Jenkins Settings

1. Set up JDK:
     Go to Manage Jenkins -- > Global Tool Configuration -- > JDK(Click on JDK installation)


    Set the JAVA_HOME property pointing to your JAVA_HOME as shown below

2. Set up Ant: I am building my projects using Ant build so i need to define the ANT properties for the Jenkins to use.

In the same section, if you scroll below, you can see ANT
Go to Manage Jenkins -- > Global Tool Configuration -- > ANT(Click on ANT installation) and set the ANT Properties as shown below


3. Set up Emails: In this example, i intend to send out email to list or recipients with build details every time a build activity happens. So i have configured the properties for the same

Go to Manage Jenkins -- > Configure System -- > Extended E-mail Notification


and update  following details



Your jenkins Setup is complete now.

Section B: Setting up project to be built using Jenkins

In this section i would try to Setup a project build in  Jenkins

1.Click on new Item in the top left of the screen:

2. The next screen would be something like:

Enter the project Name, select freestyle project and click OK in the bottom to go to the next screen

3. The Screen would look like following:

we need to update the required section from here

4.Go to General -- > Advance and update the following

This would instruct the Jenkins to checkout the code from svn to mentioned location

5. Go to Source Code Management and update the source code location with following details.

Note: you may add the credentials for subversion during 1st time
click on add(next to credentials)

6. Go to Build Environment and select "Delete workspace before build starts" so that everytime is build is requested fresh checkout happens

7. Go to Build Section, select invoke Ant (since in this example we are using Ant to create deployable artifact)


The svn path mentioned in step 5, shall have a build.xml and the target user wants to execute shall be mentioned in Ant Steps as following:

Note : Ant version was defined in Section A step 2

8. In the post build Action i need to send out an email to the recipients with the build update so add Editable Email Notification in Post build update as



Go to the advanced settings


Add a trigger as Always send email to recipient list


9. Your jenkins is ready now.
Select the project from home page and click on Build now.



The build would be ready in the local folder where the code is checked out  and as suggested in the build.xml file



The explanation is a bit lengthy but please post your questions in comment section in case you have any doubt, and i will try to answer the questions if any

Tuesday, October 18, 2016

Install-Configure Jenkins for ADF/Java/J2EE Application

Jenkins, is the most successful and widely used tool used for continuous integration.

Over next couple of tutorials i intend to help the developer working in various framework to use Jenkins in their application and align with industry standards.

Lets get started.

1. Download the Jenkins war from here

Note: the mentioned tutorial is specifically build on the this version of the jenkins, so please use this war for set up.

2. once the war is downloaded, go the the directory where the war is placed in command prompt

suppose the "jenkins.war" is placed in C:\Softwares\jenkins, in command prompt:

3. Run the following command:

java -jar jenkins.war --httpPort=9090

usually the port 8080 is busy so making the jenkins run on 9090

This command will create a folder named .jenkins in c:\user\<user_name> folder where all the configuration would be saved.
In case you want to start all over your jenkins, delete the folder .jenkins and start from step 3

the screen would prompt something like:


4. log on to http://localhost:9090/

screen will prompt to:


Since the jenkins is started for the first time, you must unlock the jenkins first, create admin user and proceed further

as suggested, the password can be found @ C:\Users\<user_name>\.jenkins\secrets\initialAdminPassword


5. proceeding further screen would be like this:




select "Install Suggested Pluing".


Next screen would be like:



6. Now the system prompts to create Admin user


After creating user, you may start using the jenkins

It will be available @ http://localhost:9090/


7. Once you close the command prompt, you will always have to start the jenkins using the java -jar option as suggested in step 3, but it would save the admin and other settings as long as .jenkins file is not deleted from user folder

you can also run the jenkins war on some local tomcat server.


Starting next tutorial, i will explain the Configuration of Jenkins to build the projects




Saturday, June 25, 2016

ADF : populating the bind variable from ViewObjectImpl Class

In ADF while working with view objects(Entity based or Readonly) user might be in need to populate the bind variable value from Security context or session scope. for this reason it can be populated easily in java class

Consider a scenario where the query to be executed is "Select * from <tablename> where userid is <logged in user>". Such scenario can be handled via regexs (since i am not very good with regex so i decided to populate such value in java class which gives me flexibility to get such values from security context or session scope and also i can modfiy  the values is needed using java APIs.


Steps.
1. create the bind variable and assign the value as expression as :
adf.object.viewObject.managerRoleIdFromSession





here the managerRoleIdFromSession is private string defined in the Impl class as:


    private String managerRoleIdFromSession;


    public void setManagerRoleIdFromSession(String managerRoleIdFromSession) {
        this.managerRoleIdFromSession = managerRoleIdFromSession;
    }

    public String getManagerRoleIdFromSession() {
        String managerRoleId="";
        Map sessionScope = ADFContext.getCurrent().getSessionScope();
        managerRoleId=sessionScope.get("Manager_roleId")!=null?sessionScope.get("Manager_roleId").toString():"";
        return managerRoleId;
    }

as demonstrated in the setter method user can use the necessary APIs to play around the variable and get desired output

ADF : populating the bind variable from ViewObjectImpl Class

In ADF while working with view objects(Entity based or Readonly) user might be in need to populate the bind variable value from Security context or session scope. for this reason it can be populated easily in java class

Consider a scenario where the query to be executed is "Select * from <tablename> where userid is <logged in user>". Such scenario can be handled via regexs (since i am not very good with regex so i decided to populate such value in java class which gives me flexibility to get such values from security context or session scope and also i can modfiy  the values is needed using java APIs.


Steps.
1. create the bind variable and assign the value as expression as :
adf.object.viewObject.managerRoleIdFromSession





here the managerRoleIdFromSession is private string defined in the Impl class as:


    private String managerRoleIdFromSession;


    public void setManagerRoleIdFromSession(String managerRoleIdFromSession) {
        this.managerRoleIdFromSession = managerRoleIdFromSession;
    }

    public String getManagerRoleIdFromSession() {
        String managerRoleId="";
        Map sessionScope = ADFContext.getCurrent().getSessionScope();
        managerRoleId=sessionScope.get("Manager_roleId")!=null?sessionScope.get("Manager_roleId").toString():"";
        return managerRoleId;
    }

as demonstrated in the setter method user can use the necessary APIs to play around the variable and get desired output

Thursday, March 3, 2016

Developing custom build Kaptcha (captcha) in adf

Web applications might often need captcha in order to prevent application from robotic attacks. Following example demonstrates how to build custom captcha in ADF Technology

Display Captcha :

Add following in jspx:

 <af:panelGroupLayout id="pgld11" layout="horizontal">
                  <af:outputLabel value="#{pageFlowScope.backingBean.secretQ}" id="otd14"
                                  inlineStyle="font-weight:normal; font-size:small; color:Black; font-family:Arial;"/>
                  <af:spacer width="18" height="5" id="sd13"/>
                  <af:inputText simple="true" label="secretQ" id="it7capta" contentStyle="width:100px; height:22px; font-family:Arial; font-size:small; color:Black; border-color:#878787;"
                                value="#{pageFlowScope.backingBean.secretUA}"
                                autoSubmit="true"
                                binding="#{pageFlowScope.backingBean.secreatAnswer_binding}">
                     </af:inputText>
            </af:panelGroupLayout>

in backing bean define the variables as:

 private String secretQ, secretA, secretUA;

 public void setSecretQ(String secretQ) {
        this.secretQ = secretQ;
    }

    public String getSecretQ() {
        List<String> secretQandA = CAPTCHAUtil.getQuestionAndAnswer();
        this.setSecretQ(secretQandA.get(0));
        this.setSecretA(secretQandA.get(1));
        this.setSecretUA("");
        return secretQ;
    }

    public void setSecretA(String secretA) {
        this.secretA = secretA;
    }

    public String getSecretA() {
        return secretA;
    }

    public void setSecretUA(String secretUA) {
        this.secretUA = secretUA;
    }

    public String getSecretUA() {
        return secretUA;
    }


please find the captcha util class attached. it can be modified as per user needs.


Validate Captcha:

Call this method to validate captcha:

    private Boolean validateCapta() {
        if(getSecretUA()== null){
            retValue=false;
        }else{
            if(getSecretUA().equals("")){
                retValue=false;
            }else if(!getSecretA().equalsIgnoreCase(getSecretUA())){
                retValue=false;
            }
             
        }
     
        return retValue;
    }

Data Source Not Found

While developing a web application i often come across following exceptions:

javax.naming.NameNotFoundException: Unable to resolve '<Data_Source_Name>'. Resolved ''; remaining name '<Data_Source_Name>'

at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:1139)
at weblogic.jndi.internal.BasicNamingNode.lookupHere(BasicNamingNode.java:252)
at weblogic.jndi.internal.ServerNamingNode.lookupHere(ServerNamingNode.java:182)
at weblogic.jndi.internal.BasicNamingNode.lookup(BasicNamingNode.java:206)
at weblogic.jndi.internal.WLEventContextImpl.lookup(WLEventContextImpl.java:254)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)



oracle.jbo.DMLException: JBO-27200: JNDI failure. Unable to lookup Data Source at context HppConnNonXA
at oracle.jbo.server.DBTransactionImpl.lookupDataSource(DBTransactionImpl.java:1491)
at oracle.jbo.server.DBTransactionImpl2.connectToDataSource(DBTransactionImpl2.java:335)
at oracle.jbo.common.ampool.DefaultConnectionStrategy.connect(DefaultConnectionStrategy.java:203)
at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolConnect(ApplicationPoolMessageHandler.java:620)
at oracle.jbo.server.ApplicationPoolMessageHandler.doPoolMessage(ApplicationPoolMessageHandler.java:425)
at oracle.jbo.server.ApplicationModuleImpl.doPoolMessage(ApplicationModuleImpl.java:9316)
at oracle.jbo.common.ampool.ApplicationPoolImpl.sendPoolMessage(ApplicationPoolImpl.java:4530)
at oracle.jbo.common.ampool.ApplicationPoolImpl.prepareApplicationModule(ApplicationPoolImpl.java:2460)





Reason:
Application Module is configured (App Mod -- > Configurations -- > App Module -->Connection Type)to connect to DB using data source defined in Weblogic(WL Console --> Service -->Data Source). The Data source is unavailable for the application


Where to Look for solution:

If you get the above mentioned error look for following :

1. Make sure the data source is targeted for the default server(in local) or the designated server you are running the application.

Go to WL Console --> Service -->Data Sources --- > Select Data source ---> Targets:




2. This might happen more often then you think. In most of the cases (atleast with me) you might have been disconnected to vpn or the data base might not be reachable due to some circumstance.

Make sure the database connection is up. quickest way to check the same is :

Go to WL Console --> Service -->Data Sources --- > Select Data source -- > Configuration --> Connection Pool and click on save.

If the data base is reachable, you would get all green in case of issue you will find it





The issue mentioned above may sound silly but believe me its occurs more often then you think.

Hope its is useful



Wednesday, January 27, 2016

Solution to ADFC-0619: Authorization check failed

Problem Statement:
My ADF Application, with security implemented through jazn-data when deployed on Weblogic box, the authorization does not happen and i often i receive
oracle.adf.controller.security.AuthorizationException: ADFC-0619: Authorization check failed: 'oracle.jbo.uicli.binding.JUFormDef@d856cd' 'VIEW'.

This issue has been discussed @:
https://community.oracle.com/message/9646751
http://oracle.developer-works.com/article/4786269/ADFC-0619%3A+Authorization+check+failed%3A+'homePageDef'+'VIEW'+-+Solved

Root Cause:
The root cause for the issue is when an ADF application with security enabled is deployed through weblogic console the <Domain_home>/config/fmwconfig/system-jazn-data.xml do not get updated and hence the server is not aware of the security policies and the page remains unavailable

Solution:

I was stuck with this issue for more than 2 weeks and following solutions were implemented:

1. Instead of going for Authentication and Authorization go for Authentication only


Not sure why this works, but it induces a new issue.
Issue with this approach if if trying to access a page with permission given to anonymous-role, the application would route to the login page in this case and user is forced to login

2. Try to deploy the application on server through Jdeveloper


This solves the issue but in most of the cases the prod servers wont be available for developers to access and makes this approach unpractical

3. Deploy through em console

This approach finally worked in my case. Deploy the application on Admin Server through em console. Make sure in Deployment Settings: Click on Configure Application Security to modify the default settings and in Configure Application Security provide following:

Select Application Policy Migration as “Append”.
Uncheck the “Remove Policies during Application undeployment
Provide Application setting id as "<Application_name>"
Click Apply



NOTE: THIS STEP WOULD UPDATE THE system-jazn-data.xml FILE

Now undeploy the application from Admin Server and deploy it on the managed server with same settings keeping the system-jazn-data.xml intact(i guess deployment to managed server can be done even from WL Console but never tried it)

probably Dimitar Dimitrov speaks of the same stuff manually in the thread



Please share your thoughts on this issue if you face it




Wednesday, January 6, 2016

Solution to JBO-25014: Another user has changed the row with primary key oracle.jbo.Key[xxx].

I have posted this issue here

Simultaneous Commit operation in ADF throws "oracle.jbo.RowInconsistentException: JBO-25014"

Chris has discussed this issue in detail here

I have how tackled the solution and such implementation can be applied as turn around solution.

The real culprit is:

We know the record in the mid-tier has been changed by the user, however ADF doesn't use the changed record in the mid-tier to compare to the database record, but rather a copy of the original record before it was changed.  This leaves us to conclude the database record has changed, but how and by who?

So,  simple call execute operation for that viewObject after commit would solve the problem .
as:            
   OperationBinding op = getBindings().getOperationBinding("searchApplication");  //searchApplication is the method which populates the VO
    op.execute();

But would reset the iterator and even though the selected row in table is (says 5th from the top), the form would be always displaying 1st row.

So i deal with problem with variable defined as:
private String currentRowKeyStr="";
i would set this variable to
currentRowKeyStr=row.getAttribute("PrimaryKeyValue")!=null?row.getAttribute("PrimaryKeyValue").toString():"";

Similarly,
on the table selection listener
selectionListener="#{pageFlowScope.Bean.selectTable_SelectionListener}"

i would set this variable every time a row is selected as:
currentRowKeyStr=rowSelected.getAttribute("PrimaryKeyValue")!=null?rowSelected.getAttribute("PrimaryKeyValue").toString():"";

Please post comment in case you need help with such issue