Android Open Source - Boxee-Thumb-Remote Http Request






From Project

Back to project page Boxee-Thumb-Remote.

License

The source code is released under:

Apache License

If you think the Android project Boxee-Thumb-Remote listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.evendanan.android.thumbremote.network;
/*  w ww  .j  a  v a 2s .c o m*/
import android.text.TextUtils;
import android.util.Log;

/*
 * Controls the live cycle of a network connection.
 * Tries to keep the connection alive as long as possible, thus, reusing HTTP connections, and reduce sockets and objects creations.
 */
public class HttpRequest {

  private static final String TAG = "HttpRequest";
  // We set these for all requests.
  private static int msTimeout = 2000;
  private static String msPassword;
  private static String msUser;
  private static HttpBlocking msRequester = null;
  
  public synchronized static void setTimeout(int timeout_ms) {
    close();
    msTimeout = timeout_ms;
  }

  public synchronized static void setUserPassword(String user, String password) {
    close();
    msUser = user;
    msPassword = password;
  }
  
  public synchronized static boolean hasCredentials()
  {
    return !TextUtils.isEmpty(msUser) && !TextUtils.isEmpty(msPassword);
  }

  public synchronized static Response getHttpResponse(final String url)
  {
    if (msRequester == null)
    {
      msRequester = new ReusableHttpClientBlocking(msTimeout, msUser, msPassword);
    }
    try
    {
      return msRequester.fetch(url);
    }
    catch(Exception e)
    {
      Log.w(TAG, "Caught an exception while fetching url "+url+". Error: "+e.getMessage());
      close();
      e.printStackTrace();
      return new Response(false, 404, "Failed to connect to server");
    }
  }

  public synchronized static void close() {
    if (msRequester != null)
      msRequester.close();
    msRequester = null;
  }
}




Java Source Code List

.HttpClientBlocking.java
com.example.android.actionbarcompat.ActionBarHelperBase.java
com.example.android.actionbarcompat.ActionBarHelperCompat.java
com.example.android.actionbarcompat.ActionBarHelperHoneycomb.java
com.example.android.actionbarcompat.ActionBarHelperICS.java
com.example.android.actionbarcompat.SimpleMenuItem.java
com.example.android.actionbarcompat.SimpleMenu.java
iharder.base64.Base64.java
net.evendanan.android.thumbremote.MediaStateListener.java
net.evendanan.android.thumbremote.RemoteApplication.java
net.evendanan.android.thumbremote.ServerAddress.java
net.evendanan.android.thumbremote.ServerConnectionListener.java
net.evendanan.android.thumbremote.ServerConnector.java
net.evendanan.android.thumbremote.ServerRemote.java
net.evendanan.android.thumbremote.ServerStatePoller.java
net.evendanan.android.thumbremote.ServerStateUrlsProvider.java
net.evendanan.android.thumbremote.ServerState.java
net.evendanan.android.thumbremote.Settings.java
net.evendanan.android.thumbremote.ShakeListener.java
net.evendanan.android.thumbremote.UiView.java
net.evendanan.android.thumbremote.boxee.BoxeeConnector.java
net.evendanan.android.thumbremote.boxee.BoxeeDiscovererThread.java
net.evendanan.android.thumbremote.network.HttpBlocking.java
net.evendanan.android.thumbremote.network.HttpRequest.java
net.evendanan.android.thumbremote.network.Response.java
net.evendanan.android.thumbremote.network.ReusableHttpClientBlocking.java
net.evendanan.android.thumbremote.service.DoServerRemoteAction.java
net.evendanan.android.thumbremote.service.ServerRemoteService.java
net.evendanan.android.thumbremote.service.State.java
net.evendanan.android.thumbremote.ui.FixedViewFlipper.java
net.evendanan.android.thumbremote.ui.FragmentAlertDialogSupport.java
net.evendanan.android.thumbremote.ui.HelpUiActivity.java
net.evendanan.android.thumbremote.ui.RemoteUiActivity.java
net.evendanan.android.thumbremote.ui.SettingsActivity.java