Skip to content

Commit

Permalink
Fix element order in data-service fault messages
Browse files Browse the repository at this point in the history
Fix element ordeing in data-service fault messages to match the WSDL definition.
Fixes wso2/product-ei/issues/4664
  • Loading branch information
GDLMadushanka committed Aug 11, 2023
1 parent 087dc02 commit 826fba4
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.wso2.micro.integrator.dataservices.core;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -91,7 +92,19 @@ public static OMElement extractFaultMessage(Throwable throwable) {
OMElement root = fac.createOMElement(new QName(
DBConstants.WSO2_DS_NAMESPACE, DBConstants.DS_FAULT_ELEMENT));
OMNamespace ns = root.getNamespace();
for (Map.Entry<String, Object> rootEntry : ((DataServiceFault) throwable).getPropertyMap().entrySet()) {
// Adding data from HashMap to a LikedHashMap to preserve the order
Map<String, Object> propLinkedHashMap = new LinkedHashMap<>();
propLinkedHashMap.put(DBConstants.FaultParams.CURRENT_PARAMS,
((DataServiceFault) throwable).getPropertyMap().get(DBConstants.FaultParams.CURRENT_PARAMS));
propLinkedHashMap.put(DBConstants.FaultParams.CURRENT_REQUEST_NAME,
((DataServiceFault) throwable).getPropertyMap().get(DBConstants.FaultParams.CURRENT_REQUEST_NAME));
propLinkedHashMap.put(DBConstants.FaultParams.NESTED_EXCEPTION,
((DataServiceFault) throwable).getPropertyMap().get(DBConstants.FaultParams.NESTED_EXCEPTION));
propLinkedHashMap.put(DBConstants.FaultParams.SOURCE_DATA_SERVICE,
((DataServiceFault) throwable).getPropertyMap().get(DBConstants.FaultParams.SOURCE_DATA_SERVICE));
propLinkedHashMap.put(DBConstants.FaultParams.DS_CODE,
((DataServiceFault) throwable).getPropertyMap().get(DBConstants.FaultParams.DS_CODE));
for (Map.Entry<String, Object> rootEntry : propLinkedHashMap.entrySet()) {
OMElement keyElement = fac.createOMElement(rootEntry.getKey(), ns);
if (rootEntry.getValue() instanceof Map) {
for (Map.Entry dataServiceEntry : (Set<Map.Entry>) ((Map) rootEntry.getValue()).entrySet()) {
Expand Down

0 comments on commit 826fba4

Please sign in to comment.