Added HTTP method constants.

This commit is contained in:
Arjen Poutsma
2008-02-17 02:27:48 +00:00
parent 9231a7d2af
commit 14eab13121
8 changed files with 32 additions and 22 deletions

View File

@@ -55,4 +55,10 @@ public interface HttpTransportConstants extends TransportConstants {
/** The "https" URI scheme. */
String HTTPS_URI_SCHEME = "https";
/** The "GET" HTTP method */
String METHOD_GET = "GET";
/** The "POST" HTTP method */
String METHOD_POST = "POST";
}

View File

@@ -38,8 +38,6 @@ import org.springframework.ws.transport.WebServiceConnection;
*/
public class HttpUrlConnectionMessageSender extends AbstractHttpWebServiceMessageSender {
private static final String HTTP_METHOD_POST = "POST";
public WebServiceConnection createConnection(URI uri) throws IOException {
URL url = uri.toURL();
URLConnection connection = url.openConnection();
@@ -48,7 +46,7 @@ public class HttpUrlConnectionMessageSender extends AbstractHttpWebServiceMessag
}
else {
HttpURLConnection httpURLConnection = (HttpURLConnection) connection;
httpURLConnection.setRequestMethod(HTTP_METHOD_POST);
httpURLConnection.setRequestMethod(HttpTransportConstants.METHOD_POST);
httpURLConnection.setUseCaches(false);
httpURLConnection.setDoInput(true);
httpURLConnection.setDoOutput(true);

View File

@@ -231,7 +231,8 @@ public class MessageDispatcherServlet extends FrameworkServlet {
* @return a definition, or <code>null</code>
*/
protected WsdlDefinition getWsdlDefinition(HttpServletRequest request) {
if ("GET".equals(request.getMethod()) && request.getRequestURI().endsWith(WSDL_SUFFIX_NAME)) {
if (HttpTransportConstants.METHOD_GET.equals(request.getMethod()) &&
request.getRequestURI().endsWith(WSDL_SUFFIX_NAME)) {
String fileName = WebUtils.extractFilenameFromUrlPath(request.getRequestURI());
return (WsdlDefinition) wsdlDefinitions.get(fileName);
}

View File

@@ -52,7 +52,7 @@ public class WebServiceMessageReceiverHandlerAdapter extends WebServiceMessageRe
public ModelAndView handle(HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse,
Object handler) throws Exception {
if ("POST".equals(httpServletRequest.getMethod())) {
if (HttpTransportConstants.METHOD_POST.equals(httpServletRequest.getMethod())) {
WebServiceConnection connection = new HttpServletConnection(httpServletRequest, httpServletResponse);
handleConnection(connection, (WebServiceMessageReceiver) handler);
}

View File

@@ -29,6 +29,9 @@ import javax.xml.transform.stream.StreamResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerAdapter;
@@ -37,8 +40,6 @@ import org.springframework.ws.wsdl.WsdlDefinition;
import org.springframework.xml.transform.TransformerObjectSupport;
import org.springframework.xml.xpath.XPathExpression;
import org.springframework.xml.xpath.XPathExpressionFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
/**
* Adapter to use the <code>WsdlDefinition</code> interface with the generic <code>DispatcherServlet</code>.
@@ -113,7 +114,7 @@ public class WsdlDefinitionHandlerAdapter extends TransformerObjectSupport imple
public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
if ("GET".equals(request.getMethod())) {
if (HttpTransportConstants.METHOD_GET.equals(request.getMethod())) {
response.setContentType(CONTENT_TYPE);
Transformer transformer = createTransformer();
WsdlDefinition definition = (WsdlDefinition) handler;

View File

@@ -9,6 +9,8 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.custommonkey.xmlunit.XMLTestCase;
import org.custommonkey.xmlunit.XMLUnit;
import org.w3c.dom.Document;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.core.io.ClassPathResource;
@@ -22,7 +24,6 @@ import org.springframework.ws.server.endpoint.adapter.PayloadEndpointAdapter;
import org.springframework.ws.server.endpoint.mapping.PayloadRootQNameEndpointMapping;
import org.springframework.ws.soap.server.endpoint.SimpleSoapExceptionResolver;
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
import org.w3c.dom.Document;
public class MessageDispatcherServletTest extends XMLTestCase {
@@ -61,7 +62,8 @@ public class MessageDispatcherServletTest extends XMLTestCase {
public void testDetectWsdlDefinitions() throws Exception {
servlet.setContextClass(WsdlDefinitionWebApplicationContext.class);
servlet.init(config);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/definition.wsdl");
MockHttpServletRequest request =
new MockHttpServletRequest(HttpTransportConstants.METHOD_GET, "/definition.wsdl");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();

View File

@@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletResponse;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.ws.FaultAwareWebServiceMessage;
@@ -65,7 +66,7 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
}
public void testHandleNonPost() throws Exception {
httpRequest.setMethod("GET");
httpRequest.setMethod(HttpTransportConstants.METHOD_GET);
replayMockControls();
WebServiceMessageReceiver endpoint = new WebServiceMessageReceiver() {
@@ -79,7 +80,7 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
}
public void testHandlePostNoResponse() throws Exception {
httpRequest.setMethod("POST");
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
httpRequest.setCharacterEncoding("UTF-8");
@@ -102,7 +103,7 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
}
public void testHandlePostResponse() throws Exception {
httpRequest.setMethod("POST");
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
httpRequest.setCharacterEncoding("UTF-8");
@@ -129,7 +130,7 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
}
public void testHandlePostFault() throws Exception {
httpRequest.setMethod("POST");
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
httpRequest.setCharacterEncoding("UTF-8");
@@ -157,7 +158,7 @@ public class WebServiceMessageReceiverHandlerAdapterTest extends TestCase {
}
public void testHandleNotFound() throws Exception {
httpRequest.setMethod("POST");
httpRequest.setMethod(HttpTransportConstants.METHOD_POST);
httpRequest.setContent(REQUEST.getBytes("UTF-8"));
httpRequest.setContentType("text/xml; charset=\"utf-8\"");
httpRequest.setCharacterEncoding("UTF-8");

View File

@@ -28,14 +28,15 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.custommonkey.xmlunit.XMLTestCase;
import org.easymock.MockControl;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.springframework.core.io.ClassPathResource;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.ws.wsdl.WsdlDefinition;
import org.springframework.ws.wsdl.wsdl11.SimpleWsdl11Definition;
import org.springframework.xml.transform.StringSource;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
@@ -59,7 +60,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
}
public void testHandleGet() throws Exception {
request.setMethod("GET");
request.setMethod(HttpTransportConstants.METHOD_GET);
String definition = "<definition xmlns='http://schemas.xmlsoap.org/wsdl/'/>";
definitionControl.expectAndReturn(definitionMock.getSource(), new StringSource(definition));
definitionControl.replay();
@@ -69,7 +70,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
}
public void testHandleNonGet() throws Exception {
request.setMethod("POST");
request.setMethod(HttpTransportConstants.METHOD_POST);
definitionControl.replay();
adapter.handle(request, response, definitionMock);
definitionControl.verify();
@@ -79,7 +80,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
public void testTransformLocations() throws Exception {
adapter.setTransformLocations(true);
request.setMethod("GET");
request.setMethod(HttpTransportConstants.METHOD_GET);
request.setScheme("http");
request.setServerName("example.com");
request.setServerPort(8080);
@@ -156,7 +157,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
public void testHandleSimpleWsdl11DefinitionWithoutTransformLocations() throws Exception {
adapter.setTransformLocations(false);
request.setMethod("GET");
request.setMethod(HttpTransportConstants.METHOD_GET);
request.setScheme("http");
request.setServerName("example.com");
request.setServerPort(8080);
@@ -189,7 +190,7 @@ public class WsdlDefinitionHandlerAdapterTest extends XMLTestCase {
public void testHandleSimpleWsdl11DefinitionWithTransformLocation() throws Exception {
adapter.setTransformLocations(true);
request.setMethod("GET");
request.setMethod(HttpTransportConstants.METHOD_GET);
request.setScheme("http");
request.setServerName("example.com");
request.setServerPort(8080);