IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Services Web Java Discussion :

Webservice : From Servlet


Sujet :

Services Web Java

  1. #1
    Membre habitué
    Inscrit en
    Novembre 2009
    Messages
    8
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 8
    Par défaut 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 : 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
    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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : 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
    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 : 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
    <?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

    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
    org.apache.axis.client.ServiceFactory
    alors que dans ma servlet j'ai effectué un import de :

    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.

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juin 2003
    Messages
    81
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2003
    Messages : 81
    Par défaut
    Je pense qu'il te manque des jars dans tes lib.

    Il te manque au minimum un jar du type axis.jar (qui contient la classe org.apache.axis.client.ServiceFactory).

    Le jar jaxrpc.jar contient la classe javax.xml.rpc.ServiceFactory.
    Mais la méthode newInstance de cette classe fait appel à l'autre classe mentionnée en erreur : org.apache.axis.client.ServiceFactory.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
        public static ServiceFactory newInstance()
            throws ServiceException
        {
            return (ServiceFactory)FactoryFinder.find("javax.xml.rpc.ServiceFactory", "org.apache.axis.client.ServiceFactory");
            FactoryFinder.ConfigurationError e;
            e;
            throw new ServiceException(e.getException());
        }
    Bon courage,

    Arnaud

Discussions similaires

  1. [Java] Certification Java EE - Webservice ou Servlet
    Par ganga dans le forum Certifications
    Réponses: 3
    Dernier message: 07/09/2011, 09h37
  2. Conflit Webservices et servlet
    Par jmmalain dans le forum Services Web
    Réponses: 0
    Dernier message: 31/08/2011, 04h05
  3. Réponses: 2
    Dernier message: 13/06/2007, 17h18
  4. Webservice, servlet et BD native xml
    Par Bapt.ice dans le forum Glassfish et Payara
    Réponses: 2
    Dernier message: 13/04/2007, 14h36
  5. [webservices] heberger un webservices dans une servlet ?
    Par n!co dans le forum Services Web
    Réponses: 14
    Dernier message: 07/12/2005, 14h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo