You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by angeloimm <an...@libero.it> on 2005/04/19 16:42:08 UTC
Axis call strange behavior
Hi all; i have a strain behavior in Axis Call; well if i use this client:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPBody;
import org.apache.axis.utils.XMLUtils;
import javax.xml.rpc.ServiceException;
import java.util.Vector;
import org.w3c.dom.Document;
import javax.xml.namespace.QName;
import org.apache.log4j.Logger;
import java.net.URL;
import java.net.MalformedURLException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
public class SimpleAxisClient {
private static final Logger LOG = Logger.getLogger(SimpleAxisClient.class.
getName());
private Call getCall(String endpoint, String operation) throws
ServiceException {
if (LOG.isDebugEnabled()) {
LOG.debug("Creating call.....");
}
Call result = (Call) (new Service()).createCall();
try {
result.setTargetEndpointAddress(new URL(endpoint));
} catch (MalformedURLException ex) {
LOG.error(ex);
}
result.setOperation(new QName(endpoint, operation), operation);
if (LOG.isDebugEnabled()) {
LOG.debug("Done!!");
}
return result;
}
public Document getDocument(Document doc, String endpoint,
String operation) throws Exception {
Call call = getCall(endpoint, operation);
Vector result = (Vector) call.invoke(new Object[] {doc});
//Vector result = (Vector) call.invoke(new SOAPBodyElement[] { new SOAPBodyElement( doc.getDocumentElement() )});
SOAPBodyElement sbe = (SOAPBodyElement) result.get(0);
if (LOG.isDebugEnabled()) {
LOG.debug("Body ricevuto: " +
XMLUtils.DocumentToString(sbe.getAsDocument()));
}
return sbe.getAsDocument();
}
public static void main(String args[]) throws Exception {
SimpleAxisClient client = new SimpleAxisClient();
Call miaCall = client.getCall(
"http://localhost:8082/ServicePublisher/services/Searcher",
"byFiscalCode");
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
fac.setValidating(false);
DocumentBuilder builder = fac.newDocumentBuilder();
Document doc = builder.parse(new java.io.ByteArrayInputStream("<?xml version='1.0' encoding='UTF-8' standalone='yes'?><ricercaIndividuo><codiceFiscale>XXXXXXXXXXXXXXXX</codiceFiscale></ricercaIndividuo>".getBytes()));
Vector result =(Vector) miaCall.invoke(new SOAPBodyElement[] {new SOAPBodyElement(doc.getDocumentElement())});
//System.out.println( "Ho preso: "+ miaCall.invoke(new Object[] {doc}) );
System.out.println(XMLUtils.DocumentToString((Document) result.get(0)));
}
}
I'm not able to do the call... infact i have an error that says:
java.lang.IllegalArgumentException: localPart cannot be null
at javax.xml.namespace.QName.<init>(QName.java:106)
at javax.xml.namespace.QName.<init>(QName.java:81)
at org.apache.axis.message.PrefixedQName.<init>(PrefixedQName.java:30)
at org.apache.axis.message.MessageElement.copyNode(MessageElement.java:2045)
at org.apache.axis.message.MessageElement.copyNode(MessageElement.java:1997)
at org.apache.axis.message.MessageElement.<init>(MessageElement.java:197)
at org.apache.axis.message.SOAPBodyElement.<init>(SOAPBodyElement.java:70)
at it.eng.test.client.util.SimpleAxisClient.main(SimpleAxisClient.java:110)
Exception in thread "main"
If i use the string:
Vector result =(Vector) miaCall.invoke(new Object[] {doc});
instead of:
Vector result =(Vector) miaCall.invoke(new SOAPBodyElement[] {new SOAPBodyElement(doc.getDocumentElement())});
I can do the call; in the request i have:
OST /ServicePublisher/services/Searcher HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.2RC2
Host: 127.0.0.1:8082
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 425
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<byFiscalCode xmlns="">
<arg0 xsi:type="ns1:Document" xmlns:ns1="http://xml.apache.org/xml-soap">
<ricercaIndividuo>
<codiceFiscale>MMDNGL74C22H703K</codiceFiscale>
</ricercaIndividuo>
</arg0>
</byFiscalCode>
</soapenv:Body></soapenv:Envelope>
Why have i the arg0 tag?
In the response i have:
HTTP/1.1 200 OK
X-Powered-By: Servlet 2.4; Tomcat-5.0.28/JBoss-3.2.6 (build: CVSTag=JBoss_3_2_6 date=200410140106)
Content-Type: text/xml;charset=utf-8
Date: Tue, 19 Apr 2005 14:35:22 GMT
Server: Apache-Coyote/1.1
Connection: close
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<byFiscalCodeReturn href="#id0"/>
<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns1:Document" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://xml.apache.org/xml-soap">
<esitoRicercaIndividuo>
<globale>
<esitoRicerca>NON OK</esitoRicerca>
<dataSistema>2005-04-19+02:00</dataSistema>
</globale>
</esitoRicercaIndividuo>
</multiRef>
</soapenv:Body></soapenv:Envelope>
Well.... in the output i have:
java.lang.NullPointerException
at it.eng.test.client.util.SimpleAxisClient.main(SimpleAxisClient.java:112)
Exception in thread "main"
Can anybody explain to me why this behavior? Thanks
____________________________________________________________
Navighi a 4 MEGA e i primi 3 mesi sono GRATIS.
Scegli Libero Adsl Flat senza limiti su http://www.libero.it