You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Manuel Lozano Melero <ml...@cc.upv.es> on 2009/04/01 19:17:04 UTC
Re: Problem with two services in a serviceGroup with scope soapsession
sharing ServiceGroupContext
I am new in AXIS2 and the problem is in this configuration:
- Two clases, in each class there is a service with operations to invoke.
- The first class(service Autenticacion) it is used to autenticate the
user in the application
- The second class(service Directorio) do a job, but it validates that
the user is autenticated
- I want a unique ServiceGroupContext where the first service
"Autenticacion" puts a valid "sessionId" if the user+password is valid.
- Then a new request to the second service "Directorio" gets from
"ServiceGroupContext " the "sessionId"
-- The problem is that there are two contexts!!! see the details......
Thanks
I have this service.xml configuration:
<serviceGroup>
<service name="Autenticacion" scope="soapsession">
<Description> Servicio WEB de autenticacion</Description>
<parameter name="ServiceClass"
locked="false">es.upv.wsasic.app.Autenticacion</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
</service>
<service name="Directorio" scope="soapsession">
<Description> Servicio WEB de directorio</Description>
<parameter name="ServiceClass"
locked="false">es.upv.wsasic.app.Directorio</parameter>
<messageReceivers>
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only"
class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
<messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out"
class="org.apache.axis2.rpc.receivers.RPCMessageReceiver" />
</messageReceivers>
</service>
<module ref="addressing" />
</serviceGroup>
------------------------------ Continue -------------------------------
I have generated the Stubs from the WSDL :
wsdl2java.bat -uri Autenticacion.wsdl -p es.upv.wsasic.cliente -d adb -s
wsdl2java.bat -uri Directorio.wsdl -p es.upv.wsasic.cliente -d adb -s
Then i have incluided in both stubs constructors:
.............
_serviceClient.engageModule("addressing");
_serviceClient.getOptions().setManageSession(true);
.............
---------------------------------Continue-----------------------------------------
package es.upv.wsasic.cliente;
................
public class ClientAutenticacion {
public static void main(String[] args) {
String puntoFinalAutenticacion =
"http://mymachine:8080/wsasic-app/services/Autenticacion";
String puntoFinalDirectorio =
"http://mymachine:8080/wsasic-app/services/Directorio";
String modulos =
"C:\\jupv\\ws_ganymedes\\wsasic-appClient\\WebContent\\WEB-INF";
String axis2xml =
"C:\\jupv\\ws_ganymedes\\wsasic-appClient\\WebContent\\WEB-INF\\conf\\axis2.xml";
ConfigurationContext contextoConfiguracion;
contextoConfiguracion =
ConfigurationContextFactory.createConfigurationContextFromFileSystem(modulos,
axis2xml); AutenticacionStub
autenticacionStub = new
AutenticacionStub(contextoConfiguracion,puntoFinalAutenticacion);
byte[] sessionId;=
obtieneSessionId(autenticacionStub);
DirectorioStub directorioStub = new
DirectorioStub(contextoConfiguracion,puntoFinalDirectorio);
Person persona = getInfoPerson(directorioStub,new
String(Base64.encodeBase64(sessionId)),"226805");
}
public static byte[] obtieneSessionId(AutenticacionStub stub) {
byte[] sessionId=null;
try {
AutenticacionStub.ObtieneSessionId req = new
AutenticacionStub.ObtieneSessionId();
req.setUsuario("user1");
req.setPassword("mypwd235");
AutenticacionStub.ObtieneSessionIdResponse res =
stub.obtieneSessionId(req); DataHandler
respuesta = res.get_return();
InputStream is = respuesta.getInputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] b= new byte[1024];
int num = is.read(b);
while (num > 0) {
baos.write(b, 0, num);
num = is.read(b);
}
sessionId = baos.toByteArray(); } catch
(Exception e) {
e.printStackTrace();
}
return sessionId; }
public static Person getInfoPerson(DirectorioStub stub,String
sessionId,String dni){
try {
DirectorioStub.GetInfoPersonaBasica req = new
DirectorioStub.GetInfoPersonaBasica();
req.setSessionId(sessionId);
req.setDni(dni);
DirectorioStub.GetInfoPersonaBasicaResponse res =
stub.getInfoPersonaBasica(req);
Person persona = res.get_return();
return persona;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
---------------------------------Continue-----------------------------------------
In the service "es.upv.wsasic.app.Autenticacion" class i have a method
to autenticate a user in my application. This is the first service
request .
public byte[] obtieneSessionId(String user,String password){
.... do validation and return a String "sessionId" variable if
autentication success
ServiceGroupContext
session=MessageContext.getCurrentMessageContext().getServiceGroupContext();
session.setProperty("sessionId", sessionId); // I want to save
this value
return AESCipher.encode(sessionId);
}
And in the other service "es.upv.wsasic.app.Directorio" class i have a
method, but before to execute the request(this is the second service
request) i validate that the user is autenticated in the application in
this way.
public Person getInfoPerson(String sessionId, String dni) throws
ServicioException{
ServiceGroupContext sesion =
MessageContext.getCurrentMessageContext().getServiceGroupContext();
String sessionIdAES = (String) sesion.getProperty("sessionId");
/*
But in this point "sessionIdAES" is null and "sesion" has a
diferent ServiceGroupContext, it seems that has two ServiceGroupContext
each for service "Autenticacion" and "Directorio", and i
only want a ServiceGroupContext for the two services in the
"soapsession" scope.
This is the problem, how to share a unique
ServiceGroupContext in this scope!
If i call the same "Atenticacion" service more than one
time, the ServiceGroupContext for this service is unique.
And then i call "Directorio" more than one time, and the
new ServiceGroupContext for this service is unique for "Directorio" but
this
situation is the problem, there are two different contexts.
*/
......
}