Comparaison des versions

Légende

  • Ces lignes ont été ajoutées. Ce mot a été ajouté.
  • Ces lignes ont été supprimées. Ce mot a été supprimé.
  • La mise en forme a été modifiée.

...

Au vu des particularités d'usage technique de ces WebServices, il a semblé intéressant d'initier cette page.

Sommaire

Web Service

...

Apogée

Intoduction

Le Web Service SOAP Apogée de l'AMUE a longtemps été livré avec un client jar.

...

Bloc de code
languagexml
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxws-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>apogee-wsdl-etudiant-metier</id>
            <goals>
                <goal>wsimport</goal>
            </goals>
            <configuration>
                <wsdlUrls>
                    <wsdlUrl>https://ws.univ-ville.fr/apo-ws/services/EtudiantMetier?wsdl</wsdlUrl>
                </wsdlUrls>
                <packageName>fr.univville.wsclient.apogee.etudiant</packageName>
            </configuration>
        </execution>
    </executions>
    <configuration>
        <verbose>true</verbose>
        <sourceDestDir>${basedir}/src/main/java</sourceDestDir>
		<args>
			<arg>-B-XautoNameResolution</arg>
		</args>     
    </configuration>
</plugin>

...

L'objectif est de partager le code permettant d'utiliser les webservices ListeAgentsWebService et DossierAgentDateWebService (et DossierParametrageWebService pour la partie Java)

Contraintes Web Service Siham (

...

mars 2020).

Nous avons identifié plusieurs contraintes à l'usage des web services siham ; nous espérons que Siham évolue rapidement pour corriger ces problèmes.

...

Le Web Service Siham DossierAgentDateWebService.RecupDonneesAgents ne supporte pas les appels en accès concurrent : si 2 clients appellent ce web service siham en même temps, le web service plante.

LEn octobre 2019, l'AMUE nous a signalé signalait qu'une correction une correction devait être apportée dans le prochain "Patch SIHAM" dédié aux corrections Web Services.

...

On configure apache pour utiliser le module worker et n'avoir qu'un seul process (server) à la fois ce qui permettra d'utiliser la directive max dans le proxypass : 


Bloc de code
titleconf.modules.d/00-mpm.conf
LoadModule mpm_worker_module modules/mod_mpm_worker.so

# ServerLimit à 1 pour pouvoir faire un max=1 dans le proxypass et faire ainsi goulot d'étranglement : 
# 1 seule requête à la fois que le WS de siham qui ne supporte pas les appels concurrents
ServerLimit         1
StartServers         1
MaxRequestWorkers  512
ThreadsPerChild     512
MaxClients	    512
ThreadLimit	    512
# MaxConnectionsPerChild à 1 pour que si ça plante entre apache et tomcat, 
# le fait que le thread qui gère cette requête/connexion soit dans un état 'incohérent' ne pose pas de pb : 
# chaque thread n'étant utilisé qu'une fois pour 1 requête : 
MaxConnectionsPerChild 1

...

Bloc de code
# mise en place du goulot d'étranglement pour les WS siham ne supportant pas la concurrence
# conf en lien avec 00-mpm.conf
# flushpackets=on ... à voir l'utilité ?
ProxyPass /DossierAgentDateWebService ajp://sachinsacha.univ-rouen.fr:8010/DossierAgentDateWebService retry=1 timeout=300 max=1 smax=50 flushpackets=on
ProxyPass /ListeAgentsWebService ajp://sachinsacha.univ-rouen.fr:8010/ListeAgentsWebService retry=1 timeout=300 max=1 smax=50 flushpackets=on
ProxyPass / ajp://sachinsacha.univ-rouen.fr:8010/ retry=1 timeout=3600

...

Code Java

Bloc de code
languagejava

import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.MessageContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.multipart.MultipartException;

