Created
March 1, 2017 01:50
-
-
Save misakuo/f59d74efae40376e20d2ef6fe9e7a3ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.alibaba.weex.extend.adapter; | |
import android.support.annotation.NonNull; | |
import android.support.annotation.Nullable; | |
import com.taobao.weex.adapter.DefaultWXHttpAdapter; | |
import com.taobao.weex.urlconnection.ByteArrayRequestEntity; | |
import com.taobao.weex.urlconnection.SimpleRequestEntity; | |
import com.taobao.weex.urlconnection.WeexURLConnectionManager; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.net.HttpURLConnection; | |
/** | |
* Created by moxun on 16/12/29. | |
*/ | |
public class InterceptWXHttpAdapter extends DefaultWXHttpAdapter { | |
@NonNull | |
@Override | |
public IEventReporterDelegate getEventReporterDelegate() { | |
return new IEventReporterDelegate() { | |
WeexURLConnectionManager manager = new WeexURLConnectionManager(null); | |
@Override | |
public void preConnect(HttpURLConnection connection, @Nullable String body) { | |
SimpleRequestEntity requestEntity = null; | |
if (body != null) { | |
requestEntity = new ByteArrayRequestEntity(body.getBytes()); | |
} | |
manager.preConnect(connection, requestEntity); | |
} | |
@Override | |
public void postConnect() { | |
try { | |
manager.postConnect(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
@Override | |
public InputStream interpretResponseStream(@Nullable InputStream inputStream) { | |
return manager.interpretResponseStream(inputStream); | |
} | |
@Override | |
public void httpExchangeFailed(IOException e) { | |
manager.httpExchangeFailed(e); | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment