2017-09-19 13 views
1

Je suis en train de développer un client pour consommer un service Web, mais pour une raison quelconque, mes demandes ne sont traitées correctement que si tous les espaces de noms sont corrects et sans aucun préfixe.Préfixe de l'espace de noms JAXB marshal

Toutes mes classes ont été créées en utilisant les XSD et les WSDL fournis par le fournisseur de services.

NfeDadosMsg.class

package br.inf.portalfiscal.nfe.wsdl.nfestatusservico4; 

import java.util.ArrayList; 
import java.util.List; 
import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlAnyElement; 
import javax.xml.bind.annotation.XmlMixed; 
import javax.xml.bind.annotation.XmlRootElement; 
import javax.xml.bind.annotation.XmlType; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "", propOrder = { 
    "content" 
}) 
@XmlRootElement(name = "nfeDadosMsg") 
public class NfeDadosMsg { 

    @XmlMixed 
    @XmlAnyElement(lax = true) 
    protected List<Object> content; 

    public List<Object> getContent() { 
     if (content == null) { 
      content = new ArrayList<Object>(); 
     } 
     return this.content; 
    } 

} 

package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
package br.inf.portalfiscal.nfe.wsdl.nfestatusservico4; 

TConsStatServ.class paquet br.inf.portalfiscal.nfe;

import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlAttribute; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlType; 
import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; 
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(
    name = "TConsStatServ", 
    propOrder = {"tpAmb", "cuf", "xServ"} 
) 
public class TConsStatServ { 
    @XmlElement(
     required = true 
    ) 
    protected String tpAmb; 
    @XmlElement(
     name = "cUF", 
     required = true 
    ) 
    protected String cuf; 
    @XmlElement(
     required = true 
    ) 
    protected String xServ; 
    @XmlAttribute(
     name = "versao", 
     required = true 
    ) 
    @XmlJavaTypeAdapter(CollapsedStringAdapter.class) 
    protected String versao; 

    public TConsStatServ() { 
    } 

    ... 

} 

package-info.java

package br.inf.portalfiscal.nfe; 

@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.portalfiscal.inf.br/nfe", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) 
package br.inf.portalfiscal.nfe 

sortie xml:

<?xml version='1.0' encoding='UTF-8'?> 
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"> 
    <S:Body> 
    <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4" xmlns:ns2="http://www.portalfiscal.inf.br/nfe"> 
     <ns2:consStatServ versao="4.00"> 
     <ns2:tpAmb>2</ns2:tpAmb> 
     <ns2:cUF>33</ns2:cUF> 
     <ns2:xServ>STATUS</ns2:xServ> 
     </ns2:consStatServ> 
    </nfeDadosMsg> 
    </S:Body> 
</S:Envelope> 

Pour une raison quelconque le service Web ne consomme correctement si j'ai un espace de noms préfixé. Alors ce que je dois

<?xml version='1.0' encoding='UTF-8'?> 
<S:Envelope xmlns:S="http://www.w3.org/2003/05/soap-envelope"> 
    <S:Body> 
    <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeStatusServico4"> 
     <consStatServ versao="4.00" xmlns="http://www.portalfiscal.inf.br/nfe"> 
     <tpAmb>2</tpAmb> 
     <cUF>33</cUF> 
     <xServ>STATUS</xServ> 
     </consStatServ> 
    </nfeDadosMsg> 
    </S:Body> 
</S:Envelope> 

Comment puis-je changer l'espace de noms sur le fichier XML de sortie?

Répondre

0

fixe par le remplacement

@XmlMixed 
@XmlAnyElement(lax = true) 
protected List<Object> content; 

avec l'entité attendu

@XmlElement(namespace="http://www.portalfiscal.inf.br/nfe") 
protected TRetEnviNfe;