import fr.univville.siham.dossieragent.DossierAgentDateWebService;
import fr.univville.siham.dossieragent.Individu;
import fr.univville.siham.dossieragent.Matricule;
import fr.univville.siham.dossieragent.ParamAgentDateWS;
import fr.univville.siham.dossieragent.ReferentielService;
import fr.univville.siham.dossieragent.WebserviceException_Exception;
import fr.univville.siham.listeagents.IListeAgentsWebService;
import fr.univville.siham.listeagents.ListeAgentsWS;
import fr.univville.siham.listeagents.ParamListeAgents;
import fr.univville.siham.listeagents.ResultatsListeAgents;
import fr.univville.siham.listeagents.WebServiceException_Exception;
import fr.univville.siham.parametrage.DossierParametrageWebService;
import fr.univville.siham.parametrage.ListeNomenclatures;
import fr.univville.siham.parametrage.ListeUO;
import fr.univville.siham.parametrage.NomenclatureService;
import fr.univville.siham.parametrage.ParamNomenclature;
import fr.univville.siham.parametrage.ParamStructure;
import fr.univville.siham.parametrage.Repertoire;
import fr.univville.siham.parametrage.Structures;

public class SihamService  {
	
	private static final int NB_AGENTS_PER_REQUEST = 20;
	
    protected final Logger log = LoggerFactory.getLogger(this.getClass());
	
	private IListeAgentsWebService listeAgentsWebService;
	
	private DossierAgentDateWebService dossierAgentDateWebService;
	
	private DossierParametrageWebService parametrageWebService;
	
	private String url;
	
	private String username;
	
	private String password;

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	private Map<String, List<String>> getWsHeaders() {
		Map<String, List<String>> headers = new HashMap<String, List<String>>();
		headers.put("Username", Collections.singletonList(username));
		headers.put("Password", Collections.singletonList(password));
		return headers;
	}
	
