diff --git a/repository/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java b/repository/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java index 2d8b41683b4..6f91afc774c 100644 --- a/repository/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java +++ b/repository/src/main/java/org/alfresco/repo/transfer/HttpClientTransmitterImpl.java @@ -53,8 +53,6 @@ import org.alfresco.service.cmr.transfer.TransferVersion; import org.alfresco.util.HttpClientHelper; import org.alfresco.util.PropertyCheck; -import org.alfresco.util.json.ExceptionJsonSerializer; -import org.alfresco.util.json.JsonSerializer; import org.apache.commons.httpclient.Credentials; import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpClient; @@ -73,8 +71,10 @@ import org.apache.commons.httpclient.protocol.Protocol; import org.apache.commons.httpclient.protocol.ProtocolSocketFactory; import org.apache.commons.httpclient.protocol.SSLProtocolSocketFactory; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.json.JSONArray; import org.json.JSONObject; /** @@ -102,7 +102,6 @@ public class HttpClientTransmitterImpl implements TransferTransmitter private Protocol httpsProtocol = new Protocol(HTTPS_SCHEME_NAME, (ProtocolSocketFactory) new SSLProtocolSocketFactory(), DEFAULT_HTTPS_PORT); private Map protocolMap = null; private HttpMethodFactory httpMethodFactory = null; - private JsonSerializer jsonErrorSerializer; private ContentService contentService; @@ -125,7 +124,6 @@ public HttpClientTransmitterImpl() httpClient = new HttpClient(); httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager()); httpMethodFactory = new StandardHttpMethodFactoryImpl(); - jsonErrorSerializer = new ExceptionJsonSerializer(); // Create an HTTP Proxy Host if appropriate system properties are set httpProxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT); @@ -852,7 +850,27 @@ protected PostMethod getPostMethod() */ private Throwable rehydrateError(JSONObject errorJSON) { - return jsonErrorSerializer.deserialize(errorJSON); + if (errorJSON == null) + { + return null; + } + + String errorMessage = errorJSON.optString("errorMessage", StringUtils.EMPTY); + String errorId = errorJSON.optString("alfrescoMessageId", null); + + Object[] errorParams = new Object[0]; + JSONArray errorParamArray = errorJSON.optJSONArray("alfrescoMessageParams"); + if (errorParamArray != null) + { + int length = errorParamArray.length(); + errorParams = new Object[length]; + for (int i = 0; i < length; ++i) + { + errorParams[i] = errorParamArray.getString(i); + } + } + + return new TransferException(errorId == null ? errorMessage : errorId, errorParams); } public void setContentService(ContentService contentService) @@ -870,11 +888,6 @@ public void setHttpMethodFactory(HttpMethodFactory httpMethodFactory) this.httpMethodFactory = httpMethodFactory; } - public void setJsonErrorSerializer(JsonSerializer jsonErrorSerializer) - { - this.jsonErrorSerializer = jsonErrorSerializer; - } - public void setNodeService(NodeService nodeService) { this.nodeService = nodeService; diff --git a/repository/src/main/java/org/alfresco/util/json/ExceptionJsonSerializer.java b/repository/src/main/java/org/alfresco/util/json/ExceptionJsonSerializer.java index 720e92dd285..f94051d9a05 100644 --- a/repository/src/main/java/org/alfresco/util/json/ExceptionJsonSerializer.java +++ b/repository/src/main/java/org/alfresco/util/json/ExceptionJsonSerializer.java @@ -41,7 +41,8 @@ public class ExceptionJsonSerializer implements JsonSerializer { private final static Log log = LogFactory.getLog(ExceptionJsonSerializer.class); - + + @Deprecated @Override public Throwable deserialize(JSONObject errorJSON) { @@ -89,38 +90,42 @@ public Throwable deserialize(JSONObject errorJSON) catch (ClassNotFoundException e) { errorClass = Exception.class; - } - Constructor constructor = null; - try - { - try - { - constructor = errorClass.getConstructor(String.class, Object[].class); - createdObject = constructor.newInstance(errorId, errorParams); - } - catch (NoSuchMethodException e) - { - try - { - constructor = errorClass.getConstructor(String.class); - createdObject = constructor.newInstance(errorId == null ? errorMessage : errorId); - } - catch (NoSuchMethodException e1) - { - try - { - constructor = errorClass.getConstructor(); - createdObject = constructor.newInstance(); - } - catch (NoSuchMethodException e2) - { - } - } - } - } - catch(Exception ex) - { - //We don't need to do anything here. Code below will fix things up + } + + if (Throwable.class.isAssignableFrom(errorClass)) + { + Constructor constructor = null; + try + { + try + { + constructor = errorClass.getConstructor(String.class, Object[].class); + createdObject = constructor.newInstance(errorId, errorParams); + } + catch (NoSuchMethodException e) + { + try + { + constructor = errorClass.getConstructor(String.class); + createdObject = constructor.newInstance(errorId == null ? errorMessage : errorId); + } + catch (NoSuchMethodException e1) + { + try + { + constructor = errorClass.getConstructor(); + createdObject = constructor.newInstance(); + } + catch (NoSuchMethodException e2) + { + } + } + } + } + catch (Exception ex) + { + // We don't need to do anything here. Code below will fix things up + } } if (createdObject == null || !Throwable.class.isAssignableFrom(createdObject.getClass())) {