From c93239a13d196e6ea0a836eec5ee8f7b03ecc162 Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Wed, 2 Jun 2010 23:11:48 -0500 Subject: [PATCH 1/4] Deleted Eclipse project and classpath. --- .classpath | 9 --------- .gitignore | 2 ++ .project | 13 ------------- 3 files changed, 2 insertions(+), 22 deletions(-) delete mode 100644 .classpath delete mode 100644 .project diff --git a/.classpath b/.classpath deleted file mode 100644 index 5cf73ed..0000000 --- a/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/.gitignore b/.gitignore index 28a5698..ac99eee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ target test-output temp-testng-customsuite.xml changes.txt +.project +.classpath diff --git a/.project b/.project deleted file mode 100644 index 8d639cd..0000000 --- a/.project +++ /dev/null @@ -1,13 +0,0 @@ - - github4j-uploader - An API for GitHub downloads in Java. - - - - org.eclipse.jdt.core.javabuilder - - - - org.eclipse.jdt.core.javanature - - From 0212d7f9cc4bc117d80119ba58cfa73aa89e6ab8 Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Wed, 2 Jun 2010 23:16:24 -0500 Subject: [PATCH 2/4] Updated copyright in MIT license. --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index eb69b2d..a2d1dbc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License -Copyright (c) 2008-2009 Alan Gutierrez +Copyright (c) 2008-2010 Alan Gutierrez Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From ddae53f717dc277dd092f43558a1628225b903fe Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Wed, 9 Jun 2010 20:47:53 -0500 Subject: [PATCH 3/4] Update Mix build after refactor of Mix. --- .../github4j/uploader/mix/GitHub4JUploaderProject.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mix/java/com/goodworkalan/github4j/uploader/mix/GitHub4JUploaderProject.java b/src/mix/java/com/goodworkalan/github4j/uploader/mix/GitHub4JUploaderProject.java index 76fcbc2..b2e87c1 100644 --- a/src/mix/java/com/goodworkalan/github4j/uploader/mix/GitHub4JUploaderProject.java +++ b/src/mix/java/com/goodworkalan/github4j/uploader/mix/GitHub4JUploaderProject.java @@ -2,7 +2,7 @@ import com.goodworkalan.mix.ProjectModule; import com.goodworkalan.mix.builder.Builder; -import com.goodworkalan.mix.builder.JavaProject; +import com.goodworkalan.mix.cookbook.JavaProject; /** * Builds the project definition for GitHub4J Uploader. From 44fbf16c52f74f22f9b659b7d14c33238e790ed1 Mon Sep 17 00:00:00 2001 From: Alan Gutierrez Date: Sat, 21 Aug 2010 03:02:30 -0500 Subject: [PATCH 4/4] Last changes, don't care. --- .../github4j/uploader/GitHubUploader.java | 41 ++++++++++++++----- .../github4j/uploader/exceptions.properties | 4 +- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/goodworkalan/github4j/uploader/GitHubUploader.java b/src/main/java/com/goodworkalan/github4j/uploader/GitHubUploader.java index 3169b35..6e6ee23 100644 --- a/src/main/java/com/goodworkalan/github4j/uploader/GitHubUploader.java +++ b/src/main/java/com/goodworkalan/github4j/uploader/GitHubUploader.java @@ -57,6 +57,14 @@ public void upload(String project, File file, String description, String content } public void upload(String project, InputStream body, long size, String description, String contentType, String fileName) throws GitHubUploadException { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db; + try { + db = dbf.newDocumentBuilder(); + } catch (ParserConfigurationException e) { + // Yeah, but we didn't do anything to change the configuration. + throw new RuntimeException(e); + } Map upload = new HashMap(); String apiCall = "http://github.com/" + login + "/" + project + "/downloads"; try { @@ -75,8 +83,6 @@ public void upload(String project, InputStream body, long size, String descripti connection.getOutputStream().write(bytes); connection.getOutputStream().flush(); if (connection.getResponseCode() / 100 != 2) { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(connection.getErrorStream()); NodeList nodes = doc.getElementsByTagName("error"); if (nodes.getLength() != 0) { @@ -84,8 +90,6 @@ public void upload(String project, InputStream body, long size, String descripti } throw new IOException(Integer.toString(connection.getResponseCode())); } - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(connection.getInputStream()); NodeList nodes = doc.getDocumentElement().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { @@ -102,9 +106,6 @@ public void upload(String project, InputStream body, long size, String descripti throw new GitHubUploadException(MALFORMED_URL, apiCall).put("url", apiCall); } catch (IOException e) { throw new GitHubUploadException(GITHUB_HTTP_IO, e); - } catch (ParserConfigurationException e) { - // Yeah, but we didn't do anything to change the configuration. - throw new RuntimeException(e); } catch (SAXException e) { throw new GitHubUploadException(GITHUB_HTTP_BAD_XML, e); } @@ -128,7 +129,6 @@ public void upload(String project, InputStream body, long size, String descripti addField(out, boundary, "success_action_status", "201"); addField(out, boundary, "key", upload.get("prefix") + fileName); addField(out, boundary, "AWSAccessKeyId", upload.get("accesskeyid")); - addField(out, boundary, "Content-Type", contentType); addField(out, boundary, "signature", upload.get("signature")); addField(out, boundary, "acl", upload.get("acl")); @@ -162,10 +162,29 @@ public void upload(String project, InputStream body, long size, String descripti int responseCode = connection.getResponseCode(); if (responseCode != 201) { - if( responseCode == HttpURLConnection.HTTP_FORBIDDEN) { - throw new GitHubUploadException(S3_HTTP_FORBIDDEN, responseCode); + Document doc = null; + try { + doc = db.parse(connection.getErrorStream()); + } catch (SAXException e) { + e.printStackTrace(); + } + String errorMessage = ""; + if (doc != null) { + Map error = new HashMap(); + NodeList nodes = doc.getDocumentElement().getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node node = nodes.item(i); + if (node.getNodeType() == Node.ELEMENT_NODE) { + Element element = (Element) node; + error.put(element.getNodeName(), element.getTextContent()); + } + } + errorMessage = error.get("Message"); + } + if(responseCode == HttpURLConnection.HTTP_FORBIDDEN) { + throw new GitHubUploadException(S3_HTTP_FORBIDDEN, responseCode, errorMessage); } - throw new GitHubUploadException(S3_HTTP_ERROR, responseCode); + throw new GitHubUploadException(S3_HTTP_ERROR, responseCode, errorMessage); } } catch (UnsupportedEncodingException e) { // Never happens because UTF-8 and ASCII are always supported. diff --git a/src/main/resources/com/goodworkalan/github4j/uploader/exceptions.properties b/src/main/resources/com/goodworkalan/github4j/uploader/exceptions.properties index d2ac417..f6316de 100644 --- a/src/main/resources/com/goodworkalan/github4j/uploader/exceptions.properties +++ b/src/main/resources/com/goodworkalan/github4j/uploader/exceptions.properties @@ -4,7 +4,7 @@ 1103: The HTTP request to github.com returned a forbidden error status [%s]. 1104: The HTTP request github.com returned unparsable XML. 1201: The HTTP request github.s3.amazonaws.com raised an I/O exception. -1202: The HTTP request github.s3.amazonaws.com returned an error status [%s]. -1203: The HTTP request github.s3.amazonaws.com returned a forbidden error status [%s]. +1202: The HTTP request github.s3.amazonaws.com returned an error status [%s] with message [%s].. +1203: The HTTP request github.s3.amazonaws.com returned a forbidden error status [%s] with message [%s]. 1401: The file containing the upload body cannot be found. [%s]. 1402: An I/O exception was raised while reading the file upload body. \ No newline at end of file