1 Reply Latest reply on Feb 8, 2010 4:36 AM by Alessio Soldano

    Help with Returning a web service client.

    Alan Terriaga Newbie

      Hi guys Im using Axis framework and I'm getting a lot of problems with it. But the most one that Im not able to solve is this:

       

      I hava an interface:

      public

       

       

           public EstabComercialVO[] consultaEstabComercial( String codigo, String nome );

       

      }

       

       

      And I have the class which implements.

      @Remote
      
      (CasEstabComercialRemote.class)
      @Stateless
      @WebService
      
      (name = "CasEstabComercial", targetNamespace = "http://www.cas.csu.com.br/CasEstabComercial", serviceName="CasEstabComercialService", portName="CasEstabComercial")
      @SOAPBinding
      
      (style = SOAPBinding.Style.RPC)
      public
      
      
      
      private static Logger log = Logger.getLogger(CasEstabComercial.class);
      
      
      
      @WebMethod(operationName="consultaEstabComercial")
      
      @WebResult(name="lista" )
      
      public EstabComercialVO[] consultaEstabComercial( @WebParam(name="codigo") String codigo, @WebParam(name="nome") String nome ) {
      
           BasicConfigurator.configure();
      
           EstabComercialDAO dao = 
      
      new EstabComercialDAO();     List<EstabComercialVO> lista = 
      
      null;     EstabComercialVO[] array = 
      
      null;
      
           
           try{
      
      
                EstabComercialVO vo = new EstabComercialVO();          vo.setCodEstabelecimento( codigo );
                vo.setNomeEstabelecimento( nome );
      
                lista = dao.consultaEstabComercial(vo);
      
      
      
      
      
                int cont = 0;          array = 
      
      new EstabComercialVO[lista.size()];
      
                for( EstabComercialVO voLista : lista ){               array[cont] = voLista;
                     cont++;
                }
           }
      
      
           catch (DAOException e) {          e.printStackTrace();
           }
      
      
      
           return array;}
      
      }
      
      
      
       class CasEstabComercial implements CasEstabComercialRemote{
      
      

       

       

      With that I could generate the follow WSDL:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <definitions name="CasEstabComercialService" targetNamespace="http://www.cas.csu.com.br/CasEstabComercial" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://www.cas.csu.com.br/CasEstabComercial" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
        <types>
          <xs:schema targetNamespace="http://www.cas.csu.com.br/CasEstabComercial" version="1.0" xmlns:tns="http://www.cas.csu.com.br/CasEstabComercial" xmlns:xs="http://www.w3.org/2001/XMLSchema">
         <xs:complexType name="estabComercialVO">
          <xs:sequence>
           <xs:element minOccurs="0" name="cep" type="xs:string"/>
           <xs:element minOccurs="0" name="cgcEstabelecimento" type="xs:string"/>
           <xs:element minOccurs="0" name="codAdquirente" type="xs:string"/>
           <xs:element minOccurs="0" name="codBloqueio" type="xs:string"/>
           <xs:element minOccurs="0" name="codBloqueioMbs" type="xs:string"/>
           <xs:element minOccurs="0" name="codEstabelecimento" type="xs:string"/>
           <xs:element minOccurs="0" name="codRegiao" type="xs:string"/>
           <xs:element minOccurs="0" name="codStatus" type="xs:string"/>
           <xs:element minOccurs="0" name="comEndereco" type="xs:string"/>
           <xs:element minOccurs="0" name="dataUltExtracao" type="xs:string"/>
           <xs:element minOccurs="0" name="endEstabelecimento" type="xs:string"/>
           <xs:element minOccurs="0" name="extracao" type="xs:string"/>
           <xs:element minOccurs="0" name="nomeBairro" type="xs:string"/>
           <xs:element minOccurs="0" name="nomeContato" type="xs:string"/>
           <xs:element minOccurs="0" name="nomeEstabelecimento" type="xs:string"/>
           <xs:element minOccurs="0" name="numeroEndereco" type="xs:string"/>
           <xs:element minOccurs="0" name="telefone" type="xs:string"/>
          </xs:sequence>
         </xs:complexType>
         <xs:complexType final="#all" name="estabComercialVOArray">
          <xs:sequence>
           <xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="tns:estabComercialVO"/>
          </xs:sequence>
         </xs:complexType>
        </xs:schema>
        </types>
        <message name="CasEstabComercial_consultaEstabComercial">
          <part name="codigo" type="xsd:string">
          </part>
          <part name="nome" type="xsd:string">
          </part>
        </message>
        <message name="CasEstabComercial_consultaEstabComercialResponse">
          <part name="lista" type="tns:estabComercialVOArray">
          </part>
        </message>
        <portType name="CasEstabComercial">
          <operation name="consultaEstabComercial" parameterOrder="codigo nome">
            <input message="tns:CasEstabComercial_consultaEstabComercial">
          </input>
            <output message="tns:CasEstabComercial_consultaEstabComercialResponse">
          </output>
          </operation>
        </portType>
        <binding name="CasEstabComercialBinding" type="tns:CasEstabComercial">
          <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
          <operation name="consultaEstabComercial">
            <soap:operation soapAction=""/>
            <input>
              <soap:body use="literal" namespace="http://www.cas.csu.com.br/CasEstabComercial"/>
            </input>
            <output>
              <soap:body use="literal" namespace="http://www.cas.csu.com.br/CasEstabComercial"/>
            </output>
          </operation>
        </binding>
        <service name="CasEstabComercialService">
          <port name="CasEstabComercial" binding="tns:CasEstabComercialBinding">
            <soap:address location="http://127.0.0.1:8080/casWS/CasEstabComercial"/>
          </port>
        </service>
      </definitions>
      
      

       

       

      Now the problem is when I try to call the webservice.

      Follow is my client class.

       

      String XSD = 
      "http://www.w3.org/2001/XMLSchema";String urlService = 
      
      "http://www.cas.csu.com.br/CasEstabComercial";String nameService = 
      
      "CasEstabComercialService";String endPoint = 
      
      http://localhost:8080/casWS/CasEstabComercial?wsdl;
      
      
      
      try{     QName qname = 
      
      new QName(urlService); 
           ServiceFactory serviceFactory = ServiceFactory.newInstance();
      
           javax.xml.rpc.Service service = serviceFactory.createService(qname);
      
           
           Call call = (Call) service.createCall();
           call.setTargetEndpointAddress(endPoint);
      
      
      
      
           // OPERATION
           QName operationName = new QName(urlService, "consultaEstabComercial");     call.setOperationName(operationName);
      
      
      
      
           // REQUEST
           QName qParametroString = new QName(XSD, "string");     call.addParameter(
      
      "codigo", qParametroString, ParameterMode.IN );     call.addParameter(
      
      "nome", qParametroString, ParameterMode.IN );
      
      
      
           // RESPONSE
           QName qReturn = new QName("http://www.cas.csu.com.br/CasEstabComercial", "estabComercialVOArray");     call.setReturnType(qReturn);
           call.setReturnQName( 
      
      new QName("", "lista"));
           call.registerTypeMapping( EstabComercialVO.
      
      class,                                qReturn,
      
      
                                     new ArraySerializerFactory(),
      
                                     new ArrayDeserializerFactory() );
      
      
           // Setting parameters
           EstabComercialVO voEntrada = 
      new EstabComercialVO();     voEntrada.setCodEstabelecimento(
      
      "1");     String codigo = 
      
      "1";     String nome = 
      
      "";
           Object[] entrada = 
      
      new Object[]{ codigo, nome };
      
           EstabComercialVO[] array = (EstabComercialVO[]) call.invoke(entrada);
      
      
      
      
      
           System.out.println("SIZE: " + array.length);
      }
      
      catch( Exception ex ){ex.printStackTrace();
      }
      
      
      
      

       

      My service can start and execute an operatioin in my database without problems, but when comes the time to fill the response:
      Now after trying many possibilites in the method "registerTypeMapping" I'm getting the follow exception:

       

       

      17:07:06,858 INFO [STDOUT] 156915 [http-127.0.0.1-8080-3] DEBUG br.com.csu.casWS.test.TestIBatis - carregando arquivo sql ibatis br/com/csu/casWS/config/SqlMapConfig_casDSS.xml
      17:07:07,427 INFO [STDOUT] 157487 [http-127.0.0.1-8080-3] INFO br.com.csu.casWS.service.CasEstabComercial - Consulta no banco os estabelecimentos comerciais.
      17:07:07,428 INFO [STDOUT] 157488 [http-127.0.0.1-8080-3] DEBUG br.com.csu.casWS.test.TestIBatis - select na tabela estbmto
      17:07:10,547 INFO [STDOUT] 160607 [http-127.0.0.1-8080-3] DEBUG com.ibatis.common.jdbc.SimpleDataSource - Created connection 5686307.
      17:07:10,556 INFO [STDOUT] 160616 [http-127.0.0.1-8080-3] DEBUG java.sql.Connection - {conn-100000} Connection
      17:07:10,573 INFO [STDOUT] 160633 [http-127.0.0.1-8080-3] DEBUG java.sql.Connection - {conn-100000} Preparing Statement: select COD_ADQUIRENTE, COD_ESTBMTO, COD_REGIAO, NOM_ESTBMTO, END_ESTBMTO, NUM_ENDERECO, COM_ENDERECO, NOM_BAIRRO, CEP, TEL_CONTATO, NOM_CONTATO, CGC_ESTBMTO, COD_BLOQUEIO, COD_STATUS, COD_BLOQUEIO_MBS, FLG_EXTRACAO, DAT_ULT_EXTRACAO from ESTBMTO where COD_ESTBMTO = ? 
      17:07:10,631 INFO [STDOUT] 160691 [http-127.0.0.1-8080-3] DEBUG java.sql.PreparedStatement - {pstm-100001} Executing Statement: select COD_ADQUIRENTE, COD_ESTBMTO, COD_REGIAO, NOM_ESTBMTO, END_ESTBMTO, NUM_ENDERECO, COM_ENDERECO, NOM_BAIRRO, CEP, TEL_CONTATO, NOM_CONTATO, CGC_ESTBMTO, COD_BLOQUEIO, COD_STATUS, COD_BLOQUEIO_MBS, FLG_EXTRACAO, DAT_ULT_EXTRACAO from ESTBMTO where COD_ESTBMTO = ? 
      17:07:10,631 INFO [STDOUT] 160691 [http-127.0.0.1-8080-3] DEBUG java.sql.PreparedStatement - {pstm-100001} Parameters: [1]
      17:07:10,631 INFO [STDOUT] 160691 [http-127.0.0.1-8080-3] DEBUG java.sql.PreparedStatement - {pstm-100001} Types: [java.lang.String]
      17:07:10,638 INFO [STDOUT] 160698 [http-127.0.0.1-8080-3] DEBUG java.sql.ResultSet - {rset-100002} ResultSet
      17:07:10,650 INFO [STDOUT] 160710 [http-127.0.0.1-8080-3] DEBUG java.sql.ResultSet - {rset-100002} Header: [COD_ADQUIRENTE, COD_ESTBMTO, COD_REGIAO, NOM_ESTBMTO, END_ESTBMTO, NUM_ENDERECO, COM_ENDERECO, NOM_BAIRRO, CEP, TEL_CONTATO, NOM_CONTATO, CGC_ESTBMTO, COD_BLOQUEIO, COD_STATUS, COD_BLOQUEIO_MBS, FLG_EXTRACAO, DAT_ULT_EXTRACAO]
      17:07:10,651 INFO [STDOUT] 160710 [http-127.0.0.1-8080-3] DEBUG java.sql.ResultSet - {rset-100002} Result: [1, 1, 7627, teste loja 1, endereco 1, 1, comp 1, bairro 1, 11111111, 1112345678, contato 1, cgc 1, null, 1, null, null, null]
      17:07:10,659 INFO [STDOUT] 160718 [http-127.0.0.1-8080-3] DEBUG com.ibatis.common.jdbc.SimpleDataSource - Returned connection 5686307 to pool.
      17:07:10,845 ERROR [Call] Exception:
      org.xml.sax.SAXException
      
      
      SimpleDeserializer.java:145)at org.apache.axis.encoding.DeserializationContext.startElement(
      
      DeserializationContext.java:1035)at org.apache.axis.message.SAX2EventRecorder.replay(
      
      SAX2EventRecorder.java:165)at org.apache.axis.message.MessageElement.publishToHandler(
      
      MessageElement.java:1141)at org.apache.axis.message.RPCElement.deserialize(
      
      RPCElement.java:236)at org.apache.axis.message.RPCElement.getParams(
      
      RPCElement.java:384)at org.apache.axis.client.Call.invoke(
      
      Call.java:2467)at org.apache.axis.client.Call.invoke(
      
      Call.java:2366)at org.apache.axis.client.Call.invoke(
      
      Call.java:1812)at br.com.csu.cas.presentation.action.cadastros.EstabComercialAction.teste(
      
      EstabComercialAction.java:127)at br.com.csu.cas.presentation.action.cadastros.EstabComercialAction.consulta(
      
      EstabComercialAction.java:62)at sun.reflect.NativeMethodAccessorImpl.invoke0(
      
      Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(
      
      NativeMethodAccessorImpl.java:39)at sun.reflect.DelegatingMethodAccessorImpl.invoke(
      
      DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(
      
      Method.java:597)at org.apache.struts.actions.DispatchAction.dispatchMethod(
      
      DispatchAction.java:276)at org.apache.struts.actions.DispatchAction.execute(
      
      DispatchAction.java:196)at org.apache.struts.action.RequestProcessor.processActionPerform(
      
      RequestProcessor.java:421)at org.apache.struts.action.RequestProcessor.process(
      
      RequestProcessor.java:226)at org.apache.struts.action.ActionServlet.process(
      
      ActionServlet.java:1164)at org.apache.struts.action.ActionServlet.doGet(
      
      ActionServlet.java:397)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.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(
      
      ReplyHeaderFilter.java:96)at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(
      
      ApplicationFilterChain.java:235)at org.apache.catalina.core.ApplicationFilterChain.doFilter(
      
      ApplicationFilterChain.java:206)at org.apache.catalina.core.StandardWrapperValve.invoke(
      
      StandardWrapperValve.java:235)at org.apache.catalina.core.StandardContextValve.invoke(
      
      StandardContextValve.java:191)at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(
      
      SecurityAssociationValve.java:190)at org.jboss.web.tomcat.security.JaccContextValve.invoke(
      
      JaccContextValve.java:92)at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(
      
      SecurityContextEstablishmentValve.java:126)at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(
      
      SecurityContextEstablishmentValve.java:70)at org.apache.catalina.core.StandardHostValve.invoke(
      
      StandardHostValve.java:127)at org.apache.catalina.valves.ErrorReportValve.invoke(
      
      ErrorReportValve.java:102)at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(
      
      CachedConnectionValve.java:158)at org.apache.catalina.core.StandardEngineValve.invoke(
      
      StandardEngineValve.java:109)at org.apache.catalina.connector.CoyoteAdapter.service(
      
      CoyoteAdapter.java:330)at org.apache.coyote.http11.Http11Processor.process(
      
      Http11Processor.java:829)at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
      
      Http11Protocol.java:598)at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(
      
      JIoEndpoint.java:447)at java.lang.Thread.run(
      
      Thread.java:619)17:07:10,855 ERROR [STDERR] AxisFault
      faultCode: {
      
      http://schemas.xmlsoap.org/soap/envelope/}Server.userExceptionfaultSubcode: 
      faultString: 
      org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.faultActor: 
      faultNode: 
      faultDetail: 
      
      
      
      
      : SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.at org.apache.axis.encoding.ser.SimpleDeserializer.onStartChild(
      

       

       

      Please I'd like to know what it's going on, or maybe there is other framework better than Axis to create WebServices in my JBoss 4.0.5.

       

      Thanks in advance.

       

      Alan

      interface CasEstabComercialRemote extends Remote {