How to maintain Web Service Session in Java

I’m trying to integrate to an online service called E-conomic (http://www.e-conomic.com).

They have a nice Web Service to control thir product. After importing their WSDL in a Java Library and copying their example in an agent i can connect and authenticate.

But when i try to do something something with the service - it tells me that I’m not authenticated. All in all - the session is not maintained.

The E-conomic example:

import javax.xml.rpc.ServiceException;

import com.e_conomic.*;

public class UserApp {

public static void main(String args){

EconomicWebServiceLocator locator = new EconomicWebServiceLocator();

locator.setMaintainSession(true);

EconomicWebServiceSoap session = locator.getEconomicWebServiceSoap();

session.connect(123456, ”username”, ”password”);

// Application code.

session.disconnect();

}

}

I have made a java agent with the included Java Library made from the E-conomic WSDL.

It looks like this:

import lotus.domino.*;

import javax.xml.rpc.ServiceException;

import com.e_conomic.*;

public class JavaAgent extends AgentBase {

public void NotesMain() {



	try {

		Session session = getSession();

		AgentContext agentContext = session.getAgentContext();



			EconomicWebServiceLocator locator = new EconomicWebServiceLocator();

			locator.setMaintainSession(true);

			

			EconomicWebServiceSoap ecsession = locator.getEconomicWebServiceSoap();

			ecsession.connect(123456, "<username>", "<password>");

			

			// Application code.

			InvoiceHandle invoice = ecsession.invoice_FindByNumber(123);

			

			ecsession.disconnect();



	} catch(Exception e) {

		e.printStackTrace();

	}

}

}

Which will not complie because of this line:

locator.setMaintainSession(true);

It tells that it cannot find the symbol - that it is not there. As far as I understand it sould be a property of the client side connection.

How do I maintain the session?

What am I doing wrong?

I am not that great developing Java - can anybody help me?

Best regards,

Christian Gravgaard,

IBM Certified Advanced Application Developer

Subject: It sounds like your problem is with e-conomic, not with Notes

The error message tells you that a method you expected isn’t available in EconomicWebServiceLocator class. IBM didn’t create that class and our Java environment doesn’t just randomly ignore methods in the classes you load. If the method is missing, you should consult with the people who supply that class.

Subject: No - and yes…

Hi Andre Guirard

Thanks for your response.

Of course the Java is not discarding anything. What is available from e-conomic is there.

I’ve talked with E-conomic that tells me that the problem is in Lotus Notes. It has to keep the session id somehow - and that’s my problem. I don’t know how to keep the session.

Their reson for this is that is my side of the commpunication that have to make sure that the sessoin is kept - not e-conomic.

So again: How do I maintain a session in Java?

In other Java based systems (I’m on loose grounds here) the classes that calls the foreign webservice maintain the session (Stub - Apache Axis - Java Web Services API).

Best regards,

Christian Gravgaard,

IBM Certified Advanced Application Developer

Subject: Your problem is in Lotus Notes because your Java code doesn’t compile?

Is there, or is there not, such a method as setMaintainSession(boolean) in the EconomicWebServiceLocator class? If there is, I see no reason Java shouldn’t be able to compile a program that calls it. If there is not, I don’t understand why you think you can invent new class methods of a class provided by someone else. If they haven’t written the method, you can’t call it.

If the E-conomic documentation says the method exists, but you can’t compile code that calls the method, then their documentation is wrong and the method does not exist in whatever library they have provided you.

A Domino web service initializes when it’s called, and is removed from memory when it exits. There is not a global variable storage that survives between invocations, if that’s what you’re asking. What you want for that is a servlet, not a web service.

Subject: Let’s try it one more time…

Hi Andre Guirard

Please hear me out; I’m not a complete newbee at developing - I’ve worked with 15+ languages in more than 15 years and been a professional developer in Lotus Notes sence before version 4.5.

I just don’t know Java that well.

No it does not compile because there is no method called setMaintainSession(boolean). That’s the problem!

I don’t expect to “invent” a new class method. I expect it to be in the lotus.domino.websvc.client.Service that is extended by a WebService Locator in Lotus Notes Java.

This is the way that for instance Apache Axis 1.4 framework is working. It has a derived method called setMaintainSession(boolean) that takes care of an authenticated session handled by the foreign WebService.

I am fully aware that the call is proberly not called setMaintainSession(boolean) in the lotus.domino.websvc.client.Service class. It is proberly called something else. But what?

This is not anything to do with a global variable storage. I’m getting an object with a WebService stub that is being authenticated in the first call.

Then I expect to have THE SAME object - now in authenticated state. I haven’t left the scope; I’m in the next line of execution.

But the object is not authenticated anymore. When I call a method in THE SAME object again - in the same scope - the foreign WebService thinks I’m not authenticated. This is happening because Lotus Notes is not passing the SAME session ID back the the foreign WebService as the one it recieved during authentication.

What is happening is that the lotus.domino.websvc.client.Service is not maintaining the session. It needs to be switched on - somehow.

That’s the issue…

How do I make lotus.domino.websvc.client.Service maintaining the webService Session ID.

Best regards,

Christian Gravgaard,

IBM Certified Advanced Application Developer

Subject: Andre, the problem is the Domino web service base class

This is a legitimate issue. The DominoSoapBindingStub class that’s auto-generated extends lotus.domino.websvc.client.Stub rather than org.apache.axis.client.Stub

The Apache stub version has a method to setMaintainSession(). The Lotus version does not, and as far as I can tell simply works directly against javax.xml.rpc

It might be possible to set javax.xml.rpc.session.maintain = true in the Domino version of the client stub.

Subject: Exactly -.but how do I implement it?

Hi Nathan T. Freeman

That’s exactly the problem! But how do I implement it?

Do I implement it like this:

EconomicWebServiceLocator locator = new EconomicWebServiceLocator();

locator.session.maintain = true;

Which doesn’t work…

or do I implement it in the WebService handler it self (somewhere?!?):

package com.e_conomic;

public class EconomicWebServiceLocator extends lotus.domino.websvc.client.Service implements com.e_conomic.EconomicWebService {

public EconomicWebServiceLocator() {

    super("HttpEConomicComEconomicWebService");

}



// Use to get a proxy class for EconomicWebServiceSoap

private final java.lang.String EconomicWebServiceSoap_address = "https://www.e-conomic.com/secure/api1/EconomicWebService.asmx";



public java.lang.String getEconomicWebServiceSoapAddress() {

    return EconomicWebServiceSoap_address;

}



// The WSDD service name defaults to the port name.

private final java.lang.String EconomicWebServiceSoapWSDDServiceName = "EconomicWebService.EconomicWebServiceSoap";



public com.e_conomic.EconomicWebServiceSoap getEconomicWebServiceSoap() throws javax.xml.rpc.ServiceException {

   java.net.URL endpoint;

    try {

        endpoint = new java.net.URL(EconomicWebServiceSoap_address);

    }

    catch (java.net.MalformedURLException e) {

        throw new javax.xml.rpc.ServiceException(e);

    }

    return getEconomicWebServiceSoap(endpoint);

}

Best regards,

Christian Gravgaard,

IBM Certified Advanced Application Developer

IBM Certified System Administrator

Subject: SOLUTION! - How to integrate to e-conomic webservice through java in Lotus Notes Domino

Thanks for the hint - it gave me the final piece of the puzzle:

The solution of using a Java Web Service in Lotus Notes Domino to connect to e-conomic is as follows:

Use the _setProperty on the stub in the Java Library where the eConomic webservice is imported:

_setProperty(javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);

Modify the getEconomicWebServiceSoap and getPort methods to include this line:

_stub._setProperty(javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);

The methods will then look like this:

public com.e_conomic.EconomicWebServiceSoap getEconomicWebServiceSoap(java.net.URL portAddress) throws javax.xml.rpc.ServiceException {

    try {

        com.e_conomic.EconomicWebServiceSoapStub _stub = new com.e_conomic.EconomicWebServiceSoapStub(portAddress, this);

        _stub.setPortName(EconomicWebServiceSoapWSDDServiceName);

	_stub._setProperty(javax.xml.rpc.Stub.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);

        return _stub;

    }

    catch (lotus.domino.types.Fault e) {

        return null;

    }

}

If you’ve got any questions, please let me know.

Best Regards,

Christian Gravgaard,

At Axis ApS

IBM Certified Advanced Application Developer

IBM Certified System Administrator

E-mail: christian.gravgaard@at-axis.dk

Web: http://at-axis.dk

Subject: Glad to see you got it working

I saw those _setProperty methods via JAD. Thanks for doing the testing on that, too. I really wasn’t clear on how to leverage that.