Galera estou precisando de uma ajuda, preciso pegar o retorno desta thread e gostaria de saber ser esta correto desta forma…
Método que starta a thread e tenta pegar o retorno…
public String getValidacao(){
thread = new Thread(this);
thread.start();
System.out.println(getRetorno());
return getRetorno();
}
Thread
public void run() {
/* os parametros são passados pela stream */
URL = "http://localhost:9080/WebService/HelloWebService";
this.append("connected...\n");
DataInputStream dis = null;
StringBuffer strBuffer = null;
try{
while(true){
conection = (HttpConnection) Connector.open(URL, Connector.READ_WRITE);
conection.setRequestMethod(HttpConnection.POST);
conection.setRequestProperty("IF-Modified-Since","20 Jan 2001 16:19:14 GMT");
conection.setRequestProperty("User-Agent","Profile/MIDP-1.0 Confirguration/CLDC-1.0");
conection.setRequestProperty("Content-Language", "en-CA");
conection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String dados = "username="+nome+"&password="+senha+"&operacao="+operacao;
byte[] data = dados.getBytes();
conection.setRequestProperty("Content-Length", Integer.toString( data.length ) );
/* passando parâmetros */
OutputStream out = conection.openOutputStream();
out.write(data);
out.close();
if (conection.getResponseCode() == HttpConnection.HTTP_OK){
strBuffer = new StringBuffer();
this.append("Connection OK...\n");
//DataOutputStream out = (DataOutputStream) conection.openDataOutputStream();
dis = (DataInputStream) conection.openDataInputStream();
/************* resposta do servidor ******************/
int ch = dis.read();
while(ch != -1){
strBuffer.append( (char) ch );
}
dis.close();
this.setRetorno(strBuffer.toString());
conection.close();
break;
/*********************************************************/
}
else{
URL = conection.getHeaderField("location").trim();
conection.close();
}
}
}catch(IOException e){
e.printStackTrace();
}
}
Galera preciso muito da ajuda de vcs…