Webservice : From Servlet
Bonjour,
OS : Windows XP SP2
IDE : ECLIPSE Ganymede
Serveur : APACHE V6 + Axis2 1.5.1
J'ai implémenté une servlet dans une application web dynamique pour invoquer le serviceweb par défault de AXIS2 (Version).
Voici le code de ma servlet :
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 54 55 56 57 58 59 60 61 62 63 64 65
|
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.ServiceFactory;
/**
* Servlet implementation class FirstServlet
*/
public class FirstServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FirstServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//String wsdlURL ="http://localhost:8080/axis2/services/Version";
String namespace = "http://axisversion.sample";
String serviceName = "Version";
try {
/* Service lookup */
ServiceFactory serviceFactory = ServiceFactory.newInstance();
javax.xml.rpc.Service service = serviceFactory.createService(
new QName(namespace, "Version"));
/* Service access */
Call call = (Call) service.createCall();
call.setTargetEndpointAddress("http://localhost:8080/axis2/services/Version.VersionHttpSoap11Endpoint/");
call.setPortTypeName(new QName(namespace, serviceName));
call.setOperationName(new QName(namespace, "getVersion"));
/* Service invocation */
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Invocation Version webService");
out.println(call.invoke(new Object[] {}));
out.close();
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
} |
Mon répertoire est donc constitué :
ServletTest
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
|-src
|-FirstServlet.java
|-WebContent
|-META-INF
|-MANIFEST.MF
|-WEB-INF
|-classes
|-FirstServlet.class
|-lib
|-jaxrpc.jar
|-web.xml
|-index.jsp pour accéder à la servlet |
Voici le wsdl du webservice :
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| <?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://axisversion.sample" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://axisversion.sample">
<wsdl:documentation>Version</wsdl:documentation>
- <wsdl:types>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://axisversion.sample">
- <xs:complexType name="Exception">
- <xs:sequence>
<xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
- <xs:element name="Exception">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="Exception" nillable="true" type="ns:Exception" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="getVersionResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="return" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
<wsdl:message name="getVersionRequest" />
- <wsdl:message name="getVersionResponse">
<wsdl:part name="parameters" element="ns:getVersionResponse" />
</wsdl:message>
- <wsdl:message name="Exception">
<wsdl:part name="parameters" element="ns:Exception" />
</wsdl:message>
- <wsdl:portType name="VersionPortType">
- <wsdl:operation name="getVersion">
<wsdl:input message="ns:getVersionRequest" wsaw:Action="urn:getVersion" />
<wsdl:output message="ns:getVersionResponse" wsaw:Action="urn:getVersionResponse" />
<wsdl:fault message="ns:Exception" name="Exception" wsaw:Action="urn:getVersionException" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="VersionSoap11Binding" type="ns:VersionPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="getVersion">
<soap:operation soapAction="urn:getVersion" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
- <wsdl:fault name="Exception">
<soap:fault use="literal" name="Exception" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="VersionSoap12Binding" type="ns:VersionPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="getVersion">
<soap12:operation soapAction="urn:getVersion" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
- <wsdl:fault name="Exception">
<soap12:fault use="literal" name="Exception" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="VersionHttpBinding" type="ns:VersionPortType">
<http:binding verb="POST" />
- <wsdl:operation name="getVersion">
<http:operation location="Version/getVersion" />
- <wsdl:input>
<mime:content type="text/xml" part="getVersion" />
</wsdl:input>
- <wsdl:output>
<mime:content type="text/xml" part="getVersion" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="Version">
- <wsdl:port name="VersionHttpSoap11Endpoint" binding="ns:VersionSoap11Binding">
<soap:address location="http://localhost:8080/axis2/services/Version.VersionHttpSoap11Endpoint/" />
</wsdl:port>
- <wsdl:port name="VersionHttpSoap12Endpoint" binding="ns:VersionSoap12Binding">
<soap12:address location="http://localhost:8080/axis2/services/Version.VersionHttpSoap12Endpoint/" />
</wsdl:port>
- <wsdl:port name="VersionHttpEndpoint" binding="ns:VersionHttpBinding">
<http:address location="http://localhost:8080/axis2/services/Version.VersionHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions> |
Voici le code du fichier web.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>ServletTest</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<description>Test invocation web service from servlet</description>
<display-name>FirstServlet</display-name>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>FirstServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/FirstServlet</url-pattern>
</servlet-mapping>
</web-app> |
J'exporte le projet sous la forme d'un fichier .war et le déploie sur Apache Tomcat. Jusqu'ici tout va bien !
Lorsque j'accède à l'adresse suivante :
http://localhost:8080/ServletTest/FirstServlet
j'obtient une erreur dans le fichier de log de tomcat
Citation:
javax.xml.rpc.ServiceException: java.lang.ClassNotFoundException: org.apache.axis.client.ServiceFactory
at javax.xml.rpc.ServiceFactory.newInstance(ServiceFactory.java:69)
at FirstServlet.doGet(FirstServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:574)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at java.lang.Thread.run(Thread.java:619)
Je ne comprend pourquoi :
Dans Eclipse mon Web App Librairie contient bien le jar jaxrpc.jar
Et pourquoi l'erreur mentionne
Citation:
org.apache.axis.client.ServiceFactory
alors que dans ma servlet j'ai effectué un import de :
Citation:
import javax.xml.rpc.Call;
import javax.xml.rpc.ServiceFactory;
Merci à vous pour votre aide, je tourne en rond et je ne trouve pas la solution.