HttpSoapConnection.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package com.dbs.mplus.knuh.httpTask;
  2. import android.os.AsyncTask;
  3. import com.dbs.mplus.knuh.BuildConfig;
  4. import com.dbs.mplus.knuh.util.ConsentConfig;
  5. import org.ksoap2.SoapEnvelope;
  6. import org.ksoap2.serialization.SoapObject;
  7. import org.ksoap2.serialization.SoapSerializationEnvelope;
  8. import org.ksoap2.transport.HttpTransportSE;
  9. import org.xmlpull.v1.XmlPullParserException;
  10. import java.io.IOException;
  11. import java.util.HashMap;
  12. public class HttpSoapConnection extends AsyncTask<Void, Void, SoapObject> {
  13. private static final String TAG = "HttpSoapConnection";
  14. private HashMap<String, String> mData;
  15. private String soapAction = "";
  16. private String callMmethod = "";
  17. public HttpSoapConnection(String soapAction, String callMmethod, HashMap<String, String> mData) {
  18. this.soapAction = soapAction;
  19. this.callMmethod = callMmethod;
  20. this.mData = mData;
  21. }
  22. @Override
  23. protected void onPreExecute() {
  24. }
  25. @Override
  26. protected SoapObject doInBackground(Void... voids) {
  27. SoapObject soapObject = soapRequestParam(callMmethod, mData);
  28. SoapObject soapResponse = null;
  29. try {
  30. SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
  31. soapEnvelope.bodyOut = soapObject;
  32. soapEnvelope.setOutputSoapObject(soapObject);
  33. soapEnvelope.dotNet = true;
  34. soapEnvelope.implicitTypes = false;
  35. HttpTransportSE hts = new HttpTransportSE(soapAction, ConsentConfig.CONNECT_TIMEOUT);
  36. hts.call(soapAction + callMmethod, soapEnvelope);
  37. if (soapEnvelope.getResponse() instanceof SoapObject) {
  38. soapResponse = (SoapObject) soapEnvelope.getResponse();
  39. } else {
  40. soapResponse = new SoapObject();
  41. soapResponse.addProperty(callMmethod, soapEnvelope.getResponse());
  42. }
  43. if (soapResponse != null) {
  44. return soapResponse;
  45. } else {
  46. // errorObject.addProperty("ERROR", "ERROR");
  47. }
  48. } catch (IOException e) {
  49. e.printStackTrace();
  50. } catch (XmlPullParserException e) {
  51. e.printStackTrace();
  52. }
  53. return null;
  54. }
  55. @Override
  56. protected void onPostExecute(SoapObject o) {
  57. // super.onPostExecute(o);
  58. }
  59. private SoapObject soapRequestParam(String callMmethod, HashMap<String, String> hashMap) {
  60. SoapObject soapObject = new SoapObject(BuildConfig.NAME_SPACE, callMmethod);
  61. for (String key : hashMap.keySet()) {
  62. soapObject.addProperty(key, hashMap.get(key));
  63. }
  64. return soapObject;
  65. }
  66. }