You know, I often see people banging their head against a wall when it comes
to Exceptions and SOAP. So let me give you a hint that has worked splendidly
for me over several projects: Don't even use them. Return an error code and
message, generated in your try / catch block.
Allow the code to explain ( axis2, but I've used the idea in both axis 1.x and
Sun's JWSDP):
public TestServiceResponseDocument testService(
TestServiceDocument testServiceDocument) {
// prepare output
TestServiceResponseDocument retDoc =
TestServiceResponseDocument.Factory.newInstance();
TestServiceResponse retElement =
TestServiceResponse.Factory.newInstance();
TestService testService =
testServiceDocument.getTestService();
String soapSessionId = testService.getSoapSessionId();
String webUserName = testService.getWebUserName();
try {
if (!authenticator.validateSoapSessionId(soapSessionId,
webUserName)) {
wiseMobilAdapter.handleDefaultTimeout(retElement,
webUserName);
} else {
wiseMobilAdapter.testService(retElement);
}
} catch (Exception ex) {
logger.error("SWAWiseEndpointSkeleton.testService:"
+ ex.getMessage(), ex);
retElement.setErrorMessage(ex.getMessage());
retElement.setSuccessErrorCode(MessagesCodes.FAILURE);
}
retDoc.setTestServiceResponse(retElement);
return retDoc;
}
The idea here is retElement is passed in to the adapter, which sets the pass /
fail status and any other variables needed to return. Or, the try catch in
the skeleton does the error handling in case of session timeout, login
problems etc.
As far as the wsdl goes, just define the error login once, and use 'extension
base' with all your services. I'll post an entire wsdl - not too large - to
prevent skipping something relevant:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="SWAWiseService" targetNamespace="http://swaWiseNS"
xmlns:tns="http://swaWiseNS" xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:ns2="http://swaWiseNS/types">
<types>
<schema targetNamespace="http://swaWiseNS/types"
xmlns:tns="http://swaWiseNS/types"
xmlns:soap11-enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
<complexType name="ReturnWebBase">
<sequence>
<element name="errorMessage" type="xsd:string"/>
<element name="successErrorCode" type="xsd:int"/>
</sequence>
</complexType>
<element name="wiseLogin">
<complexType>
<sequence>
<element name="user_name" type="xsd:string"/>
<element name="user_password" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="wiseLoginResponse">
<complexType>
<complexContent>
<extension base="tns:ReturnWebBase">
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
</sequence>
</extension>
</complexContent>
</complexType>
</element>
<element name="testService">
<complexType>
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="testServiceResponse">
<complexType>
<complexContent>
<extension base="tns:ReturnWebBase">
<sequence>
<element name="testId" type="xsd:long"/>
</sequence>
</extension>
</complexContent>
</complexType>
</element>
<!-- 13a -->
<element name="acionarAutomatico">
<complexType>
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
<element name="NumeroOS" type="xsd:string"/>
<element name="DataHoraDoAcionamento" type="xsd:dateTime"/>
</sequence>
</complexType>
</element>
<!-- 13b -->
<element name="deslocarAutomatico">
<complexType>
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
<element name="NumeroOSStc" type="xsd:string"/>
<element name="DataHoraDoDeslocamento" type="xsd:dateTime"/>
<element name="KmFinalDeDeslocamento" type="xsd:string"/>
</sequence>
</complexType>
</element>
<!-- 13c -->
<element name="receberMsgTecnicoFinalDeslocamento">
<complexType>
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
<element name="NumeroOSStc" type="xsd:string"/>
<element name="DataHoraFinalDaAtividade" type="xsd:dateTime"/>
<element name="kmFinalDeExecucao" type="xsd:string"/>
</sequence>
</complexType>
</element>
<!-- 13d -->
<element name="receberMsgTecnicoInicioExec">
<complexType>
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
<element name="NumeroOSStc" type="xsd:string"/>
<element name="DataHoraFinalDaAtividade" type="xsd:dateTime"/>
</sequence>
</complexType>
</element>
<!-- 13e -->
<element name="receberMsgTecnicoFinalAtividade">
<complexType>
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
<element name="NumeroOSStc" type="xsd:string"/>
<element name="DataHoraFinalDaAtividade" type="xsd:dateTime"/>
</sequence>
</complexType>
</element>
<complexType name="ArrayOfItemQtyConsumido">
<sequence>
<element minOccurs="0" maxOccurs="unbounded" name="ItemQtyConsumido"
nillable="false" type="tns:ItemQtyConsumido" />
</sequence>
</complexType>
<complexType name="ItemQtyConsumido">
<sequence>
<element minOccurs="1" maxOccurs="1" name="ItemConsumido"
type="xsd:string"/>
<element minOccurs="1" maxOccurs="1" name="QuantidadeItemConsumido"
type="xsd:int"/>
</sequence>
</complexType>
<!-- 14 -->
<element name="encerrarAutomatico">
<complexType>
<sequence>
<element name="soap_session_id" type="xsd:string"/>
<element name="web_user_name" type="xsd:string"/>
<element name="NumeroOSStc" type="xsd:string"/>
<element name="Status" type="xsd:string"/>
<element name="InformacoesComplementares" type="xsd:string"/>
<element name="CodigoDeEncerramento" type="xsd:string"/>
<element name="DataHoraEncerramento" type="xsd:dateTime"/>
<element name="ProprietarioModem" type="xsd:string"/>
<element name="ModemRetirado" type="xsd:string"/>
<element name="NumRAT" type="xsd:string"/>
<element name="NotaFiscal" type="xsd:string"/>
<element name="ModemSemID" type="xsd:string"/>
<element name="Fonte" type="xsd:string"/>
<element name="USB" type="xsd:string"/>
<element name="Cbfonte" type="xsd:string"/>
<element name="Manual" type="xsd:string"/>
<element name="Cbrede" type="xsd:string"/>
<element name="CD" type="xsd:string"/>
<element name="Cbvoz" type="xsd:string"/>
<element name="Filtro" type="xsd:string"/>
<element name="QtdFiltro" type="xsd:string"/>
<element name="NaoAplicavel" type="xsd:string"/>
<element name="ATT" type="xsd:string"/>
<element name="CX" type="xsd:string"/>
<element name="SNR" type="xsd:string"/>
<element name="CB" type="xsd:string"/>
<element name="MAXT" type="xsd:string"/>
<element name="LAT" type="xsd:string"/>
<element name="DIST" type="xsd:string"/>
<element name="PAR" type="xsd:string"/>
<element name="SEC" type="xsd:string"/>
<element name="ARM" type="xsd:string"/>
<element name="ItemQtyConsumido" minOccurs="0" maxOccurs="1"
type="tns:ArrayOfItemQtyConsumido"/>
<element name="SN" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="ReturnWebBaseResponse" type="ns2:ReturnWebBase"/>
</schema></types>
<message name="SWAWiseEndpoint_encerrarAutomatico">
<part name="parameters" element="ns2:encerrarAutomatico"/>
</message>
<message name="SWAWiseEndpoint_encerrarAutomaticoResponse">
<part name="result" element="ns2:ReturnWebBaseResponse"/>
</message>
<message name="SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamento">
<part name="parameters" element="ns2:receberMsgTecnicoFinalDeslocamento"/>
</message>
<message name="SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamentoResponse">
<part name="result" element="ns2:ReturnWebBaseResponse"/>
</message>
<message name="SWAWiseEndpoint_receberMsgTecnicoInicioExec">
<part name="parameters" element="ns2:receberMsgTecnicoInicioExec"/>
</message>
<message name="SWAWiseEndpoint_receberMsgTecnicoInicioExecResponse">
<part name="result" element="ns2:ReturnWebBaseResponse"/>
</message>
<message name="SWAWiseEndpoint_receberMsgTecnicoFinalAtividade">
<part name="parameters" element="ns2:receberMsgTecnicoFinalAtividade"/>
</message>
<message name="SWAWiseEndpoint_receberMsgTecnicoFinalAtividadeResponse">
<part name="result" element="ns2:ReturnWebBaseResponse"/>
</message>
<message name="SWAWiseEndpoint_deslocarAutomatico">
<part name="parameters" element="ns2:deslocarAutomatico"/>
</message>
<message name="SWAWiseEndpoint_deslocarAutomaticoResponse">
<part name="result" element="ns2:ReturnWebBaseResponse"/>
</message>
<message name="SWAWiseEndpoint_acionarAutomatico">
<part name="parameters" element="ns2:acionarAutomatico"/>
</message>
<message name="SWAWiseEndpoint_acionarAutomaticoResponse">
<part name="result" element="ns2:ReturnWebBaseResponse"/>
</message>
<message name="SWAWiseEndpoint_testService">
<part name="parameters" element="ns2:testService"/>
</message>
<message name="SWAWiseEndpoint_testServiceResponse">
<part name="result" element="ns2:testServiceResponse"/>
</message>
<message name="SWAWiseEndpoint_wiseLogin">
<part name="parameters" element="ns2:wiseLogin"/>
</message>
<message name="SWAWiseEndpoint_wiseLoginResponse">
<part name="result" element="ns2:wiseLoginResponse"/>
</message>
<portType name="SWAWiseEndpoint">
<operation name="encerrarAutomatico">
<input message="tns:SWAWiseEndpoint_encerrarAutomatico"
name="SWAWiseEndpoint_encerrarAutomatico"/>
<output message="tns:SWAWiseEndpoint_encerrarAutomaticoResponse"
name="SWAWiseEndpoint_encerrarAutomaticoResponse"/>
</operation>
<operation name="receberMsgTecnicoFinalDeslocamento">
<input message="tns:SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamento"
name="SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamento"/>
<output
message="tns:SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamentoResponse"
name="SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamentoResponse"/>
</operation>
<operation name="receberMsgTecnicoInicioExec">
<input message="tns:SWAWiseEndpoint_receberMsgTecnicoInicioExec"
name="SWAWiseEndpoint_receberMsgTecnicoInicioExec"/>
<output
message="tns:SWAWiseEndpoint_receberMsgTecnicoInicioExecResponse"
name="SWAWiseEndpoint_receberMsgTecnicoInicioExecResponse"/>
</operation>
<operation name="receberMsgTecnicoFinalAtividade">
<input message="tns:SWAWiseEndpoint_receberMsgTecnicoFinalAtividade"
name="SWAWiseEndpoint_receberMsgTecnicoFinalAtividade"/>
<output
message="tns:SWAWiseEndpoint_receberMsgTecnicoFinalAtividadeResponse"
name="SWAWiseEndpoint_receberMsgTecnicoFinalAtividadeResponse"/>
</operation>
<operation name="deslocarAutomatico">
<input message="tns:SWAWiseEndpoint_deslocarAutomatico"
name="SWAWiseEndpoint_deslocarAutomatico"/>
<output message="tns:SWAWiseEndpoint_deslocarAutomaticoResponse"
name="SWAWiseEndpoint_deslocarAutomaticoResponse"/>
</operation>
<operation name="acionarAutomatico">
<input message="tns:SWAWiseEndpoint_acionarAutomatico"
name="SWAWiseEndpoint_acionarAutomatico"/>
<output message="tns:SWAWiseEndpoint_acionarAutomaticoResponse"
name="SWAWiseEndpoint_acionarAutomaticoResponse"/>
</operation>
<operation name="testService">
<input message="tns:SWAWiseEndpoint_testService"
name="SWAWiseEndpoint_testService"/>
<output message="tns:SWAWiseEndpoint_testServiceResponse"
name="SWAWiseEndpoint_testServiceResponse"/>
</operation>
<operation name="wiseLogin">
<input message="tns:SWAWiseEndpoint_wiseLogin"
name="SWAWiseEndpoint_wiseLogin"/>
<output message="tns:SWAWiseEndpoint_wiseLoginResponse"
name="SWAWiseEndpoint_wiseLoginResponse"/>
</operation>
</portType>
<binding name="SWAWiseEndpointBinding" type="tns:SWAWiseEndpoint">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"
style="document"/>
<operation name="receberMsgTecnicoFinalDeslocamento">
<soap:operation soapAction="receberMsgTecnicoFinalDeslocamento"/>
<input name="SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamento">
<soap:body use="literal"/>
</input>
<output
name="SWAWiseEndpoint_receberMsgTecnicoFinalDeslocamentoResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="receberMsgTecnicoInicioExec">
<soap:operation soapAction="receberMsgTecnicoInicioExec"/>
<input name="SWAWiseEndpoint_receberMsgTecnicoInicioExec">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_receberMsgTecnicoInicioExecResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="receberMsgTecnicoFinalAtividade">
<soap:operation soapAction="receberMsgTecnicoFinalAtividade"/>
<input name="SWAWiseEndpoint_receberMsgTecnicoFinalAtividade">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_receberMsgTecnicoFinalAtividadeResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="encerrarAutomatico">
<soap:operation soapAction="encerrarAutomatico"/>
<input name="SWAWiseEndpoint_encerrarAutomatico">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_encerrarAutomaticoResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="receberMsgTecnicoInicioExec">
<soap:operation soapAction="receberMsgTecnicoInicioExec"/>
<input name="SWAWiseEndpoint_receberMsgTecnicoInicioExec">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_receberMsgTecnicoInicioExecResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="wiseLogin">
<soap:operation soapAction="wiseLogin"/>
<input name="SWAWiseEndpoint_wiseLogin">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_wiseLoginResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="testService">
<soap:operation soapAction="testService"/>
<input name="SWAWiseEndpoint_testService">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_testServiceResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="acionarAutomatico">
<soap:operation soapAction="acionarAutomatico"/>
<input name="SWAWiseEndpoint_acionarAutomatico">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_acionarAutomaticoResponse">
<soap:body use="literal"/>
</output>
</operation>
<operation name="deslocarAutomatico">
<soap:operation soapAction="deslocarAutomatico"/>
<input name="SWAWiseEndpoint_deslocarAutomatico">
<soap:body use="literal"/>
</input>
<output name="SWAWiseEndpoint_deslocarAutomaticoResponse">
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="SWAWiseService">
<port name="SWAWiseEndpointPort" binding="tns:SWAWiseEndpointBinding">
<soap:address
location="http://10.129.63.33/swa_ws_test/services/SWAWiseEndpoint"/></port></service></definitions>
Take a look at testServiceResponse.
HTH,
iksrazal
http://www.braziloutsource.com/
Em Quinta 12 Janeiro 2006 17:16, o Jarmo Doc escreveu:
> My Axis 1.3 server operations throw MyException which is defined something
> like this (though in reality it's more complex):
>
> public class MyException extends AxisFault implements Serializable
> {
> private String mytext;
> public String getMytext() {return mytext;}
> public void setMytext(String mytext) {this.mytext = mytext;}
> // the normal wsdl2java generated stuff such
> // as constructor, getSerializer(), getDeserializer()
> }
>
> I see this serialized on the line as:
>
> <soapenv:Fault xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
> <faultcode>soapenv:Server.userException</faultcode>
> <faultstring>mypackage.MyException</faultstring>
> <detail>
> <faultData>
> <mytext>testing exceptions</mytext>
> </faultData>
> <ns1:stackTrace
> ... stack trace here ...
> </ns1:stackTrace>
> <ns2:hostname
> xmlns:ns2="http://xml.apache.org/axis/">myhostname</ns2:hostname>
> </detail>
> </soapenv:Fault>
>
> I'm not an expert here, obviously, but I'm pretty sure that this
> serialization is wrong. In particular:
>
> 1. the fault string is the name of the exception class, which is odd
> 2. it refers to <faultData> when I'd expect to see <ns1:MyException> or
> similar
> 3. it should not contain a server-side stack trace
>
> As it stands, a client that attempts to deserialize this has no clue what
> type the contained exception is and thus fails.
>
> My cubicle wall now has a large hole from me banging my head into it on a
> regular basis ;-) so could someone please offer a clue as to what could be
> going wrong. What could cause Axis to serialize my exception in this way?
>
> Thanks.
>
> _________________________________________________________________
> On the road to retirement? Check out MSN Life Events for advice on how to
> get there! http://lifeevents.msn.com/category.aspx?cid=Retirement
--
http://www.braziloutsource.com/