Hi,
Can any one tell me why do I receive the following error while compling:"
Incompatible types found:
org.w3c.dom.Element
required: java.lang.String
return result
^
1 error.
This is the relevant code:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.utils.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
... some code here
it works when I am using command line argument:
public static void main(String [] args) throws Exception {
but not if I pass a String array to a function:
public String getBattleService(String[] uniqb) throws Exception {
DocumentBuilderFactory documentBuilderFactory = null;
DocumentBuilder parser = null;
// We need a namespace-aware parser
documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
parser = documentBuilderFactory.newDocumentBuilder();
// We create the document for the request (the XML document that will
// be embedded inside the SOAP body).
Document document = parser.newDocument();
Element element = document.getDocumentElement();
// The <portfolio/> element is the root of our document;
Element requestElement = document.createElementNS(nameSpaceURI,
orderbattleTag);
// Element command = document.createElement(args[0]);
Element command = document.createElement(uniqb[0]);
requestElement.appendChild(command);
// We add the list of ticker symbols
for(int index = 1; index < uniqb.length; index++) {
Element ticker = document.createElement(tickerTag);
// ticker.appendChild(document.createTextNode(args[index]));
ticker.appendChild(document.createTextNode(uniqb[index]));
command.appendChild(ticker);
}
// Unless the command is a get, we add the get command
if(!uniqb.equals(getCommand)) {
requestElement.appendChild(document.createElement(getCommand));
}
Element result = null;
boolean local = false; // set to true for local test (inproc)
if(local) {
// Local test, no SOAP
result = orderbattle(requestElement,
(Element)requestElement.cloneNode(true));
} else {
// We create a SOAP request to submit the XML document to the
// server. You might need to replace the following URL with what
is
// suitable for your environment
"http://localhost:8080/axis/servlet/AxisServlet";
Service service = new Service();
Call call = (Call)service.createCall();
// Create a SOAP envelope to wrap the newly formed document
SOAPEnvelope requestEnvelope = new SOAPEnvelope();
SOAPBodyElement requestBody =
new SOAPBodyElement(requestElement);
requestEnvelope.addBodyElement(requestBody);
// Set the endpoint URL (address we are talking to) and method name
call.setTargetEndpointAddress(new URL(endpointURL));
call.setSOAPActionURI(orderbattleTag); // method name = tag name
// Submit the document to the remote server
SOAPEnvelope responseEnvelope = call.invoke(requestEnvelope);
// Get the <orderbattle/> element from the response
SOAPBodyElement responseBody =
(SOAPBodyElement)responseEnvelope.getBodyElements().get(0);
result = responseBody.getAsDOM();
}
return result;
}
}
Thanks,
Arie