@@ -156,60 +156,58 @@ public List<CloudAppItem> getItems(int page, int perPage, CloudAppItem.Type type
156156 }
157157 }
158158
159- /**
160- *
161- * {@inheritDoc}
162- *
163- * @see com.cloudapp.api.CloudAppItems#upload(java.io.File)
164- */
165- public CloudAppItem upload (File file ) throws CloudAppException {
166- return upload ( file , CloudAppProgressListener .NO_OP );
167- }
159+ /**
160+ *
161+ * {@inheritDoc}
162+ *
163+ * @see com.cloudapp.api.CloudAppItems#upload(java.io.File)
164+ */
165+ public CloudAppItem upload (File file ) throws CloudAppException {
166+ return upload ( file , CloudAppProgressListener .NO_OP );
167+ }
168168
169- public CloudAppItem upload (File file , CloudAppProgressListener listener ) throws CloudAppException {
170- try {
171- // Do a GET request so we have the S3 endpoint
172- HttpGet req = new HttpGet (NEW_ITEM_URL );
173- req .addHeader ("Accept" , "application/json" );
174- HttpResponse response = client .execute (req );
175- int status = response .getStatusLine ().getStatusCode ();
176- String responseBody = EntityUtils .toString (response .getEntity ());
177- if (status != 200 )
178- throw new CloudAppException (status , responseBody , null );
169+ public CloudAppItem upload (File file , CloudAppProgressListener listener ) throws CloudAppException {
170+ try {
171+ // Do a GET request so we have the S3 endpoint
172+ HttpGet req = new HttpGet (NEW_ITEM_URL );
173+ req .addHeader ("Accept" , "application/json" );
174+ HttpResponse response = client .execute (req );
175+ int status = response .getStatusLine ().getStatusCode ();
176+ String responseBody = EntityUtils .toString (response .getEntity ());
177+ if (status != 200 )
178+ throw new CloudAppException (status , responseBody , null );
179179
180- JSONObject json = new JSONObject (responseBody );
181- if (!json .has ("params" )) {
182- // Something went wrong, maybe we crossed the treshold?
183- if (json .getInt ("uploads_remaining" ) == 0 ) {
184- throw new CloudAppException (200 , "Uploads remaining is 0" , null );
185- }
186- throw new CloudAppException (500 , "Missing params object from the CloudApp API." ,
187- null );
188- }
180+ JSONObject json = new JSONObject (responseBody );
181+ if (!json .has ("params" )) {
182+ // Something went wrong, maybe we crossed the treshold?
183+ if (json .getInt ("uploads_remaining" ) == 0 ) {
184+ throw new CloudAppException (200 , "Uploads remaining is 0" , null );
185+ }
186+ throw new CloudAppException (500 , "Missing params object from the CloudApp API." ,
187+ null );
188+ }
189189
190- return uploadToAmazon (json , file , listener );
190+ return uploadToAmazon (json , file , listener );
191191
192- } catch (ClientProtocolException e ) {
193- LOGGER .error ("Something went wrong trying to contact the CloudApp API." , e );
194- throw new CloudAppException (500 ,
195- "Something went wrong trying to contact the CloudApp API" , e );
196- } catch (IOException e ) {
197- LOGGER .error ("Something went wrong trying to contact the CloudApp API." , e );
198- throw new CloudAppException (500 ,
199- "Something went wrong trying to contact the CloudApp API." , e );
200- } catch (JSONException e ) {
201- LOGGER .error ("Something went wrong trying to handle JSON." , e );
202- throw new CloudAppException (500 , "Something went wrong trying to handle JSON." , e );
203- }
192+ } catch (ClientProtocolException e ) {
193+ LOGGER .error ("Something went wrong trying to contact the CloudApp API." , e );
194+ throw new CloudAppException (500 ,
195+ "Something went wrong trying to contact the CloudApp API" , e );
196+ } catch (IOException e ) {
197+ LOGGER .error ("Something went wrong trying to contact the CloudApp API." , e );
198+ throw new CloudAppException (500 ,
199+ "Something went wrong trying to contact the CloudApp API." , e );
200+ } catch (JSONException e ) {
201+ LOGGER .error ("Something went wrong trying to handle JSON." , e );
202+ throw new CloudAppException (500 , "Something went wrong trying to handle JSON." , e );
204203 }
204+ }
205205
206206 /**
207207 * Uploads a file to S3
208208 *
209- *
210209 * @param json
211210 * @param file
212- * @param listener
213211 * @return
214212 * @throws JSONException
215213 * @throws CloudAppException
0 commit comments