use of com.evernote.thrift.transport.TTransportException in project Notes by lguipeng.
the class TAndroidTransport method flush.
@Override
public void flush() throws TTransportException {
Util.closeQuietly(mResponseBody);
mResponseBody = null;
RequestBody requestBody = new RequestBody() {
@Override
public MediaType contentType() {
if (mHeaders != null && mHeaders.containsKey("Content-Type")) {
return MediaType.parse(mHeaders.get("Content-Type"));
} else {
return MEDIA_TYPE_THRIFT;
}
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
copy(mByteStore.getInputStream(), sink.outputStream());
}
};
try {
Request.Builder builder = new Request.Builder().url(mUrl).post(requestBody);
if (mHeaders != null) {
for (String name : mHeaders.keySet()) {
builder.header(name, mHeaders.get(name));
}
}
Response response = mHttpClient.newCall(builder.build()).execute();
if (response.code() != 200) {
throw new TTransportException("HTTP Response code: " + response.code() + ", message " + response.message());
}
mResponseBody = response.body().byteStream();
} catch (Exception e) {
throw new TTransportException(e);
} finally {
try {
mByteStore.reset();
} catch (IOException ignored) {
}
}
}
use of com.evernote.thrift.transport.TTransportException in project Notes by lguipeng.
the class TEvernoteHttpClient method flush.
@Deprecated
public void flush() throws TTransportException {
long timer = System.currentTimeMillis();
HttpEntity httpEntity;
// Extract request and reset buffer
try {
// Prepare http post request
HttpPost request = new HttpPost(url.toExternalForm());
this.request = request;
request.addHeader("Content-Type", "application/x-thrift");
request.addHeader("Cache-Control", "no-transform");
if (customHeaders != null) {
for (Map.Entry<String, String> header : customHeaders.entrySet()) {
request.addHeader(header.getKey(), header.getValue());
}
}
InputStreamEntity entity = new InputStreamEntity(requestBuffer.getInputStream(), requestBuffer.getBytesWritten());
request.setEntity(entity);
request.addHeader("Accept", "application/x-thrift");
request.addHeader("User-Agent", userAgent == null ? "Java/THttpClient" : userAgent);
request.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
DefaultHttpClient dHTTP = getHTTPClient();
//noinspection ConstantConditions
HttpResponse response = dHTTP.execute(request);
httpEntity = response.getEntity();
int responseCode = response.getStatusLine().getStatusCode();
if (responseCode != 200) {
if (httpEntity != null) {
httpEntity.consumeContent();
}
throw new TTransportException("HTTP Response code: " + responseCode);
}
// Read the responses
requestBuffer.reset();
inputStream = response.getEntity().getContent();
} catch (Exception ex) {
throw new TTransportException(ex);
} finally {
try {
requestBuffer.reset();
} catch (IOException ignored) {
}
this.request = null;
}
}
Aggregations