javax.xml.bind.UnmarshalException - liés exception: [org.xml.sax.SAXParseException: le Contenu n'est pas autorisé dans le prologue.]

Customer.java

@Entity
@Table(name = "CUSTOMER", uniqueConstraints =
{
@UniqueConstraint(columnNames =
{
"CUSTNO"
})
})
@XmlRootElement
public class Customer
implements Serializable
{
/**
* 
*/
private static final long serialVersionUID = 1L;
@Id @Column(name = "CUSTNO", length = 10, nullable = false) private String            custNo;
@Column(name = "TITLE", length = 20, nullable = false) private String                 title;
@Column(name = "FIRSTNAME", length = 20, nullable = false) private String             
firstName;
@Column(name = "MIDINIT", length = 1, nullable = true) private String                 
midInit;
@Column(name = "LASTNAME", length = 1, nullable = false) private String               
lastName;
@Column(name = "EMAIL", length = 50, nullable = false) private String                 
email;
@Column(name = "PHONE", length = 16, nullable = true) private String                  
phone;
@Column(name = "GENDER", length = 1, nullable = true) private String                  
gender;
@Column(name = "STREETADDRESS", length = 50, nullable = true) private String          
streetAddress;
@Column(name = "CITY", length = 20, nullable = true) private String                   
city;
@Column(name = "STATE", length = 2, nullable = true) private String                    
state;
@Column(name = "ZIPCODE", length = 10, nullable = true) private String                
zipCode;
@Column(name = "COMPANYNAME", length = 25, nullable = true) private String            
companyName;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "customer") private Set<ServiceRequest> 
requests;
public Customer()
{
}
...... getters/setters....

Code Client:

byte[] getCustomerResponse = (byte[])    
RestClientUtil.sendGetMethod(urlGetCustomer + URLEncoder.encode(custNo, "UTF-8"));
Unmarshaller unmarshaller = RestClientUtil.getUnmarshaller(Customer.class);
StringReader reader = new StringReader(new String(getCustomerResponse));
Customer customer = (Customer) unmarshaller.unmarshal(reader);

Je vois la sortie:

found customer :{"customer":{"city":"city1         ","companyName":"companyName1            ","custNo":"RCN1","email":"[email protected]","firstName":"first1                   ","gender":"F","lastName":"last1                    ","midInit":"K","phone":"4082229871      ","state":"CA","streetAddress":"streetAddress1","title":"S   ","zipCode":"zipCode   "}}

javax.xml.bind.UnmarshalException
- associé à l'exception:
[org.xml.sax.SAXParseException: le Contenu n'est pas autorisé dans le prologue.]
au javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
au com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:526)
au com.soleil.xml.bind.v2.moment de l'exécution.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:223)
au com.soleil.xml.bind.v2.moment de l'exécution.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:189)
au javax.xml.bind.les aides.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
au javax.xml.bind.les aides.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:194)
au com.ge.dsp.iworkRemote.remoteAgents.CustomerRemoteAgent.getCustomerByCustNo(CustomerRemoteAgent.java:151)
au com.ge.la dsp.iworkRemote.remoteAgents.CustomerRemoteAgent.execute(CustomerRemoteAgent.java:311)
au com.ge.la dsp.iworkRemote.remoteAgents.CustomerRemoteAgent.principale(CustomerRemoteAgent.java:368)
Causés par: org.xml.sax.SAXParseException: le Contenu n'est pas autorisé dans le prologue.
au org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Source Inconnue)
au org.apache.xerces.util.ErrorHandlerWrapper.fatalError(Source Inconnue)
au org.apache.xerces.impl.XMLErrorReporter.reportError(Source Inconnue)
au org.apache.xerces.impl.XMLErrorReporter.reportError(Source Inconnue)
au org.apache.xerces.impl.XMLScanner.reportFatalError(Source Inconnue)
au org.apache.xerces.impl.XMLDocumentScannerImpl$PrologDispatcher.dispatch(Source Inconnue)
au org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Source Inconnue)
au org.apache.xerces.les parseurs.XML11Configuration.parse(Source Inconnue)
au org.apache.xerces.les parseurs.XML11Configuration.parse(Source Inconnue)
au org.apache.xerces.les parseurs.XMLParser.parse(Source Inconnue)
au org.apache.xerces.les parseurs.AbstractSAXParser.parse(Source Inconnue)
au org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Source Inconnue)
au com.soleil.xml.bind.v2.moment de l'exécution.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:217)
... 6 plus
java.lang.NullPointerException
au com.ge.la dsp.iworkRemote.remoteAgents.CustomerRemoteAgent.submitRequest(CustomerRemoteAgent.java:167)
au com.ge.la dsp.iworkRemote.remoteAgents.CustomerRemoteAgent.execute(CustomerRemoteAgent.java:313)
au com.ge.la dsp.iworkRemote.remoteAgents.CustomerRemoteAgent.principale(CustomerRemoteAgent.java:368)

  • new String(byte[]) est presque certainement faux - lors de la construction d'une Chaîne à partir d'un tableau d'octets, vous devez toujours spécifier le codage des caractères. Ou dans ce cas envelopper le byte[] dans un ByteArrayInputStream et unmarshal de que au lieu d'utiliser une chaîne de caractères.
InformationsquelleAutor beetri | 2012-11-30