Solution de relevé de la position d'un mobile Orange par un programme Java embarqué.
.
, on peut recevoir un appel sans perturber le programme.
Sytème de localisation basé sur l'utilisation des antennes de téléphone mobile (GSM)
Si vous souhaitez tester la méthode et que les messages vous soient réexpédiés, signalez votre email et le numéro de téléphone suivi
/*
* avec option M
* ok nokia page xml en alcatel même comme modem
* et parle de sms
*
* lu:http://www.wirelessdevnet.com/channels/java/features/j2me_http.phtml
*
* Copyright (c) 2007, Sun Microsystems, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of Sun Microsystems nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package example.http;
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
// import javax.microedition.pki.*;
/**
* An example MIDlet to fetch a page using an HttpConnection.
* Refer to the startApp, pauseApp, and destroyApp
* methods so see how it handles each requested transition.
*
* Note: if you run this inside POSE using a multi-homed PC (with more
* than one network connections), POSE doesn't know how to resolve
* host names not connected to the first network card. To solve this,
* add a line like this in your c:/WINNT/system32/drivers/etc/hosts
* file:
*
* XXX.XXX.XXX.XXX www.sun.com
* where XXX.XXX.XXX.XXX == IP address
*/
public class HttpTest extends MIDlet implements CommandListener, Runnable {
int mailCount=0;
String xyxy="";
String afficher;
String trouve="";
int attendu=0; // cumul des attentes
String version="0.75";
StringBuffer historique= new StringBuffer();
int locSucces=0;
String options="";
boolean optionNoWait=false;
boolean optionNoEcran=false;
boolean optionTraceMail=false;
boolean optionT=false;
String SessionID="" ; //a partir de premiere reponse
int iterations;
int periodeMinutes;
int mail2Number=0;
String mail2Subject="";
String mail2Contenu="";
/** User interface command to exit the current application. */
private Command exitCommand = new Command("Exit", Command.EXIT, 2);
/** User interface command to issue an HTTP GET request. */
private Command getCommand = new Command("Start", Command.SCREEN, 1);
/** User interface command to choose a configuration */
private Command chooseCommand = new Command("Choose", Command.SCREEN, 2);
/** User interface command to Add a new location. */
private Command addCommand = new Command("Add", Command.SCREEN, 1);
/** User interface command to save a new location. */
private Command addSaveCommand = new Command("OKsave", Command.SCREEN, 1);
/** User interface command to confirm current operation. */
private Command okCommand = new Command("OKconfig", Command.OK, 1);
/** User interface command to abort current operation. */
private Command cancelCommand = new Command("Cancel", Command.CANCEL, 1);
/** The current display object. */
private Display display;
/** The configuration */
private String config;
/** Array of target configurations. */
private Vector configs;
// prochaine url a ouvrir
private String urlNext;
/** User interface list for selection. */
private List list;
/** Message area for user entered URL. */
private TextBox addTextBox;
/** Current command to process. */
private Command currentCommand;
/** The current command processing thread. */
private Thread commandThread;
/** Current attempt count. */
private int attempt;
private TextBox t;
private boolean firstTime;
private boolean started=false;
/** Initialize the MIDlet with a handle to the current display */
public HttpTest() {
configs = new Vector();
// configs.addElement("-+ test antiguide+");
configs.addElement("? build user def ---");
configs.addElement("1#1'");
configs.addElement("2#1'");
configs.addElement("2#1' T");
configs.addElement("1#1'M (mail)");
configs.addElement("10#1'");
configs.addElement("5#10'");
configs.addElement("50#20'");
configs.addElement("100#30'");
configs.addElement("100#10'");
configs.addElement("24#60'");
config = (String)configs.elementAt(0);
display = Display.getDisplay(this);
firstTime = true;
}
final void ECRAN(String titre, String texte) {
if (optionNoEcran) {
}
else
{
t = new TextBox(titre, texte.toString(), texte.length(), 0);
display.setCurrent(t);
DEBUG ("ECRAN Affiche: " +titre+" " +texte);
//laisser le temps de la lecture
display = Display.getDisplay(this);
boolean status;
//status = display.flashBacklight(60000);
waitSeconds(5);
}
}
final void ATTENDRE(int n, String comment) {
if (optionNoWait) {
}
else {
// DEBUG("=================Attendre: " +n+ " secondes. " +comment);
waitSeconds(n);
}
}
//static final
void waitSeconds(int n) {
DEBUG("wait "+n+ " secondes");
try {
int in;
for (in=1; in<=n;++in)
Thread.sleep(1000);
attendu=attendu+1;
}
catch (Exception e) {
System.out.println(e);
}
}
/**
* Debug output routine.
* @param s string to be printed.
*/
static final void DEBUG(String s) {
if (true) {
System.out.println(s);
}
}
/**
* Converts a time to a string containing the corresponding
* date.<br />
* <b>NOTE:</b> This is here only because the J2ME date class does not
* implement toString() in any meaningful way.
* <p />
* @param time time to be converted
* @return a string representation of the time in
* the form "dayOfWeek, day mon year hour:min:sec GMT"
*/
private String time2str(long time) {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
c.setTime(new Date(time));
return c.toString();
}
/**
* Start creates the thread to do the timing.
* It should return immediately to keep the dispatcher
* from hanging.
*/
public void startApp() {
DEBUG("startApp firstTime="+firstTime);
if (firstTime) {
// Use the specified URL is overriden in the descriptor
String u = getAppProperty("HttpTest-Url");
if (u != null) {
config = u;
}
// mainScreen();
firstScreen();
firstTime = false;
} else {
display.setCurrent(t);
}
}
/**
* Display the main screen.
*/
void mainScreen() {
String s =
"Press Choose .";
t = new TextBox("Iterations & période.", s, s.length(), 0);
mainCommands(t);
display.setCurrent(t);
}
void firstScreen() {
String s =
"Press Choose .";
t = new TextBox("Iterations & période.", s, s.length(), 0);
firstCommands(t);
display.setCurrent(t);
}
void suiteScreen() {
String ts = "Press Start.";
t = new TextBox(ts,config,config.length(), 0);
suiteCommands(t);
display.setCurrent(t);
}
/**
* Pick a screen.
*/
void chooseScreen() {
list = new List("Mark choice then OkConfig", Choice.EXCLUSIVE);
for (int i = 0; i < configs.size(); i++) {
list.append((String)configs.elementAt(i), null);
}
chooseCommands(list);
display.setCurrent(list);
}
void queexitScreen() {
t = new TextBox("que exit","",0,0);
queexitCommands(t);
display.setCurrent(t);
}
/**
* Add another screen.
*/
void addScreen() {
DEBUG("exec addScreen");
addTextBox = new TextBox("itérations # periode '", "", 200, 0);
addTextBox.addCommand(addSaveCommand);
addTextBox.addCommand(cancelCommand);
addTextBox.setCommandListener(this);
display.setCurrent(addTextBox);
}
/**
* Set the funtion to perform based on commands selected.
* @param d Displayable object
* @param islist flag to indicate list processing
*/
void mainCommands(Displayable d) {
DEBUG("mainCOMMANDS");
d.addCommand(exitCommand);
d.addCommand(chooseCommand);
d.addCommand(getCommand);
d.setCommandListener(this);
}
void suiteCommands(Displayable d) {
DEBUG("suiteCOMMANDS ");
d.addCommand(exitCommand);
d.addCommand(getCommand);
d.setCommandListener(this);
}
void chooseCommands(Displayable d) {
DEBUG("ChooseCOMMANDS ");
d.addCommand(okCommand);
d.setCommandListener(this);
}
void firstCommands(Displayable d) {
DEBUG("firstCOMMANDS ");
d.addCommand(exitCommand);
d.addCommand(chooseCommand);
d.setCommandListener(this);
}
void queexitCommands(Displayable d) {
DEBUG("firstCOMMANDS ");
d.addCommand(exitCommand);
// d.addCommand(chooseCommand);
d.setCommandListener(this);
}
/**
* Pause signals the thread to stop by clearing the thread field.
* If stopped before done with the iterations it will
* be restarted from scratch later.
*/
public void pauseApp() {
}
/**
* Destroy must cleanup everything. The thread is signaled
* to stop and no result is produced.
* @param unconditional Flag to indicate that forced shutdown
* is requested
*/
public void destroyApp(boolean unconditional) {
}
/**
* Respond to commands, including exit
* @param c command to perform
* @param s Screen displayable object
*/
public void commandAction(Command c, Displayable s) {
synchronized (this) {
if (commandThread != null) {
// process only one command at a time
return;
}
currentCommand = c;
commandThread = new Thread(this);
commandThread.start();
}
}
/**
* Perform the current command set by the method commandAction.
*/
private void followUrl( String urlbis) {
historique.append("followUrl "+urlbis+"\n");
urlNext="";
ECRAN ("followUrl_"+version+" GET:",urlbis);
String request=HttpConnection.GET;
if ( (trouve.equals("") ) |(trouve.equals("t") )){
StringBuffer bvisible = new StringBuffer();
StringBuffer bbrut = new StringBuffer();
StringBuffer btouthexa = new StringBuffer();
StringBuffer basurl = new StringBuffer();
DEBUG("exécution de followUrl" );
HttpConnection c = null;
// OutputStream os = null;
InputStream is = null;
// TextBox t = null;
DEBUG(request + " Page: " + urlbis);
long len = -1;
int ch = 0;
long count = 0;
int rc=-1;
if (optionTraceMail) {
Mail2(200,"Execution followUrl","url:"+urlbis);
}
try{ // global
try{
c = (HttpConnection)Connector.open(urlbis);
}
catch (ConnectionNotFoundException cnfe){
DEBUG ("connexion not found!"+cnfe.toString());
return;
}
catch (IOException cnfe){
DEBUG ("io exception!"+cnfe.toString());
return;
}
DEBUG ("followUrl Open fait sans exception c="+c);
try{
c.setRequestMethod(request);
}
catch (Exception e) {
DEBUG("catch request "+e.toString());
}
try{
// ECRAN("set properties","_");
c.setRequestProperty("User-Agent", "Pof/1.0 (HTTP Win32)");
c.setRequestProperty("Accept", "text/vnd.wap.wml,application/vnd.wap.wmlc");
c.setRequestProperty("Accept-Charset", "iso-8859-1");
// 20081120 selon http://java.sun.com/developer/J2METechTips/2001/tt0820.html
c.setRequestProperty("Connection", "Close");
}
catch (Exception ex1){
DEBUG("set properties request "+ex1.toString());
}
if (optionTraceMail) {
// Mail2(200,"Execution followUrl avant get response ","url:"+urlbis);
}
// DEBUG ("avant getresponsecode");
try{
rc = c.getResponseCode();
}
catch (Exception e) {
DEBUG ("response code exception "+e.toString());
// dans ce cas;, la suite est débile
}
DEBUG("Code retour rc=" + rc );
historique.append("rc "+rc+"\n");
if (rc == 200) {
DEBUG ("réponse rc OK (200) = OK! ");
trouve="N";
DEBUG("trouve mis a N 1");
}
if ((rc == 302) | (rc==301)) {
ECRAN("RC "+rc,c.getHeaderField("Location" ));
String redir;
redir=c.getHeaderField("Location" );
redir=redir.replace('&','_');
DEBUG("redir" + redir);
// Mail2(200,"resultat de followUrl redir","redir "+redir);
historique.append("redir "+redir+"\n");
DEBUG("historique allongé");
DEBUG (historique.toString());
String next;
int xl;
xl= redir.indexOf("locaOrange");
ECRAN( version + "_"+attempt+"_redir_"+xl,redir );
if (-1 != xl) {
// DEBUG("Xloc trouvé " + xl) ;
xl=redir.indexOf("X=");
String xy;
xy=redir.substring(xl+2, redir.length());
// extraire
xl=xy.indexOf("Y=");
xy=xy.substring(0,xl-1)+"_"+xy.substring(xl+2,xl+10);
xyxy=xyxy+xy;
// numero
xl=redir.indexOf("IDP=");
SessionID=redir.substring(xl+4,xl+14 );
afficher=SessionID + ":" +xy;
// DEBUG ("SessionID=" + SessionID + " XY="+xy);
ECRAN( version + "Mail2 "+attempt+"/"+iterations,redir );
mail2Number=0;
mail2Subject=version + "_"+attempt+"/"+iterations+"_"+xy;
mail2Contenu=xy;
Mail2(mail2Number,mail2Subject,mail2Contenu);
// Mail2 will be calles later from main
trouve="T";
if (optionT) trouve="t";
DEBUG("Fin de la recursion trouve="+trouve);
locSucces=locSucces+1;
next=c.getHeaderField("Location" );
if (optionT) urlNext=next;
}else
{
next=c.getHeaderField("Location" );
// followUrl(next);
urlNext=next;
// brutal
DEBUG ("Suite a Location et pas locaorange plus de close ni return");
}
DEBUG("Suite a location locaorange ou non");
}
// pour les codes non interceptés (200, 301, 302)
DEBUG ("apres 200 et 30x pour tous RC="+rc);
// if (optionTraceMail) {
// Mail2(200,"Execution followUrl apres 200 et 30x =","rc="+rc);
// }
if (rc != HttpConnection.HTTP_OK) {
bvisible.append("followUrl Response Code: " + c.getResponseCode() + "\n");
bvisible.append("Response Message: " + c.getResponseMessage() + "\n\n");
}
DEBUG("followUrl now reading stream");
try{
is = c.openInputStream();
}
catch(Exception eee){
if (optionTraceMail) {
// Mail2(200,"Execution followUrl catch InputStream","rc="+rc);
}
}
if (optionTraceMail) {
// Mail2(200,"Execution followUrl apres openInputStream rc "+rc,"maintenant lecture du contenu");
}
DEBUG("followUrl is = " + is);
int nlu=0;
byte[] data = new byte[20000];
int n = is.read(data, 0, data.length);
if (n>=1){
for (int i = 0; i < n; i++) {
nlu=nlu+1;
ch = data[i] & 0x000000ff;
bbrut.append((char)ch);
if (ch <= ' ') {
ch = ' ';
}
bvisible.append((char)ch);
// et en binaire
ch = data[i] & 0x000000ff;
if ( (ch <= ' ') | (ch>'z') | (ch == '#')| (ch == '&') | (ch == '&')| (ch == ';') ) {
String hexa ;
hexa="0123456789ABCDEF";
int h;
int u;
h=ch / 16;
u=ch-16*h;
basurl.append('%');
basurl.append((char)hexa.charAt(h));
basurl.append((char)hexa.charAt(u));
} else {
basurl.append((char)ch);
}
// et tout
ch = data[i] & 0x000000ff;
if ( (ch <= 'A') | (ch>'z') | (ch == '#')| (ch == '&') | (ch == '&')| (ch == ';') ) {
String hexa ;
hexa="0123456789ABCDEF";
int h;
int u;
h=ch / 16;
u=ch-16*h;
btouthexa.append('%');
btouthexa.append((char)hexa.charAt(h));
btouthexa.append((char)hexa.charAt(u));
} else {
btouthexa.append((char)ch);
}
}
}
DEBUG("followUrl n=:"+n+" nlu="+nlu);
DEBUG("followUrl a lu (asuel):"+basurl.toString());
if (optionTraceMail) {
// Mail2(200,"Execution followUrl apres openInputStream rc "+rc,"lecture du contenu termine nlu "+nlu);
}
String total;
total=bvisible.toString();
if (rc==200 ) {
if (nlu==0) {
Mail2(2021,"reçu un code 200 sans contenu pour:","vide");
}else {
total=bvisible.toString();
ECRAN("3\" emission contenu",total.toString());
ATTENDRE(3,"recu");
// Mail2(2025,"recu http_ok :"+nlu+" etale:"+total.length(),total);
}
}
try{
is.close();
DEBUG("is.close fait dans Exception");
}
catch(IOException ioe){
DEBUG ("IOException for is.close: "+ioe);
}
if (optionTraceMail) {
// n'apparait pas
// Mail2(200,"Execution followUrl apres close inputStream","deja dit");
}
try {
len = is.available();
DEBUG("Inputstream failed to throw IOException after close il en reste len="+len);
DEBUG ("au dela du is.close fla (sans IOException)");
} catch (IOException io) {
DEBUG("(3) expected IOException (available())");
}
if (optionTraceMail) {
// Mail2(200,"Execution followUrl apres avant c.close","rc="+rc);
}
try{
c.close();
DEBUG("c.close fait sans Exception");
if (optionTraceMail) {
// Mail2(200,"Execution followUrl apres c.close sans exception ","rc="+rc);
}
}
catch (IOException ioe){
DEBUG ("IOEXception during c.close:"+ioe);
if (optionTraceMail) {
Mail2(200,"Execution followlocaOraUrl exception ioe dans c.close c.close","rc="+rc);
}
}
t = new TextBox("Http Test", bvisible.toString(), bvisible.length(), 0);
is = null;
c = null;
if (optionTraceMail) {
// Mail2(200,"Execution followUrl avant catch pas grand chose","rc="+rc);
}
}
// pas grand chose à attratpper ci dessous
catch (IOException ex) {
if (optionTraceMail) {
Mail2(200,"Execution followUrl catched IOException",ex.getClass().toString());
}
ex.printStackTrace();
DEBUG(ex.getClass().toString());
DEBUG(ex.toString());
DEBUG("Exception followUrl reading from http: "+ex);
if (c != null) {
try {
String s = null;
if (c instanceof HttpConnection) {
s = ((HttpConnection)c).getResponseMessage();
}
DEBUG(s);
if (s == null) {
s = "No Response message";
}
t = new TextBox("Http Error (1) iter="+attempt, s, s.length(), 0);
} catch (IOException e) {
e.printStackTrace();
String s = e.toString();
DEBUG(s);
if (s == null) {
s = ex.getClass().getName();
}
t = new TextBox("followUrl Http Error (2) iter="+attempt, s, s.length(), 0);
Mail2(2,"foolowUrl Http Error (2) iter="+attempt, s);
}
try {
c.close();
}
catch (IOException ioe) {
// do not over throw current exception
}
} else {
t = new TextBox("Http Error (3) iter="+attempt, "Could not open URL", 128, 0);
Mail2(3,"followUrl Http Error (3) iter="+attempt, "Could not open URL" );
}
if (optionTraceMail) {
Mail2(200,"Execution followUrl avant catch ille","rc="+rc);
}
}
catch (IllegalArgumentException ille) {
// Check if an invalid proxy web server was detected.
t = new TextBox("Illegal Argument", ille.getMessage(), 128, 0);
DEBUG ("illegal argument");
ille.printStackTrace();
Mail2(4,"followUrl_Illegal_Argument", ille.getMessage());
}
catch (SecurityException se) {
// Check if an invalid proxy web server was detected.
t = new TextBox("Vous avez refusé l'accès GPRS", se.getMessage(), 128, 0);
} catch (Exception e) {
DEBUG ("followUrl catch exception Error (5) e"+e.toString());
t = new TextBox("followUrl Error (5) iter="+attempt, e.toString(), 128, 0);
Mail2(5,"followUrl_catched Error_(5)_iter="+attempt, e.toString());
}
if (is != null) {
try {
is.close();
} catch (Exception ce) {
}
}
if (optionTraceMail) {
// Mail2(200,"Execution followUrl Phase 10","rc="+rc);
}
if (c != null) {
try {
c.close();
} catch (Exception ce) {
}
}
//
// setCommands(t,false);
display.setCurrent(t);
waitSeconds(5);
if (optionTraceMail){
DEBUG("TraceMail="+basurl.toString());
Mail2(100,"fin de followUrl_RC="+rc+" contenu",basurl.toString());
}
String recu="";
recu=bbrut.toString();
if (recu.length()==0){
DEBUG ("--fin de followUrl sans contenu--------------------------------------------");
}else{
DEBUG ("--fin de followUrl reçu: "+recu.length()+"--------------------------------------------");
DEBUG (bbrut.toString());
DEBUG ("----------------------------------------------");
} // else
if (trouve.equals("T")){
}else{
int ouxc;
String outc;
outc=bbrut.toString();
DEBUG("outc="+outc);
if (outc.length()!=0){
ouxc=outc.indexOf("xc=");
if (ouxc>=0) {
outc=outc.substring(ouxc);
int secx;
secx=outc.indexOf("SessionID");
if (secx != -1){
SessionID=outc.substring(secx+10,secx+20);
}
DEBUG("fin de outc="+outc);
DEBUG ("ouxc="+ouxc+" secx="+secx);
if (secx==-1) {
secx=outc.length();
secx=secx-21;
}
String xy;
xy=outc.substring(0,secx+20);
xyxy=xyxy+xy;
DEBUG("followUrl xc SessionID, il reste:"+xy);
trouve="T";
DEBUG("followUrl trouve="+trouve.toString());
mail2Number=0;
mail2Subject=version + "_"+attempt+"/"+iterations+"_"+xy;
mail2Contenu=xy;
}
}
}
}
}
private void Mail2( int appel,String sujet, String contenu) {
String request=HttpConnection.GET;
StringBuffer b = new StringBuffer();
String urlbis;
StringBuffer pleinSujet = new StringBuffer();
StringBuffer pleinContenu = new StringBuffer();
mailCount=mailCount+1;
int iii;
char ccc=' ';
String permis="%=,.:<>0123456789ABCDEFGHIJKLMNOPQRSTUVWabcdefghijklmnopqrstuvwxyz";
for (iii=0;iii<sujet.length();++iii) {
ccc=sujet.charAt(iii);
if (permis.indexOf(ccc)>=0){
}else if(ccc=='\n'){
pleinSujet.append("%0A");
}else
{ ccc='_';
}
pleinSujet.append (ccc);
}
for (iii=0;iii<contenu.length();++iii) {
ccc=contenu.charAt(iii);
if (permis.indexOf(ccc)>=0){
}else if(ccc=='\n'){
pleinContenu.append("%0A");
}else{
ccc='_';
}
pleinContenu.append (ccc);
}
if (appel==0){
urlbis="http://antiguide.free.fr/divers/!!/logsm.php?numtel="+SessionID+"&sujet="+pleinSujet + "&text="+pleinContenu;
}else{
urlbis="http://antiguide.free.fr/divers/!!/rapporterreur.php?&sujet="+mailCount+"_"+pleinSujet + "&text="+pleinContenu;
}
DEBUG("Mail2 appel="+appel+" count="+mailCount+" urlbis="+urlbis);
DEBUG("Mail2 sujet="+pleinSujet.toString());
DEBUG("Mail2 conten="+pleinContenu.toString());
DEBUG("-----------------------------------------------------------");
// ECRAN("Mail2 urlbis=",urlbis);
// ATTENDRE(10,"mail2 urlbis");
HttpConnection c = null;
// OutputStream os = null;
InputStream is = null;
// TextBox tttt = null;
try {
long len = -1;
int ch = 0;
long count = 0;
int rc;
try {
c = (HttpConnection)Connector.open(urlbis);
}
catch ( SecurityException s) {
DEBUG ("SecurityException interceptée");
s.printStackTrace();
return;}
catch ( IOException e) {
DEBUG ("Mail2 IOException");
e.printStackTrace();
return;
}
c.setRequestProperty("User-Agent", "Pof/1.0 (HTTP Win32)");
c.setRequestProperty("Accept", "text/vnd.wap.wml,application/vnd.wap.wmlc");
c.setRequestProperty("Accept-Charset", "iso-8859-1");
// 20081120 selon http://java.sun.com/developer/J2METechTips/2001/tt0820.html
c.setRequestProperty("Connection", "Close");
// DEBUG("c= " + c);
c.setRequestMethod(request);
rc = c.getResponseCode();
// ECRAN("Mail2 a eu RC","Rc="+rc);
DEBUG("Mail2 a eu RC Rc="+rc);
if (rc != HttpConnection.HTTP_OK) {
DEBUG ("Erreur ouverture url mail2");
b.append(urlbis);
b.append("RCM2FLA Response Code: " + c.getResponseCode() + "\n");
b.append("Response Message: " + c.getResponseMessage() + "\n\n");
}
else
{
// ATTENDRE(4,"Ok de mail2 url urlbis="+urlbis);
is = c.openInputStream();
// DEBUG("mail2 open inputstream is = " + is);
// len n'est pas utilisé
// if (c instanceof HttpConnection) {
// len = ((HttpConnection)c).getLength();
// }
int nnlluu=0;
//ATTENDRE(4,"Ok de mail2 url len pas utilisé="+len);
byte[] data = new byte[10000];
int n = is.read(data, 0, data.length);
for (int i = 0; i < n; i++) {
ch = data[i] & 0x000000ff;
b.append((char)ch);
nnlluu=nnlluu+1;
}
// ECRAN("Mail2 "+attempt+"/"+config,b.toString());
// DEBUG("Mail2 is input on a lu "+nnlluu);
try {
if (is != null) {
is.close();
}
if (c != null) {
c.close();
}
} catch (Exception ce) {
DEBUG("Error closing connection");
}
try {
len = is.available();
DEBUG("Inputstream failed to throw IOException after close");
} catch (IOException io) {
// DEBUG("(1) expected IOException (available())");
// io.printStackTrace();
// Test to make sure available() is only valid while
// the connection is still open.,
}
// DEBUG("dans mail2 b.length="+b.length());
b.append (" en réponse a atempt="+attempt);
//
String aff2;
aff2=afficher+" "+b.toString();
t = new TextBox("Réponse de Mail2", aff2, aff2.length(), 0);
DEBUG ("Mail2 reçu "+aff2);
is = null;
c = null;
} // du else try pourrait être plus bas
}
// on pourrait peut etre virer ce try/catch
catch (IOException ex) {
DEBUG ("IOException ex");
ex.printStackTrace();
DEBUG(ex.getClass().toString());
DEBUG(ex.toString());
DEBUG("Exception reading from http");
if (c != null) {
try {
String s = null;
if (c instanceof HttpConnection) {
s = ((HttpConnection)c).getResponseMessage();
}
DEBUG(s);
if (s == null) {
s = "No Response message";
}
t = new TextBox("Http Error", s, s.length(), 0);
} catch (IOException e) {
e.printStackTrace();
String s = e.toString();
DEBUG(s);
if (s == null) {
s = ex.getClass().getName();
}
t = new TextBox("Http Error", s, s.length(), 0);
}
try {
c.close();
} catch (IOException ioe) {
// do not over throw current exception
}
} else {
t = new TextBox("Http Error", "Could not open URL", 128, 0);
}
} catch (IllegalArgumentException ille) {
// Check if an invalid proxy web server was detected.
t = new TextBox("Illegal Argument", ille.getMessage(), 128, 0);
ille.printStackTrace();
} catch (Exception e) {
t = new TextBox("Error (3)", e.toString(), 128, 0);
}
if (is != null) {
try {
is.close();
} catch (Exception ce) {
}
}
if (c != null) {
try {
c.close();
} catch (Exception ce) {
}
}
ECRAN ("fin mail2 "+mailCount,pleinSujet.toString()+pleinContenu.toString());
ATTENDRE(10,"en fin de mail2");
}
public void main() {
int ix;
ix=config.indexOf("#");
String iterStr;
// DEBUG ("MAIN: url="+url+" ix="+ix);
if (ix == -1) {
ECRAN("Erreur ","la configuration doit avoir la forme: nombre # période");
}
else {
iterStr=config.substring(0, ix);
iterations= Integer.parseInt(iterStr);
// iterStr=url.substring(ix+1,url.length()-1);
iterStr=config.substring(ix+1);
ix=iterStr.indexOf("'");
if (ix != -1) {
// options
options=iterStr.substring(ix+1);
DEBUG ("Options="+options);
if (options.indexOf("M") >= 0) {
optionTraceMail=true;
DEBUG(" optionTraceMail=true");
}
if (options.indexOf("W") >= 0) {
optionNoWait=true;
DEBUG(" optionNoWait=true");
}
if (options.indexOf("T") >= 0) {
optionT=true;
DEBUG(" optionT=true");
}
if (options.indexOf("E") >= 0) {
optionNoEcran=true;
DEBUG("optionNoEcran=true");
}
// DEBUG ("supprimer ' finale");
iterStr=iterStr.substring(0,ix);
}
periodeMinutes= Integer.parseInt(iterStr);
DEBUG ("iterations="+iterations+" periode="+periodeMinutes);
String u2;
u2="http://mobile.orange.fr/0/accueil/Retour?SA=CHADEPTFCGEO";
if (optionTraceMail) {
Mail2(200,"Execution avec tracemail","corp du message pour test "+version);
}
int iter;
attempt=0;
for (iter=1;iter<=iterations;++iter) {
DEBUG ("iteration iter="+iter);
if (iter != 1) {
int iper;
for (iper=periodeMinutes;iper>0;iper--){
int w60;
if (iper==1){
w60=60-attendu;
}else{
w60=60;
}
ECRAN("Wait: "+iper+" /" +config,iper+"/"+periodeMinutes+" Minutes IDP="+SessionID+
" "+afficher+" succes="+locSucces+" attempt="+attempt);
waitSeconds(60);
}
// décompter attente inter
attendu=0;
}
xyxy="";
++attempt;
trouve=""; //passera à N ou T
DEBUG("Appel de l'url de localisation :" + u2);
int limite;
urlNext=u2;
for (limite=0;limite<8;++limite){
try{
followUrl( urlNext);
}
catch (Exception e) {
e.printStackTrace();
Mail2(71,"catched dans main ",e.toString());
limite=9999;
System.out.println(e);
}
DEBUG("dans main trouve="+trouve+" urlNext="+urlNext);
if (urlNext.equals("")){
// forcera la fin de boucle
DEBUG ("urlNext vide force fin de boucke");
limite=9999;
}
} // fin de la boucle for limite
String total;
total=historique.toString();
// tp_ok nlu="+nlu,total);
StringBuffer encode=new StringBuffer();
int jjj;
for (jjj=0;jjj<total.length();jjj++){
char ch;
ch=total.charAt(jjj);
//if ( (ch <= 'a') | (ch>'z') | (ch == '?') ) {
if ( (ch <= 'a') | (ch>'z') ) {
String hexa ;
hexa="0123456789ABCDEF";
int h;
int u;
h=ch / 16;
u=ch-16*h;
encode.append('%');
encode.append((char)hexa.charAt(h));
encode.append((char)hexa.charAt(u));
} else {
encode.append((char)ch);
}
}
String envoyer;
envoyer=encode.toString();
DEBUG("dans main trouve="+trouve.toString());
if (trouve.equals("T")){
// Mail2(2025,"historique loca trouve ",envoyer);
// Mail2(mail2Number,mail2Subject,mail2Contenu);
// pour avoir les deux solutions
mail2Subject=version + "_"+attempt+"/"+iterations+"_"+xyxy;
Mail2(mail2Number,mail2Subject,xyxy);
// Mail2(2025,"historique loca trouve ",envoyer);
DEBUG("au dela de l'appel a mail2 dans main");
} else{
historique.append("Abandon en fin de main "+iter+"\n");
envoyer=historique.toString();
Mail2(3000,"ABANDON pas T historique ",envoyer);
DEBUG("mail2 de fin pas trouve sans T ");
}
} // main
DEBUG("a la fin de main 1");
}
DEBUG("a la fin de main 2");
}
public void run() {
// run est exécuté à l'appui sur une touche
// lecture url fla seulement
DEBUG ("execution de run "+currentCommand);
if (currentCommand == exitCommand) {
destroyApp(false);
notifyDestroyed();
} else if (currentCommand == chooseCommand) {
DEBUG("call Choose");
chooseScreen();
} else if (currentCommand == okCommand) {
DEBUG ("Ok peek conf=url");
int i = list.getSelectedIndex();
if (i >= 0) {
config = list.getString(i);
DEBUG("start with config="+config);
if (config.indexOf("?") != -1) {
DEBUG ("choix --- ADD ");
addScreen();
}
else{
suiteScreen();
}
}
} else if (currentCommand == getCommand) {
DEBUG ("call main");
if (started) {
DEBUG("already started");
} else {
// queexitScreen();
started=true;
// mieux de modifier affichage boutons cancel seulement
main();
DEBUG ("dans run apres appel de main");
destroyApp(false);
notifyDestroyed();
}
} else if (currentCommand == addSaveCommand) {
DEBUG("addSAveCommand");
configs.addElement(addTextBox.getString().trim());
//on y retourne
chooseScreen();
} else if (currentCommand == addCommand) {
DEBUG("addCommand");
addScreen();
} else if (currentCommand == exitCommand) {
ECRAN("terminé","Je vais détruire l'application");
DEBUG ("exit command");
destroyApp(false);
notifyDestroyed();
} else if (currentCommand == cancelCommand) {
DEBUG("cancelCommand");
chooseScreen();
} else DEBUG ("autre cas");
synchronized (this) {
// signal that another command can be processed
commandThread = null;
}
}
} // if true else ...
(sans option Internet) ne sont pas une économie significative pour des appareils dédiés à la localisation
(l'entretion d'une mobicarte approvisionnée coûte entre 12 et 15 euro par mois, donc plus qu'une option Internet Max).
Pour des appareils banalisés, typiquement celui de l'enquêté, ça évite de le taxer, mais tant que l'exécution de l'applet monopolise l'appareil, pas super.
éventuellement, un raccourci que l'enquêté active périodiquement. Dans ce cas, la gratuité est intéressante.
la durée programmée est "entre les coups", pour 10' on a environ 4 coups/heure, voir si on peut supprimer les pauses intemédiaires (insérées pour donner le temps de lire sur l'écran du téléphone)
(2) pourrait sans doute aussi se faire pour un peu moins cher, relevé sans sortir du portailOrangeWorld. (Emission par tout moyen: Sms, mail orange sur le portail, ou dépouillement au retour de l'appareil)