bot-asterios
New Member
I am trying to integrate a Usurv survey to my website. To do this, I need to submit an XML request to the URL http://app.usurv.com/API/Gateway.svc/getcampaignforframe, using HTTP POST. Then the response should contain a unique URL pointing to a survey.Unfortunately I can't get it to work - the code compiles correctly but when I load the webpage I get the following exception: \[code\]"WARNING: URL = http://app.usurv.com/API/Gateway.svc/getcampaignforframe [Fatal Error] CampaignFrameRequest%3E:6:3: The element type "link" must be terminated by the matching end-tag "</link>"."\[/code\]I'm really confused about that as the XML doesn't even have a link tag, so I'm not sure where the error could be coming from. Does anyone have any ideas what could be causing this and how I can fix it?Here is the Java code:\[code\]public class UsurvSurveyElement extends RenderController { private static Logger LOG = Logger.getLogger(UsurvSurveyElement.class.getName()); String xml = "<CampaignFrameRequest xmlns='http://Qsurv/api' xmlns:i='http://www.w3.org/2001/XMLSchema-instance'><PartnerId>236</PartnerId><PartnerWebsiteID>45</PartnerWebsiteID><RespondentID>1</RespondentID><RedirectUrlComplete>http://localhost:8080/eveningstar/home</RedirectUrlComplete><RedirectUrlSkip>http://localhost:8080/eveningstar/home</RedirectUrlSkip></CampaignFrameRequest>"; String strURL = "http://app.usurv.com/API/Gateway.svc/getcampaignforframe"; @Override public void populateModelBeforeCacheKey(RenderRequest renderRequest, TopModel topModel, ControllerContext controllerContext ) { super.populateModelBeforeCacheKey( renderRequest, topModel, controllerContext ); PostMethod post = new PostMethod(strURL); try { // Specify content type and encoding // If content encoding is not explicitly specified // ISO-8859-1 is assumed post.setRequestHeader( "Content-type", "text/xml; charset=ISO-8859-1"); LOG.warning("request headers: " +post.getRequestHeader("Content-type")); StringRequestEntity requestEntity = new StringRequestEntity(xml); post.setRequestEntity(requestEntity); LOG.warning("request entity: " +post.getRequestEntity()); String response = post.getResponseBodyAsString(); LOG.warning("XML string = " + xml); LOG.warning("URL = " + strURL); topModel.getLocal().setAttribute("thexmlresponse",response); } catch(Exception e) { LOG.warning("Errors while executing postMethod "+ e); } try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document document = docBuilder.parse(strURL+xml); processNode(document.getDocumentElement()); LOG.warning("doc output = " + document); } catch(Exception e) { LOG.warning("Errors while parsing XML: "+ e); }} private void processNode(Node node) { // do something with the current node instead of System.out LOG.warning(node.getNodeName()); NodeList nodeList = node.getChildNodes(); for (int i = 0; i < nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if (currentNode.getNodeType() == Node.ELEMENT_NODE) { //calls this method for all the children which is Element LOG.warning("current node: " + currentNode); processNode(currentNode); } }}\[/code\]}