Skip to content

Commit

Permalink
- Completed fix for JAX-RS issue #569
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerome Louvel committed Apr 17, 2012
1 parent 8e2454d commit dec7472
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -598,21 +598,21 @@ private MediaType determineMediaType(MediaType jaxRsResponseMediaType,
// (class)}.
Collection<MediaType> p = resourceMethod.getProducedMimes();

// (c) Else set P = {V (writers)} where ‘writers’ is the set of
// (c) Else set P = {V (writers)} where writers is the set of
// MessageBodyWriter that support the class of the returned entity
// object.
if (p.isEmpty()) {
p = providers.writerSubSet(entityClass, genericReturnType)
.getAllProducibleMediaTypes();
}

// 3. If P = {}, set P = {‘*/*’}
// 3. If P = {}, set P = {*/*}
if (p.isEmpty())
return MediaType.ALL;
else
p = sortByConcreteness(p);

// 4. Obtain the acceptable media types A. If A = {}, set A = {‘*/*’}
// 4. Obtain the acceptable media types A. If A = {}, set A = {*/*}
SortedMetadata<MediaType> a = callContext.getAccMediaTypes();

if (a.isEmpty())
Expand All @@ -635,23 +635,19 @@ private MediaType determineMediaType(MediaType jaxRsResponseMediaType,
}

// Otherwise test inclusion (good)
if (m.isEmpty()) {
for (MediaType a1 : a) {
for (MediaType p1 : p) {
if (a1.includes(p1)) {
m.add(MediaType.getMostSpecific(a1, p1));
}
for (MediaType a1 : a) {
for (MediaType p1 : p) {
if (a1.includes(p1)) {
m.add(MediaType.getMostSpecific(a1, p1));
}
}
}

// Finally test compatibility (most flexible)
if (m.isEmpty()) {
for (MediaType a1 : a) {
for (MediaType p1 : p) {
if (a1.isCompatible(p1)) {
m.add(MediaType.getMostSpecific(a1, p1));
}
for (MediaType a1 : a) {
for (MediaType p1 : p) {
if (a1.isCompatible(p1)) {
m.add(MediaType.getMostSpecific(a1, p1));
}
}
}
Expand All @@ -673,8 +669,8 @@ private MediaType determineMediaType(MediaType jaxRsResponseMediaType,
if (mediaType.isConcrete())
return mediaType;

// 9. If M contains ‘*/*’ or ‘application/*’, set Mselected =
// ‘application/octet-stream’, finish.
// 9. If M contains */* or application/*, set Mselected =
// application/octet-stream, finish.
if (m.contains(MediaType.ALL) || m.contains(MediaType.APPLICATION_ALL))
return MediaType.APPLICATION_OCTET_STREAM;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public WebApplicationException noMessageBodyWriter(
SortedMetadata<MediaType> accMediaTypes)
throws WebApplicationException {
String warning = "No message body writer found for " + entityClass
+ "(genericType is " + genericType + ")";
+ "(generic type is " + genericType + ")";

if (respMediaType != null) {
warning += "; response media type should be: " + respMediaType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public void testCreate() throws Exception {
final Person person = repr.getObject();
assertTrue(person.getFirstname().startsWith("firstname"));
assertEquals("lastname", person.getLastname());

final Response response3 = get(newLocation, MediaType.ALL);
sysOutEntityIfError(response3);
assertEquals(Status.SUCCESS_OK, response3.getStatus());
final JaxbRepresentation<Person> repr3 = new JaxbRepresentation<Person>(
response3.getEntity(), Person.class);
final Person person3 = repr3.getObject();
assertTrue(person3.getFirstname().startsWith("firstname"));
assertEquals("lastname", person3.getLastname());
}

public void testGetList() throws Exception {
Expand Down

0 comments on commit dec7472

Please sign in to comment.