SWS-468 - Add a new HttpsUrlConnectionMessageSender implementation to allow customization of certificate management

This commit is contained in:
Arjen Poutsma
2009-08-21 12:44:41 +00:00
parent d803e1be20
commit 2c650a53a6
7 changed files with 253 additions and 8 deletions

View File

@@ -30,4 +30,9 @@ public abstract class TransportException extends IOException {
super(msg);
}
protected TransportException(String msg, Throwable cause) {
super(msg);
initCause(cause);
}
}

View File

@@ -18,6 +18,9 @@ package org.springframework.ws.transport.http;
import java.net.URI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.ws.transport.WebServiceMessageSender;
/**
@@ -29,6 +32,11 @@ import org.springframework.ws.transport.WebServiceMessageSender;
*/
public abstract class AbstractHttpWebServiceMessageSender implements WebServiceMessageSender {
/**
* Logger available to subclasses.
*/
protected final Log logger = LogFactory.getLog(getClass());
private boolean acceptGzipEncoding = true;
/**

View File

@@ -29,4 +29,10 @@ public class HttpTransportException extends TransportException {
public HttpTransportException(String msg) {
super(msg);
}
protected HttpTransportException(String msg, Throwable cause) {
super(msg);
initCause(cause);
}
}

View File

@@ -46,16 +46,31 @@ public class HttpUrlConnectionMessageSender extends AbstractHttpWebServiceMessag
}
else {
HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
httpURLConnection.setRequestMethod(HttpTransportConstants.METHOD_POST);
httpURLConnection.setUseCaches(false);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);
if (isAcceptGzipEncoding()) {
httpURLConnection.setRequestProperty(HttpTransportConstants.HEADER_ACCEPT_ENCODING,
HttpTransportConstants.CONTENT_ENCODING_GZIP);
}
prepareConnection(httpURLConnection);
return new HttpUrlConnection(httpURLConnection);
}
}
/**
* Template method for preparing the given {@link java.net.HttpURLConnection}.
* <p/>
* The default implementation prepares the connection for input and output, sets the HTTP method to POST, disables
* caching, and sets the {@code Accept-Encoding} header to gzip, if {@linkplain #setAcceptGzipEncoding(boolean)
* applicable}.
*
* @param connection the connection to prepare
* @throws IOException in case of I/O errors
*/
protected void prepareConnection(HttpURLConnection connection) throws IOException {
connection.setRequestMethod(HttpTransportConstants.METHOD_POST);
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
if (isAcceptGzipEncoding()) {
connection.setRequestProperty(HttpTransportConstants.HEADER_ACCEPT_ENCODING,
HttpTransportConstants.CONTENT_ENCODING_GZIP);
}
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.ws.transport.http;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.zip.GZIPOutputStream;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
@@ -50,6 +51,7 @@ import org.springframework.ws.transport.FaultAwareWebServiceConnection;
import org.springframework.ws.transport.WebServiceConnection;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
import org.springframework.beans.factory.InitializingBean;
public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase extends XMLTestCase {
@@ -91,6 +93,9 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
jettyServer = new Server(8888);
jettyContext = new Context(jettyServer, "/");
messageSender = createMessageSender();
if (messageSender instanceof InitializingBean) {
((InitializingBean) messageSender).afterPropertiesSet();
}
XMLUnit.setIgnoreWhitespace(true);
saajMessageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
messageFactory = new SaajSoapMessageFactory(saajMessageFactory);
@@ -105,6 +110,10 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase ext
}
}
public void testSupports() throws URISyntaxException {
assertTrue("Message sender does not support HTTP url", messageSender.supports(new URI(URI_STRING)));
}
public void testSendAndReceiveResponse() throws Exception {
MyServlet servlet = new MyServlet();
servlet.setResponse(true);