Skip to content

Commit fb73941

Browse files
committed
SWS-219
1 parent 6c76ce5 commit fb73941

File tree

4 files changed

+72
-43
lines changed

4 files changed

+72
-43
lines changed

core/src/main/java/org/springframework/ws/client/core/WebServiceTemplate.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import javax.xml.transform.TransformerConfigurationException;
2626
import javax.xml.transform.TransformerException;
2727

28+
import org.apache.commons.logging.Log;
29+
import org.apache.commons.logging.LogFactory;
2830
import org.springframework.beans.factory.BeanInitializationException;
2931
import org.springframework.core.io.ClassPathResource;
3032
import org.springframework.core.io.Resource;
@@ -89,6 +91,13 @@
8991
*/
9092
public class WebServiceTemplate extends WebServiceAccessor implements WebServiceOperations {
9193

94+
/** Log category to use for message tracing. */
95+
public static final String MESSAGE_TRACING_LOG_CATEGORY = "org.springframework.ws.client.MessageTracing";
96+
97+
/** Additional logger to use for message tracing. */
98+
protected static final Log messageTracingLogger =
99+
LogFactory.getLog(WebServiceTemplate.MESSAGE_TRACING_LOG_CATEGORY);
100+
92101
private Marshaller marshaller;
93102

94103
private Unmarshaller unmarshaller;
@@ -527,28 +536,28 @@ protected Object handleFault(WebServiceConnection connection, WebServiceMessage
527536

528537
/** Sends the request in the given message context over the connection. */
529538
private void sendRequest(WebServiceConnection connection, WebServiceMessage request) throws IOException {
530-
if (logger.isTraceEnabled()) {
539+
if (messageTracingLogger.isTraceEnabled()) {
531540
ByteArrayOutputStream os = new ByteArrayOutputStream();
532541
request.writeTo(os);
533-
logger.trace("WebServiceTemplate sends request [" + os.toString("UTF-8") + "]");
542+
messageTracingLogger.trace("Sent request [" + os.toString("UTF-8") + "]");
534543
}
535-
else if (logger.isDebugEnabled()) {
536-
logger.debug("WebServiceTemplate sends request [" + request + "]");
544+
else if (messageTracingLogger.isDebugEnabled()) {
545+
messageTracingLogger.debug("Sent request [" + request + "]");
537546
}
538547
connection.send(request);
539548
}
540549

541550
private void logResponse(WebServiceMessage request, WebServiceMessage response) throws IOException {
542-
if (logger.isTraceEnabled()) {
551+
if (messageTracingLogger.isTraceEnabled()) {
543552
ByteArrayOutputStream requestStream = new ByteArrayOutputStream();
544553
request.writeTo(requestStream);
545554
ByteArrayOutputStream responseStream = new ByteArrayOutputStream();
546555
response.writeTo(responseStream);
547-
logger.trace("Received response [" + responseStream.toString("UTF-8") + "] for request [" +
556+
messageTracingLogger.trace("Received response [" + responseStream.toString("UTF-8") + "] for request [" +
548557
requestStream.toString("UTF-8") + "]");
549558
}
550-
else if (logger.isDebugEnabled()) {
551-
logger.debug("Received response [" + response + "] for request [" + request + "]");
559+
else if (messageTracingLogger.isDebugEnabled()) {
560+
messageTracingLogger.debug("Received response [" + response + "] for request [" + request + "]");
552561
}
553562
}
554563

core/src/main/java/org/springframework/ws/server/MessageDispatcher.java

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,21 @@
7474
*/
7575
public class MessageDispatcher implements WebServiceMessageReceiver, BeanNameAware, ApplicationContextAware {
7676

77+
/** Logger available to subclasses. */
78+
protected final Log logger = LogFactory.getLog(getClass());
79+
7780
/** Log category to use when no mapped endpoint is found for a request. */
78-
public static final String ENDPOINT_NOT_FOUND_LOG_CATEGORY = "org.springframework.ws.EndpointNotFound";
81+
public static final String ENDPOINT_NOT_FOUND_LOG_CATEGORY = "org.springframework.ws.server.EndpointNotFound";
7982

8083
/** Additional logger to use when no mapped endpoint is found for a request. */
8184
protected static final Log endpointNotFoundLogger =
8285
LogFactory.getLog(MessageDispatcher.ENDPOINT_NOT_FOUND_LOG_CATEGORY);
8386

84-
/** Logger available to subclasses. */
85-
protected final Log logger = LogFactory.getLog(getClass());
87+
/** Log category to use for message tracing. */
88+
public static final String MESSAGE_TRACING_LOG_CATEGORY = "org.springframework.ws.server.MessageTracing";
89+
90+
/** Additional logger to use for message tracing. */
91+
protected static final Log messageTracingLogger = LogFactory.getLog(MessageDispatcher.MESSAGE_TRACING_LOG_CATEGORY);
8692

8793
private final DefaultStrategiesHelper defaultStrategiesHelper;
8894

@@ -145,34 +151,32 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
145151
}
146152

147153
public void receive(MessageContext messageContext) throws Exception {
148-
if (logger.isTraceEnabled()) {
154+
if (messageTracingLogger.isTraceEnabled()) {
149155
ByteArrayOutputStream os = new ByteArrayOutputStream();
150156
messageContext.getRequest().writeTo(os);
151-
logger.trace(
152-
"MessageDispatcher with name '" + beanName + "' received request [" + os.toString("UTF-8") + "]");
157+
messageTracingLogger.trace("Received request [" + os.toString("UTF-8") + "]");
153158
}
154-
else if (logger.isDebugEnabled()) {
155-
logger.debug("MessageDispatcher with name '" + beanName + "' received request [" +
156-
messageContext.getRequest() + "]");
159+
else if (messageTracingLogger.isDebugEnabled()) {
160+
messageTracingLogger.debug("Received request [" + messageContext.getRequest() + "]");
157161
}
158162
dispatch(messageContext);
159163
if (messageContext.hasResponse()) {
160-
if (logger.isTraceEnabled()) {
164+
if (messageTracingLogger.isTraceEnabled()) {
161165
ByteArrayOutputStream requestStream = new ByteArrayOutputStream();
162166
messageContext.getRequest().writeTo(requestStream);
163167
ByteArrayOutputStream responseStream = new ByteArrayOutputStream();
164168
messageContext.getResponse().writeTo(responseStream);
165-
logger.trace("MessageDispatcher with name '" + beanName + "' sends response [" +
166-
responseStream.toString("UTF-8") + "] for request [" + requestStream.toString("UTF-8") + "]");
169+
messageTracingLogger.trace("Sent response [" + responseStream.toString("UTF-8") + "] for request [" +
170+
requestStream.toString("UTF-8") + "]");
167171
}
168-
else if (logger.isDebugEnabled()) {
169-
logger.debug("MessageDispatcher with name '" + beanName + "' sends response [" +
170-
messageContext.getResponse() + "] for request [" + messageContext.getRequest() + "]");
172+
else if (messageTracingLogger.isDebugEnabled()) {
173+
messageTracingLogger.debug("Sendt response [" + messageContext.getResponse() + "] for request [" +
174+
messageContext.getRequest() + "]");
171175
}
172176
}
173-
else if (logger.isDebugEnabled()) {
174-
logger.debug("MessageDispatcher with name '" + beanName + "' sends no response for request [" +
175-
messageContext.getRequest() + "]");
177+
else if (messageTracingLogger.isDebugEnabled()) {
178+
messageTracingLogger.debug("MessageDispatcher with name '" + beanName +
179+
"' sends no response for request [" + messageContext.getRequest() + "]");
176180
}
177181
}
178182

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
5858

5959
private final Attachments attachments;
6060

61-
private boolean payloadCaching;
61+
private final boolean payloadCaching;
6262

6363
private AxiomSoapEnvelope envelope;
6464

@@ -70,11 +70,20 @@ public class AxiomSoapMessage extends AbstractSoapMessage {
7070
* @param soapFactory the AXIOM SOAPFactory
7171
*/
7272
public AxiomSoapMessage(SOAPFactory soapFactory) {
73+
this(soapFactory, true);
74+
}
75+
76+
/**
77+
* Create a new, empty <code>AxiomSoapMessage</code>.
78+
*
79+
* @param soapFactory the AXIOM SOAPFactory
80+
*/
81+
public AxiomSoapMessage(SOAPFactory soapFactory, boolean payloadCaching) {
7382
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
7483
axiomFactory = soapFactory;
7584
axiomMessage = axiomFactory.createSOAPMessage(soapEnvelope, soapEnvelope.getBuilder());
7685
attachments = new Attachments();
77-
payloadCaching = true;
86+
this.payloadCaching = payloadCaching;
7887
soapAction = "\"\"";
7988
}
8089

@@ -198,7 +207,12 @@ public void writeTo(OutputStream outputStream) throws IOException {
198207
transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
199208
transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
200209
}
201-
axiomMessage.serializeAndConsume(outputStream, format);
210+
if (payloadCaching) {
211+
axiomMessage.serialize(outputStream, format);
212+
}
213+
else {
214+
axiomMessage.serializeAndConsume(outputStream, format);
215+
}
202216
outputStream.flush();
203217
}
204218
catch (XMLStreamException ex) {
@@ -211,21 +225,23 @@ public void writeTo(OutputStream outputStream) throws IOException {
211225

212226
public String toString() {
213227
StringBuffer buffer = new StringBuffer("AxiomSoapMessage");
214-
try {
215-
SOAPEnvelope envelope = axiomMessage.getSOAPEnvelope();
216-
if (envelope != null) {
217-
SOAPBody body = envelope.getBody();
218-
if (body != null) {
219-
OMElement bodyElement = body.getFirstElement();
220-
if (bodyElement != null) {
221-
buffer.append(' ');
222-
buffer.append(bodyElement.getQName());
228+
if (payloadCaching) {
229+
try {
230+
SOAPEnvelope envelope = axiomMessage.getSOAPEnvelope();
231+
if (envelope != null) {
232+
SOAPBody body = envelope.getBody();
233+
if (body != null) {
234+
OMElement bodyElement = body.getFirstElement();
235+
if (bodyElement != null) {
236+
buffer.append(' ');
237+
buffer.append(bodyElement.getQName());
238+
}
223239
}
224240
}
225241
}
226-
}
227-
catch (OMException ex) {
228-
// ignore
242+
catch (OMException ex) {
243+
// ignore
244+
}
229245
}
230246
return buffer.toString();
231247
}

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessageFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void afterPropertiesSet() throws Exception {
116116
}
117117

118118
public WebServiceMessage createWebServiceMessage() {
119-
return new AxiomSoapMessage(soapFactory);
119+
return new AxiomSoapMessage(soapFactory, payloadCaching);
120120
}
121121

122122
public WebServiceMessage createWebServiceMessage(InputStream inputStream) throws IOException {
@@ -175,7 +175,7 @@ private AxiomSoapMessage createMultiPartAxiomSoapMessage(InputStream inputStream
175175
Attachments attachments = new Attachments(inputStream, contentType);
176176
XMLStreamReader reader = inputFactory.createXMLStreamReader(attachments.getSOAPPartInputStream(),
177177
getCharSetEncoding(attachments.getSOAPPartContentType()));
178-
StAXSOAPModelBuilder builder = null;
178+
StAXSOAPModelBuilder builder;
179179
String envelopeNamespace = getSoapEnvelopeNamespace(contentType);
180180
if (MTOMConstants.SWA_TYPE.equals(attachments.getAttachmentSpecType()) ||
181181
MTOMConstants.SWA_TYPE_12.equals(attachments.getAttachmentSpecType())) {

0 commit comments

Comments
 (0)