9 Replies Latest reply on Nov 21, 2007 1:49 AM by kcell

    xmlstring as input to webservice from flex

    kittuokkade Level 1
      hi ,

      i want to send xml string as input to a webservice .i had a problem with this. iam pasting the code iam using.

      public var sResult:String="<?xml version='1.0' encoding='UTF-8' ?>
      <root><sample><id>8098</id><type>CD</type><unit>nm</unit></sample></root>";
      <mx:WebService id="myws"
      wsdl=" http://localhost:8080/myws/method?wsdl"
      useProxy="false">
      <mx:operation name="getCD" result="resultHandler(event)" fault="Alert.show(event.fault.message)">
      <mx:request>
      <String_1> {sResult} </String_1>
      </mx:request>
      </mx:operation>
      </mx:WebService>
      <mx:Panel width="652" height="408">
      <mx:Button x="368" y="2" label="Lot_id" id="mybutton" click="myws.getCD.send()"/>
      </mx:Panel>

      when i use any string for sResult .it is working fine.but when i use xml string it is giving the error SOAP request error.
      i need ur help.

        • 1. Re: xmlstring as input to webservice from flex
          ntsiii Level 3
          Perhaps you need to escape/unescape the xml string?

          Tracy
          • 2. Re: xmlstring as input to webservice from flex
            ntsiii Level 3
            What part of the xml string causes the problem?
            • 3. Re: xmlstring as input to webservice from flex
              Omar_Gonzalez Level 1
              try this:

              public var myXML:XML="<root><sample><id>'8098 '</id><type>'CD '</type><unit>'nm '</unit></sample></root>";

              public var sResult:String = myXML.toXMLString();
              • 4. Re: xmlstring as input to webservice from flex
                kittuokkade Level 1
                actually when i use any string ,it is invoking the webservice successfully.that is when ever i put <root> it is not accepting as input.
                i tried by inputting the string from text input .same problem.when ever i use < ..> tag it is not accepting as input.
                i got the same kind of string from webservice to flex over http succesfully.but iam not able to send back.
                thats the problem.
                • 5. Re: xmlstring as input to webservice from flex
                  Omar_Gonzalez Level 1
                  quote:

                  Originally posted by: Omar_Gonzalez
                  try this:

                  public var myXML:XML="<root><sample><id>'8098 '</id><type>'CD '</type><unit>'nm '</unit></sample></root>";

                  public var sResult:String = myXML.toXMLString();


                  code above was wrong... XML shouldn't have the quotes, like this:

                  public var myXML:XML= <root><sample><id>'8098 '</id><type>'CD '</type><unit>'nm '</unit></sample></root>;

                  public var sResult:String = myXML.toXMLString();

                  • 6. Re: xmlstring as input to webservice from flex
                    kittuokkade Level 1
                    thanx for reply,but it is giving the same error Soap request error .unable to parse the source .if i give the input like this it is working fine
                    var sResult:String=&lt;root&gt;&lt;sample&gt;&lt;id&gt;..............................soon.

                    if i replace < with &lt; and > with &gt:
                    it is working fine.but i cannot send the string like that .so whats happening .i need help in this.
                    • 7. Re: xmlstring as input to webservice from flex
                      kittuokkade Level 1
                      this is the complete trace of error iam getting

                      ERROR [SOAPFaultExceptionHelper] SOAP request exception
                      javax.xml.rpc.JAXRPCException: org.jboss.ws.binding.BindingException: org.jboss.ws.jaxb.UnmarshalException: Failed to parse source: { http://www.w3.org/2001/XMLSchema}string type of element { http://webservice.autoee/jaws}String_1 should be complex and contain root as a child element.
                      at org.jboss.ws.soap.SOAPContentElement.getObjectValue(SOAPContentElement.java:303)
                      at org.jboss.ws.binding.EndpointInvocation.transformPayloadValue(EndpointInvocation.java:233 )
                      at org.jboss.ws.binding.EndpointInvocation.getRequestParamValue(EndpointInvocation.java:103)
                      at org.jboss.ws.binding.EndpointInvocation.getRequestPayload(EndpointInvocation.java:117)
                      at org.jboss.ws.server.ServiceEndpointInvokerJSE.invokeServiceEndpoint(ServiceEndpointInvoke rJSE.java:94)
                      at org.jboss.ws.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:115)
                      at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:209)
                      at org.jboss.ws.server.ServiceEndpointManager.processSOAPRequest(ServiceEndpointManager.java :355)
                      at org.jboss.ws.server.StandardEndpointServlet.doPost(StandardEndpointServlet.java:115)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                      at org.jboss.ws.server.StandardEndpointServlet.service(StandardEndpointServlet.java:76)
                      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:252)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j ava:202)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
                      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.ja va:175)
                      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
                      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
                      at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Htt p11BaseProtocol.java:664)
                      at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
                      at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
                      at java.lang.Thread.run(Unknown Source)
                      Caused by: org.jboss.ws.binding.BindingException: org.jboss.ws.jaxb.UnmarshalException: Failed to parse source: { http://www.w3.org/2001/XMLSchema}string type of element { http://webservice.autoee/jaws}String_1 should be complex and contain root as a child element.
                      at org.jboss.ws.jaxrpc.encoding.JAXBDeserializer.deserialize(JAXBDeserializer.java:100)
                      at org.jboss.ws.soap.SOAPContentElement.getObjectValue(SOAPContentElement.java:235)
                      ... 30 more
                      Caused by: org.jboss.ws.jaxb.UnmarshalException: Failed to parse source: { http://www.w3.org/2001/XMLSchema}string type of element { http://webservice.autoee/jaws}String_1 should be complex and contain root as a child element.
                      at org.jboss.ws.jaxb.JBossXBUnmarshallerImpl.unmarshal(JBossXBUnmarshallerImpl.java:67)
                      at org.jboss.ws.jaxrpc.encoding.JAXBDeserializer.deserialize(JAXBDeserializer.java:92)
                      ... 31 more
                      Caused by: org.jboss.xb.binding.JBossXBException: Failed to parse source: { http://www.w3.org/2001/XMLSchema}string type of element { http://webservice.autoee/jaws}String_1 should be complex and contain root as a child element.
                      at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:156)
                      at org.jboss.xb.binding.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:126)
                      at org.jboss.ws.jaxb.JBossXBUnmarshallerImpl.unmarshal(JBossXBUnmarshallerImpl.java:63)
                      ... 32 more
                      Caused by: org.jboss.xb.binding.JBossXBRuntimeException: { http://www.w3.org/2001/XMLSchema}string type of element { http://webservice.autoee/jaws}String_1 should be complex and contain root as a child element.
                      at org.jboss.xb.binding.sunday.unmarshalling.SundayContentHandler.startElement(SundayContent Handler.java:187)
                      at org.jboss.xb.binding.parser.sax.SaxJBossXBParser$DelegatingContentHandler.startElement(Sa xJBossXBParser.java:301)
                      at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Source)
                      at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
                      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch( Unknown Source)
                      at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
                      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
                      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
                      at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
                      at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
                      at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:152)
                      ... 34 more
                      • 8. Re: xmlstring as input to webservice from flex
                        kittuokkade Level 1
                        yah there is a problem with flex 3 .the same code working fine with flex 2.
                        to make it work need to escape < from xml string.
                        • 9. Re: xmlstring as input to webservice from flex
                          kcell Level 2
                          Hi kittuokkade,

                          I got a similar problem and so I am searching for the easiest solution how to escape to the XML enties (&lt; .... )

                          &lt; < less than
                          &gt; > greater than
                          &amp; & ampersand
                          &apos; ' apostrophe
                          &quot; " quotation mark

                          How did you escape the String from < and friends?

                          My curent solution is with regexp and replace, but I have the impression that there must be an easier solution.

                          Thanks and best regards,
                          kcell