package com.dbs.mplus.knuh.httpTask; import android.os.AsyncTask; import com.dbs.mplus.knuh.BuildConfig; import com.dbs.mplus.knuh.util.ConsentConfig; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; import java.util.HashMap; public class HttpSoapConnection extends AsyncTask { private static final String TAG = "HttpSoapConnection"; private HashMap mData; private String soapAction = ""; private String callMmethod = ""; public HttpSoapConnection(String soapAction, String callMmethod, HashMap mData) { this.soapAction = soapAction; this.callMmethod = callMmethod; this.mData = mData; } @Override protected void onPreExecute() { } @Override protected SoapObject doInBackground(Void... voids) { SoapObject soapObject = soapRequestParam(callMmethod, mData); SoapObject soapResponse = null; try { SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER12); soapEnvelope.bodyOut = soapObject; soapEnvelope.setOutputSoapObject(soapObject); soapEnvelope.dotNet = true; soapEnvelope.implicitTypes = false; HttpTransportSE hts = new HttpTransportSE(soapAction, ConsentConfig.CONNECT_TIMEOUT); hts.call(soapAction + callMmethod, soapEnvelope); if (soapEnvelope.getResponse() instanceof SoapObject) { soapResponse = (SoapObject) soapEnvelope.getResponse(); } else { soapResponse = new SoapObject(); soapResponse.addProperty(callMmethod, soapEnvelope.getResponse()); } if (soapResponse != null) { return soapResponse; } else { // errorObject.addProperty("ERROR", "ERROR"); } } catch (IOException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } return null; } @Override protected void onPostExecute(SoapObject o) { // super.onPostExecute(o); } private SoapObject soapRequestParam(String callMmethod, HashMap hashMap) { SoapObject soapObject = new SoapObject(BuildConfig.NAME_SPACE, callMmethod); for (String key : hashMap.keySet()) { soapObject.addProperty(key, hashMap.get(key)); } return soapObject; } }