cancel
Showing results for 
Search instead for 
Did you mean: 

What should be done when client.connect() failed?

Former Member
0 Kudos

Hi guys,

I am using JCO to connect backend System. If client.connect() is called and for certain reason failed, what should I do to roll back the action so that the system keeps normal. I think client.disconnect is not the solution, because connect is not successful. I encountered this problem, and my portal is totally down, what should I do to avoid this situaltion?

My code is

try{

client.connect();

}

catch (JCO.Exception e){

//WHAT SHOULD BE DONE HERE?

System.exit(1);

}

Thanks in advance!

Regards,

Liying

Accepted Solutions (1)

Accepted Solutions (1)

former_member186016
Active Contributor
0 Kudos

Hi Liying,

When you do client.connect(); system tries to connect. And there will be only one attempt. And after timeout it will stop trying. Only thing is you can lower down is the timeout period, hence system will try connecting for less time.

The rollout code you can put in catch block. When system isn't able to connet it will throw JCo Exception. You can put your rollout login the catch block.

Regards,

Ashwani

Former Member
0 Kudos

Hi Ashwani

Thanks for ur reply.

Can u put some example code?

former_member182294
Active Contributor
0 Kudos

Hi Liying,

You might be calling client.connect() in some method. Do this..

public boolean connectToSAP()

{

boolean statusFlag = true;

try

{

client.connect();

}

catch (JCO.Exception e)

{

statusFlag = false;

}

}

In your code check the return status from this method and do not execute functions if status is false.

Regards

Abhilash

former_member186016
Active Contributor
0 Kudos

Hi,

Can you try this code.


class JCOConnector {

private JCO.Client mConnection = null;

  // loginParams will settings for connection
  public static boolean connect(Properties loginParams) {
  boolean returnCode = false;
		try {
			mConnection = JCO.createClient(loginParams);						
			long timeBeforeConnecting = System.currentTimeMillis(); 
			mConnection.connect();
			long timeAfterConnection = System.currentTimeMillis();						
			returnCode = true;
		} catch (Exception e) {
			try {
				disconnect();
			} catch (Exception e2) {
			throw new RuntimeException(e);
		}
		return returnCode;
}

  /**
	 * To Disconnect from the middleware.
	 */
	public static boolean disconnect() {
		boolean returnCode = false;
		if (mConnection != null) { // if connection exists
			try {
				mConnection.disconnect();	// disconnect from the middleware
				returnCode = true;
			}catch (Exception e2) {
				
			}finally {
				mConnection = null;			
			}	
		}else{			
			returnCode = true;
		}
		return returnCode;	
	}
	
}

Regards,

Ashwani

former_member186016
Active Contributor
0 Kudos

Hi,

You can also use connection pooling to improve performance.

Use the pdf to get more info

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/tips%20and%20tricks%20for%20sap%20java%20connector%20client%20programming.pdf">JCO Tweeking</a>

Regards

Ashwani

Former Member
0 Kudos

Thanks u all. I will try it later and give u feedback.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try this code

IWDJCOClientConnection clientCon = WDSystemLandscape.getJCOClientConnection("<WD_MODELDATA_DEST_JCO>");

JCO.Client client= clientCon.getClient();

if(client.isAlive()){

}else{

//Error message

}

Thanks,

Lohi.

Former Member
0 Kudos

Thanks Lohi

But I am not developing WebDynpro