mirror of
				https://github.com/owncloud/android-library.git
				synced 2025-10-30 01:48:14 +00:00 
			
		
		
		
	Merge pull request #166 from owncloud/antivirus_improve_feedback
Improve feedback when uploading virus files
This commit is contained in:
		
						commit
						0a4c3773b2
					
				| @ -119,7 +119,8 @@ public class RemoteOperationResult implements Serializable { | |||||||
|         DELAYED_FOR_WIFI, |         DELAYED_FOR_WIFI, | ||||||
|         LOCAL_FILE_NOT_FOUND, |         LOCAL_FILE_NOT_FOUND, | ||||||
|         SERVICE_UNAVAILABLE, |         SERVICE_UNAVAILABLE, | ||||||
|         SPECIFIC_SERVICE_UNAVAILABLE |         SPECIFIC_SERVICE_UNAVAILABLE, | ||||||
|  |         SPECIFIC_UNSUPPORTED_MEDIA_TYPE | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     private boolean mSuccess = false; |     private boolean mSuccess = false; | ||||||
| @ -135,7 +136,7 @@ public class RemoteOperationResult implements Serializable { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Public constructor from result code. |      * Public constructor from result code. | ||||||
|      * <p> |      * | ||||||
|      * To be used when the caller takes the responsibility of interpreting the result of a {@link RemoteOperation} |      * To be used when the caller takes the responsibility of interpreting the result of a {@link RemoteOperation} | ||||||
|      * |      * | ||||||
|      * @param code {@link ResultCode} decided by the caller. |      * @param code {@link ResultCode} decided by the caller. | ||||||
| @ -150,9 +151,9 @@ public class RemoteOperationResult implements Serializable { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Public constructor from exception. |      * Public constructor from exception. | ||||||
|      * <p> |      * | ||||||
|      * To be used when an exception prevented the end of the {@link RemoteOperation}. |      * To be used when an exception prevented the end of the {@link RemoteOperation}. | ||||||
|      * <p> |      * | ||||||
|      * Determines a {@link ResultCode} depending on the type of the exception. |      * Determines a {@link ResultCode} depending on the type of the exception. | ||||||
|      * |      * | ||||||
|      * @param e Exception that interrupted the {@link RemoteOperation} |      * @param e Exception that interrupted the {@link RemoteOperation} | ||||||
| @ -209,9 +210,9 @@ public class RemoteOperationResult implements Serializable { | |||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Public constructor from separate elements of an HTTP or DAV response. |      * Public constructor from separate elements of an HTTP or DAV response. | ||||||
|      * <p> |      * | ||||||
|      * To be used when the result needs to be interpreted from the response of an HTTP/DAV method. |      * To be used when the result needs to be interpreted from the response of an HTTP/DAV method. | ||||||
|      * <p> |      * | ||||||
|      * Determines a {@link ResultCode} from the already executed method received as a parameter. Generally, |      * Determines a {@link ResultCode} from the already executed method received as a parameter. Generally, | ||||||
|      * will depend on the HTTP code and HTTP response headers received. In some cases will inspect also the |      * will depend on the HTTP code and HTTP response headers received. In some cases will inspect also the | ||||||
|      * response body. |      * response body. | ||||||
| @ -229,6 +230,7 @@ public class RemoteOperationResult implements Serializable { | |||||||
|         ); |         ); | ||||||
| 
 | 
 | ||||||
|         if (mHttpCode == HttpStatus.SC_BAD_REQUEST) {   // 400 |         if (mHttpCode == HttpStatus.SC_BAD_REQUEST) {   // 400 | ||||||
|  | 
 | ||||||
|             String bodyResponse = httpMethod.getResponseBodyAsString(); |             String bodyResponse = httpMethod.getResponseBodyAsString(); | ||||||
|             // do not get for other HTTP codes!; could not be available |             // do not get for other HTTP codes!; could not be available | ||||||
| 
 | 
 | ||||||
| @ -247,26 +249,33 @@ public class RemoteOperationResult implements Serializable { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (mHttpCode == HttpStatus.SC_FORBIDDEN) { |         if (mHttpCode == HttpStatus.SC_FORBIDDEN) {  // 403 | ||||||
|             String bodyResponse = httpMethod.getResponseBodyAsString(); |  | ||||||
| 
 | 
 | ||||||
|             if (bodyResponse != null && bodyResponse.length() > 0) { |             parseErrorMessageAndSetCode(httpMethod, ResultCode.SPECIFIC_FORBIDDEN); | ||||||
|                 InputStream is = new ByteArrayInputStream(bodyResponse.getBytes()); |  | ||||||
|                 ErrorMessageParser xmlParser = new ErrorMessageParser(); |  | ||||||
|                 try { |  | ||||||
|                     String errorMessage = xmlParser.parseXMLResponse(is); |  | ||||||
|                     if (errorMessage != null && errorMessage.length() > 0) { |  | ||||||
|                         mCode = ResultCode.SPECIFIC_FORBIDDEN; |  | ||||||
|                         mHttpPhrase = errorMessage; |  | ||||||
|         } |         } | ||||||
|                 } catch (Exception e) { | 
 | ||||||
|                     Log_OC.w(TAG, "Error reading exception from server: " + e.getMessage()); |         if (mHttpCode == HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE) {    // 415 | ||||||
|                     // mCode stays as set in this(success, httpCode, headers) | 
 | ||||||
|  |             parseErrorMessageAndSetCode(httpMethod, ResultCode.SPECIFIC_UNSUPPORTED_MEDIA_TYPE); | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         if (mHttpCode == HttpStatus.SC_SERVICE_UNAVAILABLE) {   // 503 | ||||||
|  | 
 | ||||||
|  |             parseErrorMessageAndSetCode(httpMethod, ResultCode.SPECIFIC_SERVICE_UNAVAILABLE); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|         if (mHttpCode == HttpStatus.SC_SERVICE_UNAVAILABLE) { |     /** | ||||||
|  |      * Parse the error message included in the body response, if any, and set the specific result | ||||||
|  |      * code | ||||||
|  |      * @param httpMethod HTTP/DAV method already executed which response body will be parsed to get | ||||||
|  |      *                   the specific error message | ||||||
|  |      * @param resultCode specific result code | ||||||
|  |      * @throws IOException | ||||||
|  |      */ | ||||||
|  |     private void parseErrorMessageAndSetCode(HttpMethod httpMethod, ResultCode resultCode) | ||||||
|  |             throws IOException { | ||||||
|  | 
 | ||||||
|         String bodyResponse = httpMethod.getResponseBodyAsString(); |         String bodyResponse = httpMethod.getResponseBodyAsString(); | ||||||
| 
 | 
 | ||||||
|         if (bodyResponse != null && bodyResponse.length() > 0) { |         if (bodyResponse != null && bodyResponse.length() > 0) { | ||||||
| @ -275,7 +284,7 @@ public class RemoteOperationResult implements Serializable { | |||||||
|             try { |             try { | ||||||
|                 String errorMessage = xmlParser.parseXMLResponse(is); |                 String errorMessage = xmlParser.parseXMLResponse(is); | ||||||
|                 if (errorMessage != "" && errorMessage != null) { |                 if (errorMessage != "" && errorMessage != null) { | ||||||
|                         mCode = ResultCode.SPECIFIC_SERVICE_UNAVAILABLE; |                     mCode = resultCode; | ||||||
|                     mHttpPhrase = errorMessage; |                     mHttpPhrase = errorMessage; | ||||||
|                 } |                 } | ||||||
|             } catch (Exception e) { |             } catch (Exception e) { | ||||||
| @ -284,17 +293,16 @@ public class RemoteOperationResult implements Serializable { | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|      * Public constructor from separate elements of an HTTP or DAV response. |      * Public constructor from separate elements of an HTTP or DAV response. | ||||||
|      * <p> |      * | ||||||
|      * To be used when the result needs to be interpreted from HTTP response elements that could come from |      * To be used when the result needs to be interpreted from HTTP response elements that could come from | ||||||
|      * different requests (WARNING: black magic, try to avoid). |      * different requests (WARNING: black magic, try to avoid). | ||||||
|      * <p> |      * | ||||||
|      * If all the fields come from the same HTTP/DAV response, {@link #RemoteOperationResult(boolean, HttpMethod)} |      * If all the fields come from the same HTTP/DAV response, {@link #RemoteOperationResult(boolean, HttpMethod)} | ||||||
|      * should be used instead. |      * should be used instead. | ||||||
|      * <p> |      * | ||||||
|      * Determines a {@link ResultCode} depending on the HTTP code and HTTP response headers received. |      * Determines a {@link ResultCode} depending on the HTTP code and HTTP response headers received. | ||||||
|      * |      * | ||||||
|      * @param success     The operation was considered successful or not. |      * @param success     The operation was considered successful or not. | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user