Получить класс исключений в kSoap2 на Android - PullRequest
1 голос
/ 21 февраля 2012

У меня есть сообщение об ошибке.Я успешно поймал его на Android.Теперь я хотел бы получить Класс для Исключения, который вызвал ошибку.Сообщение выглядит так:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope">
         <faultcode>S:Server</faultcode>
         <faultstring>Error retrieving user`s [..]</faultstring>
         <detail>
            <ns2:exception class="com.example.UserException_Exception" note="To disable this feature, set com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false" xmlns:ns2="http://jax-ws.dev.java.net/">
               <message>EError retrieving user`s [..]</message>
               <ns2:stackTrace>
                  <ns2:frame class="sun.reflect.DelegatingMethodAccessorImpl" file="DelegatingMethodAccessorImpl.java" line="43" method="invoke"/>
                  <ns2:frame class="java.lang.reflect.Method" file="Method.java" line="601" method="invoke"/>
                  <ns2:frame class="com.sun.xml.ws.api.server.InstanceResolver$1" file="InstanceResolver.java" line="246" method="invoke"/>
                  <ns2:frame class="com.sun.xml.ws.server.InvokerTube$2" file="InvokerTube.java" line="146" method="invoke"/>
                  <ns2:frame class="com.sun.xml.ws.server.sei.EndpointMethodHandler" file="EndpointMethodHandler.java" line="257" method="invoke"/>
                  <ns2:frame class="com.sun.xml.ws.server.sei.SEIInvokerTube" file="SEIInvokerTube.java" line="95" method="processRequest"/>
                  <ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="629" method="__doRun"/>
                  <ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="588" method="_doRun"/>
                  <ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="573" method="doRun"/>
                  <ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="470" method="runSync"/>
                  <ns2:frame class="com.sun.xml.ws.server.WSEndpointImpl$2" file="WSEndpointImpl.java" line="295" method="process"/>
                  <ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit" file="HttpAdapter.java" line="515" method="handle"/>
                  <ns2:frame class="com.sun.xml.ws.transport.http.HttpAdapter" file="HttpAdapter.java" line="285" method="handle"/>
                  <ns2:frame class="com.sun.xml.ws.transport.http.servlet.ServletAdapter" file="ServletAdapter.java" line="143" method="handle"/>
                  <ns2:frame class="com.sun.xml.ws.transport.http.servlet.WSServletDelegate" file="WSServletDelegate.java" line="155" method="doGet"/>
                  <ns2:frame class="java.lang.Thread" file="Thread.java" line="722" method="run"/>
               </ns2:stackTrace>
            </ns2:exception>
         </detail>
      </S:Fault>
   </S:Body>
</S:Envelope>

Я удалил часть трассировки, потому что она не актуальна.

Это код, который я использую для транзакции:

public static Long getCount(String id)
            throws XmlPullParserException, IOException {

        SoapObject request = new SoapObject(NAMESPACE, "getCount");
        request.addProperty("id", id);

        SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);
        soapEnvelope.dotNet = true;

        soapEnvelope.setOutputSoapObject(request);

        System.setProperty("http.keepAlive", "false");

        HttpTransportSE htse = new HttpTransportSE(URL);

        htse.call(URL, soapEnvelope, null);

        SoapPrimitive response = (SoapPrimitive) soapEnvelope.getResponse();
        Long count = null;
        try {
            timestampCount = Long.parseLong(response.toString());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (SoapFault e) {
            e.printStackTrace();
        }


        return count;
    }

Итак, как мне получить class="com.ltc.mid.pdf.UserCertificateException_Exception" от объекта SoapFault?

Просто чтобыбыть совершенно ясным: я ищу:

  • Java-код для получения атрибута class от <detail><exception> element
  • SOAP-код для получения атрибута class из<detail><exception> элемент

Спасибо!

1 Ответ

1 голос
/ 23 апреля 2012

Мне удалось решить это самостоятельно.

Итак, принимая во внимание формат, показанный в вопросе, вот что мне подходит:

soapEnvelope.setOutputSoapObject(request);

        System.setProperty("http.keepAlive", "false");

        HttpTransportSE htse = new HttpTransportSE(URL, 60000);

        //htse.debug=true; //This directive is helpful while debugging
        try {
            htse.call(URL, soapEnvelope, null);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
        if (soapEnvelope.bodyIn instanceof SoapFault) {
            Node details = ((SoapFault) soapEnvelope.bodyIn).detail;
            Element detailElem = (Element) details.getElement(0).getChild(0);
            String exc = detailElem.getName();
            if (exc.equals("SomeSpecificException")) {
                throw new SomeSpecificException();
            }
            throw new Exception("SOAP PROBLEMS!");
        }
...