Skip to content

Commit

Permalink
Fixing HTTP Error code 400 on Upload
Browse files Browse the repository at this point in the history
Fixes #19 and possibly #13 (upload caused false positive on seeing if exif data was properly aquired)
  • Loading branch information
james2432 committed Aug 31, 2017
1 parent cc106ef commit aaef605
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 17 additions & 10 deletions OSVUploadr/src/main/java/ca/osmcanada/osvuploadr/JPMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@
public class JPMain extends javax.swing.JPanel {

private final String BASE_URL="https://www.openstreetmap.org/";
private final String URL_SEQUENCE = "http://openstreetview.com/1.0/sequence/";
private final String URL_PHOTO = "http://openstreetview.com/1.0/photo/";
private final String URL_FINISH = "http://openstreetview.com/1.0/sequence/finished-uploading/";
private final String URL_ACCESS = "http://openstreetview.com/auth/openstreetmap/client_auth";
private final String URL_SEQUENCE = "http://openstreetcam.com/1.0/sequence/";
private final String URL_PHOTO = "http://openstreetcam.com/1.0/photo/";
private final String URL_FINISH = "http://openstreetcam.com/1.0/sequence/finished-uploading/";
private final String URL_ACCESS = "http://openstreetcam.com/auth/openstreetmap/client_auth";
private final String API_KEY = "rBWV8Eaottv44tXfdLofdNvVemHOL62Lsutpb9tw";
private final String API_SECRET = "rpmeZIp49sEjjcz91X9dsY0vD1PpEduixuPy8T6S";
private String last_dir ="";
Expand Down Expand Up @@ -375,8 +375,9 @@ private String sendForm(String target_url,Map<String,String> arguments,String me
con.setReadTimeout(5000);

StringJoiner sj = new StringJoiner("&");
for(Map.Entry<String,String> entry : arguments.entrySet())
for(Map.Entry<String,String> entry : arguments.entrySet()){
sj.add(URLEncoder.encode(entry.getKey(), StandardCharsets.UTF_8.toString()) + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString()));
}
byte[] out = sj.toString().getBytes(StandardCharsets.UTF_8);
int length = out.length;

Expand Down Expand Up @@ -455,7 +456,7 @@ private void sendField(OutputStream out, String name, String field) {
}
}

private void sendAuthTokens(String accessToken, String accessSecret){
private String sendAuthTokens(String accessToken, String accessSecret){
try
{
URL url = new URL(URL_ACCESS);
Expand Down Expand Up @@ -493,11 +494,14 @@ private void sendAuthTokens(String accessToken, String accessSecret){

String data;
data = new String(baos.toByteArray(), StandardCharsets.UTF_8);
String access_token = data.substring(data.indexOf("\"access_token\":\"")+16,data.indexOf("\"", data.indexOf("\"access_token\":\"")+16));
http.disconnect();
return access_token;

}
catch(Exception ex){
Logger.getLogger(JPMain.class.getName()).log(Level.SEVERE, null, ex);
return "";
}
}
private void sendFinished(long Sequence_id, String accessToken)
Expand Down Expand Up @@ -566,6 +570,7 @@ private long getSequence(ImageProperties imp, String accessToken)
StringJoiner sj = new StringJoiner("&");
for(Map.Entry<String,String> entry : arguments.entrySet())
sj.add(URLEncoder.encode(entry.getKey(), "UTF-8") + "=" + URLEncoder.encode(entry.getValue(), "UTF-8"));

byte[] out = sj.toString().getBytes(StandardCharsets.UTF_8);
int length = out.length;
System.out.println("Sending request:" + sj.toString());
Expand Down Expand Up @@ -1062,12 +1067,14 @@ private void jbUploadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
return;

}
Path targetPath = Paths.get("./access_token.txt");
byte[] bytes = token.split("\\|")[0].getBytes(StandardCharsets.UTF_8);
Files.write(targetPath, bytes, StandardOpenOption.CREATE);
Path targetPath = Paths.get(decodedPath + File.pathSeparator +"access_token.txt");
accessToken = token.split("\\|")[0];
String accessSecret = token.split("\\|")[1];
sendAuthTokens(accessToken,accessSecret);

accessToken=sendAuthTokens(accessToken,accessSecret);

byte[] bytes = accessToken.getBytes(StandardCharsets.UTF_8);
Files.write(targetPath, bytes, StandardOpenOption.CREATE);
}
catch(Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public static PageContent getPageContent(String url, HttpClient client) throws E
BufferedReader rd=null;
StringBuffer result=null;
try{
rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent(),response.getEntity().getContentEncoding().getValue()));
rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent(),"UTF-8"));//response.getEntity().getContentEncoding().getValue()));

result = new StringBuffer();
String line = "";
Expand Down

0 comments on commit aaef605

Please sign in to comment.