Bonjour,
J'ai un souci avec les WebService, je n'arrive pas à faire la communication entre client/serveur.
Je développe sous NetBeans et voilà ce que je fais étape par étape :
Etape 1: Je crée un projet EJBModule, je crée ensuite un bean (clic droit -> new session Bean) que je nomme Validation.java :
Avant de définir cette fonction, je déploie mon projet et dans le dossier webService je fais un clic droit -> Générer wsdl. Une fois cela fait, j'ouvre le wsdl et dans la dernière partie service, j'ajoute l'URL de mon service
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package webservice; import javax.ejb.Stateless; import javax.ejb.LocalBean; import javax.jws.WebMethod; import javax.jws.WebService; @Stateless @LocalBean @WebService public class Validation { //permet de faire la validation d'un doc xml avec xsd @WebMethod public int valide(byte[] file){ return 0; } }Voilà après je crée un autre projet simple (java application) clique droit sur source packages -> New -> Web Service client, je lui donne le fichier local (wsdl), après je crée un main clic droit -> insert code -> call web service opération choisir ma fonction valide
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <service name="ValidationService"> <port name="ValidationPort" binding="tns:ValidationPortBinding"> <soap:address location="http://localhost:8080/ValidationService/Validation"/> </port> </service>
Client.javaAprès je définis ma fonction valide du WebService
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 public static void main(String[] args) throws FileNotFoundException, IOException { File monFichier = new File("fichier.xml"); FileInputStream fileInputStream = new FileInputStream(monFichier); byte[] fic = new byte[(int)monFichier.length()]; fileInputStream.read(fic); valide(fic); fileInputStream.close(); } private static int valide(byte[] arg0) { webservice.ValidationService service = new webservice.ValidationService(); webservice.Validation port = service.getValidationPort(); return port.valide(arg0); }
Lorsque je lance mon client j'ai cette erreur :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 public int valide(byte[] file) throws FileNotFoundException, IOException, SAXException, XMLStreamException{ File xmlFile= new File("fichier.xml"); FileOutputStream fileOutputStream = new FileOutputStream(xmlFile); fileOutputStream.write(file); fileOutputStream.flush(); fileOutputStream.close(); XMLInputFactory xmlif = XMLInputFactory.newInstance(); xmlif.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,Boolean.FALSE); SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); Schema schemaGrammar = schemaFactory.newSchema(new File("schema.xsd")); int id=xmlFile.hashCode(); Validator schemaValidator = schemaGrammar.newValidator(); Source source = new StreamSource(xmlFile); XMLStreamReader xmlr = xmlif.createXMLStreamReader(source); schemaValidator.validate(source); return 0; }
Je ne comprends pas d'où ça vient.Exception in thread "main" java.lang.NullPointerException
at com.sun.proxy.$Proxy31.valide(Unknown Source)
at client.Client.valide(Client.java:35)
at client.Client.main(Client.java:29)
Java Result: 1
Est-ce que j'ai raté une étape pour la communication ?
Merci d'avance pour votre aide.








Répondre avec citation
Partager