	private IListeAgentsWebService getIListeAgentsWebService() {
		if(listeAgentsWebService==null) {
			try {
				initAuthenticator();
				URL listeAgentsWsUrl = new URL(url + "/ListeAgentsWebService/ListeAgentsWebService?wsdl");
				ListeAgentsWS listeAgentsWS = new ListeAgentsWS(listeAgentsWsUrl);
				listeAgentsWebService = listeAgentsWS.getListeAgentsWebServiceImplPort();
				Map<String, Object> req_ctx = ((BindingProvider)listeAgentsWebService).getRequestContext();
				req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, getWsHeaders());
				log.info("Siham listeAgentsWebService OK");
			} catch(Exception ex) {
				throw new RuntimeException("Exception during initialization of siham ws ListeAgentsWebService", ex); 
			} finally {
				resetAuthenticator();
			}
		}
		return listeAgentsWebService;
	}
	
	private DossierAgentDateWebService getDossierAgentDateWebService() {
		if(dossierAgentDateWebService==null) {
			try {
				initAuthenticator();
				URL dossierAgentWsUrl = new URL(url + "/DossierAgentDateWebService/DossierAgentDateWebService?wsdl");
				ReferentielService referentielService = new ReferentielService(dossierAgentWsUrl);
				dossierAgentDateWebService = referentielService.getDossierAgentDateWebServiceImpPort();
				Map<String, Object> req_ctx_ref = ((BindingProvider)dossierAgentDateWebService).getRequestContext();
				req_ctx_ref.put(MessageContext.HTTP_REQUEST_HEADERS, getWsHeaders());
				log.info("Siham dossierAgentDateWebService OK");
			} catch(Exception ex) {
				throw new RuntimeException("Exception during initialization of siham ws DossierAgentDateWebService", ex); 
			} finally {
				resetAuthenticator();
			}
		}
		return dossierAgentDateWebService;
	}
	
	private DossierParametrageWebService getDossierParametrageWebService() {
		if(parametrageWebService==null) {
			try {
				initAuthenticator();
				URL parametrageWsUrl = new URL(url + "/DossierParametrageWebService/DossierParametrageWebService?wsdl");
				NomenclatureService nomenclatureService = new NomenclatureService(parametrageWsUrl);
				parametrageWebService = nomenclatureService.getDossierParametrageWebServiceImpPort();
				Map<String, Object> req_ctx_par = ((BindingProvider)parametrageWebService).getRequestContext();
				req_ctx_par.put(MessageContext.HTTP_REQUEST_HEADERS, getWsHeaders());
				log.info("Siham parametrageWebService OK");
			} catch(Exception ex) {
				throw new RuntimeException("Exception during initialization of siham ws DossierAgentDateWebService", ex); 
			} finally {
				resetAuthenticator();
			}
		}
		return parametrageWebService;	
	}

	
	private void initAuthenticator() {
		Authenticator.setDefault(new Authenticator() {
			 @Override
			 protected PasswordAuthentication getPasswordAuthentication() {
			   return new PasswordAuthentication(
				 username,
				 password.toCharArray());
			 }
		});
	}
	
	private void resetAuthenticator() {		
		Authenticator.setDefault(null);
	}
	
	protected List<String> getAgentsMatricules(String nomUsuel) {
		List<String> matricules = new ArrayList<String>();
		ParamListeAgents paramRecupListeAgents = new ParamListeAgents();
		paramRecupListeAgents.setNomUsuel(nomUsuel);
		try {
			 List<ResultatsListeAgents> agents= getIListeAgentsWebService().recupListeAgents(paramRecupListeAgents);
			 for(ResultatsListeAgents agent : agents) {
				 matricules.add(agent.getMatricule());
			 }
			 log.debug(agents.size() + " matricules d'agents récupérés depuis Siham");
		} catch (WebServiceException_Exception e) {
			throw new MultipartException("Erreur lors de la récupération agents depuis web-service siham", e);
		}
		return matricules;
	}
	
	public Individu getSihamIndividu(String matricule) {
		Map<String, Individu> sihamIndividus = getSihamIndividus(Arrays.asList(new String[] {matricule}));
		return sihamIndividus.get(matricule);
	}
	
	public synchronized Map<String, Individu> getSihamIndividus(List<String> matricules) {
		Map<String, Individu> sihamIndividus = new HashMap<String, Individu>();
		ParamAgentDateWS paramAgentDateWS = new ParamAgentDateWS();
		int i = 0;
		int n = 0;
		List<String> matriculesErreurs = new ArrayList<String>();
		for(String matricule: matricules) {
			i++;
			n++;
			Matricule matriculeObj = new Matricule();
			matriculeObj.setMatricule(matricule);
			paramAgentDateWS.getListeMatricules().add(matriculeObj);
			if(i==NB_AGENTS_PER_REQUEST || n==matricules.size()) {
				try {
					List<Individu> agents = getDossierAgentDateWebService().recupDonneesAgents(paramAgentDateWS);
					for(Individu agent: agents) {
						sihamIndividus.put(agent.getDonneesPersonnelles().getMatricule(), agent);
					}
				} catch (WebserviceException_Exception e) {
					log.info("Erreur lors de la récupération agents depuis web-service siham", e);
					for(Matricule agentMatricule : paramAgentDateWS.getListeMatricules()) {
						ParamAgentDateWS agentParamAgentDateWS = new ParamAgentDateWS();
						agentParamAgentDateWS.getListeMatricules().add(agentMatricule);
						try {
							List<Individu> agents = getDossierAgentDateWebService().recupDonneesAgents(agentParamAgentDateWS);
							for(Individu agent: agents) {
								sihamIndividus.put(agent.getDonneesPersonnelles().getMatricule(), agent);
							}
						} catch (WebserviceException_Exception ee) {
							log.warn("Erreur lors de la récupération de cet agent depuis web-service siham : " + agentMatricule.getMatricule(), ee);
							sihamIndividus.put(agentMatricule.getMatricule(), new SihamIndividuAgentInError());
							matriculesErreurs.add(agentMatricule.getMatricule());
						}
					}
				}
				paramAgentDateWS = new ParamAgentDateWS();
				i = 0;
			}
		}
		if(matriculesErreurs.size() > 0) {
			log.error("Matricules en erreur lors de la récupération de ces agents depuis web-service siham : " + matriculesErreurs);
		}
		log.info(sihamIndividus.size() + " agents récupérés depuis Siham dont " + matriculesErreurs.size() + " en erreur.");
		return sihamIndividus;
	}
	
	public Map<String, Individu> getSihamIndividuFromNomUsuel(String nomUsuel) {
		List<String> matricules = getAgentsMatricules(nomUsuel);
		Map<String, Individu> sihamIndividus = getSihamIndividus(matricules);
		return sihamIndividus;
	}
	
	public List<Structures> getSihamStructures() {
		List<Structures> structures;
		try {
			ParamStructure paramStructure = new ParamStructure();
			paramStructure.setCodeAdministration("");
			paramStructure.setDateObservation("");
			paramStructure.getListeUO().add(new ListeUO());
			structures = getDossierParametrageWebService().recupStructures(paramStructure);
		} catch (fr.univville.siham.parametrage.WebserviceException_Exception e) {
			throw new RuntimeException("Erreur lors de la récupération des structures depuis web-service siham", e);
		}
		log.info(structures.size() + " structures récupérées depuis Siham");
		return structures;
	}
	
	
	public List<Repertoire> getSihamNomenclaturesRepertoires() {
		List<Repertoire> repertoires;
		try {
			ParamNomenclature paramNomenclature = new ParamNomenclature();
			paramNomenclature.setCodeAdministration("");
			paramNomenclature.setDateObservation("");
			paramNomenclature.getListeNomenclatures().add(new ListeNomenclatures());
			repertoires = getDossierParametrageWebService().recupNomenclaturesRH(paramNomenclature);
		} catch (fr.univville.siham.parametrage.WebserviceException_Exception e) {
			throw new RuntimeException("Erreur lors de la récupération des répertoires de nomenclatures depuis web-service siham", e);
		}
		log.info(repertoires.size() + " répertoires de nomenclatures récupérées depuis Siham");
		return repertoires;
	}


}

