mirror of
				https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
				synced 2025-11-04 02:53:08 +00:00 
			
		
		
		
	[CLIENT] Mise en place d'un mécanisme d'encoding en UTF-8 lors de l'envoi de requêtes HTTP vers le serveur
This commit is contained in:
		@@ -61,7 +61,7 @@ public class ConnectionService {
 | 
				
			|||||||
	        throw new IllegalStateException("No url specified for data server");
 | 
						        throw new IllegalStateException("No url specified for data server");
 | 
				
			||||||
	    if(executor.isShutdown() || executor.isTerminated())
 | 
						    if(executor.isShutdown() || executor.isTerminated())
 | 
				
			||||||
	        throw new IllegalStateException("Service was shut down : unable to send text");
 | 
						        throw new IllegalStateException("Service was shut down : unable to send text");
 | 
				
			||||||
        executor.submit(()->textSender.send(serverUrl, "message="+text, listener));
 | 
					        executor.submit(()->textSender.send(serverUrl, text, listener));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public void shutdown() {
 | 
					    public void shutdown() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,12 +1,8 @@
 | 
				
			|||||||
package com.pqt.client.module.connection.senders;
 | 
					package com.pqt.client.module.connection.senders;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.pqt.client.module.connection.listeners.IConnectionListener;
 | 
					import com.pqt.client.module.connection.listeners.IConnectionListener;
 | 
				
			||||||
import com.sun.javafx.binding.StringFormatter;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.io.BufferedReader;
 | 
					import java.io.*;
 | 
				
			||||||
import java.io.DataOutputStream;
 | 
					 | 
				
			||||||
import java.io.IOException;
 | 
					 | 
				
			||||||
import java.io.InputStreamReader;
 | 
					 | 
				
			||||||
import java.net.ConnectException;
 | 
					import java.net.ConnectException;
 | 
				
			||||||
import java.net.HttpURLConnection;
 | 
					import java.net.HttpURLConnection;
 | 
				
			||||||
import java.net.URL;
 | 
					import java.net.URL;
 | 
				
			||||||
@@ -16,7 +12,7 @@ public class HttpTextSender implements ITextSender{
 | 
				
			|||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void send(String host, String text, IConnectionListener listener) {
 | 
					    public void send(String host, String text, IConnectionListener listener) {
 | 
				
			||||||
        try {
 | 
					        try {
 | 
				
			||||||
            String trueURL = String.format("http://%s?%s", host, encode(text));
 | 
					            String trueURL = String.format("http://%s?%s", host, format(text));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            HttpURLConnection con = (HttpURLConnection) new URL(trueURL).openConnection();
 | 
					            HttpURLConnection con = (HttpURLConnection) new URL(trueURL).openConnection();
 | 
				
			||||||
            con.setRequestMethod("GET");
 | 
					            con.setRequestMethod("GET");
 | 
				
			||||||
@@ -53,7 +49,14 @@ public class HttpTextSender implements ITextSender{
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Méthode à modifier pour encoder le message suivant un algorithme spécifique
 | 
					    // Méthode à modifier pour encoder le message suivant un algorithme spécifique
 | 
				
			||||||
    private String encode(String toEncode){
 | 
					    private String format(String toFormat){
 | 
				
			||||||
        return toEncode;
 | 
					        try {
 | 
				
			||||||
 | 
					            String encodeTo = "UTF-8";
 | 
				
			||||||
 | 
					            return String.format("format=%s&message=%s", encodeTo, URLEncoder.encode(toFormat, encodeTo));
 | 
				
			||||||
 | 
					        }catch(UnsupportedEncodingException e){
 | 
				
			||||||
 | 
					            //TODO Issue #6 : ajouter un log ici
 | 
				
			||||||
 | 
					            e.printStackTrace();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return String.format("message=%s", toFormat);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user