Error while reading xml response in java plugin

If you think that something doesn't work in Aware IM post your message here
Post Reply
bondicoffee
Posts: 130
Joined: Tue Dec 03, 2013 10:19 pm

Error while reading xml response in java plugin

Post by bondicoffee »

I have written a java plugin where i am fetching data from REST API using XML response. For fetching data , i am using Document parser .While code is giving correct response in Eclipse which is using AwareIm JDK, its throwing an exception at AwareIm server.
Following is the java code for custom process implemented :
public Object execute(IExecutionEngine engine, Object[] processParameters)
throws SuspendProcessException, ExecutionException, AccessDeniedException {


try
{
URL url = new URL("https://crm.zoho.com/crm/private/xml/Ac ... (Sync:Yes)");



DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(url.openStream());


doc.getDocumentElement().normalize();
System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
NodeList nList = doc.getElementsByTagName("row");
System.out.println("----------------------------");
IEntity[] entity = null;
int countUpdates = nList.getLength();
if(countUpdates == 0)
{
throw new ExecutionException("No updates",-1,false);
}
else{
for (int temp = 0; temp < nList.getLength(); temp++)
{
Node nNode = nList.item(temp);
System.out.println("\nCurrent Element :" + nNode.getNodeName());
if (nNode.getNodeType() == Node.ELEMENT_NODE)
{
Element eElement = (Element) nNode;



System.out.println("Account Id"+eElement.getElementsByTagName("FL").item(0).getTextContent());
String AccountId = eElement.getElementsByTagName("FL").item(0).getTextContent();
System.out.println("Account id after assigning is"+eElement.getElementsByTagName("FL").item(0).getTextContent());
Query q = Query.createFromRuleLanguageString("FIND Account WHERE Account.ZACCOUNTID="+AccountId+"");

QueryResult qr = engine.executeQuery(this,q, null, null);
entity= qr.getEntities();

if(entity == null)
{
throw new ExecutionException("No Contacts to Sync",-1,false);



}
IEntity Account = entity[0];

Account.setAttributeValue("AccountOwner", eElement.getElementsByTagName("FL").item(2).getTextContent());
Account.setAttributeValue("AccountName", eElement.getElementsByTagName("FL").item(3).getTextContent());
Account.setAttributeValue("Phone", (Integer.valueOf(eElement.getElementsByTagName("FL").item(4).getTextContent().replaceAll("\\s+",""))));
Account.setAttributeValue("AccountType", eElement.getElementsByTagName("FL").item(5).getTextContent());
Account.setAttributeValue("AccountAddress", eElement.getElementsByTagName("FL").item(14).getTextContent());
Account.setAttributeValue("AccountArea", eElement.getElementsByTagName("FL").item(15).getTextContent());
Account.setAttributeValue("AccountSuburb", eElement.getElementsByTagName("FL").item(16).getTextContent());
Account.setAttributeValue("AccountCity", eElement.getElementsByTagName("FL").item(17).getTextContent());
Account.setAttributeValue("CommercialOrResidential", eElement.getElementsByTagName("FL").item(19).getTextContent());
engine.updateEntity(this, Account);


}
}

}

}
catch(Exception e)
{
e.printStackTrace();
}

return null;
}

Following is the exception :
xception thrown com.bas.connectionserver.server.D Internal error. org.apache.xerces.dom.DeferredElementImpl.getTextContent()Ljava/lang/String;
com.bas.connectionserver.server.D: Internal error. org.apache.xerces.dom.DeferredElementImpl.getTextContent()Ljava/lang/String;
at com.bas.connectionserver.server.ConnectionFactory.A(Unknown Source)
at com.bas.connectionserver.server.ConnectionFactory.sendMessage(Unknown Source)
at com.bas.webapp.common.WebAppUtils.sendMessageToExecutionEngine(Unknown Source)
at com.bas.webapp.thin.A.E.A(Unknown Source)
at com.bas.webapp.thin.handlers.B.C.A(Unknown Source)
at com.bas.webapp.thin.handlers.XMLRequestHandler.A(Unknown Source)
at com.bas.webapp.thin.handlers.XMLRequestHandler.handleRequest(Unknown Source)
at com.bas.webapp.thin.servlets.WebInterfaceServlet.doPost(Unknown Source)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:537)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1081)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:658)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Post Reply