Ticket #2437: OSMAPI-conflict-patch.txt

File OSMAPI-conflict-patch.txt, 5.0 KB (added by Gubaer, 17 years ago)

patch

Line 
1Index: src/org/openstreetmap/josm/io/OsmApi.java
2===================================================================
3--- src/org/openstreetmap/josm/io/OsmApi.java (revision 1545)
4+++ src/org/openstreetmap/josm/io/OsmApi.java (working copy)
5@@ -22,6 +22,8 @@
6 import java.util.Properties;
7 import java.util.HashMap;
8 import java.util.StringTokenizer;
9+import java.util.logging.Level;
10+import java.util.logging.Logger;
11
12 import javax.xml.parsers.SAXParserFactory;
13
14@@ -47,6 +49,9 @@
15 *
16 */
17 public class OsmApi extends OsmConnection {
18+
19+ /** the logger */
20+ static private final Logger logger = Logger.getLogger(OsmApi.class.getName());
21
22 /**
23 * Object describing current changeset
24@@ -411,16 +416,8 @@
25 continue;
26 }
27 }
28-
29- // populate return fields.
30- responseBody.setLength(0);
31- BufferedReader in = new BufferedReader(new InputStreamReader(activeConnection.getInputStream()));
32- String s;
33- while((s = in.readLine()) != null) {
34- responseBody.append(s);
35- responseBody.append("\n");
36- }
37-
38+
39+
40 statusMessage.setLength(0);
41 statusMessage.append (activeConnection.getResponseMessage());
42 // Look for a detailed error message from the server
43@@ -430,11 +427,25 @@
44 if (serverErrorTranslations.containsKey(er)) er = serverErrorTranslations.get(er);
45 statusMessage.append(er);
46 }
47- activeConnection.disconnect();
48
49- if (retCode != 200) {
50+ // abort by throwing an exception if the return code is not 200 OK
51+ if (retCode != HttpURLConnection.HTTP_OK) {
52 throw new OsmTransferException(statusMessage.toString());
53 }
54+
55+
56+ // read the response body
57+ //
58+ responseBody.setLength(0);
59+ BufferedReader in = new BufferedReader(new InputStreamReader(activeConnection.getInputStream()));
60+ String s;
61+ while((s = in.readLine()) != null) {
62+ responseBody.append(s);
63+ responseBody.append("\n");
64+ }
65+
66+ activeConnection.disconnect();
67+
68 return responseBody.toString();
69 } catch (UnknownHostException e) {
70 throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e);
71@@ -449,7 +460,7 @@
72 } catch (Exception e) {
73 if (e instanceof OsmTransferException) throw (OsmTransferException) e;
74 throw new OsmTransferException(e);
75- }
76+ }
77 }
78 }
79 }
80Index: src/org/openstreetmap/josm/io/OsmServerWriter.java
81===================================================================
82--- src/org/openstreetmap/josm/io/OsmServerWriter.java (revision 1545)
83+++ src/org/openstreetmap/josm/io/OsmServerWriter.java (working copy)
84@@ -118,6 +118,7 @@
85 }
86 if (useChangesets) api.stopChangeset();
87 } catch (OsmTransferException e) {
88+
89 try {
90 if (useChangesets) api.stopChangeset();
91 } catch (Exception ee) {
92@@ -138,10 +139,32 @@
93 }
94
95 private void dealWithTransferException (OsmTransferException e) {
96- Main.pleaseWaitDlg.currentAction.setText(tr("Transfer aborted due to error (will wait for 5 seconds):") + e.getMessage());
97- try {
98- Thread.sleep(5000);
99+
100+ // warn user if the API replies a 409 Conflict. The text line in
101+ // Main.pleaseWaitDlg.currentAction is easily overread and
102+ // data may be lost
103+ //
104+ if (e.getMessage().startsWith("Conflict")) {
105+ JOptionPane.showMessageDialog(
106+ null,
107+ tr("The server reported one or more conflicts between the\n"
108+ + "data you tried to upload and the data on the server.\n"
109+ + "Your data has NOT been saved on the server.\n"
110+ + "Please reload the data and resolve any conflicts using\n"
111+ + "the merge tool."),
112+ tr("Conflict in changeset"),
113+ JOptionPane.ERROR_MESSAGE
114+ );
115+ } else {
116+ // any other error. display a text in please wait dialog
117+ // FIXME: why Thread.sleep(50000)? JOSM wan't retry after 5s. Why not a
118+ // normal warning dialog the user has to close with a mouse click?
119+ //
120+ Main.pleaseWaitDlg.currentAction.setText(tr("Transfer aborted due to error (will wait for 5 seconds):") + e.getMessage());
121+ try {
122+ Thread.sleep(5000);
123+ }
124+ catch (InterruptedException ex) {}
125 }
126- catch (InterruptedException ex) {}
127 }
128 }