Search in sources :

Example 11 with Header

use of cz.msebera.android.httpclient.Header in project xabber-android by redsolution.

the class FileManager method getFileUrlSize.

private static void getFileUrlSize(final MessageItem messageItem) {
    LogManager.i(FileManager.class, "Requesting file size");
    AsyncHttpClient client = new AsyncHttpClient();
    client.head(messageItem.getText(), new AsyncHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            for (Header header : headers) {
                if (header.getName().equals(HttpHeaders.CONTENT_LENGTH)) {
                    messageItem.setFileSize(Long.parseLong(header.getValue()));
                    MessageManager.getInstance().onChatChanged(messageItem.getChat().getAccount(), messageItem.getChat().getUser(), false);
                    break;
                }
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
        }
    });
}
Also used : Header(cz.msebera.android.httpclient.Header) AsyncHttpResponseHandler(com.loopj.android.http.AsyncHttpResponseHandler) AsyncHttpClient(com.loopj.android.http.AsyncHttpClient)

Example 12 with Header

use of cz.msebera.android.httpclient.Header in project android-booksearch-exercise by codepath.

the class BookListActivity method fetchBooks.

// Executes an API call to the OpenLibrary search endpoint, parses the results
// Converts them into an array of book objects and adds them to the adapter
private void fetchBooks(String query) {
    client = new BookClient();
    client.getBooks(query, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                JSONArray docs;
                if (response != null) {
                    // Get the docs json array
                    docs = response.getJSONArray("docs");
                    // Parse json array into array of model objects
                    final ArrayList<Book> books = Book.fromJson(docs);
                    // Remove all books from the adapter
                    abooks.clear();
                    // Load model objects into the adapter
                    for (Book book : books) {
                        // add book through the adapter
                        abooks.add(book);
                    }
                    bookAdapter.notifyDataSetChanged();
                }
            } catch (JSONException e) {
                // Invalid JSON format, show appropriate error.
                e.printStackTrace();
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
        }
    });
}
Also used : BookClient(com.codepath.android.booksearch.net.BookClient) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Header(cz.msebera.android.httpclient.Header) JSONObject(org.json.JSONObject) Book(com.codepath.android.booksearch.models.Book) JsonHttpResponseHandler(com.loopj.android.http.JsonHttpResponseHandler)

Example 13 with Header

use of cz.msebera.android.httpclient.Header in project android-sex-http by dtboy1995.

the class Request method setHeaders.

public Request setHeaders(Map<String, String> headers) {
    this.headers.clear();
    for (Map.Entry<String, String> header : headers.entrySet()) {
        Header h = new BasicHeader(header.getKey(), header.getValue());
        this.headers.add(h);
    }
    return this;
}
Also used : Header(cz.msebera.android.httpclient.Header) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader) Map(java.util.Map) BasicHeader(cz.msebera.android.httpclient.message.BasicHeader)

Aggregations

Header (cz.msebera.android.httpclient.Header)13 BasicHeader (cz.msebera.android.httpclient.message.BasicHeader)6 AsyncHttpResponseHandler (com.loopj.android.http.AsyncHttpResponseHandler)3 AsyncHttpClient (com.loopj.android.http.AsyncHttpClient)2 ArrayList (java.util.ArrayList)2 Book (com.codepath.android.booksearch.models.Book)1 BookClient (com.codepath.android.booksearch.net.BookClient)1 JsonFactory (com.fasterxml.jackson.core.JsonFactory)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 BaseJsonHttpResponseHandler (com.loopj.android.http.BaseJsonHttpResponseHandler)1 JsonHttpResponseHandler (com.loopj.android.http.JsonHttpResponseHandler)1 RangeFileAsyncHttpResponseHandler (com.loopj.android.http.RangeFileAsyncHttpResponseHandler)1 ResponseHandlerInterface (com.loopj.android.http.ResponseHandlerInterface)1 SampleJSON (com.loopj.android.http.sample.util.SampleJSON)1 HttpHost (cz.msebera.android.httpclient.HttpHost)1 HttpRequest (cz.msebera.android.httpclient.HttpRequest)1 ProtocolException (cz.msebera.android.httpclient.ProtocolException)1 StatusLine (cz.msebera.android.httpclient.StatusLine)1 CircularRedirectException (cz.msebera.android.httpclient.client.CircularRedirectException)1 HttpResponseException (cz.msebera.android.httpclient.client.HttpResponseException)1