emoran / QuickBooksDesktopService

QuickBooks Desktop Integration using JAVA webservice. Integration with Salesforce.com
http://yucelmoran.com
6 stars 1 forks source link

JAXB unmarshalling error #2

Closed singicus closed 3 years ago

singicus commented 3 years ago

Is there anything I should be doing to not receive this error:

(QBXML) jaxbUnmarshaller.unmarshal(new StringReader(receiveResponseXML.getResponse())) = >Exception occurred in target VM: unexpected element (uri:"", local:"QBXML"). Expected elements are (none)

This error occurs in the skeleton class. Your example project has: JAXBContext jaxbContext = JAXBContext.newInstance(QBXML.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
QBXML mainDocument = (QBXML) jaxbUnmarshaller.unmarshal(new StringReader(receiveResponseXML.getResponse()));

The error I get is: (QBXML) jaxbUnmarshaller.unmarshal(new StringReader(receiveResponseXML.getResponse())) = >Exception occurred in target VM: unexpected element (uri:"", local:"QBXML"). Expected elements are (none)

Here's the XML request followed by XML response:


 java.net.URL url = QBWebConnectorSvcSkeleton.class.getResource("queryRq.xml");
this is queryRq.xml:
<?xml version="1.0" ?>
<?qbxml version="10.0" ?>
 <QBXML>
    <QBXMLMsgsRq onError = "stopOnError">
        <InvoiceQueryRq requestID ="0">
            <MaxReturned>1</MaxReturned>
            <IncludeRetElement >TxnID</IncludeRetElement>
        </InvoiceQueryRq>
    </QBXMLMsgsRq>
</QBXML> 

public ReceiveResponseXMLResponse receiveResponseXML(ReceiveResponseXML receiveResponseXML)
receiveResponseXML is:
<?xml version="1.0" ?>
<QBXML>
<QBXMLMsgsRs>
<InvoiceQueryRs requestID="0" statusCode="0" statusSeverity="Info" statusMessage="Status OK">
<InvoiceRet>
<TxnID>7-808571530</TxnID>
</InvoiceRet>
</InvoiceQueryRs>
</QBXMLMsgsRs>
</QBXML> ```
singicus commented 3 years ago

FOUND IT! I am not sure it there is another way but this works: Annotate QBXML.java class with

@XmlRootElement(name = "QBXML")

You'll need to add this import: import javax.xml.bind.annotation.XmlRootElement;

so that your class looks like this (provided a screen shot as well): import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "QBXML") public class QBXML {
public QBXMLMsgsRs QBXMLMsgsRs; }

image

emoran commented 3 years ago

Thanks @singicus, are you deploying this to tomcat or it's a direct run from the code? I have seen that error before too when the Quickbooks Desktop client runs sometimes, so definitely this will be updated.

Best :)

singicus commented 3 years ago

I deployed to Tomcat, ran “Update Selected” from the QBWebConnector, and was debugging in NetBeans using the attached debugger (NetBeans deployment).

From: Edgar Moran notifications@github.com Sent: Monday, November 16, 2020 10:22 PM To: emoran/QuickBooksDesktopService QuickBooksDesktopService@noreply.github.com Cc: singicus sandra@webcatgraphics.com; Mention mention@noreply.github.com Subject: Re: [emoran/QuickBooksDesktopService] JAXB unmarshalling error (#2)

Thanks @singicus https://github.com/singicus , are you deploying this to tomcat or it's a direct run from the code? I have seen that error before too when the Quickbooks Desktop client runs sometimes, so definitely this will be updated.

Best :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/emoran/QuickBooksDesktopService/issues/2#issuecomment-728661107 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AARMRBTEDJ3BWQMR6GSJJK3SQHT4JANCNFSM4TXZZX7Q . https://github.com/notifications/beacon/AARMRBWYBOXOXYEANGSQMRTSQHT4JA5CNFSM4TXZZX72YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOFNXHY4Y.gif