Android Open Source - rwestful-android Default Handler






From Project

Back to project page rwestful-android.

License

The source code is released under:

MIT License

If you think the Android project rwestful-android 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 com.rwestful.android.web.handlers;
/*from ww w. ja  v a2  s.  c  o  m*/
import org.apache.http.protocol.HttpRequestHandler;


import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.entity.ContentProducer;
import org.apache.http.entity.EntityTemplate;
import org.apache.http.protocol.HttpContext;

import android.content.Context;

import com.rwestful.android.constants.Constants;

public class DefaultHandler implements HttpRequestHandler {

  static final String LOG_TAG = "DEFAULT_HANDLER";

  public DefaultHandler(){
  }

  @Override
  public void handle(HttpRequest request, HttpResponse response, HttpContext httpContext) throws HttpException, IOException {
    final String uriString = request.getRequestLine().getUri();
  
    EntityTemplate entity = new EntityTemplate(new ContentProducer() {
      public void writeTo(final OutputStream outstream) throws IOException {
        OutputStreamWriter writer = null;
        try {
          writer = new OutputStreamWriter(outstream, Constants.CHARSET_UTF8);
          writer.write(uriString);
        } finally {
          if(writer != null) {
            writer.close();
          }
        }
      }
    });

    entity.setContentType(Constants.CONTENT_TYPE);
    response.setEntity(entity);

  }
  
}




Java Source Code List

com.rwestful.android.MainActivity.java
com.rwestful.android.SettingsActivity.java
com.rwestful.android.constants.Constants.java
com.rwestful.android.listeners.OnSettingsMenuItemClickListener.java
com.rwestful.android.receivers.BootReceiver.java
com.rwestful.android.web.handlers.DefaultHandler.java
com.rwestful.android.web.handlers.storage.StorageWriteHandler.java
com.rwestful.android.web.servers.HTTPServer.java
com.rwestful.android.web.services.HTTPService.java