Refactored TransportOutputStream to represent TransportIntputStream more.

This commit is contained in:
Arjen Poutsma
2007-02-17 12:50:32 +00:00
parent 4db01de468
commit ce3182bb6a
10 changed files with 76 additions and 35 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -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();
}

View File

@@ -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();
}
/**

View File

@@ -34,7 +34,7 @@ public class StubTransportOutputStream extends TransportOutputStream {
this.outputStream = outputStream;
}
protected OutputStream getOutputStream() throws IOException {
protected OutputStream createOutputStream() throws IOException {
return outputStream;
}

View File

@@ -90,7 +90,7 @@ public class JmsTransportOutputStream extends TransportOutputStream {
return message;
}
protected OutputStream getOutputStream() throws IOException {
protected OutputStream createOutputStream() throws IOException {
return new BytesMessageOutputStream();
}

View File

@@ -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 <code>WebServiceMessageReceiver</code> used by this listener.
*/
public WebServiceMessageReceiver getMessageReceiver() {
return messageReceiver;
}
/**
* Sets the <code>WebServiceMessageReceiver</code> 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 <code>Message</code>s. Uses the given <code>Session</code> 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(

View File

@@ -43,7 +43,7 @@ public class MailTransportOutputStream extends TransportOutputStream {
}
}
protected OutputStream getOutputStream() throws IOException {
protected OutputStream createOutputStream() throws IOException {
try {
return message.getDataHandler().getOutputStream();
}

View File

@@ -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 <code>WebServiceMessageReceiver</code> used by this listener.
*/
public WebServiceMessageReceiver getMessageReceiver() {
return messageReceiver;
}
/**
* Sets the <code>WebServiceMessageReceiver</code> 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());
}
}