Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a9d77a2

Browse files
committed
Reduce code duplication in ApplicationXMLFormatter.
git-svn-id: https://svn.apache.org/repos/asf/axis/axis2/java/core/trunk@1849539 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8464a0d commit a9d77a2

File tree

1 file changed

+3
-44
lines changed

1 file changed

+3
-44
lines changed

modules/kernel/src/org/apache/axis2/transport/http/ApplicationXMLFormatter.java

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -61,50 +61,9 @@ public byte[] getBytes(MessageContext
6161
public byte[] getBytes(MessageContext messageContext,
6262
OMOutputFormat format,
6363
boolean preserve) throws AxisFault {
64-
65-
if (log.isDebugEnabled()) {
66-
log.debug("start getBytes()");
67-
log.debug(" fault flow=" +
68-
(messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW));
69-
}
70-
try {
71-
OMElement omElement;
72-
73-
// Find the correct element to serialize. Normally it is the first element
74-
// in the body. But if this is a fault, use the detail entry element or the
75-
// fault reason.
76-
if (messageContext.getFLOW() == MessageContext.OUT_FAULT_FLOW) {
77-
SOAPFault fault = messageContext.getEnvelope().getBody().getFault();
78-
SOAPFaultDetail soapFaultDetail = fault.getDetail();
79-
omElement = soapFaultDetail.getFirstElement();
80-
81-
if (omElement == null) {
82-
omElement = fault.getReason();
83-
}
84-
85-
} else {
86-
// Normal case: The xml payload is the first element in the body.
87-
omElement = messageContext.getEnvelope().getBody().getFirstElement();
88-
}
89-
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
90-
91-
if (omElement != null) {
92-
93-
try {
94-
omElement.serialize(bytesOut, format, preserve);
95-
} catch (IOException e) {
96-
throw AxisFault.makeFault(e);
97-
}
98-
99-
return bytesOut.toByteArray();
100-
}
101-
102-
return new byte[0];
103-
} finally {
104-
if (log.isDebugEnabled()) {
105-
log.debug("end getBytes()");
106-
}
107-
}
64+
ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
65+
writeTo(messageContext, format, bytesOut, preserve);
66+
return bytesOut.toByteArray();
10867
}
10968

11069
public void writeTo(MessageContext messageContext, OMOutputFormat format,

0 commit comments

Comments
 (0)