cancel
Showing results for 
Search instead for 
Did you mean: 

How to catch JCO exception in web dynpro java

Former Member
0 Kudos

Hi,

I'm using an Adaptative RFC Model to recover some values from R3 through a RFC function. I've created and configured JCOs and it's all working OK.

Now I have to trap any exception that could be triggered from JCO, and instead showing JAVA stacktrace, I have to show a more user-friendly message.

In order to generate an exception, I blocked R3 user used in JCO security tab.

Next is the code I'm using for trapping the exception:


try {
	wdContext.nodeBapi_Exchangerate_Getdetail_Input().bind(new Bapi_Exchangerate_Getdetail_Input());
		
	java.sql.Date fechaHoy = new java.sql.Date((new java.util.Date()).getTime());	
	wdContext.currentBapi_Exchangerate_Getdetail_InputElement().setDate(fechaHoy);
		
	wdContext.currentBapi_Exchangerate_Getdetail_InputElement().setRate_Type("G");
	wdContext.currentBapi_Exchangerate_Getdetail_InputElement().setFrom_Curr("USD");
	wdContext.currentBapi_Exchangerate_Getdetail_InputElement().setTo_Currncy("ARS");
		
	wdContext.currentBapi_Exchangerate_Getdetail_InputElement().modelObject().execute();
	wdContext.nodeBapi_Exchangerate_Getdetail_Input().invalidate();
		
} catch (WDDynamicRFCExecuteException ex) {
	ex.printStackTrace();
	wdComponentAPI.getMessageManager().reportSuccess("-WDDynamicRFCExecuteException------------------------");
	wdComponentAPI.getMessageManager().reportSuccess(ex.getMessage());
} catch (JCO.Exception ex) {
	ex.printStackTrace();
	wdComponentAPI.getMessageManager().reportSuccess("-JCO.EXCEPTION------------------------");
	wdComponentAPI.getMessageManager().reportSuccess(ex.getMessage());
} catch (WDRuntimeException ex) {
	ex.printStackTrace();
	wdComponentAPI.getMessageManager().reportSuccess("-WDRuntimeEXCEPTION------------------------");
	wdComponentAPI.getMessageManager().reportSuccess(ex.getMessage());
} catch (Exception e) {
	e.printStackTrace();
	wdComponentAPI.getMessageManager().reportSuccess("-EXCEPTION----------------------------");
	wdComponentAPI.getMessageManager().reportSuccess("getClass: " + e.getClass());
}

I'm having no correct result: the exception it's not being captured and stackTrace is kept showing on screen. Following is the obtained stacktrace


500   Internal Server Error 
SAP NetWeaver Application Server 7.00/Java AS 7.00  

Failed to process request. Please contact your system administrator. 

[Hide]

Error Summary 

... 

Root Cause 
The initial exception that caused the request to fail, was:

   com.sap.mw.jco.JCO$Exception: (103) RFC_ERROR_LOGON_FAILURE: Usuario bloqueado -> Informar al responsable. 

    at com.sap.mw.jco.MiddlewareJRfc.generateJCoException(MiddlewareJRfc.java:516)
    at com.sap.mw.jco.MiddlewareJRfc$Client.connect(MiddlewareJRfc.java:1086)
    at com.sap.mw.jco.JCO$Client.connect(JCO.java:3256)
    at com.sap.dictionary.runtime.mdi.DataProvider.<init>(DataProvider.java:91)
    at com.sap.dictionary.runtime.mdi.DataProvider.<init>(DataProvider.java:123)
    ... 45 more

Anyone knows the reason? Is the code wrong? Please, help.

<<text removed>>

Thans in advance.

Marcelo

Edited by: Matt on Apr 25, 2011 8:01 AM

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Since its an error you cannot handle it from the programming end.

Regards,

Suresh.

Former Member
0 Kudos

Hi Suresh,

If I can't handle from the programming end, is there any configuration on the SLD or JCO setting? which options do I have left?

I mean, it don't believe this kind of exceptions couldn't be catched! Is this mean that users going to see the java stacktrace every time an exception occurs?

Thanks,

Regards,

Marcelo

Former Member
0 Kudos

Hi Marcelo,

Have you configured Jco destination properly & able to ping the SAP System successfully..?

Thanks,

Arun.

Former Member
0 Kudos

Hi Arun,

thanks for your answer, and sorry for my late response (again 😛 )

The Jco configuration is ok, and I'm able to ping it successfully.

 A ping to the JCo destination 'WD_JCOTEST_MODELDATA_DEST' was sucessfully executed. 

But what I'm trying to do from my Web Dynpro App is capture any possible exception when (for example) the user used on Jco Configuration is locked. So, with a locked user, when I test the Jco, I get (as expected):

 com.sap.mw.jco.JCO$Exception: (103) RFC_ERROR_LOGON_FAILURE: User is locked. Please notify the person responsible 

I need to capture this exception properly, and show a user-friendly message, instead the usual next stacktrace message


500   Internal Server Error 
  SAP NetWeaver Application Server 7.00/Java AS 7.00  
 Failed to process request. Please contact your system administrator. 

Resuming, I need to trap this exception from my web dynpro application!!

Again, thanks in advance.

Regards,

Marcelo

Qualiture
Active Contributor
0 Kudos

Hi Marcelo,