...

Bloc de code
languagejava
List<Structures> sihamStructures = sihamService.getSihamStructures();
// ...


List<Repertoire> sihamRepertoiresNomenclatures = sihamService.getSihamNomenclaturesRepertoires();
// ...

Map<String, Individu> sihamIndividus = sihamService.getSihamIndividuFromNomUsuel("%");
for(String matricule : sihamIndividus.keySet()) {
	Individu sihamIndividu = sihamIndividus.get(matricule);
	if(sihamIndividu instanceof SihamIndividuAgentInError) {
		// l'individu siham est en erreur - ne rien faire -> ne pas le supprimer notamment ;-) 
	} else {
		// ...
	}
}


Contrainte supplémentaire Web Service Siham (février 2022 - SIHPRD.2.09.52).

Suite à la mise à jour des WebService Siham en janvier/février 2022, une nouvelle contrainte est apparue sur la récupération des matricules

La méthode recupListeAgents de /ListeAgentsWebService/ListeAgentsWebService?wsdl ne supporte pas l'absence de certains paramètres. Il est nécessaire de les positionner à vide, sous peine d'avoir une erreur du type

Bloc de code
languagexml
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
	<soap:Body>
		<soap:Fault><faultcode>soap:Server</faultcode><faultstring>Fault occurred while processing.</faultstring></soap:Fault>
	</soap:Body>
</soap:Envelope>

Ainsi la requête minimale est maintenant la suivante : 

Bloc de code
languagexml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sih="http://siham.amue.fr"> 
	<soapenv:Header/> 
	<soapenv:Body> 
		<sih:recupListeAgents> 
			<ParamRecupListeAgents> 
				<listeTypeContrat> 
					<codeTypeContrat></codeTypeContrat> 
					<modeGest></modeGest> 
				</listeTypeContrat> 
				<temEtat>A</temEtat> 
				<temoinValide></temoinValide> 
			</ParamRecupListeAgents> 
		</sih:recupListeAgents> 
	</soapenv:Body> 
</soapenv:Envelope>

En Java, on a ainsi modifié notre code ainsi, suite à cette mise à jour : 

Bloc de code
languagejava
...
ParamListeAgents paramRecupListeAgents = new ParamListeAgents();
paramRecupListeAgents.setTemEtat("A");

/*
HACK WS SIHAM
Depuis la màj de février 2022, ces paramètres, même vides, doivent figurer dans l'appel SOAP
Sinon ça plante.
 */
paramRecupListeAgents.setTemoinValide("");
ListeTypeContrat dummyListeTypeContrat = new ListeTypeContrat();
dummyListeTypeContrat.setCodeTypeContrat("");
dummyListeTypeContrat.setModeGest("");
paramRecupListeAgents.getListeTypeContrat().add(dummyListeTypeContrat);
/*
FIN HACK WS SIHAM
*/

try {
   List<ResultatsListeAgents> agents= getIListeAgentsWebService().recupListeAgents(paramRecupListeAgents);

...