*
*/
if (protocol.equalsIgnoreCase("file") && mode != null && mode.equalsIgnoreCase("w")) {
File f = new File(url.toURI());
output = new FileOutputStream(f);
this.setOptAccessList(new OptAccessList(this.getDEFAULT_OPTIONS()));
this.getOptAccessList().add(oa_Protocol);
}
/**
* cas de tcp://
*/
else if (protocol.equalsIgnoreCase("tcp")) {
tcpHost = url.getHost();
tcpPort = url.getPort();
if (tcpPort < 0 || tcpPort > 65535) {
throw new InterpreterException(StdErrors.extend(StdErrors.Out_of_range, "" + tcpPort));
}
//System.out.println("host:"+tcpHost); // debug
//System.out.println("port:"+tcpPort); // debug
socket = new Socket(tcpHost, tcpPort);
if (readTimeOut > 0) {
socket.setSoTimeout(readTimeOut);
}
tcpIP = socket.getInetAddress().getHostAddress();
tcpHost = socket.getInetAddress().getHostName();
input = socket.getInputStream();
output = socket.getOutputStream();
this.setOptAccessList(new OptAccessList(this.getSOCKET_OPTIONS()));
this.getOptAccessList().set(oa_Host);
this.getOptAccessList().set(oa_IP);
this.getOptAccessList().set(oa_Port);
}
/**
* cas de ssl+tcp://
*/
else if (protocol.equalsIgnoreCase("ssl+tcp")) {
tcpHost = url.getHost();
tcpPort = url.getPort();
if (tcpPort < 0 || tcpPort > 65535) {
throw new InterpreterException(StdErrors.extend(StdErrors.Out_of_range, "" + tcpPort));
}
SocketFactory socketFactory = SSLSocketFactory.getDefault();
socket = socketFactory.createSocket(tcpHost, tcpPort);
if (readTimeOut > 0) {
socket.setSoTimeout(readTimeOut);
}
tcpIP = socket.getInetAddress().getHostAddress();
tcpHost = socket.getInetAddress().getHostName();
input = socket.getInputStream();
output = socket.getOutputStream();
this.setOptAccessList(new OptAccessList(this.getSOCKET_OPTIONS()));
this.getOptAccessList().set(oa_Host);
this.getOptAccessList().set(oa_IP);
this.getOptAccessList().set(oa_Port);
}
/**
* cas de stdout://
*/
else if (protocol.equalsIgnoreCase("stdout")) {
output = System.out;
this.setOptAccessList(new OptAccessList(this.getDEFAULT_OPTIONS()));
this.getOptAccessList().add(oa_Protocol);
}
/**
* cas de stdout://
*/
else if (protocol.equalsIgnoreCase("stderr")) {
output = System.err;
this.setOptAccessList(new OptAccessList(this.getDEFAULT_OPTIONS()));
this.getOptAccessList().add(oa_Protocol);
}
/**
* cas de stdin://
*/
else if (protocol.equalsIgnoreCase("stdin")) {
input = System.in;
this.setOptAccessList(new OptAccessList(this.getDEFAULT_OPTIONS()));
this.getOptAccessList().add(oa_Protocol);
}
/*
* autres protocoles...
*/
else {
/**
* sinon dans les autres cas, on ouvre réellement une connexion vers l'url...
*/
urlConnection = url.openConnection();
tcpHost = url.getHost();
tcpPort = url.getPort();
/*
* timeout
*/
if (connectTimeOut > 0) {
urlConnection.setConnectTimeout(connectTimeOut);
}
if (readTimeOut > 0) {
urlConnection.setReadTimeout(readTimeOut);
}
/*
* pas de cache et toujours en lecture (par défaut)...
*/
urlConnection.setUseCaches(false);
urlConnection.setDoInput(true);
/**
* Typiquement HTTP
*
* Remarque: HttpsURLConnection est une sous-classe de HttpURLConnection.
* -------- Donc le protocole http est respecté en https.
*/
if (urlConnection instanceof HttpURLConnection) {
HttpURLConnection httpCon = (HttpURLConnection) urlConnection;
if (props != null) {
// il y a des propriétés header...
Hash hash=props.getHash();
ArrayList<String> ks=hash.keys_strings();
for (int i = 0; i < ks.size(); i++) {
String header_s = ks.get(i);
String value_s = Node.node2VString(hash.get(header_s)).getString();
Interpreter.Log(" HTTP-Header: " + header_s + " : " + value_s);
httpCon.setRequestProperty(header_s, value_s);
}
}
if (mode != null && (mode.equals("POST") || mode.equals("PUT"))) {
// c'est la méthode POST...
if (mode.equals("PUT")) {
Interpreter.Log(" HTTP PUT: " + url.toString());
}
else {
Interpreter.Log(" HTTP POST: " + url.toString());
}
urlConnection.setDoOutput(true);
httpCon.setRequestMethod(mode);
output = urlConnection.getOutputStream();
// envoyer...
output.write(buffer);
if (isAutoflush())
output.flush();
}
input = urlConnection.getInputStream();
this.setOptAccessList(new OptAccessList(this.getSOCKET_OPTIONS()));
if (tcpHost != null)
this.getOptAccessList().set(oa_Host);
if (tcpPort > 0)
this.getOptAccessList().set(oa_Port);
}
/**
* Autres protocoles...
*/
else {
/*
* par défaut méthode "r"... (r)ead...
*/
if (mode == null || (mode != null && mode.equalsIgnoreCase("r"))) {
Interpreter.Log(" " + protocol + " read : " + url.toString());
input = urlConnection.getInputStream();
}
/*
* sinon, méthode "w"... (w)rite...
*/
else {
Interpreter.Log(" " + protocol + " write : " + url.toString());
output = urlConnection.getOutputStream();
}
this.setOptAccessList(new OptAccessList(this.getSOCKET_OPTIONS()));
if (tcpHost != null)
this.getOptAccessList().set(oa_Host);
if (tcpPort > 0)
this.getOptAccessList().set(oa_Port);
}