Although I cannot test it myself right now, in my code I have used the following try-catch block to handle JCO exceptions:

    try {
        //your code
        //...
    }
    catch (AbapException ex) {
        //handle RFM exception
    }
    catch (JCoException ex) {
        //handle system failure
    }
    catch (JCoRuntimeException ex) {        
        //handle basic jco runtime exceptions
    }
    catch (Exception ex) {
        //anything else
    }

Hope this helps!

Best regards,

Robin van het Hof

Former Member
0 Kudos

HI Robin,

thanks for your quick answer.

I guess you're right. The code that you're using is ok.

However, I'm not interested on catching the AbapException because there is no exception generated on BAPI's side (it's a provided by SAP BAPI, and it is working ok: I've tested it with SE37 transaction).

The actual problem is capture any exception occurring when, for example, there is no conection between Portal and R/3. On that case, I need to avoid executing any code, and show a user-friendly message, like "The application is offline right now, please try again later".

I guess the exception is being generated before the try-catch blocks that you mentioned, because I'm getting this message:

The initial exception that caused the request to fail, was: com.sap.mw.jco.JCO$Exception: (103) RFC_ERROR_LOGON_FAILURE: Access key access is no longer possible: Too many failed attempts at com.sap.mw.jco.MiddlewareJRfc.generateJCoException(MiddlewareJRfc.java:516) at com.sap.mw.jco.MiddlewareJRfc$Client.connect(MiddlewareJRfc.java:1086) at com.sap.mw.jco.JCO$Client.connect(JCO.java:3256) at com.sap.dictionary.runtime.mdi.DataProvider.<init>(DataProvider.java:91) at com.sap.dictionary.runtime.mdi.DataProvider.<init>(DataProvider.java:123) ... com.sap.tc.webdynpro.services.exceptions.TypeNotFoundException: type bat.com.jcotest.divisasmodel.types.Tcurr_Curr could not be loaded: com.sap.dictionary.runtime.DdException: failed to create provider: Acceso clave acceso ya no es posible: Demasiados intentos fallidos at com.sap.tc.webdynpro.services.datatypes.core.DataTypeBroker.getSimpleType(DataTypeBroker.java:268) at com.sap.tc.webdynpro.services.datatypes.core.DataTypeBroker.getDataType(DataTypeBroker.java:231) ...

Remember: the "Access key access is no longer possible: Too many failed attempts" message is expected, because I've locked the JCO connection user on purpose, in order to see if I can capture the exception generated. Sadly, the exception it's not captured or it's happening before try-catch block.

Any help would be highly appreciated.

Best Regards,

Marcelo

Former Member
0 Kudos

Hi

Have you noticed this:

com.sap.tc.webdynpro.services.exceptions.TypeNotFoundException: type bat.com.jcotest.divisasmodel.types.Tcurr_Curr could not be loaded: com.sap.dictionary.runtime.DdException: failed

??

regards

yuval

Former Member
0 Kudos

Hi yuval,

yes, I've noticed it. But I don't know how to trap it, because I can't get to it!! There is no file on my Web Dynpro proyect that holds it, and therefore I cant' write the code to trap it.

Thanks and Help!

Best regards,

Marcelo

Qualiture
Active Contributor
0 Kudos

Hi Marcelo,

It might not solve your initial problem, but if you want to check whether a connection is available, you could use the following code prior to executing your function, and handling a fault by deliberately throwing a JcoException:

public void checkConnectionl() throws JCoException {
    JCoDestination destination = JCoDestinationManager.getDestination(YOUR_DESTINATION_NAME);
    destination.ping();
}

Hope this helps!

Robin

Former Member
0 Kudos

Hi,



com.sap.mw.jco.JCO$Exception: (103) RFC_ERROR_LOGON_FAILURE:

This Error is because of SSO failure. See this link

http://help.sap.com/saphelp_erp2004/helpdata/en/ca/115e4088dc0272e10000000a155106/content.htm

For JCo Exception handling see this,

http://help.sap.com/saphelp_nw70ehp1/helpdata/en/f6/daea401675752ae10000000a155106/content.htm

Thanks,

Arun

Former Member
0 Kudos

Hi Arun,

thanks for your answer, and sorry for my late response.

I've checked what you said, but I think that is not useful for my case, because I'm not using dynamic JCOs but static JCOs, defined in Web Dynpro Content Administrator.

My problem is to find where the exception occurs. In this case, it occurs outside my web dynpro application: I think the exception occurrs BEFORE any code of my web dynpro application executes, and that is way I can't capture the exception.

Check the trace:

Caused by: com.sap.mw.jco.JCO$Exception: (103) RFC_ERROR_LOGON_FAILURE: Usuario bloqueado -> Informar al responsable.

at com.sap.mw.jco.MiddlewareJRfc.generateJCoException(MiddlewareJRfc.java:516)

at com.sap.mw.jco.MiddlewareJRfc$Client.connect(MiddlewareJRfc.java:1086)

at com.sap.mw.jco.JCO$Client.connect(JCO.java:3256)

at com.sap.dictionary.runtime.mdi.DataProvider.<init>(DataProvider.java:91)

at com.sap.dictionary.runtime.mdi.DataProvider.<init>(DataProvider.java:123)

... 46 more

Thanks in advance.

Regards,

Marcelo