package com.cramdroid.api; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpRetryException; import java.net.URI; import org.apache.http.HttpResponse; import org.apache.http.ParseException; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntity; import org.apache.http.entity.mime.content.ByteArrayBody; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import org.json.JSONException; import org.json.JSONObject; import android.content.Context; import android.net.Uri; import android.util.Log; import android.widget.Toast; public abstract class HttpHandler { // private String url; private final HttpUriRequest request; // private ArrayList<Pair<String, String>> params; // private MultipartEntity entity; private static HttpClient httpClient = null; private static HttpClient getHttpClient() { if (httpClient == null) { httpClient = new DefaultHttpClient(); } return httpClient; } this.apiPath = apiPath; this.request = request; } return apiPath; } public final HttpResponse getResponse() { HttpUriRequest request = buildHttpUriRequest(); if (request == null) { return null; } HttpResponse response = null; try { response = getHttpClient().execute(request); Log.w(TAG, "apiPath"+this.apiPath); Log.w(TAG, "HttpClient exec, IOException", e); } return response; } public final JSONObject getResult() throws HttpRetryException { return getResultFromResponse(getResponse()); } request.addHeader(name, value); } public abstract HttpUriRequest buildHttpUriRequest(); public static final class GetHttpHandler extends HttpHandler { private Uri.Builder builder; super(path, new HttpGet()); builder = Uri.parse((isFullUrl ? "" : APIConstants.SERVER_HOST) + path) .buildUpon(); } this(apiPath, false); } @Override this.builder.appendQueryParameter(key, value); return false; } @Override public HttpUriRequest buildHttpUriRequest() { HttpGet get = (HttpGet) super.request; Log.d(TAG,"GetHttpHandler PATH="+this.builder.build().toString()); get.setURI(URI.create(this.builder.build().toString())); return get; } } public static final class PostHttpHandler extends HttpHandler { private MultipartEntity multipart; super(path, new HttpPost((isFullUrl ? "" : APIConstants.SERVER_HOST) + path)); multipart = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE); } this(apiPath, false); } @Override try { multipart.addPart(key, new StringBody(value)); return false; } return true; } @Override public HttpUriRequest buildHttpUriRequest() { Log.d(TAG,"GetHttpHandler PATH="+super.request.getURI().getPath()); HttpPost post = (HttpPost) super.request; post.setEntity(multipart); return post; } multipart.addPart(key, new ByteArrayBody(value, fileName)); } addByte(key, value, "FilenameUnknown"); } multipart.addPart(key, new FileBody(value)); } } /** * @return JSONObject , JSONArray * @param response * Get statuscode and stringbody form this HttpResponse * @throws IOException * @throws ParseException * @throws JSONException */ public static JSONObject getResultFromResponse(HttpResponse response) throws HttpRetryException { if (response == null) return null; try { res = EntityUtils.toString(response.getEntity()); Log.w(TAG, "getResultFromResponse, ParseException", e); Log.w(TAG, "getResultFromResponse, IOException", e); } if (res == null) return null; int statusCode = response.getStatusLine().getStatusCode(); Log.d(TAG, "getResultFromResponse: " + res); Log.d(TAG, "statusCode: " + statusCode); JSONObject obj = null; try { obj = new JSONObject(res); } catch (JSONException e) { Log.w(TAG, "getResultFromResponse, JSONException", e); } if (obj == null) return null; if (statusCode <= 300) { return obj; } else if (statusCode >= 400) { try { error = obj.getString("error"); } catch (JSONException e) { Log.w(TAG, "getResultFromResponse, JSONException", e); } throw new HttpRetryException(error, statusCode); } return null; } /** * TODO * * @param ctx */ Toast.makeText(ctx, "Alert No Network!!!!!", 0).show(); Log.d(TAG, "Alert No Network!!!!!"); } /** * TODO * * @return always return true * @param ctx */ Log.d("Network", "Checking Network... (Without Checking!!!!!)"); // HttpClient httpClient = new DefaultHttpClient(); // HttpGet httpGet = new HttpGet("http://www.google.com"); // // try { // httpClient.execute(httpGet); // } catch (Exception e) { // Log.d("Network", "Checking Network Done!!"); // return false; // } Log.d("Network", "Checking Network Done!!"); return true; // ConnectivityManager cm = (ConnectivityManager) // context.getSystemService(Context.CONNECTIVITY_SERVICE); // NetworkInfo netInfo = cm.getActiveNetworkInfo(); // // if (netInfo!=null && netInfo.isConnected()) { // return true; // } // // return false; } }
Standard input is empty
Main.java:29: class HttpHandler is public, should be declared in a file named HttpHandler.java
public abstract class HttpHandler {
^
Main.java:8: package org.apache.http does not exist
import org.apache.http.HttpResponse;
^
Main.java:9: package org.apache.http does not exist
import org.apache.http.ParseException;
^
Main.java:10: package org.apache.http.client does not exist
import org.apache.http.client.HttpClient;
^
Main.java:11: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpGet;
^
Main.java:12: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpPost;
^
Main.java:13: package org.apache.http.client.methods does not exist
import org.apache.http.client.methods.HttpUriRequest;
^
Main.java:14: package org.apache.http.entity.mime does not exist
import org.apache.http.entity.mime.HttpMultipartMode;
^
Main.java:15: package org.apache.http.entity.mime does not exist
import org.apache.http.entity.mime.MultipartEntity;
^
Main.java:16: package org.apache.http.entity.mime.content does not exist
import org.apache.http.entity.mime.content.ByteArrayBody;
^
Main.java:17: package org.apache.http.entity.mime.content does not exist
import org.apache.http.entity.mime.content.FileBody;
^
Main.java:18: package org.apache.http.entity.mime.content does not exist
import org.apache.http.entity.mime.content.StringBody;
^
Main.java:19: package org.apache.http.impl.client does not exist
import org.apache.http.impl.client.DefaultHttpClient;
^
Main.java:20: package org.apache.http.util does not exist
import org.apache.http.util.EntityUtils;
^
Main.java:21: package org.json does not exist
import org.json.JSONException;
^
Main.java:22: package org.json does not exist
import org.json.JSONObject;
^
Main.java:24: package android.content does not exist
import android.content.Context;
^
Main.java:25: package android.net does not exist
import android.net.Uri;
^
Main.java:26: package android.util does not exist
import android.util.Log;
^
Main.java:27: package android.widget does not exist
import android.widget.Toast;
^
Main.java:35: cannot find symbol
symbol : class HttpUriRequest
location: class com.cramdroid.api.HttpHandler
private final HttpUriRequest request;
^
Main.java:38: cannot find symbol
symbol : class HttpClient
location: class com.cramdroid.api.HttpHandler
private static HttpClient httpClient = null;
^
Main.java:40: cannot find symbol
symbol : class HttpClient
location: class com.cramdroid.api.HttpHandler
private static HttpClient getHttpClient() {
^
Main.java:47: cannot find symbol
symbol : class HttpUriRequest
location: class com.cramdroid.api.HttpHandler
protected HttpHandler(String apiPath, HttpUriRequest request) {
^
Main.java:56: cannot find symbol
symbol : class HttpResponse
location: class com.cramdroid.api.HttpHandler
public final HttpResponse getResponse() {
^
Main.java:72: cannot find symbol
symbol : class JSONObject
location: class com.cramdroid.api.HttpHandler
public final JSONObject getResult() throws HttpRetryException {
^
Main.java:82: cannot find symbol
symbol : class HttpUriRequest
location: class com.cramdroid.api.HttpHandler
public abstract HttpUriRequest buildHttpUriRequest();
^
Main.java:166: cannot find symbol
symbol : class HttpResponse
location: class com.cramdroid.api.HttpHandler
public static JSONObject getResultFromResponse(HttpResponse response)
^
Main.java:166: cannot find symbol
symbol : class JSONObject
location: class com.cramdroid.api.HttpHandler
public static JSONObject getResultFromResponse(HttpResponse response)
^
Main.java:212: cannot find symbol
symbol : class Context
location: class com.cramdroid.api.HttpHandler
public static void AlertNoNetwork(Context ctx) {
^
Main.java:224: cannot find symbol
symbol : class Context
location: class com.cramdroid.api.HttpHandler
public static boolean checkNetworkStatus(Context ctx) {
^
Main.java:85: package Uri does not exist
private Uri.Builder builder;
^
Main.java:104: cannot find symbol
symbol : class HttpUriRequest
location: class com.cramdroid.api.HttpHandler.GetHttpHandler
public HttpUriRequest buildHttpUriRequest() {
^
Main.java:114: cannot find symbol
symbol : class MultipartEntity
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
private MultipartEntity multipart;
^
Main.java:137: cannot find symbol
symbol : class HttpUriRequest
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
public HttpUriRequest buildHttpUriRequest() {
^
Main.java:42: cannot find symbol
symbol : class DefaultHttpClient
location: class com.cramdroid.api.HttpHandler
httpClient = new DefaultHttpClient();
^
Main.java:58: cannot find symbol
symbol : class HttpUriRequest
location: class com.cramdroid.api.HttpHandler
HttpUriRequest request = buildHttpUriRequest();
^
Main.java:62: cannot find symbol
symbol : class HttpResponse
location: class com.cramdroid.api.HttpHandler
HttpResponse response = null;
^
Main.java:66: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.w(TAG, "apiPath"+this.apiPath);
^
Main.java:67: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.w(TAG, "HttpClient exec, IOException", e);
^
Main.java:88: cannot find symbol
symbol : class HttpGet
location: class com.cramdroid.api.HttpHandler.GetHttpHandler
super(path, new HttpGet());
^
Main.java:89: cannot find symbol
symbol : variable APIConstants
location: class com.cramdroid.api.HttpHandler.GetHttpHandler
builder = Uri.parse((isFullUrl ? "" : APIConstants.SERVER_HOST) + path)
^
Main.java:89: cannot find symbol
symbol : variable Uri
location: class com.cramdroid.api.HttpHandler.GetHttpHandler
builder = Uri.parse((isFullUrl ? "" : APIConstants.SERVER_HOST) + path)
^
Main.java:105: cannot find symbol
symbol : class HttpGet
location: class com.cramdroid.api.HttpHandler.GetHttpHandler
HttpGet get = (HttpGet) super.request;
^
Main.java:105: cannot find symbol
symbol : class HttpGet
location: class com.cramdroid.api.HttpHandler.GetHttpHandler
HttpGet get = (HttpGet) super.request;
^
Main.java:106: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler.GetHttpHandler
Log.d(TAG,"GetHttpHandler PATH="+this.builder.build().toString());
^
Main.java:117: cannot find symbol
symbol : class HttpPost
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
super(path, new HttpPost((isFullUrl ? "" : APIConstants.SERVER_HOST) + path));
^
Main.java:117: cannot find symbol
symbol : variable APIConstants
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
super(path, new HttpPost((isFullUrl ? "" : APIConstants.SERVER_HOST) + path));
^
Main.java:118: cannot find symbol
symbol : class MultipartEntity
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
multipart = new MultipartEntity(
^
Main.java:119: cannot find symbol
symbol : variable HttpMultipartMode
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
HttpMultipartMode.BROWSER_COMPATIBLE);
^
Main.java:129: cannot find symbol
symbol : class StringBody
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
multipart.addPart(key, new StringBody(value));
^
Main.java:138: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
Log.d(TAG,"GetHttpHandler PATH="+super.request.getURI().getPath());
^
Main.java:139: cannot find symbol
symbol : class HttpPost
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
HttpPost post = (HttpPost) super.request;
^
Main.java:139: cannot find symbol
symbol : class HttpPost
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
HttpPost post = (HttpPost) super.request;
^
Main.java:145: cannot find symbol
symbol : class ByteArrayBody
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
multipart.addPart(key, new ByteArrayBody(value, fileName));
^
Main.java:153: cannot find symbol
symbol : class FileBody
location: class com.cramdroid.api.HttpHandler.PostHttpHandler
multipart.addPart(key, new FileBody(value));
^
Main.java:172: cannot find symbol
symbol : variable EntityUtils
location: class com.cramdroid.api.HttpHandler
res = EntityUtils.toString(response.getEntity());
^
Main.java:173: cannot find symbol
symbol : class ParseException
location: class com.cramdroid.api.HttpHandler
} catch (ParseException e) {
^
Main.java:174: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.w(TAG, "getResultFromResponse, ParseException", e);
^
Main.java:176: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.w(TAG, "getResultFromResponse, IOException", e);
^
Main.java:181: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.d(TAG, "getResultFromResponse: " + res);
^
Main.java:182: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.d(TAG, "statusCode: " + statusCode);
^
Main.java:184: cannot find symbol
symbol : class JSONObject
location: class com.cramdroid.api.HttpHandler
JSONObject obj = null;
^
Main.java:186: cannot find symbol
symbol : class JSONObject
location: class com.cramdroid.api.HttpHandler
obj = new JSONObject(res);
^
Main.java:187: cannot find symbol
symbol : class JSONException
location: class com.cramdroid.api.HttpHandler
} catch (JSONException e) {
^
Main.java:188: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.w(TAG, "getResultFromResponse, JSONException", e);
^
Main.java:199: cannot find symbol
symbol : class JSONException
location: class com.cramdroid.api.HttpHandler
} catch (JSONException e) {
^
Main.java:200: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.w(TAG, "getResultFromResponse, JSONException", e);
^
Main.java:213: cannot find symbol
symbol : variable Toast
location: class com.cramdroid.api.HttpHandler
Toast.makeText(ctx, "Alert No Network!!!!!", 0).show();
^
Main.java:214: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.d(TAG, "Alert No Network!!!!!");
^
Main.java:225: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.d("Network", "Checking Network... (Without Checking!!!!!)");
^
Main.java:237: cannot find symbol
symbol : variable Log
location: class com.cramdroid.api.HttpHandler
Log.d("Network", "Checking Network Done!!");
^
72 errors
Standard output is empty