You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2009/03/24 23:14:04 UTC
svn commit: r758055 - in /cxf/branches/2.1.x-fixes: ./
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/front...
Author: sergeyb
Date: Tue Mar 24 22:14:03 2009
New Revision: 758055
URL: http://svn.apache.org/viewvc?rev=758055&view=rev
Log:
Merged revisions 757499 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r757499 | sergeyb | 2009-03-23 18:55:06 +0000 (Mon, 23 Mar 2009) | 1 line
JAXRS: minor updates to do with conneg
........
Modified:
cxf/branches/2.1.x-fixes/ (props changed)
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Mar 24 22:14:03 2009
@@ -1 +1 @@
-/cxf/trunk:753380,753397,753421,754585,755365,757859,757899,757935,757951
+/cxf/trunk:753380,753397,753421,754585,755365,757499,757859,757899,757935,757951
Propchange: cxf/branches/2.1.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java Tue Mar 24 22:14:03 2009
@@ -300,10 +300,22 @@
}
private MediaType checkFinalContentType(MediaType mt) {
- if (mt.isWildcardType() && mt.isWildcardSubtype()) {
+ if (mt.isWildcardType() || mt.isWildcardSubtype()) {
return MediaType.APPLICATION_OCTET_STREAM_TYPE;
+ } else if (mt.getParameters().containsKey("q")) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(mt.getType()).append('/').append(mt.getSubtype());
+ if (mt.getParameters().size() > 1) {
+ for (String key : mt.getParameters().keySet()) {
+ if (!"q".equals(key)) {
+ sb.append(';').append(key).append('=').append(mt.getParameters().get(key));
+ }
+ }
+ }
+ return MediaType.valueOf(sb.toString());
} else {
return mt;
}
+
}
}
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/JAXBElementProvider.java Tue Mar 24 22:14:03 2009
@@ -46,8 +46,8 @@
import org.apache.cxf.jaxrs.utils.schemas.SchemaHandler;
import org.apache.cxf.staxutils.StaxUtils;
-@ProduceMime({"application/xml", "text/xml" })
-@ConsumeMime({"application/xml", "text/xml" })
+@ProduceMime({"application/xml", "application/*+xml", "text/xml" })
+@ConsumeMime({"application/xml", "application/*+xml", "text/xml" })
@Provider
public class JAXBElementProvider extends AbstractJAXBProvider {
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/SourceProvider.java Tue Mar 24 22:14:03 2009
@@ -48,8 +48,8 @@
import org.apache.cxf.jaxrs.utils.XMLSource;
@Provider
-@ProduceMime({"application/xml", "text/xml" })
-@ConsumeMime({"application/xml", "text/xml" })
+@ProduceMime({"application/xml", "application/*+xml", "text/xml" })
+@ConsumeMime({"application/xml", "application/*+xml", "text/xml" })
public class SourceProvider implements
MessageBodyReader<Object>, MessageBodyWriter<Source> {
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue Mar 24 22:14:03 2009
@@ -834,8 +834,19 @@
for (MediaType requiredType : requiredMediaTypes) {
for (MediaType userType : userMediaTypes) {
- if (requiredType.isCompatible(userType) || userType.isCompatible(requiredType)) {
-
+ boolean isCompatible =
+ requiredType.isCompatible(userType) || userType.isCompatible(requiredType);
+ if (!isCompatible && requiredType.getType().equalsIgnoreCase(userType.getType())) {
+ // check if we have composite subtypes
+ String[] subtypes1 = requiredType.getSubtype().split("\\+");
+ String[] subtypes2 = userType.getSubtype().split("\\+");
+ if (subtypes1.length == 2 && subtypes2.length == 2
+ && subtypes1[1].equalsIgnoreCase(subtypes2[1])
+ && (subtypes1[0].equals("*") || subtypes2[0].equals("*"))) {
+ isCompatible = true;
+ }
+ }
+ if (isCompatible) {
boolean parametersMatched = true;
for (Map.Entry<String, String> entry : userType.getParameters().entrySet()) {
String value = requiredType.getParameters().get(entry.getKey());
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/SelectMethodCandidatesTest.java Tue Mar 24 22:14:03 2009
@@ -153,4 +153,51 @@
ori.getMethodToInvoke().getName());
}
+
+ @Test
+ public void testSelectBar() throws Exception {
+ JAXRSServiceFactoryBean sf = new JAXRSServiceFactoryBean();
+ sf.setResourceClasses(org.apache.cxf.jaxrs.resources.TestResource.class);
+ sf.create();
+ List<ClassResourceInfo> resources = ((JAXRSServiceImpl)sf.getService()).getClassResourceInfos();
+
+ MetadataMap<String, String> values = new MetadataMap<String, String>();
+ ClassResourceInfo resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values);
+
+ String contentTypes = "*/*";
+ String acceptContentTypes = "application/bar,application/foo";
+ OperationResourceInfo ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ JAXRSUtils.sortMediaTypes(acceptContentTypes));
+ assertNotNull(ori);
+ assertEquals("readBar", ori.getMethodToInvoke().getName());
+ acceptContentTypes = "application/foo,application/bar";
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ JAXRSUtils.sortMediaTypes(acceptContentTypes));
+ assertNotNull(ori);
+ assertEquals("readFoo", ori.getMethodToInvoke().getName());
+
+ acceptContentTypes = "application/foo;q=0.5,application/bar";
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ JAXRSUtils.sortMediaTypes(acceptContentTypes));
+ assertNotNull(ori);
+ assertEquals("readBar", ori.getMethodToInvoke().getName());
+
+ acceptContentTypes = "application/foo,application/bar;q=0.5";
+ resource = JAXRSUtils.selectResourceClass(resources, "/1/2/3/d/custom", values);
+ ori = JAXRSUtils.findTargetMethod(resource,
+ values.getFirst(URITemplate.FINAL_MATCH_GROUP),
+ "GET", values, contentTypes,
+ JAXRSUtils.sortMediaTypes(acceptContentTypes));
+ assertNotNull(ori);
+ assertEquals("readFoo", ori.getMethodToInvoke().getName());
+
+ }
}
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/resources/TestResource.java Tue Mar 24 22:14:03 2009
@@ -89,6 +89,20 @@
public String readMethod2() {
return "This is a list method";
}
+
+ @GET
+ @Path("{id:custom}")
+ @ProduceMime("application/bar")
+ public String readBar() {
+ return "This is a bar method";
+ }
+
+ @GET
+ @Path("{id:custom}")
+ @ProduceMime("application/foo")
+ public String readFoo() {
+ return "This is a foo method";
+ }
}
Modified: cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/branches/2.1.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Tue Mar 24 22:14:03 2009
@@ -289,6 +289,15 @@
}
@Test
+ public void testIntersectMimeTypesCompositeSubtype() throws Exception {
+ List <MediaType> candidateList =
+ JAXRSUtils.intersectMimeTypes("application/bar+xml", "application/*+xml");
+
+ assertEquals(1, candidateList.size());
+ assertEquals("application/bar+xml", candidateList.get(0).toString());
+ }
+
+ @Test
public void testIntersectMimeTypes() throws Exception {
//test basic
List<MediaType> methodMimeTypes = new ArrayList<MediaType>(
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Mar 24 22:14:03 2009
@@ -448,7 +448,7 @@
@GET
@Path("/cdwithmultitypes/{CDId}/")
- @ProduceMime({"application/xml", "application/json" })
+ @ProduceMime({"application/xml", "application/bar+xml", "application/json" })
public CD getCDWithMultiContentTypes(@PathParam("CDId") String id) {
CD cd = cds.get(Long.parseLong(id));
Modified: cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=758055&r1=758054&r2=758055&view=diff
==============================================================================
--- cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/branches/2.1.x-fixes/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Tue Mar 24 22:14:03 2009
@@ -24,6 +24,7 @@
import java.net.URL;
import java.net.URLConnection;
+import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.DeleteMethod;
import org.apache.commons.httpclient.methods.FileRequestEntity;
@@ -137,13 +138,11 @@
@Test
public void testNoMessageWriterFound() throws Exception {
- // TODO : more specific message is needed
String msg1 = ".No message body writer found for response class : GregorianCalendar.";
String msg2 = ".No message body writer found for response class : Calendar.";
- getAndCompareStrings("http://localhost:9080/bookstore/timetable",
- msg1, msg2,
- "*/*", 500);
+ getAndCompareStrings("http://localhost:9080/bookstore/timetable",
+ new String[]{msg1, msg2}, "*/*", 500);
}
@SuppressWarnings("deprecation")
@@ -232,6 +231,18 @@
}
@Test
+ public void testGetBookTypeAndWildcard() throws Exception {
+ getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
+ "resources/expected_get_book123.txt",
+ "application/xml;q=0.8,*/*",
+ "application/xml", 200);
+ getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
+ "resources/expected_get_book123.txt",
+ "application/*",
+ "application/xml", 200);
+ }
+
+ @Test
public void testGetBook123() throws Exception {
getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
"resources/expected_get_book123.txt",
@@ -251,7 +262,13 @@
getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
"resources/expected_get_book123json.txt",
- "application/json, application/xml", 200);
+ "application/json, application/xml",
+ "application/json", 200);
+
+ getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
+ "resources/expected_get_book123.txt",
+ "application/xml, application/json",
+ "application/xml", 200);
}
@Test
@@ -259,7 +276,7 @@
getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
"resources/expected_get_book123.txt",
- "*/*", 200);
+ "*/*", "application/xml", 200);
}
@@ -303,14 +320,14 @@
public void testGetBookByHeader() throws Exception {
getAndCompareAsStrings("http://localhost:9080/bookstore/bookheaders",
"resources/expected_get_book123.txt",
- "application/xml;q=0.5,text/xml", 200);
+ "application/xml;q=0.5,text/xml", "text/xml", 200);
}
@Test
public void testGetBookByHeaderDefault() throws Exception {
getAndCompareAsStrings("http://localhost:9080/bookstore/bookheaders2",
"resources/expected_get_book123.txt",
- "application/xml;q=0.5,text/xml", 200);
+ "application/xml;q=0.5,text/xml", "text/xml", 200);
}
@Test
@@ -335,14 +352,15 @@
getAndCompareAsStrings("http://localhost:9080/bookstore/books/123",
"resources/expected_get_book123json.txt",
- "application/xml;q=0.1,application/json", 200);
+ "application/xml;q=0.1,application/json", "application/json", 200);
}
@Test
public void testGetBook123FromSubObject() throws Exception {
getAndCompareAsStrings(
"http://localhost:9080/bookstore/booksubresourceobject/123/chaptersobject/sub/1",
- "resources/expected_get_chapter1.txt", "application/xml", 200);
+ "resources/expected_get_chapter1.txt", "application/xml",
+ "application/xml;charset=iso-8859-1", 200);
}
@Test
@@ -350,7 +368,7 @@
getAndCompareAsStrings("http://localhost:9080/bookstore/booksubresource/123/chapters/1",
"resources/expected_get_chapter1.txt",
- "application/xml", 200);
+ "application/xml", "application/xml;charset=iso-8859-1", 200);
}
@Test
@@ -361,7 +379,7 @@
"application/xml", 200);
getAndCompareAsStrings("http://localhost:9080/bookstore/booksubresource/123/chapters/sub/1/recurse2",
"resources/expected_get_chapter1.txt",
- "application/xml", 200);
+ "application/xml", "application/xml;charset=iso-8859-1", 200);
}
@Test
@@ -376,7 +394,7 @@
getAndCompareAsStrings("http://localhost:9080/bookstore/books/126",
"resources/expected_get_book_notfound.txt",
- "application/xml", 500);
+ "application/xml", "text/xml; charset=utf-8", 500);
}
@Test
@@ -662,7 +680,15 @@
getAndCompareAsStrings("http://localhost:9080/bookstore/cdwithmultitypes/123",
"resources/expected_get_cd.txt",
- "application/json;q=0.8,application/xml", 200);
+ "application/json;q=0.8,application/xml,*/*", "application/xml", 200);
+ }
+
+ @Test
+ public void testGetCDWithMultiContentTypesCustomXML() throws Exception {
+
+ getAndCompareAsStrings("http://localhost:9080/bookstore/cdwithmultitypes/123",
+ "resources/expected_get_cd.txt",
+ "application/bar+xml", "application/bar+xml", 200);
}
@Test
@@ -672,7 +698,7 @@
"application/json", 200);
getAndCompareAsStrings("http://localhost:9080/bookstore/cdwithmultitypes/123",
"resources/expected_get_cdjson.txt",
- "application/xml;q=0.9,application/json", 200);
+ "*/*,application/xml;q=0.9,application/json", "application/json", 200);
}
@Test
@@ -682,7 +708,7 @@
"[class org.apache.cxf.systest.jaxrs.BookStore, "
+ "class org.apache.cxf.systest.jaxrs.Book, "
+ "class org.apache.cxf.systest.jaxrs.Chapter]",
- "text/plain", 200);
+ "text/plain", "text/plain", 200);
}
@Test
@@ -692,7 +718,7 @@
"[class org.apache.cxf.systest.jaxrs.BookStore, "
+ "class org.apache.cxf.systest.jaxrs.Book, "
+ "class org.apache.cxf.systest.jaxrs.Chapter]",
- "text/plain", 200);
+ "text/plain", "text/plain", 200);
}
@Test
@@ -702,8 +728,7 @@
+ "/bookstore/booksubresource/123/chapters/sub/1/matched!uris]";
getAndCompare("http://localhost:9080/bookstore/"
+ "booksubresource/123/chapters/sub/1/matched%21uris?decode=true",
- expected,
- "text/plain", 200);
+ expected, "text/plain", "text/plain", 200);
}
@Test
@@ -715,7 +740,7 @@
getAndCompare("http://localhost:9080/bookstore/"
+ "booksubresource/123/chapters/sub/1/matched%21uris?decode=false",
expected,
- "text/plain", 200);
+ "text/plain", "text/plain", 200);
}
private void getAndCompareAsStrings(String address,
@@ -727,6 +752,21 @@
getAndCompare(address,
expected,
acceptType,
+ acceptType,
+ status);
+ }
+
+ private void getAndCompareAsStrings(String address,
+ String resourcePath,
+ String acceptType,
+ String expectedContentType,
+ int status) throws Exception {
+ String expected = getStringFromInputStream(
+ getClass().getResourceAsStream(resourcePath));
+ getAndCompare(address,
+ expected,
+ acceptType,
+ expectedContentType,
status);
}
@@ -734,6 +774,18 @@
String expectedValue,
String acceptType,
int expectedStatus) throws Exception {
+ getAndCompare(address,
+ expectedValue,
+ acceptType,
+ null,
+ expectedStatus);
+ }
+
+ private void getAndCompare(String address,
+ String expectedValue,
+ String acceptType,
+ String expectedContentType,
+ int expectedStatus) throws Exception {
GetMethod get = new GetMethod(address);
get.setRequestHeader("Accept", acceptType);
get.setRequestHeader("Accept-Language", "da;q=0.8,en");
@@ -748,16 +800,20 @@
if (expectedStatus == 200) {
assertEquals("123", get.getResponseHeader("BookId").getValue());
}
+ if (expectedContentType != null) {
+ Header ct = get.getResponseHeader("Content-Type");
+ assertEquals("Wrong type of response", expectedContentType, ct.getValue());
+ }
} finally {
get.releaseConnection();
}
}
private void getAndCompareStrings(String address,
- String expectedValue1,
- String expectedValue2,
+ String[] expectedValue,
String acceptType,
int expectedStatus) throws Exception {
+ assertEquals(2, expectedValue.length);
GetMethod get = new GetMethod(address);
get.setRequestHeader("Accept", acceptType);
HttpClient httpClient = new HttpClient();
@@ -766,7 +822,7 @@
assertEquals(expectedStatus, result);
String jsonContent = getStringFromInputStream(get.getResponseBodyAsStream());
assertTrue("Expected value is wrong",
- expectedValue1.equals(jsonContent) || expectedValue2.equals(jsonContent));
+ expectedValue[0].equals(jsonContent) || expectedValue[1].equals(jsonContent));
} finally {
get.releaseConnection();
}