eed3si9n / scalaxb

scalaxb is an XML data binding tool for Scala.
http://scalaxb.org/
MIT License
337 stars 156 forks source link

wsdl with mixed complex type generates incorrect code #149

Closed jcranky closed 12 years ago

jcranky commented 12 years ago

steps

When processing NfeStatusServico2.wsdl, which can be found in this zip file: https://www.fazenda.sp.gov.br/nfe/url_webservices/WSDL_26_02_10.zip, the generated code doesn't compile.

This is the exact command line I'm trying:

scalaxb -d status -p gen.nfe.statusservico --package-dir NfeStatusServico2.wsdl

problem

[ERROR] /home/jcranky/projects/doit-​projects/easy-nfe/easy-nfe-​server/src/main/java/gen/nfe/​statusservico/xmlprotocol.​scala:112: error: value any is not a member of gen.nfe.statusservico.​NfeStatusServicoNF2Result
[INFO]             Right(gen.nfe.statusservico.​NfeStatusServicoNF2Output(​scalaxb.fromXML[gen.nfe.​statusservico.​NfeStatusServicoNF2Result](​body.headOption getOrElse {body}).any,
eed3si9n commented 12 years ago

Thanks, I'll take a look at this later.

eed3si9n commented 12 years ago

A new version of 0.6.9-SNAPSHOT is published with the fix. Run the following to clear the boot dir, and the new scalaxb should be downloaded automatically:

$ cs --clean-boot

I created a sample project for testing: https://github.com/eed3si9n/scalaxb-sample/tree/nfe/nfe

jcranky commented 12 years ago

Hi Eugene,

Thank you! And sorry to bother you so much with this stuff. I still feel a bit noob when it comes to xml in scala.

Now the project compiles completely. But it isn't working as expected yet. This might be my fault, but I'm not sure. This is the error I'm getting when the response is received:

java.util.NoSuchElementException: next on empty iterator at scala.collection.Iterator$$anon$3.next(Iterator.scala:28) at scala.collection.Iterator$$anon$3.next(Iterator.scala:26) at scala.collection.LinearSeqLike$$anon$1.next(LinearSeqLike.scala:56) at scala.collection.IterableLike$class.head(IterableLike.scala:90) at scala.xml.NodeSeq.head(NodeSeq.scala:43) at gen.nfe.statusservico.XMLProtocol$NfeStatusServico2Soap12Bindings$NfeStatusServico2Soap12Binding$class.nfeStatusServicoNF2(xmlprotocol.scala:113) at gen.nfe.statusservico.XMLProtocol$NfeStatusServico2Soap12Bindings$$anon$4.nfeStatusServicoNF2(xmlprotocol.scala:103)

And this is the response that should be parsed:

<?xml version="1.0" encoding="utf-8"?>soap:Header352.00/soap:Headersoap:Body<nfeStatusServicoNF2Result xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2"><retConsStatServ versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe">2SP_NFE_PL_006j252Rejeio: Ambiente informado diverge do Ambiente de recebimento352012-03-24T17:05:03/soap:Body/soap:Envelope

The line mentioned in the stack trace:

Right(gen.nfe.statusservico.NfeStatusServicoNF2Output(scalaxb.fromXML[gen.nfe.statusservico.NfeStatusServicoNF2Result](body.headOption getOrElse {body}), scalaxb.fromXMLgen.nfe.statusservico.NfeCabecMsg.head)))

Looks like it isn't finding the header? Namespace problems perhaps?

thanks again!

[]s,

Paulo "JCranky" Siqueira Visit my blog: http://www.jcranky.com/

eed3si9n commented 12 years ago

It's not you, it's scalaxb. There was a bug in header parsing, which I filed as #150 and fixed it now. Run $ cs --clean-boot and you'll get a new snapshot.

I also updated https://github.com/eed3si9n/scalaxb-sample/tree/nfe/nfe using your sample response, which now outputs the following:


Right(NfeStatusServicoNF2Output(NfeStatusServicoNF2Result(List(DataRecord(
          ), DataRecord({http://www.portalfiscal.inf.br/nfe}retConsStatServ,<retConsStatServ versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
            <tpAmb>2</tpAmb>
            <verAplic>SP_NFE_PL_006j</verAplic>
            <cStat>252</cStat>
            <xMotivo>Rejeio: Ambiente informado diverge do Ambiente de recebimento</xMotivo>
            <cUF>35</cUF>
            <dhRecbto>2012-03-24T17:05:03</dhRecbto>
          </retConsStatServ>), DataRecord(
        ))),NfeCabecMsg(Some(35),Some(2.00),Map())))
jcranky commented 12 years ago

thank you!

everything seems ok now, which leaves me with my own bugs XD

thank you again!

[]s,

2012/3/24 eugene yokota < reply@reply.github.com

It's not you, it's scalaxb. There was a bug in header parsing, which I filed as #150 and fixed it now. Run $ cs --clean-boot and you'll get a new snapshot.

I also updated https://github.com/eed3si9n/scalaxb-sample/tree/nfe/nfeusing your sample response, which now outputs the following:


Right(NfeStatusServicoNF2Output(NfeStatusServicoNF2Result(List(DataRecord(
         ), DataRecord({
http://www.portalfiscal.inf.br/nfe}retConsStatServ,<retConsStatServ
versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe" xmlns="
http://www.portalfiscal.inf.br/nfe/wsdl/NfeStatusServico2" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="
http://www.w3.org/2001/XMLSchema" xmlns:soap="
http://www.w3.org/2003/05/soap-envelope">
            <tpAmb>2</tpAmb>
           <verAplic>SP_NFE_PL_006j</verAplic>
           <cStat>252</cStat>
            <xMotivo>Rejeio: Ambiente informado diverge do Ambiente de
recebimento</xMotivo>
            <cUF>35</cUF>
           <dhRecbto>2012-03-24T17:05:03</dhRecbto>
          </retConsStatServ>), DataRecord(
       ))),NfeCabecMsg(Some(35),Some(2.00),Map())))

Reply to this email directly or view it on GitHub: https://github.com/eed3si9n/scalaxb/issues/149#issuecomment-4678112

Paulo "JCranky" Siqueira Visit my blog: http://www.jcranky.com/

jcranky commented 12 years ago

What is the proper way of reading the retConsStatServ in the DataRecord? Casting it for NodeSeq? Although casting feel a bit awkward...

EDIT: I mean casting the "mixed" value or something like that. Already tested here and seems to work. It just doesn't feel right XD

eed3si9n commented 12 years ago

That's what you have to do because nfeStatusServicoNF2Result doesn't have any data binding:

  <s:element name="nfeStatusServicoNF2Result">
    <s:complexType mixed="true">
      <s:sequence>
        <s:any />
      </s:sequence>
    </s:complexType>
  </s:element>

xs:any is a wildcard just allows anything in there.

jcranky commented 12 years ago

I guessed so... thanks =)

I'll have to live with this "ugliness" - and it ended up not being that much ugly after all XD