0 Replies Latest reply on Apr 16, 2009 4:37 PM by Fabrice Sommavilla

    PHP and Seam webservice : org.xml.sax.SAXParseException

    Fabrice Sommavilla Newbie

      Hi,


      I've been trying to access the seambay example from a small PHP client-webservice. Here's my code:



      <?php
      
      function login($username,$password) {
          global $mobyviewCrm;
      
           $loginResult = $mobyviewCrm->login();
           
           if($loginResult){
                echo 'Login Successful<br/>';
               createSession();
                
           } else {          
               echo "Not Authenticated<br/>";
               exit();     
           }
      }
      
      function createSession() {
          global $mobyviewCrm;
          #
          # Retrive the Last Response Header from the LiveTime server
          $responseHeader = $mobyviewCrm->__getLastResponseHeaders();
          $lastRequest = $mobyviewCrm->__getLastRequest();
      
          //echo $responseHeader."<br/>".$lastRequest."<br/>";
          $sessionPos=strpos($responseHeader, 'JSESSIONID=');
      
          if ($sessionPos === false) {
              echo 'No session id was found. Exiting.<br/>';
              exit();
          }
           //cookie will always be 32 bytes
           $cookie = substr($responseHeader,$sessionPos + 11,32);
      
           #
           # Set the Cookie name for the next request
           $mobyviewCrm->__setCookie('JSESSIONID', $cookie);
      }
      
      function getConversationId() {
          global $mobyviewCrm;     
          $lastResponse = $mobyviewCrm->__getLastResponse();
          $pos = strpos($lastResponse, 'f');
          $res = substr($lastResponse, 0, $pos);
          //echo $res."<br/>";
          return $res;
      }
      
      function logout() {
          global $mobyviewCrm;
          
           $mobyviewCrm = new SoapClient("http://localhost:8080/jboss-seam-bay-jboss-seam-bay/AuctionService?wsdl", array('trace' => true));
          
           $loginResult = $mobyviewCrm->logout();
           if(!$loginResult){
               echo 'Logout Unsuccessful<br/>';          
              exit();
          }
          echo 'Logout Successful<br/>';
          exit();
      }
      
      $mobyviewCrm = new SoapClient("http://localhost:8080/jboss-seam-bay-jboss-seam-bay/AuctionService?wsdl", array('trace' => true));
      
      //construct the soap client to create a connection and then login
      login("demo","demo");
      
      // Query CRM for all application
      try {
           // Set connection data
             $conversationHeader = sprintf('<seam:conversationId xmlns:seam="http://www.jboss.org/seam/webservice">%s</seam:conversationId>', getConversationId());
      
          $conversationVar = new SoapVar($conversationHeader, XSD_ANYXML);
          $header = new SoapHeader("http://www.jboss.org/seam/webservice", "conversationId", $conversationVar);
          $mobyviewCrm->__setSoapHeaders(array($header));
          $categories = $mobyviewCrm->listCategories();
          print_r($categories);
      
      } catch (Exception $e) {
          print_r($e);
      }
      
      logout();
      
      ?>



      The login seems to succeed (returns true), but when the $mobyviewCrm-listCategories(); is invoked, the server-side throws this exception:



      javax.xml.rpc.soap.SOAPFaultException: org.xml.sax.SAXParseException: The element type "return" must be terminated by the matching end-tag "</return>".
           at org.jboss.ws.core.jaxrpc.SOAPFaultHelperJAXRPC.exceptionToFaultMessage(SOAPFaultHelperJAXRPC.java:189)
           at org.jboss.ws.core.jaxws.SOAPFaultHelperJAXWS.exceptionToFaultMessage(SOAPFaultHelperJAXWS.java:170)
           at org.jboss.ws.core.jaxws.binding.SOAP11BindingJAXWS.createFaultMessageFromException(SOAP11BindingJAXWS.java:104)
           at org.jboss.ws.core.CommonSOAPBinding.bindFaultMessage(CommonSOAPBinding.java:671)
           at org.jboss.wsf.stack.jbws.RequestHandlerImpl.processRequest(RequestHandlerImpl.java:488)
           at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:284)
           at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:201)
           at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:134)
           at org.jboss.wsf.stack.jbws.EndpointServlet.service(EndpointServlet.java:84)
           at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
           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:230)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
           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:157)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
           at java.lang.Thread.run(Thread.java:613)
      



      It seems like the header session is wrong formated when invoking listCategories(). Any idea what I'm doing wrong?


      Using Seam 2.1.1.GA and AS 4.2.2


      Fabrice