Search in sources :

Example 1 with HttpMessage

use of cz.msebera.android.httpclient.HttpMessage in project Zom-Android by zom.

the class OtrDataHandler method sendRequest.

private void sendRequest(Request request) {
    MemorySessionOutputBuffer outBuf = new MemorySessionOutputBuffer();
    HttpMessageWriter writer = new HttpRequestWriter(outBuf, lineFormatter, params);
    HttpMessage req = new BasicHttpRequest(request.method, request.url, PROTOCOL_VERSION);
    String uid = UUID.randomUUID().toString();
    req.addHeader("Request-Id", uid);
    if (request.headers != null) {
        for (Entry<String, String> entry : request.headers.entrySet()) {
            req.addHeader(entry.getKey(), entry.getValue());
        }
    }
    try {
        writer.write(req);
        outBuf.write(request.body);
        outBuf.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (HttpException e) {
        throw new RuntimeException(e);
    }
    byte[] data = outBuf.getOutput();
    Message message = new Message("");
    message.setFrom(request.us);
    message.setTo(request.them);
    if (req.containsHeader("Range"))
        debug("send request " + request.method + " " + request.url + " " + req.getFirstHeader("Range"));
    else
        debug("send request " + request.method + " " + request.url);
    requestCache.put(uid, request);
    mChatSession.sendDataAsync(message, false, data);
}
Also used : HttpMessageWriter(cz.msebera.android.httpclient.io.HttpMessageWriter) HttpMessage(cz.msebera.android.httpclient.HttpMessage) Message(org.awesomeapp.messenger.model.Message) HttpRequestWriter(cz.msebera.android.httpclient.impl.io.HttpRequestWriter) HttpException(cz.msebera.android.httpclient.HttpException) IOException(java.io.IOException) HttpMessage(cz.msebera.android.httpclient.HttpMessage) BasicHttpRequest(cz.msebera.android.httpclient.message.BasicHttpRequest)

Example 2 with HttpMessage

use of cz.msebera.android.httpclient.HttpMessage in project Zom-Android by zom.

the class OtrDataHandler method sendResponse.

private void sendResponse(Address us, Address them, int code, String statusString, String uid, byte[] body) {
    MemorySessionOutputBuffer outBuf = new MemorySessionOutputBuffer();
    HttpMessageWriter writer = new HttpResponseWriter(outBuf, lineFormatter, params);
    HttpMessage response = new BasicHttpResponse(new BasicStatusLine(PROTOCOL_VERSION, code, statusString));
    response.addHeader("Request-Id", uid);
    try {
        writer.write(response);
        outBuf.write(body);
        outBuf.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } catch (HttpException e) {
        throw new RuntimeException(e);
    }
    byte[] data = outBuf.getOutput();
    Message message = new Message("");
    message.setFrom(us);
    message.setTo(them);
    debug("send response " + statusString + " for " + uid);
    mChatSession.sendDataAsync(message, true, data);
}
Also used : BasicHttpResponse(cz.msebera.android.httpclient.message.BasicHttpResponse) HttpMessageWriter(cz.msebera.android.httpclient.io.HttpMessageWriter) HttpResponseWriter(cz.msebera.android.httpclient.impl.io.HttpResponseWriter) HttpMessage(cz.msebera.android.httpclient.HttpMessage) Message(org.awesomeapp.messenger.model.Message) HttpException(cz.msebera.android.httpclient.HttpException) IOException(java.io.IOException) HttpMessage(cz.msebera.android.httpclient.HttpMessage) BasicStatusLine(cz.msebera.android.httpclient.message.BasicStatusLine)

Aggregations

HttpException (cz.msebera.android.httpclient.HttpException)2 HttpMessage (cz.msebera.android.httpclient.HttpMessage)2 HttpMessageWriter (cz.msebera.android.httpclient.io.HttpMessageWriter)2 IOException (java.io.IOException)2 Message (org.awesomeapp.messenger.model.Message)2 HttpRequestWriter (cz.msebera.android.httpclient.impl.io.HttpRequestWriter)1 HttpResponseWriter (cz.msebera.android.httpclient.impl.io.HttpResponseWriter)1 BasicHttpRequest (cz.msebera.android.httpclient.message.BasicHttpRequest)1 BasicHttpResponse (cz.msebera.android.httpclient.message.BasicHttpResponse)1 BasicStatusLine (cz.msebera.android.httpclient.message.BasicStatusLine)1