Skip to main content

Posts

Showing posts from August, 2015

Improve your REST Webservice response time using java.util.TimerTask

A while ago, I built an MAF application, which was consuming a few REST webservices from Oracle Java Cloud. But for each request from the app, the response JSON was getting created, and which made the app response very slow.  So, I created the contents of the REST response as a scheduled job. My data wasn't getting changed that often, so I choose to build my REST responses every morning at 10am using java.util.TimerTask. Used Software: JDeveloper 12.1.3 #1. REST response POJOs : public class Feed {         public String url;     public String source;         public Feed() {         super();     }         public Feed(String source, String url) {         setSource(source);         setUrl(url);     }         public void setSource(String source) {         this.source = source;     }     public String getSource() {         return source;     }     public void setUrl(String url) {         this.url = url;     }     public String getUrl() {         return url;     } } ============

Calling Synchronous WebServices Asynchronously from ADF Managed Bean

Recently I had to implement a SOAP webservice call from a af:commandButton action, but the requirement was to make it an asynchronous call. So that the user doesn't have to wait till the Webservice finish processing the request. So I built : Interface which extends java.util.concurrent.Callable. Interface so that I can use the same technique to call multiple Webservices, if required. A session scoped bean to invoke the above interface. #1. Interface : WebserviceCallee public interface WebserviceCallee<T> extends Callable<Boolean> {          // Base URL of the Webservice to call     public String getBaseUrl();     public void setBaseUrl(String baseUrl);     // To identify this object uniquely         public String getUniqueIdentifier(); } #2. Implentation :   public class WebServiceA implements WebserviceCallee<Boolean> {         private static Log log = LogFactory.getLog( WebServiceA .class);         private String baseUrl;     private Thread

Problem with "double" type elements in JAXB

I have recently faced quite a lot of problem using JAXB objects to invoke SOAP webservices. There were several elements declared as : <xs:simpleType name="someAttr"><xs:restriction base="xs:double"/></xs:simpleType> When I used "wsimport" command line tool to generate Java classes for the WSDL, all those attributes generated as private double someAttr; What happened later was all the values were transformed automatically to scientific notation like : 2.85292746E8 This was a major issue, as the actual values were getting truncated.  After a long search and trial and error, I found an easy solution to my problem, to change the declaration  private double someAttr; To : private BigDecimal someAttr; No value truncation or transformation happened after that.  

Custom LOV with AutoSuggest implementation in ADF

Prerequisites of this implementation : ViewObject (in the example it is "MyViewObject") Some utility is used in the example, check my other blogs "ADF  Utility" #1. Create LOV Listener class This class will open the LOV window in a popup and also when user selects a row and click OK in the popup, it will set the value property of the input Text ui component where this LOV is invoked from. // Add the getters and setters of all the class level attributes. // I have removed them from this example to shorten the length of the blog. // For "getUIComponent()" check my other blog to find a UI Component from managed bean public class MyLOVListener {         /**      * ID of the popup where af:table is defined      */     private String popupId;     /**      * ID of the inputText component where the selected value      * from the popup should be copied back      */     private String inputTextId;     /**      * Name of the iterator defined the in paged

ADF Utility : Retrieve ApplicationModule object from Managed Bean

Many a times it is required to retrieve the ApplicationModule object from ADF managed beans, for example, to programmatically query a view object.  Invoke the below class like : AppModuleBean.getService(FacesContext.getCurrentInstance(), APP_MODULE_NAME)) This gives 3 different ways to retrieve the AppModule. Using BindingContext. Evaluating DataControl EL expression. Evaluating Bindings EL expression.     public class AppModuleBean {     public static ApplicationModule getService(FacesContext fc, String name) {                 DCDataControl dc = fromBindingContext(name);                 if(dc == null) {                        dc = fromEvaluatingDataControlEL(fc, name);         }                 if(dc == null) {             dc = fromEvaluatingBindingsEL(fc, name);         }                 return (ApplicationModule) dc.getDataProvider();     }         private static DCDataControl fromBindingContext(String name) {                 DCDataControl dc = null;         BindingConte

ADF Utility : Find UIComponent from Managed Bean

Many a times, it is required to find an UIComponent from ADF managed bean, to do something with it, for example : change the value of an af:outputText, change readOnly property of an af:inputText etc.     private UIComponent getUIComponent(String id) {                  FacesContext facesCtx = FacesContext.getCurrentInstance();          return findComponent(facesCtx.getViewRoot(), id);     }          private UIComponent findComponent(UIComponent base, String id) {                 if (id.equals(base.getId())) {             return base;         }         UIComponent children = null;         UIComponent result = null;         Iterator childrens = base.getFacetsAndChildren();         while (childrens.hasNext() && (result == null)) {             children = (UIComponent)childrens.next();             if (id.equals(children.getId())) {                 result = children;                 break;             }             result = findComponent(children, id);             if (result != nu

ADF Utility : Evaluating EL expressions

To evaluate an EL expression from ADF managed classes, such as managed beans.   public Object getExpressionValue(String jsfExpression)   {     // when specifying EL expression in managed bean as "literal" value     // so t can be evaluated later, the # is replaced with $, quite strange     if (jsfExpression == null)     {       return jsfExpression;     }     if (jsfExpression.startsWith("${"))     {       jsfExpression = "#{" + jsfExpression.substring(2);     }     if (!jsfExpression.startsWith("#{"))     {       if (jsfExpression.equalsIgnoreCase("true"))       {         return Boolean.TRUE;       }       else if (jsfExpression.equalsIgnoreCase("false"))       {         return Boolean.FALSE;       }       // there can be literal text preceding the expression...       else if (jsfExpression.indexOf("#{")<0)       {         return jsfExpression;       }     }     ValueExpression ve =  getApplication().getExpres

Exception Handling in ADF

This blog will give you an overview on how you can successfully deal with unhandled Runtime exceptions in an ADF application. This will give you an idea of: How to catch the unhandled exceptions. Write a separate log file with stacktrace and thread dumps. Redirect the user to an static error page #1. Catch unhandled exceptions :  Create a class "MyExceptionHandler" which extends : oracle.adf.view.rich.context.ExceptionHandler. Override handleException() method.     public void handleException(FacesContext facesContext, Throwable throwable, PhaseId phaseId) throws Throwable {         // this method is going to create a separate file with stacktrace and thread dumps         writeException(throwable);         // redirect to error page         redirectToErrorPage(facesContext);     }  Create a folder "services" inside : ViewController\src\META-INF and then create a file named "oracle.adf.view.rich.context.ExceptionHandler". In the file, add