Bonjour,
Est-ce que vous pouvez m'expliquer comment cela fonctionne au niveau librairies d'utilisation entre client et server d'application ?
En effet hier j'ai tenté de faire communiquer un client java dont j'avais généré les .class et les .java via CXF d'apache en version 2.6.0. J'ai donc pris les lib JAXB api et impl de l'installation d'apache vu que j'ai utilisé le wsdl2java du répertoire bin associé. Seulement le fait d'utiliser les lib jaxb d'apache pour le client alors que le server d'application est Websphere cela génère un message d'erreur lorsque l'exécution arrive sur la ligne en gras.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| try {
URL wsdlURL = new URL("http://192.168.1.76:9081/exchange/DataExchangeService?wsdl");
DataExchangeService_Service ss = new DataExchangeService_Service(wsdlURL, SERVICE_NAME);
DataExchangeService port = ss.getDataExchangeServicePort();
System.out.println("Invoking login...");
soa.dataexchange.Error _login__return = port.login();
System.out.println("login.result=" + _login__return);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} |
Cela me génère cette erreur :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:150)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:97)
at javax.xml.ws.Service.<init>(Service.java:56)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148)
... 4 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'http://192.168.1.76:9081/exchange/DataExchangeService?wsdl'.: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.1.76:9081/exchange/DataExchangeService?wsdl
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:244)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
... 6 more
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://192.168.1.76:9081/exchange/DataExchangeService?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(XMLEntityManager.java:677)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:186)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:772)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284)
... 12 more |
Du coup j'ai essayé en passant directement le login et mot de passe dans l'url comme ceci :
1 2
|
URL wsdlURL = new URL("http://"+ login+":"+password+"@192.168.1.76:9081/exchange/DataExchangeService?wsdl"); |
Puis j'ai essayé la version encodée:
1 2 3 4 5
|
String loginPassword = login + ":" + password;
String encoded = new sun.misc.BASE64Encoder().encode (loginPassword.getBytes());
URLConnection conn = wsdlURL.openConnection();
conn.setRequestProperty ("Authorization", "Basic " + encoded); |
Mais cela ne change absolument rien les erreurs sont exactement les mêmes.
Après j'ai essayé l'authentification comme ceci :
1 2 3 4 5 6 7
| Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(login, password.toCharArray());
}
}); |
Cette fois l'erreur change mais l'accès au service ne fonctionne toujours pas.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Exception in thread "main" javax.xml.ws.WebServiceException: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:150)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:97)
at javax.xml.ws.Service.<init>(Service.java:56)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:94)
at org.apache.cxf.jaxws.ServiceImpl.initializePorts(ServiceImpl.java:204)
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:148)
... 4 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
at [row,col,system-id]: [1,0,"http://192.168.1.76:9081/exchange/DataExchangeService?wsdl"]
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:240)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:92)
... 6 more
Caused by: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
at [row,col,system-id]: [1,0,"http://192.168.1.76:9081/exchange/DataExchangeService?wsdl"]
at com.ctc.wstx.sr.StreamScanner.throwUnexpectedEOF(StreamScanner.java:677)
at com.ctc.wstx.sr.BasicStreamReader.handleEOF(BasicStreamReader.java:2119)
at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2025)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1117)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:1100)
at org.apache.cxf.staxutils.StaxUtils.readDocElements(StaxUtils.java:994)
at org.apache.cxf.staxutils.StaxUtils.read(StaxUtils.java:921)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:231)
... 8 more
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [../../../src/share/back/util.c:820] |
Alors du coup ne sachant pas comment passer les arguments de login et password au server d'application j'ai regénéré l'ensemble des .class et .java à
partir des outils mis en disposition sur le server Websphere.
J'ai notamment utilisé l'exe wsimport pour la génération. Du coup pour les librairies jaxb api , impl etc j'ai pris celles qui sont sur le server websphere.
Et quand j'exécute exactement le même code qu'avant la ligne
DataExchangeService_Service ss = new DataExchangeService_Service(wsdlURL, SERVICE_NAME);
Passe très bien
par contre c'est la ligne qui suit qui ne passe pas
DataExchangeService port = ss.getDataExchangeServicePort();
le getDataExchangeServicePort lance une exception du type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
Exception in thread "main" javax.xml.ws.WebServiceException: Unable to create JAXBContext
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.createJAXBContext(AbstractSEIModelImpl.java:153)
at com.sun.xml.internal.ws.model.AbstractSEIModelImpl.postProcess(AbstractSEIModelImpl.java:83)
at com.sun.xml.internal.ws.model.RuntimeModeler.buildRuntimeModel(RuntimeModeler.java:244)
at com.sun.xml.internal.ws.client.WSServiceDelegate.createSEIPortInfo(WSServiceDelegate.java:687)
at com.sun.xml.internal.ws.client.WSServiceDelegate.addSEI(WSServiceDelegate.java:675)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:330)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:313)
at com.sun.xml.internal.ws.client.WSServiceDelegate.getPort(WSServiceDelegate.java:295)
at javax.xml.ws.Service.getPort(Service.java:92)
at dataexchange.DataExchangeService_Service.getDataExchangeServicePort(DataExchangeService_Service.java:47)
at client.MyFirstWebService.main(MyFirstWebService.java:51)
Caused by: java.security.PrivilegedActionException: com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException: 5 counts of IllegalAnnotationExceptions
There's no ObjectFactory with an @XmlElementDecl for the element {http://www.bank.net/folio}portfolio.
this problem is related to the following location: |
Alors qu'il y a bien un element de ce type dans le ObjectType.java associé.
J'ai trouvé un poste similaire en terme d'erreur ici :http://old.nabble.com/There's-no-ObjectFactory-with-an-@XmlElementDecl-for-the-element-td12798615.html
Mais je ne vois pas non plus ce qu'il faudrait mettre dans le getResult.
Si quelqu'un peut m'expliquer quel est la marche à suivre quand on veut générer un proxy java. C'est-à-dire dois-je prendre l'exe apache ou bien celui de websphere ? Est-on obligé de générer le client à partir des outils du server d'application ?
Pourquoi ai-je une erreur d'authentification dans le cas où j'utilise les lib d'apache et non pour le cas de websphere ?
Et aussi qu'est-ce qui fait que le getPort ne fonctionne pas étant donné que j'ai généré le proxy via l'outil du server d'application ?
Je vous remercie,
Partager