SWS-950 Support RFC 7230 for HTTP headers

Make HTTP headers handle case insensitivity.
This commit is contained in:
Greg Turnquist
2016-04-04 21:28:56 -05:00
parent 6b3f990a91
commit 218e25c6c1
2 changed files with 18 additions and 7 deletions

View File

@@ -23,6 +23,7 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -39,6 +40,7 @@ import org.springframework.ws.transport.WebServiceConnection;
*
* @author Arjen Poutsma
* @author Greg Turnquist
* @author Oddgeir Gitlestad
* @since 1.0.0
*/
public class HttpUrlConnection extends AbstractHttpSenderConnection {
@@ -119,12 +121,20 @@ public class HttpUrlConnection extends AbstractHttpSenderConnection {
@Override
public Iterator<String> getResponseHeaders(String name) throws IOException {
Map<String, List<String>> mapHeader = connection.getHeaderFields();
List<String> listHeaderValues = mapHeader.get(name);
if (listHeaderValues == null) {
Map<String, List<String>> headersListMappedByLowerCaseName = new HashMap<>();
for (String key : connection.getHeaderFields().keySet()) {
if (key != null) {
headersListMappedByLowerCaseName.put(key.toLowerCase(), connection.getHeaderFields().get(key));
}
}
List<String> headerValues = headersListMappedByLowerCaseName.get(name.toLowerCase());
if (headerValues == null) {
return Collections.<String>emptyList().iterator();
} else {
return listHeaderValues.iterator();
return headerValues.iterator();
}
}

View File

@@ -36,11 +36,9 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMResult;
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.After;
import org.junit.Assert;
import static org.junit.Assert.assertEquals;
import org.junit.Before;
import org.junit.Test;
import org.mortbay.jetty.Server;
@@ -59,6 +57,9 @@ import org.springframework.ws.transport.support.FreePortScanner;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
import static org.custommonkey.xmlunit.XMLAssert.*;
import static org.junit.Assert.assertEquals;
public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase {
private Server jettyServer;
@@ -283,7 +284,7 @@ public abstract class AbstractHttpWebServiceMessageSenderIntegrationTestCase {
httpServletResponse.setStatus(responseStatus);
if (response) {
httpServletResponse.setContentType("text/xml");
httpServletResponse.addHeader("content-type", "text/xml");
if (contentLength != null) {
httpServletResponse.setContentLength(contentLength);
}