Android Open Source - Android-Project-Manager Web Service Manager






From Project

Back to project page Android-Project-Manager.

License

The source code is released under:

GNU General Public License

If you think the Android project Android-Project-Manager 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.vaquerosisd.object;
//  w  ww.ja va  2  s  .  c o  m
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.SocketException;
import java.net.URL;

import org.apache.http.HttpStatus;
import org.json.JSONObject;

public class WebServiceManager{

    
    private static HttpURLConnection urlConnection;
    public WebServiceManager(){
      super();
    }
    
      //
      // Metodos JSON
      
    //Metodo para obtener una respuesta Json de un webservice
    public JSONObject getJSONFromUrl(String url, String json) throws SocketException{
    
      JSONObject jsonObject = null;
    //HttpURLConnection urlConnection = null;
    
    try{
      
      URL myUrl = new URL(url);
      
      urlConnection =(HttpURLConnection)myUrl.openConnection();
      
      urlConnection.setDoOutput(true);
      urlConnection.setDoInput(true);
      urlConnection.setRequestMethod("POST");
      urlConnection.setRequestProperty("Content-Type", "application/json");
      urlConnection.setRequestProperty("Accept", "application/json");
      
      OutputStreamWriter out= new OutputStreamWriter(urlConnection.getOutputStream());
      System.out.println(json);
      out.write(json);
      out.flush();
      out.close();
      
      urlConnection.connect();
      
      int responseCode = urlConnection.getResponseCode();
      if(responseCode == HttpStatus.SC_OK){
        String responseString = readStream(urlConnection.getInputStream());
        jsonObject = new JSONObject(responseString);
      }
      
    }
    catch (Exception e){
      System.out.println(e);
    }
    finally{
      if(urlConnection!=null)
        urlConnection.disconnect();
    }
    
    
    return jsonObject;
    
    } // end getJSONFromUrl
    
    
    // Metodo privado para leer un buffered reader del inputstream
    private String readStream(InputStream  in)  {  
      BufferedReader reader  =  null;  
      StringBuffer  response  =  null;       
      try  {  
             reader  =  new  BufferedReader(new  InputStreamReader(in,  "UTF-8"));  
             String  line  =  "";  
             response  =  new  StringBuffer();  
            while  ((line  =  reader.readLine())  !=  null)  {  
                       response.append(line);  
               }  
             }  catch  (IOException  e)  {  
                   e.printStackTrace();  
             }  finally  {  
                   if  (reader  !=  null)  {  
                       try  {  
                           reader.close();  
                       }  catch  (IOException e)  {  
                           e.printStackTrace();  
                       }  
                   }  
               }  
               return  response.toString();  
           }  //end readStream method  

    
    
    
}   //end class webServiceManager





Java Source Code List

com.vaquerosisd.adapters.ProjectListViewAdapter.java
com.vaquerosisd.adapters.TaskListViewAdapter.java
com.vaquerosisd.adapters.VideoNoteGridViewAdapter.java
com.vaquerosisd.adapters.VoiceNoteGridViewAdapter.java
com.vaquerosisd.database.DatabaseHelper.java
com.vaquerosisd.database.ProjectOperations.java
com.vaquerosisd.dialog.CustomStatus.java
com.vaquerosisd.dialog.DatePickerFragment.java
com.vaquerosisd.dialog.DeleteDialog.java
com.vaquerosisd.dialog.DeletePhotoDialog.java
com.vaquerosisd.dialog.DeleteTaskDialog.java
com.vaquerosisd.dialog.EditProject.java
com.vaquerosisd.fragments.TaskDescriptionFragment.java
com.vaquerosisd.fragments.VideoNotesFragment.java
com.vaquerosisd.fragments.VoiceNotesFragment.java
com.vaquerosisd.object.JsonWrapper.java
com.vaquerosisd.object.PhotoRef.java
com.vaquerosisd.object.Project.java
com.vaquerosisd.object.Task.java
com.vaquerosisd.object.User.java
com.vaquerosisd.object.WebServiceManager.java
com.vaquerosisd.projectmanager.About.java
com.vaquerosisd.projectmanager.ContentTask.java
com.vaquerosisd.projectmanager.Login.java
com.vaquerosisd.projectmanager.MainActivity.java
com.vaquerosisd.projectmanager.NewAccount.java
com.vaquerosisd.projectmanager.NewProject.java
com.vaquerosisd.projectmanager.NewTask.java
com.vaquerosisd.projectmanager.OnSwipeListener.java
com.vaquerosisd.projectmanager.PhotoManager.java
com.vaquerosisd.projectmanager.ProjectList.java
com.vaquerosisd.projectmanager.TaskList.java
com.vaquerosisd.projectmanager.WebserviceCallback.java
com.vaquerosisd.utils.FileOperations.java
com.vaquerosisd.utils.OnSwipeListener.java
com.vaquerosisd.utils.SpinnerUtil.java
com.vaquerosisd.utils.TabListener.java