Quelqu'un a t-il des "bonnes adresses" pour savoir comment appeler un WebService à l'aide de Spring ?
J'aimerai savoir de quoi Spring a besoin pour faire cet appel ?
Merci.
Quelqu'un a t-il des "bonnes adresses" pour savoir comment appeler un WebService à l'aide de Spring ?
J'aimerai savoir de quoi Spring a besoin pour faire cet appel ?
Merci.
mais j'ai quelques questions !
- Je ne vois pas où on met le nom du fichier xml utilisé pour la configuration de Spring, dans l'application ?
- L'appel au web service me semble un peu trop magique
- Mon Web Service n'est pas instancier ! où le faire et comment ?
Du coup, au lancement, j'ai un super nullPointerException !!
Mon code :
- fichier de conf Spring :
- L'appli :
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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="consultWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean"> <property name="serviceInterface"> <value>com.socgen.bva.cdn.consultationimagevaleur.ConsultationImageValeur</value> </property> <property name="portInterface"> <value>com.socgen.bva.cdn.consultationimagevaleur.ConsultationImageValeur.RemoteConsultationImageValeur</value> </property> <property name="wsdlDocumentUrl"> <value> https://...consultationImageValeurCDN.wsdl </value> </property> <property name="namespaceUri"> <value> http://www.socgen.com/wsdl/ConsultationImageValeur/ </value> </property> <property name="serviceName"> <value>ConsultationImageValeur</value> </property> <property name="portName"> <value>IConsultationImageValeur</value> </property> </bean> <bean id="client" class="com.socgen.bva.cdn.consultationimagevaleur.ConsultationImageValeur"> <property name="service"> <ref bean="consultWebService" /> </property> </bean> </beans>
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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 //imports... public class TestAppli { public TestAppli() { } ConsultationImageValeur service ; //nom de mon WebService /** * @param args * @throws GenericException */ public static void main(String[] args) throws GenericException { System.out.println("bonjour"); String res = maMethode(); System.out.println(res); } public void setService(ConsultationImageValeur service) { this.service = service; } public static String maMethode() throws GenericException { TestAppli ta = new TestAppli(); DataIn1 param = ta.init(); DataOut1 sortie = ta.serv(param); return ta.transform(sortie); } public DataIn1 init() { DataIn1 param = new DataIn1(); return param; } public DataOut1 serv(DataIn1 param) throws GenericException { DataOut1 sortie = service.getValeur(param); return sortie; } public String transform(DataOut1 sortie) { String aff = sortie.getActif().getCodeIsin(); return aff ; } }
J'ai donc voulu instancier mon Web Service -> nullPointer
this.service = (ConsultationImageValeur) getWebApplicationContext().getBean("consultWebService");
il va chercher cette méthode dans Spring ->
public class TestAppli extends ServletEndpointSupport{
Mon fichier de conf :
L'appli :
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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 <beans> <bean id="consultWebService" class="org.springframework.remoting.jaxrpc.JaxRpcPortProxyFactoryBean"> <property name="serviceInterface"> <value>com.socgen.bva.cdn.consultationimagevaleur.IConsultationImageValeur</value> </property> <!-- <property name="portInterface"> <value>com.socgen.bva.cdn.consultationimagevaleur.ConsultationImageValeur.RemoteConsultationImageValeur</value> </property> --> <property name="wsdlDocumentUrl"> <value> http://.../consultationImageValeurCDN.wsdl </value> </property> <property name="namespaceUri"> <value> http://..../ConsultationImageValeur/ </value> </property> <property name="serviceName"> <value>ConsultationImageValeur</value> </property> <property name="portName"> <value>IConsultationImageValeur</value> </property> <property name="username"> <value>...</value> </property> <property name="password"> <value>...</value> </property> </bean> <bean id="client" class="com.socgen.bva.consultationimagevaleur.ConsultationImageValeur"> <property name="service"> <ref bean="consultWebService"/> </property> </bean> </beans>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 try { BeanFactory factory = new XmlBeanFactory(new FileSystemResource("src/ApplicationContext.xml")); service=(ConsultationImageValeur)factory.getBean("client"); sortie = service.getValeur(param); } catch (Exception e) { e.printStackTrace(); }
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager