Thursday, March 28, 2013

Glassfish plugin for JDeveloper 11gR2

Hello, all. As some of you already know, ADF Essentials is a great framework for building web applications using java and it is free to develop and free to deploy. You deploy ADF Essentials applications on Glassfish (3.1+) server. Nevertheless, JDeveloper does not come with an embedded Glassfish server but with an embedded Weblogic server.

In this post, we are going to talk about when to use the integrated Weblogic server and when you should use an external Glassfish server during your ADF Essentials application development.

What you need

Once you have installed the above software, you may start creating your ADF Essentials applications. There are tons of documentation online: books, tutorials and videos to help you. My recommendation is try to use the integrated Weblogic server during development so you can debug and run your applications right from JDeveloper. When you finish developing some functionality, test your development on Glassfish server, at the end, if you are developing an ADF Essentials applications this is the application server you are most likely to use in a production environment. Make sure you have configured your Glassfish server for ADF Essentials applications as described here:


The version of JDeveloper you installed, comes with a built in functionality to deploy your applications to Glassfish server. However, you have to start the server before you can deploy your applications. One way to do it is to use the Glassfish server controls (they are installed once you install Glassfish) outside of JDeveloper.
My recommended way is to use the Glassfish plugin for JDeveloper so you can start/stop Glassfish server right from the IDE! The plugin was created by Shay Shmeltzer and the version 1.3 has been modified to run on Linux (thx to me, @aa_lopez) and to run on Mac (thx to David Aroca).

The plugin can be found at help->check for updates. More information here:
https://blogs.oracle.com/shay/entry/glassfish_extension_for_oracle_jdeveloper

If you want to make contributions to the source code, you can find the project at java.net:
http://java.net/projects/jdev-3rd-party-ext/sources/svn-repository/show

Once you have installed the plugin, your JDeveloper presents four new buttons:



From left to right:
  • The first one lets you start the Glassfish server.
  • The second one lets you stop Glassfish server.
  • The third one starts Glassfish server in debug mode.
  • The fourth one starts the Glassfish server web console app.

Before you can start using these new buttons, you have to configure the paths to the Glassfish server. To do this, go to Tools->Preferences and select the Glassfish Preferences:



The plugin comes with Windows OS paths by default. So if you are using Linux or Mac, you have to change these paths in order to have the plugin buttons working. In my case, I'm using Linux, so I changed the paths to match the paths where I installed my Glassfish server.
Note: I had to add the --verbose option to the start command, otherwise, Glassfish starts and stops immediately.

Glassfish Home Directory: /home/aalopez/development/glassfish-3.1.2.2/

Start Glassfish Command: /home/aalopez/development/glassfish-3.1.2.2/glassfish/bin/asadmin start-domain --verbose domain1

Stop Glassfish Command: /home/aalopez/development/glassfish-3.1.2.2/glassfish/bin/asadmin stop-domain domain1

Start Glassfish in Debug Mode Command: /home/aalopez/development/glassfish-3.1.2.2/glassfish/bin/asadmin start-domain --debug=true

Glassfish Admin URL: http://localhost:4848

Once you finish the configuration, you are ready to start using Glassfish server from JDeveloper, just don't close the window that pops up when you hit the "Start Glassfish" button.


How to deal with data sources between Weblogic and Glassfish servers?
When you are working with the integrated Weblogic server, JDeveloper creates a data source to access the database. This data source has the following structure:

java:comp/env/jdbc/DATASOURCE_NAME

Where DATASOURCE_NAME is the name you gave to the data source when configuring the connection to the data base. The problem is that Glassfish server uses another structure. When you define a data source in the Glassfish server web console app, you define it like this:

jdbc/DATASOURCE_NAME

If you keep running your application using Weblogic and Glassfish servers, I recommend the following configuration, so you don't have to manually change the data source structure every time you change the application server:

Define the resource at Web Content/WEB­INF/web.xml

<resource-ref>
   <res-ref-name>jdbc/DATASOURCE_NAME</res-ref-name>
   <res-type>javax.sql.DataSource</res-type>
   <res-auth>Container</res-auth>
   <res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

As stated by the Java EE web-app deployment descriptor version 2.5:

The res-ref-name element specifies the name of a
resource manager connection factory reference.  The name
is a JNDI name relative to the java:comp/env context.
The name must be unique within a web application.

So we are not defining what to do with jdbc/DATASOURCE_NAME but we are actually defining   java:comp/env/jdbc/DATASOURCE_NAME which matches exactly the data source structure configured in the application and used by Weblogic server.

This is actually a good practice, since at development time you don't have to worry about what is going to be the structure or name of the data source at deployment time. You just define, in the web.xml deployment descriptor, the structure or name of the data source and the deployer (yes, the person who makes the deployment) can map that structure or name to something else. This is done in a container-specific configuration file, as we shall see next.

Create the glassfish-web.xml configuration file. Right click on the Web Content/WEB-INF folder and select the New... option:




A window pops up, select the General category and then choose the File option:



Enter the name of the file as glassfish-web.xml and make sure the path to this new file is inside the WEB-INF folder:



Once the file is created, open it and enter the following code:

<?xml version="1.0" encoding="UTF-8" ?>
<glassfish-web-app>
    <context-root>YOUR_APP_NAME</context-root>
    <property name="useBundledJsf" value="true"/>
    <class-loader delegate="false"/>
    <resource-ref>
        <res-ref-name>java:comp/env/jdbc/DATASOURCE_NAME</res-ref-name>
        <jndi-name>jdbc/DATASOURCE_NAME_AT_GLASSFISH</jndi-name>
    </resource-ref>
</glassfish-web-app>

Here I copied the configuration that JDeveloper adds to the glassfish-web.xml file at deployment time. I also added the configuration that let us map the data sources. The resource-ref element is what we are going to focus on this post.
Change DATASOURCE_NAME for the name you defined for your data source in the web.xml deployment descriptor and DATASOURCE_NAME_AT_GLASSFISH for the name you defined in the Glassfish Web console app.

How it works:
  1. We defined the data source as a resource in the web.xml deployment descriptor. Remember that we are using the structure jdbc/DATASOURCE_NAME but what it really means is that we are using java:comp/env/jdbc/DATASOURCE_NAME
  2. We created the glassfish-web.xml deployment descriptor. This is a container-specific configuration file and is created automatically by JDeveloper when you deploy to a Glassfish server. However, if the file already exists it is not overridden  Here we mapped the data sources definitions so we are telling Glassfish that when we are looking for java:comp/env/jdbc/DATASOURCE_NAME in our application, what we really mean is that we are looking for jdbc/DATASOURCE_NAME in the Glassfish server.

That's it. With this configuration you don't have to worry about the data source configuration differences between Weblogic and Glassfish servers. Happy ADF Essentials coding.

see ya!


References:

Oracle ADF Essentials. Oracle [online].
Available on Internet: http://www.oracle.com/technetwork/developer-tools/adf/overview/adfessentials-1719844.html
[accessed on March 24 2013].

Deploying ADF Applications to GlassFish. Oracle [online].
Available on Internet: http://docs.oracle.com/cd/E35521_01/web.111230/e16182/appendix_glassfish.htm#CEGDIGEE
[accessed on March 28 2013].

Java EE: XML Schemas for Java EE Deployment Descriptors. Oracle [online].
Available on Internet: http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#5
[accessed on March 28 2013].

What is resource-ref in web.xml used for?. Oracle [online].
Available on Internet: http://stackoverflow.com/questions/2887967/what-is-resource-ref-in-web-xml-used-for/2888169#2888169
[accessed on March 28 2013].

Friday, March 22, 2013

CLOJUG - March 2013

Hello all! This is a small update about what we are working on at the Cali (CLO) Java User Group - CLOJUG. As I've mentioned before, we started a web site using the meetup.com platform, so all our events are scheduled using this platform and members are encourage to make their RSVPs. Visit www.clojug.org for more information.

During this month (March 2013) we had our first meeting with new members, where we introduced them to the Java User Group's proposal and presented them three conferences: Java 6<7<8 by @aa_lopez, i18n in JSF 2 and Log4J2 by @daviaroc and Service distributed applications using JavaEE 6 and JBoss AS 7 by @guidogranobles

On the left you can see how the group looked like two months ago. On the right, you can see how it looks now :)





We even have a logo now! It is inspired by one of the iconic monument of our city called "statue of Sebastián de Belalcázar", founder of our city: Santiago de Cali (CLO).





What do you think about our logo? cool, right? 

We are now preparing our meeting for the next month (April 2013), but before, we are going to have an extraordinary meeting where we''ll be hanging out with Arun Gupta about Java EE 7:



So, stay tuned for our events and if you live in Cali-Colombia, come to our meetings and become a member of our great community!

see ya

Thursday, March 7, 2013

JDeveloper 11gR2 - Integrated Weblogic Server Password Reset

Hello everyone. After months of working with ADF Essentials, I needed to log in to the Console application of the integrated Weblogic Server that comes with JDeveloper 11.1.2.3 (Weblogic Server 10.3.5) and then I realized that I have forgotten the password of the weblogic user... So I started looking and found two solutions:
  1. Solution 1: Remove the default domain folder created by the Integrated Weblogic Server.
  2. Solution 2: Generate a new password for the weblogic user. 
What's the difference between solution 1 and 2?
In solution 1, you will lose any configuration you have made to your integrated weblogic server, this includes: data sources, security configuration, etc.
In solution 2, you will lose only security configurations you have made. For example, if you have created more users, or groups, or configured access to an external LDAP service, but will keep everything else. I have to say that this solution is more difficult than solution 1.

If you have not made any configurations to your integrated Weblogic server, I suggest you to go with solution 1. 

Before we continue with the solutions, we first need to find the IDE system directory. In order to do that, open JDeveloper, go to the Help menu and select the About option. A popup shows up, select the Properties tab and scroll down until you find any of  these: ide.pref.dir or ide.system.dir or ide.user.dir 

In a Linux environment, you may find something like this:



In a windows environment, you may find something like this:



Actually, the dir we are looking for is the ide.system.dir so lets write it down so we can use it later:

Linux (my case, yours may be different)
SYS_DIR=/home/aalopez/.jdeveloper/system.11.1.2.3.39.62.76.1

Windows (my case, yours may be different)
SYS_DIR=C:\Users\CVDESA\AppData\Roaming\JDeveloper\system11.1.2.3.39.62.76.1

Make sure Weblogic server is shut down before you continue.


Solution 1: Removing the DefaultDomain folder
The first and easiest solution is to Remove the following folder (DefaultDomain):
SYS_DIR/DefaultDomain

The folder will get re-created for you the next time you start the Weblogic server. The problem is that you will lose any configuration you may have done including: users, passwords, datasources, etc. All of it.
Once you remove the folder, open JDeveloper go to the Run menu, and select the Start Server Instance (IntegratedWeblogicServer) option. A popup shows up asking you to set the weblogic user credentials. That's it!

Solution 2: Reset the weblogic user password
Please follow the next steps in order reset the password in a Linux system (Ubuntu 12.1), steps for Windows system are also presented:

Linux
  1. Go to this path: SYS_DIR/DefaultDomain/bin, where SYS_DIR is the path we defined above.
  2. Execute the setDomainEnvironment.sh
  3. Go to this path: SYS_DIR/DefaultDomain/security
  4. Rename the DefaultAuthenticatorInit.ldift file to something like oldDefaultAuthenticatorInit.ldift
  5. Export the weblogic.jar file to the classpath, so we can create a new password for the weblogic user (in my case, the installation directory of JDeveloper is /home/aalopez/Oracle):
  6. export CLASSPATH=$CLASSPATH:/home/aalopez/Oracle/Middleware/wlserver_10.3/server/lib/weblogic.jar
  7. Execute the following command in order to create the new password. Notice that the command has a dot at the end, this is necessary so the new password is created in the current directory. Change NEW_PASSSWORD for the new password of the weblogic user:
  8. java weblogic.security.utils.AdminAccount weblogic NEW_PASSWORD .
  9. Go to this path: SYS_DIR/DefaultDomain/servers/DefaultServer
  10. Rename the data directory to something like data_old
  11. Go to this path: SYS_DIR/DefaultDomain/servers/DefaultServer/security
  12. Rename the boot.properties file to something like oldboot.properties
  13. Create a new boot.properties file in the same directory. This is necessary if you want autologin when launching the Weblogic server from within JDeveloper. The content of the file should be something like the following (change NEW_PASSWORD for the password you defined in previous steps):
  14. username=weblogic
    password=NEW_PASSWORD
  15. It's time to test our changes. Go to this path: SYS_DIR/DefaultDomain/bin
  16. Execute the startWeblogic.sh file and verify that Weblogic server starts without exceptions.
  17. Open a new browser and enter the following URL (the port may be different for you):
  18. http://localhost:7101/console
  19. The Weblogic server console application should display and you can login with your new credentials.
  20. When you are ready to stop the Weblogic server, go to this path: SYS_DIR/DefaultDomain/bin
  21. Execute the stopWeblogic.sh file in order to stop the server.

There's one extra step that we'll cover after we check the Windows steps:


Windows

  1. Go to this path: SYS_DIR\DefaultDomain\bin, where SYS_DIR is the path we defined above.
  2. Execute the setDomainEnvironment.cmd
  3. Go to this path: SYS_DIR\DefaultDomain\security
  4. Rename the DefaultAuthenticatorInit.ldift file to something like oldDefaultAuthenticatorInit.ldift
  5. Execute the following command in order to create the new password. Notice that the command has a dot at the end, this is necessary so the new password is created in the current directory. Change NEW_PASSSWORD for the new password of the weblogic user:
  6. java weblogic.security.utils.AdminAccount weblogic NEW_PASSWORD .
  7. Go to this path: SYS_DIR\DefaultDomain\servers\DefaultServer
  8. Rename the data directory to something like data_old
  9. Go to this path: SYS_DIR\DefaultDomain\servers\DefaultServer\security
  10. Rename the boot.properties file to something like oldboot.properties
  11. Create a new boot.properties file in the same directory. This is necessary if you want autologin when launching the Weblogic server from within JDeveloper. The content of the file should be something like the following (change NEW_PASSWORD for the password you defined in previous steps):
  12. username=weblogic
    password=NEW_PASSWORD
  13. It's time to test our changes. Go to this path: SYS_DIR\DefaultDomain\bin
  14. Execute the startWeblogic.cmd file and verify that Weblogic server starts without exceptions.
  15. Open a new browser and enter the following URL (the port may be different for you):
  16. http://localhost:7101/console
  17. The Weblogic server console application should display and you can login with your new credentials.
  18. When you are ready to stop the Weblogic server, go to this path: SYS_DIR\DefaultDomain\bin
  19. Execute the stopWeblogic.cmd file in order to stop the server.


Once you have changed and tested the new password for the weblogic user, is time to update the information in JDeveloper. Open JDeveloper and go to the Resource Palette, if you can't find it, go to the View menu and select the Resource Palette option:




There, select the Application Server category and the IntegratedWebLogicServer. Right click and select the Properties option. A new popup shows up, select the Authentication tab:



There you can set the new weblogic user password that you just defined steps above. Apply changes and that's it!


see ya,


References:

Reset lost weblogic admin password | Beyond Oracle. João Oliveira [online].
Available on Internet: http://www.beyondoracle.com/2010/08/30/reset-lost-weblogic-admin-password/
[accessed on March 02 2013].

Enabling Auto Login by Using the Boot Identity File. Oracle [online].
Available on Internet: http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/wls/10g/r3/installconfig/enable...
[accessed on March 02 2013].

Changing DefaultServer's Password running in JDeveloper. Brenda [online].
Available on Internet: http://newsoalife.blogspot.com/2011/07/changing-defaultservers-password.html
[accessed on March 04 2013].

OTN Discussion Forums. Oracle [online].
Available on Internet: https://forums.oracle.com/forums/thread.jspa?threadID=2285290
[accessed on March 07 2013].