use of retrofit2.Callback in project BBS-Android by bdpqchen.
the class CollectionClient method collectByTid.
// TODO: 2017/5/23 传入Prenster来处理返回数据
void collectByTid(String tid) {
Retrofit retrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).baseUrl("https://bbs.twtstudio.com/api/home/").build();
CollectionApi collectionApi = retrofit.create(CollectionApi.class);
Call<SimpleBean> call = collectionApi.collectByTid(uidToken, tid);
call.enqueue(new Callback<SimpleBean>() {
@Override
public void onResponse(Call<SimpleBean> call, Response<SimpleBean> response) {
collectionPresenter.dealCollectData(response.body());
}
@Override
public void onFailure(Call<SimpleBean> call, Throwable t) {
}
});
}
use of retrofit2.Callback in project iNGAGE by davis123123.
the class UserInfoHandler method enqueue.
public void enqueue(String username) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
httpClient.addInterceptor(logging);
Log.i("STATE", "Retrofit url" + get_url);
Retrofit retrofit = new Retrofit.Builder().client(httpClient.build()).addConverterFactory(GsonConverterFactory.create()).baseUrl(get_url).build();
Interface service = retrofit.create(Interface.class);
Call<ResponseBody> call = service.get(username);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
Log.i("STATE", "Retrofit response code: " + response.code());
if (response.isSuccessful()) {
Log.i("STATE", "Retrofit POST Success");
try {
serverResponse = response.body().string();
callBackData.notifyChange(serverResponse);
} catch (IOException e) {
e.printStackTrace();
}
} else {
Log.i("Retrofit Error Code:", String.valueOf(response.code()));
Log.i("Retrofit Error Body", response.errorBody().toString());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.i("STATE", "Retrofit Failure");
}
});
}
use of retrofit2.Callback in project xabber-android by redsolution.
the class HttpFileUploadManager method uploadFile.
public void uploadFile(final AccountJid account, final UserJid user, final String filePath) {
final Jid uploadServerUrl = uploadServers.get(account);
if (uploadServerUrl == null) {
return;
}
AccountItem accountItem = AccountManager.getInstance().getAccount(account);
if (accountItem == null) {
return;
}
final File file = new File(filePath);
final com.xabber.xmpp.httpfileupload.Request httpFileUpload = new com.xabber.xmpp.httpfileupload.Request();
httpFileUpload.setFilename(file.getName());
httpFileUpload.setSize(String.valueOf(file.length()));
httpFileUpload.setTo(uploadServerUrl);
try {
accountItem.getConnection().sendIqWithResponseCallback(httpFileUpload, new StanzaListener() {
@Override
public void processStanza(Stanza packet) throws SmackException.NotConnectedException, InterruptedException {
if (!(packet instanceof Slot)) {
return;
}
uploadFileToSlot(account, (Slot) packet);
}
private void uploadFileToSlot(final AccountJid account, final Slot slot) {
SSLSocketFactory sslSocketFactory = null;
MemorizingTrustManager mtm = CertificateManager.getInstance().getNewFileUploadManager(account);
final SSLContext sslContext;
try {
sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, new X509TrustManager[] { mtm }, new java.security.SecureRandom());
sslSocketFactory = sslContext.getSocketFactory();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
return;
}
OkHttpClient client = new OkHttpClient().newBuilder().sslSocketFactory(sslSocketFactory).hostnameVerifier(mtm.wrapHostnameVerifier(new org.apache.http.conn.ssl.StrictHostnameVerifier())).writeTimeout(5, TimeUnit.MINUTES).connectTimeout(5, TimeUnit.MINUTES).readTimeout(5, TimeUnit.MINUTES).build();
Request request = new Request.Builder().url(slot.getPutUrl()).put(RequestBody.create(CONTENT_TYPE, file)).build();
final String fileMessageId;
fileMessageId = MessageManager.getInstance().createFileMessage(account, user, file);
LogManager.i(HttpFileUploadManager.this, "starting upload file to " + slot.getPutUrl() + " size " + file.length());
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LogManager.i(HttpFileUploadManager.this, "onFailure " + e.getMessage());
MessageManager.getInstance().updateMessageWithError(fileMessageId, e.toString());
}
@Override
public void onResponse(Call call, Response response) throws IOException {
LogManager.i(HttpFileUploadManager.this, "onResponse " + response.isSuccessful() + " " + response.body().string());
if (response.isSuccessful()) {
MessageManager.getInstance().updateFileMessage(account, user, fileMessageId, slot.getGetUrl());
} else {
MessageManager.getInstance().updateMessageWithError(fileMessageId, response.message());
}
}
});
}
}, new ExceptionCallback() {
@Override
public void processException(Exception exception) {
LogManager.i(this, "On HTTP file upload slot error");
LogManager.exception(this, exception);
Application.getInstance().onError(R.string.http_file_upload_slot_error);
}
});
} catch (SmackException.NotConnectedException | InterruptedException e) {
LogManager.exception(this, e);
}
}
use of retrofit2.Callback in project Meizhi by drakeet.
the class GankFragment method getOldVideoPreview.
private void getOldVideoPreview(OkHttpClient client) {
String url = "http://gank.io/" + String.format("%s/%s/%s", mYear, mMonth, mDay);
Request request = new Request.Builder().url(url).build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String body = response.body().string();
mVideoPreviewUrl = LoveStrings.getVideoPreviewImageUrl(body);
startPreview(mVideoPreviewUrl);
}
});
}
use of retrofit2.Callback in project buck by facebook.
the class ClientSideSlbTest method testAllServersArePinged.
@Test
@SuppressWarnings("unchecked")
public void testAllServersArePinged() throws IOException {
Capture<Runnable> capture = EasyMock.newCapture();
EasyMock.expect(mockScheduler.scheduleWithFixedDelay(EasyMock.capture(capture), EasyMock.anyLong(), EasyMock.anyLong(), EasyMock.anyObject(TimeUnit.class))).andReturn(mockFuture).once();
Call mockCall = createMock(Call.class);
for (URI server : SERVERS) {
EasyMock.expect(mockClient.newCall(EasyMock.anyObject(Request.class))).andReturn(mockCall);
mockCall.enqueue(EasyMock.anyObject(ClientSideSlb.ServerPing.class));
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
Callback callback = (Callback) EasyMock.getCurrentArguments()[0];
ResponseBody body = ResponseBody.create(MediaType.parse("text/plain"), "The Body.");
Response response = new Response.Builder().body(body).code(200).protocol(Protocol.HTTP_1_1).request(new Request.Builder().url(server.toString()).build()).build();
callback.onResponse(mockCall, response);
return null;
}
});
}
mockBus.post(EasyMock.anyObject(LoadBalancerPingEvent.class));
EasyMock.expectLastCall();
EasyMock.expect(mockFuture.cancel(true)).andReturn(true).once();
replayAll();
try (ClientSideSlb slb = new ClientSideSlb(config, mockClient)) {
Runnable healthCheckLoop = capture.getValue();
healthCheckLoop.run();
}
verifyAll();
}
Aggregations