Back to project page RestLib.
The source code is released under:
MIT License
If you think the Android project RestLib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package github.crazymumu.restlib; //w ww . j ava2 s. co m import github.crazymumu.restlib.http.RequestMethod; import github.crazymumu.restlib.http.UserAgent; import java.util.HashMap; import java.util.Map; import org.json.JSONArray; import org.json.JSONObject; import android.os.Bundle; import android.os.Parcel; import android.os.Parcelable; /** * A request message from a client to a server includes, the method to be * applied to the resource, the request-header fields, and the message-body. * * @author Crazy MuMu */ public class RestRequest implements Parcelable { private Map<String, String> headers = new HashMap<String, String>(); private Map<String, String> params = new HashMap<String, String>(); private String userAgent = UserAgent.Java_1_6_0_26; private String method = RequestMethod.Get; private String resource; public RestRequest() { } public void setHeader(String key, String value) { headers.put(key, value); } public void setParam(String key, String value) { params.put(key, value); } public void setParam(JSONObject json) { params.put("", json.toString()); } public void setUserAgent(String userAgent) { this.userAgent = userAgent; } public void setMethod(String method) { this.method = method; } public void setResource(String resource) { this.resource = resource; } public Map<String, String> getHeaders() { return headers; } public Map<String, String> getParams() { return params; } public String getUserAgent() { return userAgent; } public String getMethod() { return method; } public String getResource() { return resource; } @Override public int describeContents() { return 0; } @Override public void writeToParcel(Parcel dest, int flags) { Bundle extras = new Bundle(); extras.putSerializable("headers", (HashMap<String, String>) headers); extras.putSerializable("params", (HashMap<String, String>) params); dest.writeString(userAgent); dest.writeString(method); dest.writeString(resource); dest.writeBundle(extras); } @SuppressWarnings("unchecked") private RestRequest(Parcel source) { userAgent = source.readString(); method = source.readString(); resource = source.readString(); Bundle extras = source.readBundle(); if (extras != null) { headers = (HashMap<String, String>) extras.getSerializable("headers"); params = (HashMap<String, String>) extras.getSerializable("params"); } } public static final Parcelable.Creator<RestRequest> CREATOR = new Parcelable.Creator<RestRequest>() { @Override public RestRequest createFromParcel(Parcel source) { return new RestRequest(source); } @Override public RestRequest[] newArray(int size) { return new RestRequest[size]; } }; }