Exception handling in ADF can be done at following three places:
a. Taskflow Exception Handler
b. Extending Controller level ExceptionHandler - for controller level exceptions
c. Extending DCErrorHandlerImpl- for model
- Whenever there is an exception in model layer it is being handled by custom class extending DCErrorHandlerImpl.
- Exception in ADF Controller can be handled by creating a custom class extending Controller level ExceptionHandler.
- If an exception rethrown from above, it can be handled at TaskFlow level exception handler which can be a view activity, router or a method call.
One by one let`s discuss all of them:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
a. Taskflow Exception Handler
Here We will discuss on session timeout and exception handling for at taskflow level by creating an Exception Handler
STEP 1: Task Flow changes
Create a router in your taskflow:
Add a condition which points to a method in backing bean.
The method returns true if session expires and user is redirected to home/login page as needed.
And if method returns false, the user is redirected to default outcome - errorPage.
Mark the router as exception handler like this:
STEP 2: BEAN changes
Add the following method in your bean:
public boolean isSessionExpired()
{
Exception e =
ControllerContext.getInstance().getCurrentViewPort().getExceptionData();
if (e != null && (e instanceof ViewExpiredException))
{
// session timeout case
return true;
}
// IF SOA is down or some other fault in SOA process
else if (e != null &&
(e instanceof ConnectException || e instanceof javax.xml.ws.WebServiceException ||
e instanceof javax.xml.ws.soap.SOAPFaultException || e.toString().contains("Failed to access the WSDL")))
putParameterinPageFlowScope("errorMessage",
"Currently the system is in maintenance mode. Please try after sometime.");
else
putParameterinPageFlowScope("errorMessage",
"Some unexpected error has occurred. Please try after sometime.");
if (e != null)
{
StringWriter errors = new StringWriter();
e.printStackTrace(new PrintWriter(errors));
if(errors != null)
putParameterinPageFlowScope("detailedException",errors.toString());
}
return false;
}
In case where there is an exception other than ViewExpiredException(session timeout), write two parameters in request or pageFlowScope as written above:
- putParameterinPageFlowScope("errorMessage", "Currently the system is in maintenance mode. Please try after sometime.");
- putParameterinPageFlowScope("detailedException",errors.toString());
STEP 3 : Error Page
<af:outputFormatted value="#{pageFlowScope.errorMessage}"/>
<af:outputFormatted value="#{pageFlowScope.detailedException}" visible="false"/>
visible="false" makes sure the detailed exception is there in source of the page and user doesn`t see it.
You can see the same in page source.
You can add more conditions and messages in your bean method based on your scenarios like Content Server related exceptions, etc.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
b. Extending Controller level ExceptionHandler
Any exception in controller will first come here and if re-thrown will be handled at taskflow level(explained before).
STEP 1: Declaring custom exception handler class
You need to create a folder named services under Application Resources -> Descriptors -> ADF META-INF. Under the folder create a file named oracle.adf.view.rich.context.ExceptionHandler and inside the file just mention the name of your custom exception handler.
STEP 2: Custom Exception Class
We are creating a custom exception class which will be thrown in our code whenever we want to show a faces message for any validation, failure, etc.
public class XxCustomException
extends JboException
{
private String resourceBundleKey;
private String error_type;
private String client_id;
private MessageToken[] tokens;
//setters and getters with required constructors
}
STEP 3: Custom ExceptionHandler Class
import oracle.adf.view.rich.context.ExceptionHandler;
public class XxControllerExpHandler
extends ExceptionHandler
{
public void handleException(FacesContext facesContext,
Throwable throwable, PhaseId phaseId)
throws Throwable
{
boolean isCustomExp = false;
for (int i = 0; i < 10; i++)
{
if (throwable instanceof XxCustomException)
{
isCustomExp = true;
break;
}
if (throwable != null)
{
throwable = throwable.getCause();
}
}
if (isCustomExp)
{
if (throwable!= null)
{
// The below method will show a Faces Message. If client id of xxCustomException is not null then it will show a faces message on that component. It will try to get the message from resource bundle based on resourceBundleKey attribute. Error_type will decide if it is info, warning, severe
XxUtils.showMessage((XxCustomException)throwable);
}
}
else
{
//this will be handled at taskflow level
throw z;
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
c. Extending DCErrorHandlerImpl- for model
STEP 1: Custom ExceptionHandler Class for model
package xx.view.exp.model;
import javax.faces.application.FacesMessage;
import oracle.adf.model.binding.DCErrorHandlerImpl;
import oracle.adf.model.BindingContext;
import oracle.adf.model.binding.DCBindingContainer;
import oracle.jbo.JboException;
public class XxModelExpHandler
extends DCErrorHandlerImpl
{
public XxModelExpHandler()
{
super(true);
}
public XxModelExpHandler(boolean b)
{
super(b);
}
@Override
public String getDisplayMessage(BindingContext ctx, Exception th)
{
return super.getDisplayMessage(ctx, th);
}
@Override
public void reportException(DCBindingContainer formBnd, Exception ex)
{
if (ex instanceof XxCustomException)
{
//get message to be displayed from resource bundle or hardcode the message when throwing exception
String msg = XxUtils.getMessageString((XxCustomException) ex);
JboException jex=new JboException(msg);
super.reportException(formBnd,jex);
}
else
{
super.reportException(formBnd, ex);
}
}
}
STEP 2: Databindings.cpx
Specify your custom handler as ErrorHandlerClass in databindings.cpx:
<Application xmlns="http://xmlns.oracle.com/adfm/application"
version="11.1.1.59.23" id="DataBindings" SeparateXMLFiles="false"
Package="xx.view" ClientType="Generic"
ErrorHandlerClass="xx.view.exp.model.XxModelExpHandler">
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
With all the above setups you can throw an exception from your model as well as controller whenever there is any validation failure, etc and it should handle all unexpected exceptions also.
Please let me know if there is any issue in this.
I hope this is helpful.
Regards,
Deepak
Hi Deepak,
ReplyDeleteI created a custom exception handler class , created text file in services folder and in the file I mentioned the exception handler class name like view.CustomExceptionHandler as my custom class is in view package of view controller. The exception handler class is not invoked. Please help me to fix this.
Thanks,
Ravi
Are you extending ExceptionHandler class and overrriding handleException method?
ReplyDeleteAlso make sure the name of the file under services is correct.
Yes Deepak I extended ExceptionHandler class. In the text file under service folder, I mentioned the view.CustomExceptionHandler in the file. My CustomExceptionHandler is in view package of ViewController project. Please help to fix this.
ReplyDeleteThanks,
Ravi
Hi Ravi,
ReplyDeleteIt should work. Please confirm the following:
a. The name of the folder is services and not service
b. oracle.adf.view.rich.context.ExceptionHandler file doesn`t have any extension
c. The path of the services folder is like this: .adf\META-INF\services
Regards,
Deepak
Hi Deepak,
ReplyDeleteIt worked. I had txt extension for the file under services folder. I created a file under services folder with no extension. It worked. Thanks for your kind and quick response. Your blog is very helpful.
Thanks,
Ravi
Hi Deepak,
ReplyDeleteI have a question regarding the Custom ExceptionHandler Class. Why do you have this lie Throwable throwable = z;? What is z and why are you assigning it to throwable? My IDE won't even let me do this because an input parameter of a method is named the same. I suppose it's some kind of mistake..
Thanks,
Maja
Yeah that line should not be there as I was doing some more stuff in my class and had a private variable z, which I forgot to remove. Thanks.
ReplyDeleteGood post sirji :)
ReplyDeleteAre you still working in fujitsu
ReplyDeleteNo I left Fujitsu last month. Who is that anyways?
DeleteDear Deepak can you please let me know how can we redirect to error page from custom exception handler handleexception().
DeleteHi Deepak,
ReplyDeleteCan you please share the source code for this.
Hi Deepak,
ReplyDeleteCan you please share the code?
Hi Deepak, Does it cover http errors? If not is there a way to catch http errors with stack trace?
ReplyDeleteI really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post I would like to read this
ReplyDeleteClick here:
angularjs training in chennai
Click here:
angularjs2 training in chennai
Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
ReplyDeleteBlueprism training in velachery
Blueprism training in marathahalli
AWS Training in chennai
AWS Training in bangalore
Thanks for sharing this great information I am impressed by the information that you have on this blog. Same as your blog i found another one Oracle ADF .
ReplyDeleteActually, I was looking for the same information on internet for
Oracle ADF Interview Questions and Answers/Tips and came across your blog. I am impressed by the information that you have on this blog. It shows how well you understand this subject.
Smart move for your career is Choosing to do Oracle Course in Chennai at Infycle!! Do you know why this name is chosen for Infycle. Infycle where the place we offered Infinity of Oracle.
ReplyDeleteYes!!! But not only Oracle, More than 20+ courses are offered here 5000+ students are placed in top MNC’s Company with good salary packages. For admission 7502633633.
mmorpg oyunlar
ReplyDeleteinstagram takipçi satın al
tiktok jeton hilesi
TİKTOK JETON HİLESİ
antalya saç ekim
takipci satin al
İnstagram Takipçi Satın Al
metin2 pvp serverlar
ınstagram takipci satin al
özel ambulans
ReplyDeleteyurtdışı kargo
uc satın al
en son çıkan perde modelleri
lisans satın al
minecraft premium
en son çıkan perde modelleri
nft nasıl alınır
Good content. You write beautiful things.
ReplyDeletetaksi
vbet
sportsbet
mrbahis
hacklink
vbet
korsan taksi
hacklink
mrbahis
Good text Write good content success. Thank you
ReplyDeletekibris bahis siteleri
poker siteleri
betmatik
bonus veren siteler
slot siteleri
betpark
kralbet
mobil ödeme bahis
شركة مكافحة حشرات بالجبيل
ReplyDeleteشركة مكافحة حشرات بالدمام
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
SFVT6L
izmir
ReplyDeleteErzurum
Diyarbakır
Tekirdağ
Ankara
R7KKM
Adana
ReplyDeleteElazığ
Kayseri
Şırnak
Antep
NİX0
van
ReplyDeleteelazığ
zonguldak
uşak
sakarya
2EVİT4
Bolu Lojistik
ReplyDeleteMardin Lojistik
Kocaeli Lojistik
Diyarbakır Lojistik
İstanbul Lojistik
3E4
sivas evden eve nakliyat
ReplyDeleteerzurum evden eve nakliyat
bitlis evden eve nakliyat
mardin evden eve nakliyat
rize evden eve nakliyat
8JUY
B8931
ReplyDeleteMersin Evden Eve Nakliyat
Diyarbakır Evden Eve Nakliyat
Niğde Lojistik
Adıyaman Şehirler Arası Nakliyat
Tunceli Evden Eve Nakliyat
Burdur Şehirler Arası Nakliyat
Rize Parça Eşya Taşıma
Tekirdağ Parke Ustası
Bartın Şehir İçi Nakliyat
08050
ReplyDeletebinance komisyon indirimi %20
7F0FE
ReplyDeleteSoundcloud Beğeni Hilesi
Tiktok Takipçi Hilesi
Periscope Takipçi Hilesi
Bitcoin Nasıl Üretilir
Spotify Takipçi Hilesi
Sohbet
Binance Referans Kodu
Coin Nasıl Çıkarılır
Clubhouse Takipçi Satın Al
18559
ReplyDeleteGörüntülü Sohbet Parasız
Pinterest Takipçi Satın Al
Lovely Coin Hangi Borsada
Parasız Görüntülü Sohbet
Binance Yaş Sınırı
Binance Referans Kodu
Coin Madenciliği Nasıl Yapılır
Tumblr Takipçi Hilesi
Okex Borsası Güvenilir mi
16644
ReplyDeleteSohbet
Binance Para Kazanma
Binance Madencilik Nasıl Yapılır
Threads Yeniden Paylaş Hilesi
Binance Referans Kodu
Gate io Borsası Güvenilir mi
Mexc Borsası Güvenilir mi
Gate io Borsası Güvenilir mi
Telegram Görüntüleme Satın Al
1B919
ReplyDeleteKofçaz
Çemişgezek
Nazimiye
Hadim
Ağın
İbradi
Yayladere
Ovacık
Mazgirt
GNHMHJ
ReplyDeleteشركة كشف تسربات المياه بالاحساء
شركة عزل اسطح بالمزاحمية 0nJgJnLSRV
ReplyDeleteThank You and I have a tremendous proposal: Renovation House Company dream home renovations
ReplyDeleteشركة صيانة افران بالاحساء eLwssWqKP3
ReplyDeleteشركة مكافحة الحشرات بالاحساء Ix8yIndOQw
ReplyDeleteشركة مكافحة حشرات بالاحساء cVpWLj9Zis
ReplyDeleteشركة مكافحة حشرات بالخبر UvlGAcHhz7
ReplyDeleteشركة عزل اسطح بالخبر KWiECC1frq
ReplyDeleteشركة مكافحة بق الفراش بالقطيف 27HULCgIs2
ReplyDelete