package fr.univnantes.atal.web.trashnao.servlets;

import au.com.bytecode.opencsv.CSVReader;
import fr.univnantes.atal.web.trashnao.model.Address;
import fr.univnantes.atal.web.trashnao.model.CollectDay;
import fr.univnantes.atal.web.trashnao.persistence.PMF;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.io.PrintWriter;

public class FetchJson extends HttpServlet {

    //PersistenceManager pm = PMF.get().getPersistenceManager();

    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //System.setProperty("http.proxyHost", "cache.wifi.univ-nantes.fr");
        //System.setProperty("http.proxyPort", "3128");
        URL url = new URL("http://data.nantes.fr/api/publication/"
                + "JOURS_COLLECTE_DECHETS_VDN/JOURS_COLLECTE_DECHETS_VDN_STBL/"
                + "content/?format=json");
        //Collection<Address> addresses = new ArrayList<>();
        URLConnection yc = url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(
                yc.getInputStream()));
        String inputLine;
        response.setContentType("application/json");
        response.setCharacterEncoding("UTF-8");
        PrintWriter pw = response.getWriter();
        while ((inputLine = in.readLine()) != null)
             pw.println(inputLine);
        in.close();
    }
}

@@ -55,409 +55,82 @@
 ort 
-au.com.bytecode.opencsv.CSVReader;%0Aimport fr.univnantes.atal.web.trashnao.model.Address;%0Aimport fr.univnantes.atal.web.trashnao.model.CollectDay;%0Aimport fr.univnantes.atal.web.trashnao.persistence.PMF;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URL;%0Aimport java.util.ArrayList;%0Aimport java.util.Collection;%0Aimport javax.jdo.PersistenceManager;%0Aimport javax.jdo.Query
+java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.net.URL
 ;%0Aim
@@ -302,39 +302,8 @@
 se;%0A
-import java.net.URLConnection;%0A
 impo
@@ -469,17 +469,16 @@
 ager();%0A
-%0A
     /**%0A
@@ -895,141 +895,8 @@
 n %7B%0A
-        //System.setProperty(%22http.proxyHost%22, %22cache.wifi.univ-nantes.fr%22);%0A        //System.setProperty(%22http.proxyPort%22, %223128%22);%0A
     
@@ -1093,118 +1093,13 @@
     
-//Collection%3CAddress%3E addresses = new ArrayList%3C%3E();%0A        URLConnection yc = url.openConnection();%0A        
+try (
 Buff
@@ -1176,31 +1176,48 @@
     
-yc.getInputStream()));%0A
+     url.openStream(), %22UTF-8%22))) %7B%0A    
     
@@ -1238,32 +1238,36 @@
 utLine;%0A        
+ 
+   
 response.setCont
@@ -1295,32 +1295,36 @@
 json%22);%0A        
+   
+ 
 response.setChar
@@ -1355,16 +1355,20 @@
         
+    
 PrintWri
@@ -1406,16 +1406,20 @@
         
+ 
+   
 while ((
@@ -1453,17 +1453,20 @@
 != null)
-%0A
+ %7B%0A 
         
@@ -1470,16 +1470,18 @@
         
+  
 pw.print
@@ -1507,19 +1507,23 @@
     
-in.close();
+    %7D%0A        %7D
 %0A   

fix encoding