Android Open Source - FrameLite Abstract Web Service Request






From Project

Back to project page FrameLite.

License

The source code is released under:

GNU General Public License

If you think the Android project FrameLite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.miku.framelite.api.webservice;
//ww w  .ja  va 2  s  .  c  o m
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.kxml2.kdom.Element;

import com.miku.framelite.api.BaseRequest;
import com.miku.framelite.api.RetResult;

public abstract class AbstractWebServiceRequest<T,V>  extends BaseRequest<T, V> {
  
  private static final int DEFAULT_CONNECT_TIMEOUT = 8 * 1000;
  private static final int DEFAULT_READ_TIMEOUT = 60 * 1000;
  
  protected abstract String getNameSpace();

  protected abstract String getUrl();

  protected abstract String getMethodName();

  protected abstract String getSoapAction();
  
  
  /**
   * ??????rawHttpEntity???????????V,???onParse?????
   * 
   * @param rawResponse
   * @return ????????V
   * @throws Exception
   */
  protected abstract V handlerRawResponse(Object rawResponse) throws Exception;

  protected Element[] getSoapHeader() {
    return null;
  }

  protected void addParams(SoapObject request) {
  }
  
  /**
   * ??????,???8?(???????)
   * 
   * @return ???????????
   */
  protected int getConnectTimeOut() {
    return DEFAULT_CONNECT_TIMEOUT;
  }
  
  /**
   * ????????????1??
   * @return
   */
  protected int getReadTimeOut(){
    return DEFAULT_READ_TIMEOUT;
  }

  @Override
  public V doInBackground(RetResult<T> result) {
    isCancelled=false;
    try {
      SoapSerializationEnvelope envelope = createEnvelope();
      SoapObject request = new SoapObject(getNameSpace(), getMethodName());
      addParams(request);
      envelope.setOutputSoapObject(request);
      WebServiceHttpTransportSE androidHttpTransport = new WebServiceHttpTransportSE(getUrl(),getConnectTimeOut(),getReadTimeOut());
      androidHttpTransport.call(getSoapAction(), envelope);
      return handlerRawResponse(envelope.getResponse());
    } catch (Exception e) {
      e.printStackTrace();
      result.setMsg("??????????????");
    }
    return null;
  }

  private SoapSerializationEnvelope createEnvelope() {
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
    Element[] header = getSoapHeader();
    if (header != null) {
      envelope.headerOut = header;
    }
    envelope.dotNet = true;
    return envelope;
  };

}




Java Source Code List

com.miku.framelite.FrameApplication.java
com.miku.framelite.FrameBaseActivity.java
com.miku.framelite.FrameOrmBaseActivity.java
com.miku.framelite.adapter.FrameBaseAdapter.java
com.miku.framelite.annotations.ViewInject.java
com.miku.framelite.api.BaseRequest.java
com.miku.framelite.api.IRequest.java
com.miku.framelite.api.RetResult.java
com.miku.framelite.api.core.Executor.java
com.miku.framelite.api.database.AbstractDatabaseRequest.java
com.miku.framelite.api.database.AbstractOrmDatabaseRequest.java
com.miku.framelite.api.database.DatabaseQueryRequest.java
com.miku.framelite.api.database.DatabaseType.java
com.miku.framelite.api.http.AbstractHttpRequest.java
com.miku.framelite.api.http.HttpStringGetRequest.java
com.miku.framelite.api.http.HttpStringPostRequest.java
com.miku.framelite.api.http.HttpType.java
com.miku.framelite.api.webservice.AbstractWebServiceRequest.java
com.miku.framelite.api.webservice.WebServiceConnectionSE.java
com.miku.framelite.api.webservice.WebServiceHttpTransportSE.java
com.miku.framelite.api.webservice.WebServiceJsonRequest.java
com.miku.framelite.api.webservice.WebServiceStringRequest.java
com.miku.framelite.httpx.IDownloadHandler.java
com.miku.framelite.httpx.IHttpX.java
com.miku.framelite.httpx.core.DownloadHandler.java
com.miku.framelite.httpx.core.HttpX.java
com.miku.framelite.services.CrashHandler.java
com.miku.framelite.utils.BitmapUtils.java
com.miku.framelite.utils.DateUtils.java
com.miku.framelite.utils.DimensionUtils.java
com.miku.framelite.utils.EncryptionUtils.java
com.miku.framelite.utils.HttpUtils.java
com.miku.framelite.utils.Log.java
com.miku.framelite.utils.TelePhoneUtils.java
com.miku.framelite.utils.ViewUtils.java