Problèmes ave un exemple SpringWS
Bonjour;
Mon projet consiste à travailler avec Spring ws, malheureusement c'est la première fois que j'utilise les web services.
j'ai suivi le tutorial http://hikage.developpez.com/java/tu...ice/spring-ws/mais je retrouve des problèmes:
1- D'abord dans mon endPoint j'arrive pas à saisir cette partie
"Traduction traduction = traductionService.traduitTexte(langueOrigine, langueDestination,
texteOriginal);"
2- J'ai lu dans le tuto du site http://static.springsource.org/sprin.../tutorial.html que le wsdl sera généré "we don't need to write a WSDL ourselves; Spring-WS can generate one for us based on some conventions", j'ai essayé mais il me génère pas le wsdl.
3-Finalement, j'ai essayé d'écrire mon ficheir tradution.wsdl je ne sais aps si c'est correct ou pas, bref je vous mets mon code:
TraductionEndPoint.java:
Code:
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 45 46 47 48 49 50 51 52 53
| package com.hr.ws;
import org.springframework.ws.server.endpoint.AbstractJDomPayloadEndpoint;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.xpath.XPath;
import com.hr.service.TraductionService;
public class TraductionEndpoint extends AbstractJDomPayloadEndpoint {
private XPath langueOrigineExpression;
private XPath langueDestinationExpression;
private XPath texteExpression;
private TraductionService traductionService;
public TraductionEndpoint(TraductionService traductionService) throws JDOMException {
this.traductionService=traductionService;
Namespace namespace = Namespace.getNamespace("traduction", "http://www.hikage.be/schema/traduction");
langueOrigineExpression=XPath.newInstance("//traduction:langueOrigine");
langueOrigineExpression.addNamespace(namespace);
langueDestinationExpression = XPath.newInstance("//traduction:langueDestination");
langueDestinationExpression.addNamespace(namespace);
texteExpression =XPath.newInstance("//traduction:TraductionRequest/traduction:texte");
texteExpression.addNamespace(namespace);
}
protected Element invokeInternal(Element traductionRequest) throws Exception {
String langueOrigine = langueOrigineExpression.valueOf(traductionRequest);
String langueDestination = langueDestinationExpression.valueOf(traductionRequest);
String texteOriginal = texteExpression.valueOf(traductionRequest);
traductionService.traduitTexte(langueOrigine, langueDestination,texteOriginal);
return null;
}
/*
// Création de la réponse
Namespace namespace = Namespace.getNamespace("traduction", "http://www.hikage.be/schema/traduction");
Element root = new Element("TraductionResponse", namespace);
Element auteur = new Element("auteur", namespace);
auteur.setText(traductionService.getAuteur());
Element texteTraduit = new Element("texte", namespace);
texteTraduit.setText(traductionService.getTexte());
root.addContent(auteur);
root.addContent(texteTraduit);
return root;
}*/
} |
traduction.wsdl
Code:
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 45
| <?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:schema="http://www.hikage.be/schema/traduction"
xmlns:tns="http://www.hikage.be/definitions"
targetNamespace="http://www.hikage.be/definitions">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.hikage.be/schema/traduction" schemaLocation="traduction.xsd"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="TraductionRequest">
<wsdl:part element="schema:TraductionRequest" name="TraductionRequest">
</wsdl:part>
</wsdl:message>
<wsdl:message name="TraductionResponse">
<wsdl:part element="schema:TraductionResponse" name="TraductionResponse">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="traduction">
<wsdl:operation name="Holiday">
<wsdl:input message="tns:TraductionRequest" name="TraductionRequest">
</wsdl:input>
<wsdl:output message="tns:TraductionResponse" name="TraductionResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="traductionBinding" type="tns:traduction">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="Holiday">
<soap:operation soapAction=""/>
<wsdl:input name="TraductionRequest">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="TraductionResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TraductionService">
<wsdl:port binding="tns:traductionBinding" name="traductionPort">
<soap:address location="http://localhost:8080/traductionService/"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions> |
traduction.xsd
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:traduction="http://www.hikage.be/schema/traduction"
targetNamespace="http://www.hikage.be/schema/traduction" elementFormDefault="qualified">
<xs:element name="TraductionRequest" type="traduction:TraductionRequestType"/>
<xs:element name="TraductionResponse" type="traduction:TraductionResponseType"/>
<xs:complexType name="TraductionRequestType">
<xs:sequence>
<xs:element name="langueOrigine" type="xs:string"/>
<xs:element name="langueDestination" type="xs:string"/>
<xs:element name="texte" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TraductionResponseType">
<xs:sequence>
<xs:element name="auteur" type="xs:string"/>
<xs:element name="texte" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema> |
traductionService.java
Code:
1 2 3 4 5 6 7 8 9
| package com.hr.service;
public interface TraductionService {
void traduitTexte(String langueOrigine, String langueDestination,String
texteOriginal);
} |
Est ce que vous pouvez m'éclairer sur la partie "Création de la réponse" dans mon endPoint et voir sin monwsdl est correct!
merci
IWAB0135E An unexpected error has occurred.
Salut, c encore moi :oops:
J'essaye depuis hier mais je ne vois toujours pas où est le problème:
voici le contenu de mon projet:
TraductionEndpoint.java
Code:
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 45 46 47 48
|
package com.hr.ws;
import org.springframework.ws.server.endpoint.AbstractJDomPayloadEndpoint;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.Namespace;
import org.jdom.xpath.XPath;
import com.hr.service.TraductionService;
public class TraductionEndpoint extends AbstractJDomPayloadEndpoint {
private XPath langueOrigineExpression;
private XPath langueDestinationExpression;
private XPath texteExpression;
private TraductionService traductionService;
public TraductionEndpoint(TraductionService traductionService) throws JDOMException {
this.traductionService=traductionService;
Namespace namespace = Namespace.getNamespace("traduction", "http://com.hr.ws/schema/traduction");
langueOrigineExpression=XPath.newInstance("//traduction:langueOrigine");
langueOrigineExpression.addNamespace(namespace);
langueDestinationExpression = XPath.newInstance("//traduction:langueDestination");
langueDestinationExpression.addNamespace(namespace);
texteExpression =XPath.newInstance("//traduction:TraductionRequest/traduction:texte");
texteExpression.addNamespace(namespace);
}
protected Element invokeInternal(Element traductionRequest) throws Exception {
String langueOrigine = langueOrigineExpression.valueOf(traductionRequest);
String langueDestination = langueDestinationExpression.valueOf(traductionRequest);
String texteOriginal = texteExpression.valueOf(traductionRequest);
traductionService.traduitTexte(langueOrigine, langueDestination,texteOriginal);
return null;
}
/*
// Création de la réponse
*/
} |
TraductionService.java
Code:
1 2 3 4 5 6 7 8 9
| package com.hr.service;
public interface TraductionService {
void traduitTexte(String langueOrigine, String langueDestination,String
texteOriginal);
} |
StubtraductionService.java
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| package com.hr.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class StubtraductionService implements TraductionService {
private static final Log logger = LogFactory.getLog(StubtraductionService.class);
public void traduitTexte(String langueOrigine, String langueDestination,String
texteOriginal){
logger.info("Traduction du texte " + texteOriginal + "de la langue" + langueOrigine + " en " + langueDestination );
}
} |
spring-ws-servlet.xml
Code:
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
| <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="traductionEndpoint" class="com.hr.ws.TraductionEndpoint">
<constructor-arg ref="hrService"/>
</bean>
<bean id="hrService" class="com.hr.service.StubtraductionService"/>
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping">
<property name="mappings">
<props>
<prop key="{http://com.hr.ws/schema/traduction}TraductionRequest">traductionEndpoint</prop>
</props>
</property>
<property name="interceptors">
<list>
<bean
class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"></bean>
</list>
</property>
</bean>
<bean id="traduction" class="org.springframework.ws.wsdl.wsdl11.DynamicWsdl11Definition">
<property name="builder">
<bean class="org.springframework.ws.wsdl.wsdl11.builder.XsdBasedSoap11Wsdl4jDefinitionBuilder">
<property name="schema" value="/WEB-INF/traduction.xsd"/>
<property name="portTypeName" value="HumanResource"/>
<property name="locationUri" value="http://localhost:8080/traductionService/"/>
</bean>
</property>
</bean>
</beans> |
traduction.wsdl
Code:
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 45 46 47 48 49 50 51 52
|
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions xmlns:schema="http://com.hr.ws/schema/traduction" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://com.hr.ws/schema/traduction">
<wsdl:types>
<xs:schema xmlns:traduction="http://com.hr.ws/schema/traduction" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="http://com.hr.ws/schema/traduction">
<xs:element name="TraductionRequest" type="traduction:TraductionRequestType" />
<xs:element name="TraductionResponse" type="traduction:TraductionResponseType" />
<xs:complexType name="TraductionRequestType">
<xs:sequence>
<xs:element name="langueOrigine" type="xs:string" />
<xs:element name="langueDestination" type="xs:string" />
<xs:element name="texte" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="TraductionResponseType">
<xs:sequence>
<xs:element name="auteur" type="xs:string" />
<xs:element name="texte" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="TraductionResponse">
<wsdl:part element="schema:TraductionResponse" name="TraductionResponse" />
</wsdl:message>
<wsdl:message name="TraductionRequest">
<wsdl:part element="schema:TraductionRequest" name="TraductionRequest" />
</wsdl:message>
<wsdl:portType name="HumanResource">
<wsdl:operation name="Traduction">
<wsdl:input message="schema:TraductionRequest" name="TraductionRequest" />
<wsdl:output message="schema:TraductionResponse" name="TraductionResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="HumanResourceBinding" type="schema:HumanResource">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="Traduction">
<soap:operation soapAction="" />
<wsdl:input name="TraductionRequest">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="TraductionResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="HumanResourceService">
<wsdl:port binding="schema:HumanResourceBinding" name="HumanResourcePort">
<soap:address location="http://localhost:8080/traductionService/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions> |
traduction.wsd
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:traduction="http://com.hr.ws/schema/traduction"
targetNamespace="http://com.hr.ws/schema/traduction" elementFormDefault="qualified">
<xs:element name="TraductionRequest" type="traduction:TraductionRequestType"/>
<xs:element name="TraductionResponse" type="traduction:TraductionResponseType"/>
<xs:complexType name="TraductionRequestType">
<xs:sequence>
<xs:element name="langueOrigine" type="xs:string"/>
<xs:element name="langueDestination" type="xs:string"/>
<xs:element name="texte" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="TraductionResponseType">
<xs:sequence>
<xs:element name="auteur" type="xs:string"/>
<xs:element name="texte" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema> |
web.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>spring-ws</servlet-name>
<servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>spring-ws</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app> |
je teste mon wsdl avec soapUI et j'obtiens cette erreur:
Etat HTTP 404 - /traductionService/Rapport d'état
La ressource demandée (/traductionService/) n'est pas disponible
Apache Tomcat/5.5.25
org.apache.xmlbeans.XmlException: error:
does not close tag
Il ne retrouve pas mon service mais je vois pas où se trouve l'erreur!!