Thank you for visiting! If you liked the site, please add a bookmark, else add a critical comment! Would you like to visit Greece? Traditional Greek flag This real estate site is only available in Greek! The holy mountain

Monday 18 October 2010

JDeveloper 11g: Making use of Http Analyzer for testing and debugging

Anyone who has  developed a JEE or SOA application, sooner or later faces some kind of unexpected, or strange behaviour  of the system under development. However helpful the audit process screens of the weblogic server, once you enter and submit the sometimes numerous input values, one is not allowed to tamper with the request values anymore; you just wait  until you get hopefully a response, or an error. An interesting , but often overlooked, alternative is  Http Analyzer. It lets you save some time, by copying the request so that you don't have to enter all values from scratch, you can edit the value of interest and resend your modified request. Let's see some specific examples.

Setting up the browser

In order to quickly set it up, you go to "Tools" menu and click on "Preferences" in JDeveloper 11g as shown in the image. You need to copy the "Listen on port" value, which is 8099. Next,  you need to setup the browser of your choice. The images below show the screen shots for Mozilla Firefox, I suppose finding your way in IE or other browser won't be such an onerous task!

Again click on "Options", then on "Advanced", "Network" and lastly on "Settings" to reach the connection settings window as shown . You need to select "Manual proxy configuration", enter your computer name, and paste the port number you copied before, i.e 8099. The "No proxy for" section must not contain any entries, such as localhost, nor 127.0.0.1, because in that case Http Analyzer will only analyze your internet requests! When you are done with debugging, you might need to  reenter here your old values. That means you need to save them, i.e in a new back up text file! For an alternative more elegant configuration using profiles, you can consult the JDeveloper documentation, by searching for"Configuring External Web Browsers"



Testing a trivial ADF form
Next, you start the  application, using the "Run project" button, and click the "Start HTTP analyzer" button. The small  form of the ADF ejb bidding application window appears. You should now see the output in the log window. If you enter the form values and submit, the HTTP analyzer captures all submitted values. You can now copy the request,  edit only the bidder's name for instance, and resend.

Testing a plain SOA component
For the second example, you need to reenter your old settings to your browser(i.e. No proxy). The request values will be submitted by JDeveloper itself, by right clicking on the service, as shown.
Here a US stock exchange price in dollars, i.e. for OTE or GE, is converted into a different currency, i.e. EUR or GBP for British pounds.  You can see the request and response values as well. As mentioned before, you need to copy the request, modify only where necessary and resubmit.
Although the  examples given are deliberately simple, a small relevant quotation will be given, concerning the importance of retaining the input parameters, and another alternative as well. I quote from the Oracle SOA Suite 11g Developer's guide: "If you have a very complicated interface, you may not want to have to enter the parameter values every time you test the composite. In 10g, there was a facility to set a default input to a BPEL process. Unfortunately, there is no such facility for 11g composites. In order to avoid retyping complex inputs, the input can be saved to a file and then pasted into the test dialog every time...". Finally, if your needs are bigger, you might consider another alternative testing tool like SOAPUI which is  available online.

Wednesday 6 October 2010

JDeveloper 11g: Using assert() for testing and debugging

Assertions are a very useful feature for testing and debugging, but are rather neglected. Instead of using loggers to provide continuously diagnostic messages in critical programme  flow points, or even worse if- else - System.out.println() constructs, assert statements can only be enabled only when necessary. Thus, you avoid wasting valuable resources. In addition, you do not need to add any jar libraries to your IDE  project, or application server to use it. In order to use assert, you need to  pass the -ea argument, call a non void java method and check a Boolean  condition. For instance: assert(Month < 13). Nonetheless, you can not  use an assert statement to check the values passed to public methods. Consider for example the following code snippet, from an business components, employees entity object:
              
protected void doDML(int operation, TransactionEvent e) {
                if (operation == DML_UPDATE) {
    ...
               histStartDate = row.getEndDate();
              /*Check whether end date equals current date*/
              /*if (histStartDate.equals(new Date(Date.getCurrentDate()))){
                  System.out.println("End date equals current date!");
                  }*/
               assert(histStartDate.equals(new Date(Date.getCurrentDate() ) )) :
                          "End date equals current date! ";

Another trivial example from an ejb client follows:

public class PlaceBidClient {
    public static void main(String [] args) {
...
                     Bid bid = placeBid.addBid("Lila",  Long.valueOf(100),  2001.50);
                     System.out.println("Bid Successful, BidId Received is:" + bid.getBidId());
                     assert(bid.getBidId() == 502):"BidId Received is "+bid.getBidId();
  }
}
Finally, when run, the log output reads:

-javaagent:C:\Oracle\Middleware\jdev_11gR1\jdeveloper\..\modules\org.eclipse.persistence_1.0.0.0_2-0.jar -Duser.language=en -Duser.country=US -ea actionbazaar.buslogic.client.PlaceBidClient

Exception in thread "main" java.lang.AssertionError: BidId Received is 393
    at actionbazaar.buslogic.client.PlaceBidClient.main(PlaceBidClient.java:24)
Bid Successful, BidId Received is:393

Sunday 3 October 2010

A free site for sports funs: http://www.woop.gr/

This is a new free online Greek sports channel covering both national and international soccer, basketball matches, motorcycle racing events and so on. Since Eurosport channel now asks for subscription and payments, this could be an interesting alternative, in case your spouse insists on watching that boring soap opera. Most text is in Greek, but you can find your way around. Try clicking on "Live" links, in order to find something interesting to watch. So, this is it: http://www.woop.gr/
Finally, if you would like to try other online tv channels there is http://2onlinetv.com.