import java.net.URL;
import java.util.Collection;
-import javax.net.ssl.HttpsURLConnection;
+import java.net.HttpURLConnection;
import org.eclipse.jdt.annotation.Nullable;
import android.content.Context;
*/
/**
- * ExecutableRunnable that makes a HTTPS call to the server and hands the response to a callback
+ * ExecutableRunnable that makes a HTTP(S) call to the server and hands the response to a callback
*
* @author Marius Gavrilescu <marius@ieval.ro>
*/
*
* @author Marius Gavrilescu
*/
- public static interface ResultCallback{
+ public interface ResultCallback{
/**
* Callback invoked if the HTTP call is successful.
*
* @param responseMessage HTTP response message
* @param inputStream HTTP content InputStream
*/
- public void onResult(final int responseCode, final String responseMessage, final InputStream inputStream);
+ void onResult(final int responseCode, final String responseMessage, final InputStream inputStream);
/**
* Callback invoked if the HTTP call is unsuccessful.
*
* @param error localized error message
*/
- public void onError(final String error);
+ void onError(final String error);
}
/**
public void run() {
try {
final URL url=Utils.getServerURL(toNonNull(context),toNonNull(path));
- final HttpsURLConnection conn=(HttpsURLConnection) url.openConnection();
+ final HttpURLConnection conn=(HttpURLConnection) url.openConnection();
if(data!=null){
conn.setDoOutput(true);
conn.setFixedLengthStreamingMode(data.length);
stream.close();
}
Log.d(getClass().getName(),"HTTP Response: "+conn.getResponseCode()+" "+conn.getResponseMessage());
- final String message=conn.getResponseMessage();
+ String message=conn.getResponseMessage();
if(message==null && callback != null)
callback.onError(toNonNull(context.getString(no_response_returned_from_server)));
- else if(message != null && callback != null)
- callback.onResult(conn.getResponseCode(), message,
- toNonNull(conn.getInputStream()));
+ else if(message != null && callback != null){
+ if(message.charAt(message.length()-1) == ')')//message is (something)
+ message=message.substring(1, message.length()-1);
+ else
+ message=message.substring(message.indexOf(')')+2);
+ callback.onResult(conn.getResponseCode(), message, conn.getResponseCode() == 200 ? conn.getInputStream() : null);
+ }
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();