1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
| public class TestThread extends Thread {
boolean interrupted = false;
Context ctx = null;
LibrarySessionBeanRemote libraryBean = null;
InstanciateBeanInterface instanciateBeanInterface = null;
//String viewClassName = LibrarySessionBeanRemote.class.getName();
String viewClassName = InstanciateBeanInterface.class.getName();
Set<LibrarySessionBeanRemote> slsbSet = new HashSet<LibrarySessionBeanRemote>();
static Logger log = LogManager.getLogger(TestThread.class.getName());
public String postURL(URL a_Url, String a_sParamsToPost)
{
StringBuilder o_oSb = new StringBuilder();
//recup du saut de ligne
String o_sLineSep = null;
try
{
o_sLineSep = System.getProperty("line.separator");
}
catch (Exception e)
{
o_sLineSep = "\n";
}
try
{
HttpURLConnection o_oUrlConn = (HttpURLConnection) a_Url.openConnection();
o_oUrlConn.setRequestMethod("POST");
o_oUrlConn.setAllowUserInteraction(false);
//envoyer des params
o_oUrlConn.setDoOutput(true);
//poster les params
PrintWriter o_oParamWriter = new PrintWriter(o_oUrlConn.getOutputStream());
o_oParamWriter.print(a_sParamsToPost);
//fermer le post avant de lire le resultat ... logique
o_oParamWriter.flush();
o_oParamWriter.close();
//Lire la reponse
InputStream o_oResponse = o_oUrlConn.getInputStream();
BufferedReader o_oBufReader = new BufferedReader(new InputStreamReader(o_oResponse));
String sLine;
while ((sLine = o_oBufReader.readLine()) != null)
{
o_oSb.append(sLine);
o_oSb.append(o_sLineSep);
}
//deconnection
o_oUrlConn.disconnect();
}
catch(ConnectException ctx)
{
log.fatal("Connection lost : server may be down");
ctx.printStackTrace();
}
catch (Exception e)
{
log.error("postURL : "+e.getMessage());
e.printStackTrace();
}
log.debug("retour url="+o_oSb.toString());
return o_oSb.toString();
} |
Partager