mirror of https://github.com/noisymime/Arduino.git
silencing http client output
gracefully (?) handling errors setting a connection timeout of 5 secs
This commit is contained in:
parent
e1049aacc9
commit
f7797d8621
|
@ -32,6 +32,8 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import javax.jmdns.ServiceEvent;
|
import javax.jmdns.ServiceEvent;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.impl.LogFactoryImpl;
|
||||||
|
import org.apache.commons.logging.impl.NoOpLog;
|
||||||
import processing.app.debug.TargetBoard;
|
import processing.app.debug.TargetBoard;
|
||||||
import processing.app.debug.TargetPackage;
|
import processing.app.debug.TargetPackage;
|
||||||
import processing.app.debug.TargetPlatform;
|
import processing.app.debug.TargetPlatform;
|
||||||
|
@ -123,6 +125,8 @@ public class Base {
|
||||||
static final String portableSketchbookFolder = "sketchbook";
|
static final String portableSketchbookFolder = "sketchbook";
|
||||||
|
|
||||||
static public void main(String args[]) throws Exception {
|
static public void main(String args[]) throws Exception {
|
||||||
|
System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getCanonicalName());
|
||||||
|
|
||||||
initPlatform();
|
initPlatform();
|
||||||
|
|
||||||
// Portable folder
|
// Portable folder
|
||||||
|
|
|
@ -6,8 +6,11 @@ import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
import org.apache.commons.httpclient.methods.multipart.FilePart;
|
||||||
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
|
||||||
import org.apache.commons.httpclient.methods.multipart.Part;
|
import org.apache.commons.httpclient.methods.multipart.Part;
|
||||||
|
import org.apache.commons.httpclient.methods.multipart.StringPart;
|
||||||
|
import processing.app.Base;
|
||||||
import processing.app.Preferences;
|
import processing.app.Preferences;
|
||||||
import processing.app.SerialException;
|
import processing.app.SerialException;
|
||||||
|
import processing.app.helpers.PreferencesMap;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -24,6 +27,7 @@ public class HttpUploader extends Uploader {
|
||||||
|
|
||||||
public HttpUploader(String port) {
|
public HttpUploader(String port) {
|
||||||
this.client = new HttpClient();
|
this.client = new HttpClient();
|
||||||
|
this.client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
|
||||||
Matcher matcher = IPV4_ADDRESS.matcher(port);
|
Matcher matcher = IPV4_ADDRESS.matcher(port);
|
||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
throw new IllegalArgumentException(port);
|
throw new IllegalArgumentException(port);
|
||||||
|
@ -46,14 +50,22 @@ public class HttpUploader extends Uploader {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FilePart filePart;
|
FilePart sketch;
|
||||||
try {
|
try {
|
||||||
filePart = new FilePart("sketch", new File(buildPath, className + ".hex"));
|
sketch = new FilePart("sketch", new File(buildPath, className + ".hex"));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Part[] parts = {filePart};
|
TargetPlatform targetPlatform = Base.getTargetPlatform();
|
||||||
|
PreferencesMap prefs = Preferences.getMap();
|
||||||
|
prefs.putAll(Base.getBoardPreferences());
|
||||||
|
prefs.putAll(targetPlatform.getTool(prefs.get("upload.tool")));
|
||||||
|
boolean verbose = prefs.containsKey("upload.verbose") && Boolean.parseBoolean(prefs.get("upload.verbose"));
|
||||||
|
|
||||||
|
StringPart params = new StringPart("params", verbose ? prefs.get("upload.params.verbose") : prefs.get("upload.params.quiet"));
|
||||||
|
|
||||||
|
Part[] parts = {sketch, params};
|
||||||
PostMethod post = newPostMethod();
|
PostMethod post = newPostMethod();
|
||||||
post.setRequestHeader("Cookie", "pwd=" + Preferences.get(getAuthorizationKey()));
|
post.setRequestHeader("Cookie", "pwd=" + Preferences.get(getAuthorizationKey()));
|
||||||
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
|
post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
|
||||||
|
@ -61,15 +73,13 @@ public class HttpUploader extends Uploader {
|
||||||
int statusCode;
|
int statusCode;
|
||||||
try {
|
try {
|
||||||
statusCode = client.executeMethod(post);
|
statusCode = client.executeMethod(post);
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RunnerException(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
System.err.println(post.getResponseBodyAsString());
|
System.err.println(post.getResponseBodyAsString());
|
||||||
return statusCode == HttpStatus.SC_OK;
|
return statusCode == HttpStatus.SC_OK;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RunnerException(e);
|
throw new RunnerException(e);
|
||||||
|
} finally {
|
||||||
|
post.releaseConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue