SWS-333
This commit is contained in:
@@ -47,17 +47,6 @@ public abstract class AbstractReceiverConnection extends AbstractWebServiceConne
|
||||
return responseOutputStream;
|
||||
}
|
||||
|
||||
public final void close() throws IOException {
|
||||
try {
|
||||
if (requestInputStream != null) {
|
||||
requestInputStream.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method invoked from {@link #close()}. Default implementation is empty.
|
||||
*
|
||||
@@ -108,11 +97,6 @@ public abstract class AbstractReceiverConnection extends AbstractWebServiceConne
|
||||
return getRequestHeaders(name);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
// defer close, some SoapMessage implementations (Axis) lazy-initialize the SOAPMessage
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/** Implementation of <code>TransportOutputStream</code> for sending-side connections. */
|
||||
|
||||
@@ -52,17 +52,6 @@ public abstract class AbstractSenderConnection extends AbstractWebServiceConnect
|
||||
}
|
||||
}
|
||||
|
||||
public final void close() throws IOException {
|
||||
try {
|
||||
if (responseInputStream != null) {
|
||||
responseInputStream.close();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
onClose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method invoked from {@link #close()}. Default implementation is empty.
|
||||
*
|
||||
@@ -128,10 +117,6 @@ public abstract class AbstractSenderConnection extends AbstractWebServiceConnect
|
||||
return getResponseHeaders(name);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
// defer close, some SoapMessage implementations (Axis) lazy-initialize the SOAPMessage
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,45 +29,21 @@ import org.springframework.ws.WebServiceMessageFactory;
|
||||
*/
|
||||
public abstract class AbstractWebServiceConnection implements WebServiceConnection {
|
||||
|
||||
private TransportInputStream tis;
|
||||
|
||||
private TransportOutputStream tos;
|
||||
|
||||
public final void send(WebServiceMessage message) throws IOException {
|
||||
onSendBeforeWrite(message);
|
||||
TransportOutputStream tos = createTransportOutputStream();
|
||||
try {
|
||||
message.writeTo(tos);
|
||||
tos.flush();
|
||||
}
|
||||
finally {
|
||||
tos.close();
|
||||
tos = createTransportOutputStream();
|
||||
if (tos == null) {
|
||||
return;
|
||||
}
|
||||
message.writeTo(tos);
|
||||
tos.flush();
|
||||
onSendAfterWrite(message);
|
||||
}
|
||||
|
||||
public final WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
|
||||
onReceiveBeforeRead();
|
||||
TransportInputStream tis = createTransportInputStream();
|
||||
if (tis == null) {
|
||||
return null;
|
||||
}
|
||||
WebServiceMessage message = null;
|
||||
try {
|
||||
message = messageFactory.createWebServiceMessage(tis);
|
||||
}
|
||||
finally {
|
||||
tis.close();
|
||||
}
|
||||
onReceiveAfterRead(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <code>TransportOutputStream</code> for the given message. Called from {@link
|
||||
* #send(WebServiceMessage)}.
|
||||
*
|
||||
* @return the output stream
|
||||
* @throws IOException when an I/O exception occurs
|
||||
*/
|
||||
protected abstract TransportOutputStream createTransportOutputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Called before the given message has been written to the <code>TransportOutputStream</code>. Called from {@link
|
||||
* #send(WebServiceMessage)}.
|
||||
@@ -80,6 +56,15 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
|
||||
protected void onSendBeforeWrite(WebServiceMessage message) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <code>TransportOutputStream</code> for the given message. Called from {@link
|
||||
* #send(WebServiceMessage)}.
|
||||
*
|
||||
* @return the output stream
|
||||
* @throws IOException when an I/O exception occurs
|
||||
*/
|
||||
protected abstract TransportOutputStream createTransportOutputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Called after the given message has been written to the <code>TransportOutputStream</code>. Called from {@link
|
||||
* #send(WebServiceMessage)}.
|
||||
@@ -92,13 +77,16 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
|
||||
protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <code>TransportInputStream</code>. Called from {@link #receive(WebServiceMessageFactory)}.
|
||||
*
|
||||
* @return the input stream, or <code>null</code> if no response can be read
|
||||
* @throws IOException when an I/O exception occurs
|
||||
*/
|
||||
protected abstract TransportInputStream createTransportInputStream() throws IOException;
|
||||
public final WebServiceMessage receive(WebServiceMessageFactory messageFactory) throws IOException {
|
||||
onReceiveBeforeRead();
|
||||
tis = createTransportInputStream();
|
||||
if (tis == null) {
|
||||
return null;
|
||||
}
|
||||
WebServiceMessage message = messageFactory.createWebServiceMessage(tis);
|
||||
onReceiveAfterRead(message);
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before a message has been read from the <code>TransportInputStream</code>. Called from {@link
|
||||
@@ -111,6 +99,14 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
|
||||
protected void onReceiveBeforeRead() throws IOException {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <code>TransportInputStream</code>. Called from {@link #receive(WebServiceMessageFactory)}.
|
||||
*
|
||||
* @return the input stream, or <code>null</code> if no response can be read
|
||||
* @throws IOException when an I/O exception occurs
|
||||
*/
|
||||
protected abstract TransportInputStream createTransportInputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Called when the given message has been read from the <code>TransportInputStream</code>. Called from {@link
|
||||
* #receive(WebServiceMessageFactory)}.
|
||||
@@ -123,4 +119,36 @@ public abstract class AbstractWebServiceConnection implements WebServiceConnecti
|
||||
protected void onReceiveAfterRead(WebServiceMessage message) throws IOException {
|
||||
}
|
||||
|
||||
public final void close() throws IOException {
|
||||
IOException ioex = null;
|
||||
if (tis != null) {
|
||||
try {
|
||||
tis.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
ioex = ex;
|
||||
}
|
||||
}
|
||||
if (tos != null) {
|
||||
try {
|
||||
tos.close();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
ioex = ex;
|
||||
}
|
||||
}
|
||||
onClose();
|
||||
if (ioex != null) {
|
||||
throw ioex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Template method invoked from {@link #close()}. Default implementation is empty.
|
||||
*
|
||||
* @throws IOException if an I/O error occurs when closing this connection
|
||||
*/
|
||||
protected void onClose() throws IOException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -77,7 +77,8 @@ public class CommonsHttpConnection extends AbstractHttpSenderConnection {
|
||||
throw new URISyntaxException("", ex.getMessage());
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
/*
|
||||
* Sending request
|
||||
*/
|
||||
|
||||
|
||||
Reference in New Issue
Block a user