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

This commit is contained in:
Mark Fisher
2010-07-27 02:20:22 +00:00
parent 787b76f480
commit 02766517ff
2 changed files with 90 additions and 0 deletions

View File

@@ -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");
}
}

View File

@@ -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");
}
}