diff --git a/core/src/main/java/org/springframework/ws/transport/TransportOutputStream.java b/core/src/main/java/org/springframework/ws/transport/TransportOutputStream.java index 3b8a788f..a490eca0 100644 --- a/core/src/main/java/org/springframework/ws/transport/TransportOutputStream.java +++ b/core/src/main/java/org/springframework/ws/transport/TransportOutputStream.java @@ -28,9 +28,18 @@ import java.io.OutputStream; */ public abstract class TransportOutputStream extends OutputStream { + private OutputStream outputStream; + protected TransportOutputStream() { } + private OutputStream getOutputStream() throws IOException { + if (outputStream == null) { + outputStream = createOutputStream(); + } + return outputStream; + } + public void close() throws IOException { getOutputStream().close(); } @@ -63,5 +72,5 @@ public abstract class TransportOutputStream extends OutputStream { /** * Returns the output stream to write to. */ - protected abstract OutputStream getOutputStream() throws IOException; + protected abstract OutputStream createOutputStream() throws IOException; } diff --git a/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpTransportOutputStream.java b/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpTransportOutputStream.java index 7578ddb0..4abc6e19 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpTransportOutputStream.java +++ b/core/src/main/java/org/springframework/ws/transport/http/CommonsHttpTransportOutputStream.java @@ -53,7 +53,7 @@ public class CommonsHttpTransportOutputStream extends TransportOutputStream { postMethod.setRequestEntity(new ByteArrayRequestEntity(bos.toByteArray())); } - protected OutputStream getOutputStream() throws IOException { + protected OutputStream createOutputStream() throws IOException { return bos; } diff --git a/core/src/main/java/org/springframework/ws/transport/http/HttpServletTransportOutputStream.java b/core/src/main/java/org/springframework/ws/transport/http/HttpServletTransportOutputStream.java index 99c32588..51703459 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/HttpServletTransportOutputStream.java +++ b/core/src/main/java/org/springframework/ws/transport/http/HttpServletTransportOutputStream.java @@ -41,7 +41,7 @@ public class HttpServletTransportOutputStream extends TransportOutputStream { this.httpServletResponse = httpServletResponse; } - protected OutputStream getOutputStream() throws IOException { + protected OutputStream createOutputStream() throws IOException { return httpServletResponse.getOutputStream(); } diff --git a/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnectionTransportOutputStream.java b/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnectionTransportOutputStream.java index 19ed3966..8d3a15e6 100644 --- a/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnectionTransportOutputStream.java +++ b/core/src/main/java/org/springframework/ws/transport/http/HttpUrlConnectionTransportOutputStream.java @@ -46,7 +46,7 @@ public class HttpUrlConnectionTransportOutputStream extends TransportOutputStrea connection.setRequestProperty(name, value); } - protected OutputStream getOutputStream() throws IOException { + protected OutputStream createOutputStream() throws IOException { return connection.getOutputStream(); } diff --git a/core/src/main/java/org/springframework/ws/transport/support/WebServiceMessageReceiverObjectSupport.java b/core/src/main/java/org/springframework/ws/transport/support/WebServiceMessageReceiverObjectSupport.java index edee4e79..88b77573 100644 --- a/core/src/main/java/org/springframework/ws/transport/support/WebServiceMessageReceiverObjectSupport.java +++ b/core/src/main/java/org/springframework/ws/transport/support/WebServiceMessageReceiverObjectSupport.java @@ -115,6 +115,7 @@ public abstract class WebServiceMessageReceiverObjectSupport implements Initiali protected void handleResponse(TransportInputStream tis, TransportOutputStream tos, WebServiceMessage response) throws Exception { response.writeTo(tos); + tos.flush(); } /** diff --git a/core/src/test/java/org/springframework/ws/transport/StubTransportOutputStream.java b/core/src/test/java/org/springframework/ws/transport/StubTransportOutputStream.java index 3e9e568c..95e2ebcb 100644 --- a/core/src/test/java/org/springframework/ws/transport/StubTransportOutputStream.java +++ b/core/src/test/java/org/springframework/ws/transport/StubTransportOutputStream.java @@ -34,7 +34,7 @@ public class StubTransportOutputStream extends TransportOutputStream { this.outputStream = outputStream; } - protected OutputStream getOutputStream() throws IOException { + protected OutputStream createOutputStream() throws IOException { return outputStream; } diff --git a/sandbox/src/main/java/org/springframework/ws/transport/jms/JmsTransportOutputStream.java b/sandbox/src/main/java/org/springframework/ws/transport/jms/JmsTransportOutputStream.java index f92ee604..9b7a8e69 100644 --- a/sandbox/src/main/java/org/springframework/ws/transport/jms/JmsTransportOutputStream.java +++ b/sandbox/src/main/java/org/springframework/ws/transport/jms/JmsTransportOutputStream.java @@ -90,7 +90,7 @@ public class JmsTransportOutputStream extends TransportOutputStream { return message; } - protected OutputStream getOutputStream() throws IOException { + protected OutputStream createOutputStream() throws IOException { return new BytesMessageOutputStream(); } diff --git a/sandbox/src/main/java/org/springframework/ws/transport/jms/support/JmsWebServiceMessageReceiverObjectSupport.java b/sandbox/src/main/java/org/springframework/ws/transport/jms/support/JmsWebServiceMessageReceiverObjectSupport.java index 1c22b852..5ed9cb18 100644 --- a/sandbox/src/main/java/org/springframework/ws/transport/jms/support/JmsWebServiceMessageReceiverObjectSupport.java +++ b/sandbox/src/main/java/org/springframework/ws/transport/jms/support/JmsWebServiceMessageReceiverObjectSupport.java @@ -21,16 +21,14 @@ import javax.jms.Message; import javax.jms.MessageProducer; import javax.jms.Session; -import org.springframework.beans.factory.InitializingBean; import org.springframework.jms.support.JmsUtils; -import org.springframework.util.Assert; import org.springframework.ws.WebServiceMessage; import org.springframework.ws.transport.TransportInputStream; import org.springframework.ws.transport.TransportOutputStream; import org.springframework.ws.transport.WebServiceMessageReceiver; import org.springframework.ws.transport.jms.JmsTransportInputStream; import org.springframework.ws.transport.jms.JmsTransportOutputStream; -import org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport; +import org.springframework.ws.transport.support.SimpleWebServiceMessageReceiverObjectSupport; /** * Convenience base class for JMS server-side transport objects. Contains a {@link WebServiceMessageReceiver}, and has @@ -41,30 +39,7 @@ import org.springframework.ws.transport.support.WebServiceMessageReceiverObjectS * @author Arjen Poutsma * @see #handle(javax.jms.Message,javax.jms.Session) */ -public abstract class JmsWebServiceMessageReceiverObjectSupport extends WebServiceMessageReceiverObjectSupport - implements InitializingBean { - - private WebServiceMessageReceiver messageReceiver; - - /** - * Returns the WebServiceMessageReceiver used by this listener. - */ - public WebServiceMessageReceiver getMessageReceiver() { - return messageReceiver; - } - - /** - * Sets the WebServiceMessageReceiver used by this listener. - */ - public void setMessageReceiver(WebServiceMessageReceiver messageReceiver) { - this.messageReceiver = messageReceiver; - } - - public void afterPropertiesSet() throws Exception { - Assert.notNull(getMessageFactory(), "messageFactory is required"); - Assert.notNull(getMessageReceiver(), "messageReceiver must not be null"); - logger.info("Using message factory [" + getMessageFactory() + "]"); - } +public abstract class JmsWebServiceMessageReceiverObjectSupport extends SimpleWebServiceMessageReceiverObjectSupport { /** * Handles an incoming Messages. Uses the given Session to create a response request. @@ -77,7 +52,7 @@ public abstract class JmsWebServiceMessageReceiverObjectSupport extends WebServi if (request instanceof BytesMessage) { TransportInputStream tis = new JmsTransportInputStream((BytesMessage) request); TransportOutputStream tos = new JmsTransportOutputStream(session, request.getJMSCorrelationID()); - handle(tis, tos, getMessageReceiver()); + handle(tis, tos); } else { throw new IllegalArgumentException( diff --git a/sandbox/src/main/java/org/springframework/ws/transport/mail/MailTransportOutputStream.java b/sandbox/src/main/java/org/springframework/ws/transport/mail/MailTransportOutputStream.java index d25fd518..07a5468e 100644 --- a/sandbox/src/main/java/org/springframework/ws/transport/mail/MailTransportOutputStream.java +++ b/sandbox/src/main/java/org/springframework/ws/transport/mail/MailTransportOutputStream.java @@ -43,7 +43,7 @@ public class MailTransportOutputStream extends TransportOutputStream { } } - protected OutputStream getOutputStream() throws IOException { + protected OutputStream createOutputStream() throws IOException { try { return message.getDataHandler().getOutputStream(); } diff --git a/sandbox/src/main/java/org/springframework/ws/transport/support/SimpleWebServiceMessageReceiverObjectSupport.java b/sandbox/src/main/java/org/springframework/ws/transport/support/SimpleWebServiceMessageReceiverObjectSupport.java new file mode 100644 index 00000000..e6e31477 --- /dev/null +++ b/sandbox/src/main/java/org/springframework/ws/transport/support/SimpleWebServiceMessageReceiverObjectSupport.java @@ -0,0 +1,56 @@ +/* + * Copyright 2007 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.ws.transport.support; + +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; +import org.springframework.ws.transport.TransportInputStream; +import org.springframework.ws.transport.TransportOutputStream; +import org.springframework.ws.transport.WebServiceMessageReceiver; + +/** + * @author Arjen Poutsma + */ +public class SimpleWebServiceMessageReceiverObjectSupport extends WebServiceMessageReceiverObjectSupport + implements InitializingBean { + + private WebServiceMessageReceiver messageReceiver; + + /** + * Returns the WebServiceMessageReceiver used by this listener. + */ + public WebServiceMessageReceiver getMessageReceiver() { + return messageReceiver; + } + + /** + * Sets the WebServiceMessageReceiver used by this listener. + */ + public void setMessageReceiver(WebServiceMessageReceiver messageReceiver) { + this.messageReceiver = messageReceiver; + } + + public void afterPropertiesSet() throws Exception { + super.afterPropertiesSet(); + Assert.notNull(getMessageReceiver(), "messageReceiver must not be null"); + } + + protected final void handle(TransportInputStream tis, TransportOutputStream tos) throws Exception { + handle(tis, tos, getMessageReceiver()); + } + +}