From 02766517ffcb817bcd0706a18455b9c84ae00104 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 27 Jul 2010 02:20:22 +0000 Subject: [PATCH] extended MockHttpServletRequest and MockHttpServletResponse so that the "Content-Type" header is set in a way that it can be read from the ServletServerHttpRequest and ServletServerHttpResponse instances --- .../http/MockHttpServletRequest.java | 47 +++++++++++++++++++ .../http/MockHttpServletResponse.java | 43 +++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java create mode 100644 spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java new file mode 100644 index 0000000000..4b46ce5783 --- /dev/null +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletRequest.java @@ -0,0 +1,47 @@ +/* + * Copyright 2002-2010 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.integration.http; + +/** + * Modified version of the MockHttpServletRequest that sets the "Content-Type" + * header so that it will be available from a ServletServerHttpRequest instance. + * + * @author Mark Fisher + * @since 2.0 + */ +public class MockHttpServletRequest extends org.springframework.mock.web.MockHttpServletRequest { + + public MockHttpServletRequest() { + super(); + } + + public MockHttpServletRequest(String method, String url) { + super(method, url); + } + + + @Override + public void setContentType(String contentType) { + this.addHeader("Content-Type", contentType); + } + + @Override + public String getContentType() { + return this.getHeader("Content-Type"); + } + +} diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java new file mode 100644 index 0000000000..5cbe49b127 --- /dev/null +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/MockHttpServletResponse.java @@ -0,0 +1,43 @@ +/* + * Copyright 2002-2010 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.integration.http; + +/** + * Modified version of the MockHttpServletResponse that sets the "Content-Type" + * header so that it will be available from a ServletServerHttpResponse instance. + * + * @author Mark Fisher + * @since 2.0 + */ +public class MockHttpServletResponse extends org.springframework.mock.web.MockHttpServletResponse { + + public MockHttpServletResponse() { + super(); + } + + + @Override + public void setContentType(String contentType) { + this.addHeader("Content-Type", contentType); + } + + @Override + public String getContentType() { + return (String) this.getHeader("Content-Type"); + } + +}